mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1452445 - Fix update error observer in unit test. r=gcp
We should only observe for update errors while we are expecting a successful update. MozReview-Commit-ID: 3grGhmxqhIX
This commit is contained in:
parent
397ec728bc
commit
3ebbf5d1af
@ -436,14 +436,24 @@ function waitUntilMetaDataSaved(expectedState, expectedChecksum, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
var gUpdateFinishedObserverEnabled = false;
|
||||
var gUpdateFinishedObserver = function (aSubject, aTopic, aData) {
|
||||
info("[" + aTopic + "] " + aData);
|
||||
if (aData != "success") {
|
||||
updateError(aData);
|
||||
}
|
||||
};
|
||||
|
||||
function throwOnUpdateErrors() {
|
||||
Services.obs.addObserver(function observer(aSubject, aTopic, aData) {
|
||||
info("[" + aTopic + "] " + aData);
|
||||
if (aData != "success") {
|
||||
Services.obs.removeObserver(observer, aTopic);
|
||||
updateError(aData);
|
||||
}
|
||||
}, "safebrowsing-update-finished");
|
||||
Services.obs.addObserver(gUpdateFinishedObserver, "safebrowsing-update-finished");
|
||||
gUpdateFinishedObserverEnabled = true;
|
||||
}
|
||||
|
||||
function stopThrowingOnUpdateErrors() {
|
||||
if (gUpdateFinishedObserverEnabled) {
|
||||
Services.obs.removeObserver(gUpdateFinishedObserver, "safebrowsing-update-finished");
|
||||
gUpdateFinishedObserverEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
cleanUp();
|
||||
|
@ -239,3 +239,7 @@ function run_test() {
|
||||
gHttpServV4.start(5555);
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
stopThrowingOnUpdateErrors();
|
||||
});
|
||||
|
@ -192,8 +192,6 @@ add_test(function test_getGethashUrl() {
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
throwOnUpdateErrors();
|
||||
|
||||
// Setup primary testing server.
|
||||
gHttpServ = new HttpServer();
|
||||
gHttpServ.registerDirectory("/", do_get_cwd());
|
||||
@ -304,12 +302,14 @@ function run_test() {
|
||||
// A trick to force updating tables. However, before calling this, we have to
|
||||
// call disableAllUpdates() first to clean up the updateCheckers in listmanager.
|
||||
function forceTableUpdate() {
|
||||
throwOnUpdateErrors();
|
||||
Services.prefs.setCharPref(PREF_NEXTUPDATETIME, "1");
|
||||
Services.prefs.setCharPref(PREF_NEXTUPDATETIME_V4, "1");
|
||||
gListManager.maybeToggleUpdateChecking();
|
||||
}
|
||||
|
||||
function disableAllUpdates() {
|
||||
stopThrowingOnUpdateErrors();
|
||||
TEST_TABLE_DATA_LIST.forEach(t => gListManager.disableUpdate(t.tableName));
|
||||
gListManager.disableUpdate(TEST_TABLE_DATA_V4.tableName);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user