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:
Francois Marier 2018-05-29 18:06:49 -07:00
Родитель 397ec728bc
Коммит 3ebbf5d1af
3 изменённых файлов: 23 добавлений и 9 удалений

Просмотреть файл

@ -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);
}