Bug 1344665 Wait for full extension startup in permission tests r=kmag

I'm not sure this is necessarily going to do anything about the intermittent,
but at the least it will remove a bunch of noise from the logs hopefully
making it easier to get to the real problem.

MozReview-Commit-ID: KeGWJlHUlzh

--HG--
extra : rebase_source : f1603fe652bace143ff5e73d85181592028dbc24
This commit is contained in:
Andrew Swan 2017-03-29 16:07:40 -07:00
Родитель aaea07bd8e
Коммит 4d9840ea9f
3 изменённых файлов: 60 добавлений и 18 удалений

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

@ -151,7 +151,7 @@ function* backgroundUpdateTest(url, id, checkIconFn) {
is(win.gViewController.currentViewId, VIEW, "about:addons is at extensions list");
// Wait for the permission prompt and accept it this time
updatePromise = promiseInstallEvent(addon, "onInstallEnded");
updatePromise = waitForUpdate(addon);
panel = yield popupPromise;
panel.button.click();
@ -176,7 +176,6 @@ function checkDefaultIcon(icon) {
add_task(() => backgroundUpdateTest(`${BASE}/browser_webext_update1.xpi`,
ID, checkDefaultIcon));
function checkNonDefaultIcon(icon) {
// The icon should come from the extension, don't bother with the precise
// path, just make sure we've got a jar url pointing to the right path
@ -209,7 +208,7 @@ async function testNoPrompt(origUrl, id) {
{once: true});
// Trigger an update check and wait for the update to be applied.
let updatePromise = promiseInstallEvent(addon, "onInstallEnded");
let updatePromise = waitForUpdate(addon);
AddonManagerPrivate.backgroundUpdateCheck();
await updatePromise;
@ -239,4 +238,3 @@ add_task(() => testNoPrompt(`${BASE}/browser_webext_update_perms1.xpi`,
// doesn't show a prompt even when the webextension uses
// promptable required permissions.
add_task(() => testNoPrompt(`${BASE}/browser_legacy.xpi`, ID_LEGACY));

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

@ -34,7 +34,7 @@ async function testUpdateNoPrompt(filename, id,
PopupNotifications.panel.addEventListener("popupshown", popupListener);
// Trigger an update check, we should see the update get applied
let updatePromise = promiseInstallEvent(addon, "onInstallEnded");
let updatePromise = waitForUpdate(addon);
win.gViewController.doCommand("cmd_findAllUpdates");
await updatePromise;

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

@ -3,6 +3,11 @@ const BASE = getRootDirectory(gTestPath)
.replace("chrome://mochitests/content/", "https://example.com/");
Cu.import("resource:///modules/ExtensionsUI.jsm");
XPCOMUtils.defineLazyGetter(this, "Management", () => {
const {Management} = Components.utils.import("resource://gre/modules/Extension.jsm", {});
return Management;
});
/**
* Wait for the given PopupNotification to display
@ -65,19 +70,58 @@ function promiseInstallEvent(addon, event) {
* Resolves when the extension has been installed with the Addon
* object as the resolution value.
*/
function promiseInstallAddon(url) {
return AddonManager.getInstallForURL(url, null, "application/x-xpinstall")
.then(install => {
ok(install, "Created install");
return new Promise(resolve => {
install.addListener({
onInstallEnded(_install, addon) {
resolve(addon);
},
});
install.install();
});
});
async function promiseInstallAddon(url) {
let install = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall");
install.install();
let addon = await new Promise(resolve => {
install.addListener({
onInstallEnded(_install, _addon) {
resolve(_addon);
},
});
});
if (addon.isWebExtension) {
await new Promise(resolve => {
function listener(event, extension) {
if (extension.id == addon.id) {
Management.off("ready", listener);
resolve();
}
}
Management.on("ready", listener);
});
}
return addon;
}
/**
* Wait for an update to the given webextension to complete.
* (This does not actually perform an update, it just watches for
* the events that occur as a result of an update.)
*
* @param {AddonWrapper} addon
* The addon to be updated.
*
* @returns {Promise}
* Resolves when the extension has ben updated.
*/
async function waitForUpdate(addon) {
let installPromise = promiseInstallEvent(addon, "onInstallEnded");
let readyPromise = new Promise(resolve => {
function listener(event, extension) {
if (extension.id == addon.id) {
Management.off("ready", listener);
resolve();
}
}
Management.on("ready", listener);
});
let [newAddon, ] = await Promise.all([installPromise, readyPromise]);
return newAddon;
}
function isDefaultIcon(icon) {