gecko-dev/browser/components/safebrowsing/content/test/browser_bug400731.js
Henry Chang f3be63826d Bug 1339050 - Asynchronously apply safebrowsing DB update. r=francois,gcp
A new function Classifier::AsyncApplyUpdates() is implemented for async update.
Besides, all public Classifier interfaces become "worker thread only" and
we remove DBServiceWorker::ApplyUpdatesBackground/Foreground.

In DBServiceWorker::FinishUpdate, instead of calling Classifier::ApplyUpdates,
we call Classifier::AsyncApplyUpdates and install a callback for notifying
the update observer when update is finished. The callback will occur on the
caller thread (i.e. worker thread.)

As for the shutdown issue, when the main thread is notified to shut down,
we at first *synchronously* dispatch an event to the worker thread to
shut down the update thread. After getting synchronized with all other
threads, we send last two events "CancelUpdate" and "CloseDb" to notify
dangling update (i.e. BeginUpdate is called but FinishUpdate isn't)
and do cleanup work.

MozReview-Commit-ID: DXZvA2eFKlc

--HG--
extra : rebase_source : cd2e27a6b679d2c96e769854d1582ed2dcda12bb
2017-04-06 07:07:56 +08:00

62 lines
1.9 KiB
JavaScript

/* Check presence of the "Ignore this warning" button */
/* eslint-env mozilla/frame-script */
function onDOMContentLoaded(callback) {
function complete({ data }) {
mm.removeMessageListener("Test:DOMContentLoaded", complete);
callback(data);
}
let mm = gBrowser.selectedBrowser.messageManager;
mm.addMessageListener("Test:DOMContentLoaded", complete);
function contentScript() {
let listener = function() {
removeEventListener("DOMContentLoaded", listener);
let button = content.document.getElementById("ignoreWarningButton");
sendAsyncMessage("Test:DOMContentLoaded", { buttonPresent: !!button });
};
addEventListener("DOMContentLoaded", listener);
}
mm.loadFrameScript("data:,(" + contentScript.toString() + ")();", true);
}
function test() {
waitForExplicitFinish();
waitForDBInit(() => {
gBrowser.selectedTab = gBrowser.addTab("http://www.itisatrap.org/firefox/its-an-attack.html");
onDOMContentLoaded(testMalware);
});
}
function testMalware(data) {
ok(data.buttonPresent, "Ignore warning button should be present for malware");
Services.prefs.setBoolPref("browser.safebrowsing.allowOverride", false);
// Now launch the unwanted software test
onDOMContentLoaded(testUnwanted);
gBrowser.loadURI("http://www.itisatrap.org/firefox/unwanted.html");
}
function testUnwanted(data) {
// Confirm that "Ignore this warning" is visible - bug 422410
ok(!data.buttonPresent, "Ignore warning button should be missing for unwanted software");
Services.prefs.setBoolPref("browser.safebrowsing.allowOverride", true);
// Now launch the phishing test
onDOMContentLoaded(testPhishing);
gBrowser.loadURI("http://www.itisatrap.org/firefox/its-a-trap.html");
}
function testPhishing(data) {
ok(data.buttonPresent, "Ignore warning button should be present for phishing");
gBrowser.removeCurrentTab();
finish();
}