Bug 633062 p6 - Remove event loop spinning from head_helper.js addon-related methods. r=markh

MozReview-Commit-ID: 4Be253tJlXq

--HG--
extra : rebase_source : 461b2c5ad4076d39933b491a6d7a0065e2eb75b3
This commit is contained in:
Edouard Oger 2017-12-08 16:07:49 -05:00
Родитель 4bc7feea45
Коммит 71ff2629c2
5 изменённых файлов: 91 добавлений и 105 удалений

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

@ -114,41 +114,28 @@ function loadWebExtensionTestFunctions() {
Services.scriptloader.loadSubScript(uri.spec, gGlobalScope);
}
// Returns a promise
function getAddonInstall(name) {
let f = do_get_file(ExtensionsTestPath("/addons/" + name + ".xpi"));
let cb = Async.makeSyncCallback();
AddonManager.getInstallForFile(f, cb);
return Async.waitForSyncCallback(cb);
return AddonManager.getInstallForFile(f);
}
/**
* Obtains an addon from the add-on manager by id.
*
* This is merely a synchronous wrapper.
*
* @param id
* ID of add-on to fetch
* @return addon object on success or undefined or null on failure
*/
function getAddonFromAddonManagerByID(id) {
let cb = Async.makeSyncCallback();
AddonManager.getAddonByID(id, cb);
return Async.waitForSyncCallback(cb);
}
/**
* Installs an add-on synchronously from an addonInstall
* Installs an add-on from an addonInstall
*
* @param install addonInstall instance to install
*/
function installAddonFromInstall(install) {
let cb = Async.makeSyncCallback();
let listener = {onInstallEnded: cb};
AddonManager.addInstallListener(listener);
install.install();
Async.waitForSyncCallback(cb);
AddonManager.removeAddonListener(listener);
async function installAddonFromInstall(install) {
await new Promise(res => {
let listener = {
onInstallEnded() {
AddonManager.removeAddonListener(listener);
res();
}
};
AddonManager.addInstallListener(listener);
install.install();
});
Assert.notEqual(null, install.addon);
Assert.notEqual(null, install.addon.syncGUID);
@ -163,30 +150,30 @@ function installAddonFromInstall(install) {
* String name of add-on to install. e.g. test_install1
* @return addon object that was installed
*/
function installAddon(name) {
let install = getAddonInstall(name);
async function installAddon(name) {
let install = await getAddonInstall(name);
Assert.notEqual(null, install);
return installAddonFromInstall(install);
}
/**
* Convenience function to uninstall an add-on synchronously.
* Convenience function to uninstall an add-on.
*
* @param addon
* Addon instance to uninstall
*/
function uninstallAddon(addon) {
let cb = Async.makeSyncCallback();
let listener = {onUninstalled(uninstalled) {
if (uninstalled.id == addon.id) {
AddonManager.removeAddonListener(listener);
cb(uninstalled);
}
}};
return new Promise(res => {
let listener = {onUninstalled(uninstalled) {
if (uninstalled.id == addon.id) {
AddonManager.removeAddonListener(listener);
res(uninstalled);
}
}};
AddonManager.addAddonListener(listener);
addon.uninstall();
Async.waitForSyncCallback(cb);
AddonManager.addAddonListener(listener);
addon.uninstall();
});
}
async function generateNewKeys(collectionKeys, collections = null) {

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

@ -53,7 +53,7 @@ add_task(async function setup() {
add_task(async function test_addon_install() {
_("Ensure basic add-on APIs work as expected.");
let install = getAddonInstall("test_bootstrap1_1");
let install = await getAddonInstall("test_bootstrap1_1");
Assert.notEqual(install, null);
Assert.equal(install.type, "extension");
Assert.equal(install.name, "Test Bootstrap 1");
@ -68,7 +68,7 @@ add_task(async function test_find_dupe() {
// test, so we do it manually.
await engine._refreshReconcilerState();
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
let record = {
id: Utils.makeGUID(),
@ -85,7 +85,7 @@ add_task(async function test_find_dupe() {
dupe = await engine._findDupe(record);
Assert.equal(null, dupe);
uninstallAddon(addon);
await uninstallAddon(addon);
await resetReconciler();
});
@ -112,7 +112,7 @@ add_task(async function test_get_changed_ids() {
tracker.clearChangedIDs();
_("Ensure reconciler changes are populated.");
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
tracker.clearChangedIDs(); // Just in case.
changes = await engine.getChangedIDs();
Assert.equal("object", typeof(changes));
@ -123,7 +123,7 @@ add_task(async function test_get_changed_ids() {
let oldTime = changes[addon.syncGUID];
let guid2 = addon.syncGUID;
uninstallAddon(addon);
await uninstallAddon(addon);
changes = await engine.getChangedIDs();
Assert.equal(1, Object.keys(changes).length);
Assert.ok(guid2 in changes);

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

@ -52,7 +52,7 @@ add_task(async function test_install_detection() {
reconciler.startListening();
let before = new Date();
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
let after = new Date();
Assert.equal(1, Object.keys(reconciler.addons).length);
@ -80,7 +80,7 @@ add_task(async function test_install_detection() {
Assert.equal(CHANGE_INSTALLED, change[1]);
Assert.equal(addon.id, change[2]);
uninstallAddon(addon);
await uninstallAddon(addon);
});
add_task(async function test_uninstall_detection() {
@ -93,11 +93,11 @@ add_task(async function test_uninstall_detection() {
reconciler._addons = {};
reconciler._changes = [];
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
let id = addon.id;
reconciler._changes = [];
uninstallAddon(addon);
await uninstallAddon(addon);
Assert.equal(1, Object.keys(reconciler.addons).length);
Assert.ok(id in reconciler.addons);

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

@ -119,20 +119,20 @@ add_task(async function setup() {
add_task(async function test_remove() {
_("Ensure removing add-ons from deleted records works.");
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
let record = createRecordForThisApp(addon.syncGUID, addon.id, true, true);
let failed = await store.applyIncomingBatch([record]);
Assert.equal(0, failed.length);
let newAddon = getAddonFromAddonManagerByID(addon.id);
let newAddon = await AddonManager.getAddonByID(addon.id);
Assert.equal(null, newAddon);
});
add_task(async function test_apply_enabled() {
_("Ensures that changes to the userEnabled flag apply.");
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
Assert.ok(addon.isActive);
Assert.ok(!addon.userDisabled);
@ -141,7 +141,7 @@ add_task(async function test_apply_enabled() {
records.push(createRecordForThisApp(addon.syncGUID, addon.id, false, false));
let failed = await store.applyIncomingBatch(records);
Assert.equal(0, failed.length);
addon = getAddonFromAddonManagerByID(addon.id);
addon = await AddonManager.getAddonByID(addon.id);
Assert.ok(addon.userDisabled);
checkReconcilerUpToDate(addon);
records = [];
@ -150,7 +150,7 @@ add_task(async function test_apply_enabled() {
records.push(createRecordForThisApp(addon.syncGUID, addon.id, true, false));
failed = await store.applyIncomingBatch(records);
Assert.equal(0, failed.length);
addon = getAddonFromAddonManagerByID(addon.id);
addon = await AddonManager.getAddonByID(addon.id);
Assert.ok(!addon.userDisabled);
checkReconcilerUpToDate(addon);
records = [];
@ -160,18 +160,18 @@ add_task(async function test_apply_enabled() {
Svc.Prefs.set("addons.ignoreUserEnabledChanges", true);
failed = await store.applyIncomingBatch(records);
Assert.equal(0, failed.length);
addon = getAddonFromAddonManagerByID(addon.id);
addon = await AddonManager.getAddonByID(addon.id);
Assert.ok(!addon.userDisabled);
records = [];
uninstallAddon(addon);
await uninstallAddon(addon);
Svc.Prefs.reset("addons.ignoreUserEnabledChanges");
});
add_task(async function test_apply_enabled_appDisabled() {
_("Ensures that changes to the userEnabled flag apply when the addon is appDisabled.");
let addon = installAddon("test_install3"); // this addon is appDisabled by default.
let addon = await installAddon("test_install3"); // this addon is appDisabled by default.
Assert.ok(addon.appDisabled);
Assert.ok(!addon.isActive);
Assert.ok(!addon.userDisabled);
@ -183,7 +183,7 @@ add_task(async function test_apply_enabled_appDisabled() {
records.push(createRecordForThisApp(addon.syncGUID, addon.id, false, false));
let failed = await store.applyIncomingBatch(records);
Assert.equal(0, failed.length);
addon = getAddonFromAddonManagerByID(addon.id);
addon = await AddonManager.getAddonByID(addon.id);
Assert.ok(addon.userDisabled);
checkReconcilerUpToDate(addon);
records = [];
@ -192,19 +192,19 @@ add_task(async function test_apply_enabled_appDisabled() {
records.push(createRecordForThisApp(addon.syncGUID, addon.id, true, false));
failed = await store.applyIncomingBatch(records);
Assert.equal(0, failed.length);
addon = getAddonFromAddonManagerByID(addon.id);
addon = await AddonManager.getAddonByID(addon.id);
Assert.ok(!addon.userDisabled);
checkReconcilerUpToDate(addon);
records = [];
uninstallAddon(addon);
await uninstallAddon(addon);
});
add_task(async function test_ignore_different_appid() {
_("Ensure that incoming records with a different application ID are ignored.");
// We test by creating a record that should result in an update.
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
Assert.ok(!addon.userDisabled);
let record = createRecordForThisApp(addon.syncGUID, addon.id, false, false);
@ -213,16 +213,16 @@ add_task(async function test_ignore_different_appid() {
let failed = await store.applyIncomingBatch([record]);
Assert.equal(0, failed.length);
let newAddon = getAddonFromAddonManagerByID(addon.id);
let newAddon = await AddonManager.getAddonByID(addon.id);
Assert.ok(!newAddon.userDisabled);
uninstallAddon(addon);
await uninstallAddon(addon);
});
add_task(async function test_ignore_unknown_source() {
_("Ensure incoming records with unknown source are ignored.");
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
let record = createRecordForThisApp(addon.syncGUID, addon.id, false, false);
record.source = "DUMMY_SOURCE";
@ -230,23 +230,23 @@ add_task(async function test_ignore_unknown_source() {
let failed = await store.applyIncomingBatch([record]);
Assert.equal(0, failed.length);
let newAddon = getAddonFromAddonManagerByID(addon.id);
let newAddon = await AddonManager.getAddonByID(addon.id);
Assert.ok(!newAddon.userDisabled);
uninstallAddon(addon);
await uninstallAddon(addon);
});
add_task(async function test_apply_uninstall() {
_("Ensures that uninstalling an add-on from a record works.");
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
let records = [];
records.push(createRecordForThisApp(addon.syncGUID, addon.id, true, true));
let failed = await store.applyIncomingBatch(records);
Assert.equal(0, failed.length);
addon = getAddonFromAddonManagerByID(addon.id);
addon = await AddonManager.getAddonByID(addon.id);
Assert.equal(null, addon);
});
@ -258,7 +258,7 @@ add_task(async function test_addon_syncability() {
Assert.ok(!(await store.isAddonSyncable(null)));
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
Assert.ok((await store.isAddonSyncable(addon)));
let dummy = {};
@ -285,7 +285,7 @@ add_task(async function test_addon_syncability() {
Assert.ok(!(await store.isAddonSyncable(dummy)));
dummy.foreignInstall = false;
uninstallAddon(addon);
await uninstallAddon(addon);
Assert.ok(!store.isSourceURITrusted(null));
@ -328,10 +328,10 @@ add_task(async function test_get_all_ids() {
// tests, even though those tests uninstalled the addon.
// So if any tests above ever add a new addon ID, they are going to need to
// be added here too.
// do_check_eq(0, Object.keys(store.getAllIDs()).length);
let addon1 = installAddon("test_install1");
let addon2 = installAddon("test_bootstrap1_1");
let addon3 = installAddon("test_install3");
// Assert.equal(0, Object.keys(store.getAllIDs()).length);
let addon1 = await installAddon("test_install1");
let addon2 = await installAddon("test_bootstrap1_1");
let addon3 = await installAddon("test_install3");
_("Ensure they're syncable.");
Assert.ok((await store.isAddonSyncable(addon1)));
@ -347,25 +347,25 @@ add_task(async function test_get_all_ids() {
Assert.ok(addon3.syncGUID in ids);
addon1.install.cancel();
uninstallAddon(addon2);
uninstallAddon(addon3);
await uninstallAddon(addon2);
await uninstallAddon(addon3);
});
add_task(async function test_change_item_id() {
_("Ensures that changeItemID() works properly.");
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
let oldID = addon.syncGUID;
let newID = Utils.makeGUID();
await store.changeItemID(oldID, newID);
let newAddon = getAddonFromAddonManagerByID(addon.id);
let newAddon = await AddonManager.getAddonByID(addon.id);
Assert.notEqual(null, newAddon);
Assert.equal(newID, newAddon.syncGUID);
uninstallAddon(newAddon);
await uninstallAddon(newAddon);
});
add_task(async function test_create() {
@ -373,9 +373,9 @@ add_task(async function test_create() {
let server = createAndStartHTTPServer(HTTP_PORT);
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
let id = addon.id;
uninstallAddon(addon);
await uninstallAddon(addon);
let guid = Utils.makeGUID();
let record = createRecordForThisApp(guid, id, true, false);
@ -383,12 +383,12 @@ add_task(async function test_create() {
let failed = await store.applyIncomingBatch([record]);
Assert.equal(0, failed.length);
let newAddon = getAddonFromAddonManagerByID(id);
let newAddon = await AddonManager.getAddonByID(id);
Assert.notEqual(null, newAddon);
Assert.equal(guid, newAddon.syncGUID);
Assert.ok(!newAddon.userDisabled);
uninstallAddon(newAddon);
await uninstallAddon(newAddon);
await promiseStopServer(server);
});
@ -407,7 +407,7 @@ add_task(async function test_create_missing_search() {
Assert.equal(1, failed.length);
Assert.equal(guid, failed[0]);
let addon = getAddonFromAddonManagerByID(id);
let addon = await AddonManager.getAddonByID(id);
Assert.equal(null, addon);
await promiseStopServer(server);
@ -435,9 +435,9 @@ add_task(async function test_create_bad_install() {
// to be tricky to distinguish a 404 from other transient network errors
// where we do want the addon to end up in |failed|.
// This is being tracked in bug 1284778.
// do_check_eq(0, failed.length);
// Assert.equal(0, failed.length);
let addon = getAddonFromAddonManagerByID(id);
let addon = await AddonManager.getAddonByID(id);
Assert.equal(null, addon);
await promiseStopServer(server);
@ -464,7 +464,7 @@ add_task(async function test_incoming_system() {
// to this.
// before we start, ensure the system addon isn't disabled.
Assert.ok(!getAddonFromAddonManagerByID(SYSTEM_ADDON_ID).userDisabled);
Assert.ok(!(await AddonManager.getAddonByID(SYSTEM_ADDON_ID).userDisabled));
// Now simulate an incoming record with the same ID as the system addon,
// but flagged as disabled - it should not be applied.
@ -478,7 +478,7 @@ add_task(async function test_incoming_system() {
Assert.equal(0, failed.length);
// The system addon should still not be userDisabled.
Assert.ok(!getAddonFromAddonManagerByID(SYSTEM_ADDON_ID).userDisabled);
Assert.ok(!(await AddonManager.getAddonByID(SYSTEM_ADDON_ID).userDisabled));
await promiseStopServer(server);
});
@ -486,11 +486,11 @@ add_task(async function test_incoming_system() {
add_task(async function test_wipe() {
_("Ensures that wiping causes add-ons to be uninstalled.");
let addon1 = installAddon("test_bootstrap1_1");
let addon1 = await installAddon("test_bootstrap1_1");
await store.wipe();
let addon = getAddonFromAddonManagerByID(addon1.id);
let addon = await AddonManager.getAddonByID(addon1.id);
Assert.equal(null, addon);
});
@ -500,14 +500,14 @@ add_task(async function test_wipe_and_install() {
// This tests the reset sync flow where remote data is replaced by local. The
// receiving client will see a wipe followed by a record which should undo
// the wipe.
let installed = installAddon("test_bootstrap1_1");
let installed = await installAddon("test_bootstrap1_1");
let record = createRecordForThisApp(installed.syncGUID, installed.id, true,
false);
await store.wipe();
let deleted = getAddonFromAddonManagerByID(installed.id);
let deleted = await AddonManager.getAddonByID(installed.id);
Assert.equal(null, deleted);
// Re-applying the record can require re-fetching the XPI.
@ -515,14 +515,13 @@ add_task(async function test_wipe_and_install() {
await store.applyIncoming(record);
let fetched = getAddonFromAddonManagerByID(record.addonID);
let fetched = await AddonManager.getAddonByID(record.addonID);
Assert.ok(!!fetched);
await promiseStopServer(server);
});
add_test(function cleanup() {
add_task(async function cleanup() {
// There's an xpcom-shutdown hook for this, but let's give this a shot.
reconciler.stopListening();
run_next_test();
});

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

@ -57,8 +57,8 @@ add_task(async function test_empty() {
add_task(async function test_not_tracking() {
_("Ensures the tracker doesn't do anything when it isn't tracking.");
let addon = installAddon("test_bootstrap1_1");
uninstallAddon(addon);
let addon = await installAddon("test_bootstrap1_1");
await uninstallAddon(addon);
Assert.equal(0, Object.keys(tracker.changedIDs).length);
Assert.equal(0, tracker.score);
@ -74,14 +74,14 @@ add_task(async function test_track_install() {
Svc.Obs.notify("weave:engine:start-tracking");
Assert.equal(0, tracker.score);
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
let changed = tracker.changedIDs;
Assert.equal(1, Object.keys(changed).length);
Assert.ok(addon.syncGUID in changed);
Assert.equal(SCORE_INCREMENT_XLARGE, tracker.score);
uninstallAddon(addon);
await uninstallAddon(addon);
await cleanup();
});
@ -90,13 +90,13 @@ add_task(async function test_track_uninstall() {
reconciler.startListening();
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
let guid = addon.syncGUID;
Assert.equal(0, tracker.score);
Svc.Obs.notify("weave:engine:start-tracking");
uninstallAddon(addon);
await uninstallAddon(addon);
let changed = tracker.changedIDs;
Assert.equal(1, Object.keys(changed).length);
Assert.ok(guid in changed);
@ -110,7 +110,7 @@ add_task(async function test_track_user_disable() {
reconciler.startListening();
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
Assert.ok(!addon.userDisabled);
Assert.ok(!addon.appDisabled);
Assert.ok(addon.isActive);
@ -144,7 +144,7 @@ add_task(async function test_track_user_disable() {
Assert.ok(addon.syncGUID in changed);
Assert.equal(SCORE_INCREMENT_XLARGE, tracker.score);
uninstallAddon(addon);
await uninstallAddon(addon);
await cleanup();
});
@ -153,7 +153,7 @@ add_task(async function test_track_enable() {
reconciler.startListening();
let addon = installAddon("test_bootstrap1_1");
let addon = await installAddon("test_bootstrap1_1");
addon.userDisabled = true;
await Async.promiseYield();
@ -168,6 +168,6 @@ add_task(async function test_track_enable() {
Assert.ok(addon.syncGUID in changed);
Assert.equal(SCORE_INCREMENT_XLARGE, tracker.score);
uninstallAddon(addon);
await uninstallAddon(addon);
await cleanup();
});