mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1000695 - Part 2: Rewrite browser_hotfix.js to Task.jsm and yield to event loop after receiving onInstallEnded. r=Unfocused
This commit is contained in:
parent
e8f9e05f60
commit
739cbf8116
@ -464,6 +464,7 @@ var gUpdateEnabled = true;
|
||||
var gAutoUpdateDefault = true;
|
||||
var gHotfixID = null;
|
||||
|
||||
var gUpdateCheckInProgress = false;
|
||||
/**
|
||||
* This is the real manager, kept here rather than in AddonManager to keep its
|
||||
* contents hidden from API users.
|
||||
@ -479,7 +480,6 @@ var AddonManagerInternal = {
|
||||
// Store telemetry details per addon provider
|
||||
telemetryDetails: {},
|
||||
|
||||
|
||||
// A read-only wrapper around the types dictionary
|
||||
typesProxy: Proxy.create({
|
||||
getOwnPropertyDescriptor: function typesProxy_getOwnPropertyDescriptor(aName) {
|
||||
@ -1142,6 +1142,12 @@ var AddonManagerInternal = {
|
||||
throw Components.Exception("AddonManager is not initialized",
|
||||
Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
if (gUpdateCheckInProgress) {
|
||||
throw Components.Exception("Background update check already in progress",
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
gUpdateCheckInProgress = true;
|
||||
|
||||
return Task.spawn(function* backgroundUpdateTask() {
|
||||
let hotfixID = this.hotfixID;
|
||||
|
||||
@ -1284,6 +1290,7 @@ var AddonManagerInternal = {
|
||||
}
|
||||
}
|
||||
|
||||
gUpdateCheckInProgress = false;
|
||||
Services.obs.notifyObservers(null,
|
||||
"addons-background-update-complete",
|
||||
null);
|
||||
|
@ -3610,7 +3610,13 @@ this.XPIProvider = {
|
||||
* The AddonInstall to remove
|
||||
*/
|
||||
removeActiveInstall: function XPI_removeActiveInstall(aInstall) {
|
||||
this.installs = this.installs.filter(function installFilter(i) i != aInstall);
|
||||
let where = this.installs.indexOf(aInstall);
|
||||
if (where == -1) {
|
||||
logger.warn("removeActiveInstall: could not find active install for "
|
||||
+ aInstall.sourceURI.spec);
|
||||
return;
|
||||
}
|
||||
this.installs.splice(where, 1);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -75,7 +75,7 @@ function install_test_addons(aCallback) {
|
||||
// Switch to the test update URL
|
||||
Services.prefs.setCharPref(PREF_UPDATEURL, TESTROOT + "browser_bug557956.rdf");
|
||||
|
||||
aCallback();
|
||||
executeSoon(aCallback);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -41,7 +41,7 @@ add_test(function () {
|
||||
gInstall = new MockInstall(undefined, undefined, addon);
|
||||
gInstall.addTestListener({
|
||||
onNewInstall: function () {
|
||||
run_next_test();
|
||||
executeSoon(run_next_test);
|
||||
}
|
||||
});
|
||||
gProvider.addInstall(gInstall);
|
||||
@ -65,7 +65,7 @@ add_test(function () {
|
||||
}
|
||||
}
|
||||
ok(false, "Item with correct name was not found");
|
||||
run_next_test();
|
||||
executeSoon(run_next_test);
|
||||
}
|
||||
});
|
||||
gInstall.install();
|
||||
|
@ -21,17 +21,18 @@ var gTestInstallListener = {
|
||||
|
||||
onInstallEnded: function(aInstall) {
|
||||
check_hidden(false);
|
||||
run_next_test();
|
||||
executeSoon(run_next_test);
|
||||
},
|
||||
|
||||
onInstallCancelled: function(aInstall) {
|
||||
ok(gExpectedCancel, "Should expect install cancel");
|
||||
check_hidden(false);
|
||||
run_next_test();
|
||||
executeSoon(run_next_test);
|
||||
},
|
||||
|
||||
onInstallFailed: function(aInstall) {
|
||||
ok(false, "Did not expect onInstallFailed");
|
||||
executeSoon(run_next_test);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -40,7 +40,7 @@ function install_locale(aCallback) {
|
||||
gInstall.addTestListener({
|
||||
onInstallEnded: function(aInstall) {
|
||||
gInstall.removeTestListener(this);
|
||||
aCallback();
|
||||
executeSoon(aCallback);
|
||||
}
|
||||
});
|
||||
gInstall.install();
|
||||
|
@ -97,7 +97,7 @@ add_test(function() {
|
||||
},
|
||||
onInstallEnded: function() {
|
||||
check_list(gItem);
|
||||
run_next_test();
|
||||
executeSoon(run_next_test);
|
||||
}
|
||||
});
|
||||
|
||||
@ -136,7 +136,7 @@ add_test(function() {
|
||||
onInstallEnded: function() {
|
||||
check_list(null);
|
||||
extension.cancel();
|
||||
run_next_test();
|
||||
executeSoon(run_next_test);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -15,51 +15,56 @@ const PREF_APP_UPDATE_ENABLED = "app.update.enabled";
|
||||
|
||||
const HOTFIX_ID = "hotfix@tests.mozilla.org";
|
||||
|
||||
var gNextTest;
|
||||
|
||||
var SuccessfulInstallListener = {
|
||||
onDownloadCancelled: function(aInstall) {
|
||||
ok(false, "Should not have seen the download cancelled");
|
||||
is(aInstall.addon.id, HOTFIX_ID, "Should have seen the right add-on");
|
||||
|
||||
AddonManager.removeInstallListener(this);
|
||||
gNextTest();
|
||||
},
|
||||
|
||||
onInstallEnded: function(aInstall) {
|
||||
ok(true, "Should have seen the install complete");
|
||||
is(aInstall.addon.id, HOTFIX_ID, "Should have installed the right add-on");
|
||||
|
||||
AddonManager.removeInstallListener(this);
|
||||
aInstall.addon.uninstall();
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_LASTVERSION);
|
||||
gNextTest();
|
||||
}
|
||||
/*
|
||||
* Register an addon install listener and return a promise that:
|
||||
* resolves with the AddonInstall object if the install succeeds
|
||||
* rejects with the AddonInstall if the install fails
|
||||
*/
|
||||
function promiseInstallListener() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let listener = {
|
||||
onInstallEnded: ai => {
|
||||
AddonManager.removeInstallListener(listener);
|
||||
resolve(ai);
|
||||
},
|
||||
onDownloadCancelled: ai => {
|
||||
AddonManager.removeInstallListener(listener);
|
||||
reject(ai);
|
||||
}
|
||||
};
|
||||
AddonManager.addInstallListener(listener);
|
||||
});
|
||||
}
|
||||
|
||||
var FailedInstallListener = {
|
||||
onDownloadCancelled: function(aInstall) {
|
||||
ok(true, "Should have seen the download cancelled");
|
||||
is(aInstall.addon.id, HOTFIX_ID, "Should have seen the right add-on");
|
||||
|
||||
AddonManager.removeInstallListener(this);
|
||||
gNextTest();
|
||||
},
|
||||
|
||||
onInstallEnded: function(aInstall) {
|
||||
ok(false, "Should not have seen the install complete");
|
||||
is(aInstall.addon.id, HOTFIX_ID, "Should have installed the right add-on");
|
||||
|
||||
AddonManager.removeInstallListener(this);
|
||||
aInstall.addon.uninstall();
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_LASTVERSION);
|
||||
gNextTest();
|
||||
}
|
||||
function promiseSuccessfulInstall() {
|
||||
return promiseInstallListener().then(
|
||||
aInstall => {
|
||||
ok(true, "Should have seen the install complete");
|
||||
is(aInstall.addon.id, HOTFIX_ID, "Should have installed the right add-on");
|
||||
aInstall.addon.uninstall();
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_LASTVERSION);
|
||||
},
|
||||
aInstall => {
|
||||
ok(false, "Should not have seen the download cancelled");
|
||||
is(aInstall.addon.id, HOTFIX_ID, "Should have seen the right add-on");
|
||||
});
|
||||
}
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
function promiseFailedInstall() {
|
||||
return promiseInstallListener().then(
|
||||
aInstall => {
|
||||
ok(false, "Should not have seen the install complete");
|
||||
is(aInstall.addon.id, HOTFIX_ID, "Should have installed the right add-on");
|
||||
aInstall.addon.uninstall();
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_LASTVERSION);
|
||||
},
|
||||
aInstall => {
|
||||
ok(true, "Should have seen the download cancelled");
|
||||
is(aInstall.addon.id, HOTFIX_ID, "Should have seen the right add-on");
|
||||
});
|
||||
}
|
||||
|
||||
add_task(function setup() {
|
||||
Services.prefs.setBoolPref(PREF_APP_UPDATE_ENABLED, true);
|
||||
Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
|
||||
Services.prefs.setBoolPref(PREF_UPDATE_REQUIREBUILTINCERTS, false);
|
||||
@ -78,109 +83,85 @@ function test() {
|
||||
var prefs = Services.prefs.getChildList(PREF_EM_HOTFIX_CERTS);
|
||||
prefs.forEach(Services.prefs.clearUserPref);
|
||||
});
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
function end_test() {
|
||||
finish();
|
||||
}
|
||||
|
||||
add_test(function check_no_cert_checks() {
|
||||
Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, false);
|
||||
AddonManager.addInstallListener(SuccessfulInstallListener);
|
||||
|
||||
gNextTest = run_next_test;
|
||||
|
||||
AddonManagerPrivate.backgroundUpdateCheck();
|
||||
});
|
||||
|
||||
add_test(function check_wrong_cert_fingerprint() {
|
||||
add_task(function* check_no_cert_checks() {
|
||||
Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, false);
|
||||
yield Promise.all([
|
||||
promiseSuccessfulInstall(),
|
||||
AddonManagerPrivate.backgroundUpdateCheck()
|
||||
]);
|
||||
});
|
||||
|
||||
add_task(function* check_wrong_cert_fingerprint() {
|
||||
Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, true);
|
||||
Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint", "foo");
|
||||
|
||||
AddonManager.addInstallListener(FailedInstallListener);
|
||||
|
||||
gNextTest = function() {
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint");
|
||||
|
||||
run_next_test();
|
||||
};
|
||||
|
||||
AddonManagerPrivate.backgroundUpdateCheck();
|
||||
yield Promise.all([
|
||||
promiseFailedInstall(),
|
||||
AddonManagerPrivate.backgroundUpdateCheck()
|
||||
]);
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint");
|
||||
});
|
||||
|
||||
add_test(function check_right_cert_fingerprint() {
|
||||
add_task(function* check_right_cert_fingerprint() {
|
||||
Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, true);
|
||||
Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint", "3E:B9:4E:07:12:FE:3C:01:41:46:13:46:FC:84:52:1A:8C:BE:1D:A2");
|
||||
|
||||
AddonManager.addInstallListener(SuccessfulInstallListener);
|
||||
yield Promise.all([
|
||||
promiseSuccessfulInstall(),
|
||||
AddonManagerPrivate.backgroundUpdateCheck()
|
||||
]);
|
||||
|
||||
gNextTest = function() {
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint");
|
||||
|
||||
run_next_test();
|
||||
};
|
||||
|
||||
AddonManagerPrivate.backgroundUpdateCheck();
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint");
|
||||
});
|
||||
|
||||
add_test(function check_multi_cert_fingerprint_1() {
|
||||
add_task(function* check_multi_cert_fingerprint_1() {
|
||||
Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, true);
|
||||
Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint", "3E:B9:4E:07:12:FE:3C:01:41:46:13:46:FC:84:52:1A:8C:BE:1D:A2");
|
||||
Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "2.sha1Fingerprint", "foo");
|
||||
|
||||
AddonManager.addInstallListener(SuccessfulInstallListener);
|
||||
yield Promise.all([
|
||||
promiseSuccessfulInstall(),
|
||||
AddonManagerPrivate.backgroundUpdateCheck()
|
||||
]);
|
||||
|
||||
gNextTest = function() {
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint");
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "2.sha1Fingerprint");
|
||||
|
||||
run_next_test();
|
||||
};
|
||||
|
||||
AddonManagerPrivate.backgroundUpdateCheck();
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint");
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "2.sha1Fingerprint");
|
||||
});
|
||||
|
||||
add_test(function check_multi_cert_fingerprint_2() {
|
||||
add_task(function* check_multi_cert_fingerprint_2() {
|
||||
Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, true);
|
||||
Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint", "foo");
|
||||
Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "2.sha1Fingerprint", "3E:B9:4E:07:12:FE:3C:01:41:46:13:46:FC:84:52:1A:8C:BE:1D:A2");
|
||||
|
||||
AddonManager.addInstallListener(SuccessfulInstallListener);
|
||||
yield Promise.all([
|
||||
promiseSuccessfulInstall(),
|
||||
AddonManagerPrivate.backgroundUpdateCheck()
|
||||
]);
|
||||
|
||||
gNextTest = function() {
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint");
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "2.sha1Fingerprint");
|
||||
|
||||
run_next_test();
|
||||
};
|
||||
|
||||
AddonManagerPrivate.backgroundUpdateCheck();
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint");
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "2.sha1Fingerprint");
|
||||
});
|
||||
|
||||
add_test(function check_no_cert_no_checks() {
|
||||
add_task(function* check_no_cert_no_checks() {
|
||||
Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, false);
|
||||
Services.prefs.setCharPref(PREF_EM_HOTFIX_URL, TESTROOT + "unsigned_hotfix.rdf");
|
||||
|
||||
AddonManager.addInstallListener(SuccessfulInstallListener);
|
||||
|
||||
gNextTest = run_next_test;
|
||||
|
||||
AddonManagerPrivate.backgroundUpdateCheck();
|
||||
yield Promise.all([
|
||||
promiseSuccessfulInstall(),
|
||||
AddonManagerPrivate.backgroundUpdateCheck()
|
||||
]);
|
||||
});
|
||||
|
||||
add_test(function check_no_cert_cert_fingerprint_check() {
|
||||
add_task(function* check_no_cert_cert_fingerprint_check() {
|
||||
Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, true);
|
||||
Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint", "3E:B9:4E:07:12:FE:3C:01:41:46:13:46:FC:84:52:1A:8C:BE:1D:A2");
|
||||
|
||||
AddonManager.addInstallListener(FailedInstallListener);
|
||||
yield Promise.all([
|
||||
promiseFailedInstall(),
|
||||
AddonManagerPrivate.backgroundUpdateCheck()
|
||||
]);
|
||||
|
||||
gNextTest = function() {
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint");
|
||||
|
||||
run_next_test();
|
||||
};
|
||||
|
||||
AddonManagerPrivate.backgroundUpdateCheck();
|
||||
Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint");
|
||||
});
|
||||
|
@ -184,7 +184,7 @@ add_test(function() {
|
||||
is_element_hidden(item._installStatus, "Install progress widget should be hidden");
|
||||
|
||||
if (badgeUpdated)
|
||||
run_next_test();
|
||||
executeSoon(run_next_test);
|
||||
else
|
||||
installCompleted = true;
|
||||
}
|
||||
|
@ -566,7 +566,7 @@ add_test(function() {
|
||||
|
||||
is(installBtn.hidden, true, "Install button should be hidden after install ended");
|
||||
check_filtered_results(QUERY, "relevancescore", false);
|
||||
run_next_test();
|
||||
executeSoon(run_next_test);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ function install_test_addon(aCallback) {
|
||||
onInstallEnded: function() {
|
||||
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
|
||||
gTestAddon = addon;
|
||||
aCallback();
|
||||
executeSoon(aCallback);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user