--- a/browser/base/content/test/general/browser_extension_permissions.js
+++ b/browser/base/content/test/general/browser_extension_permissions.js
@@ -1,16 +1,16 @@
"use strict";
const BASE = getRootDirectory(gTestPath)
.replace("chrome://mochitests/content/", "https://example.com/");
-const PAGE = `${BASE}/file_install_extensions.html`;
-const PERMS_XPI = `${BASE}/browser_webext_permissions.xpi`;
-const NO_PERMS_XPI = `${BASE}/browser_webext_nopermissions.xpi`;
+const INSTALL_PAGE = `${BASE}/file_install_extensions.html`;
+const PERMS_XPI = "browser_webext_permissions.xpi";
+const NO_PERMS_XPI = "browser_webext_nopermissions.xpi";
const ID = "permissions@test.mozilla.org";
const DEFAULT_EXTENSION_ICON = "chrome://browser/content/extension.svg";
Services.perms.add(makeURI("https://example.com/"), "install",
Services.perms.ALLOW_ACTION);
function promisePopupNotificationShown(name) {
@@ -31,67 +31,97 @@ function promisePopupNotificationShown(n
}
function promiseGetAddonByID(id) {
return new Promise(resolve => {
AddonManager.getAddonByID(id, resolve);
});
}
-function checkNotification(panel, url) {
+function checkNotification(panel, filename) {
let icon = panel.getAttribute("icon");
let ul = document.getElementById("addon-webext-perm-list");
let header = document.getElementById("addon-webext-perm-intro");
- if (url == PERMS_XPI) {
+ if (filename == PERMS_XPI) {
// 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
// inside the jar.
ok(icon.startsWith("jar:file://"), "Icon is a jar url");
ok(icon.endsWith("/icon.png"), "Icon is icon.png inside a jar");
is(header.getAttribute("hidden"), "", "Permission list header is visible");
is(ul.childElementCount, 4, "Permissions list has 4 entries");
// Real checking of the contents here is deferred until bug 1316996 lands
- } else if (url == NO_PERMS_XPI) {
+ } else if (filename == NO_PERMS_XPI) {
// This extension has no icon, it should have the default
is(icon, DEFAULT_EXTENSION_ICON, "Icon is the default extension icon");
is(header.getAttribute("hidden"), "true", "Permission list header is hidden");
is(ul.childElementCount, 0, "Permissions list has 0 entries");
}
}
+// Navigate the current tab to the given url and return a Promise
+// that resolves when the page is loaded.
+function load(url) {
+ gBrowser.selectedBrowser.loadURI(INSTALL_PAGE);
+ return BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
+}
+
const INSTALL_FUNCTIONS = [
- function installMozAM(url) {
- return ContentTask.spawn(gBrowser.selectedBrowser, url, function*(cUrl) {
- yield content.wrappedJSObject.installMozAM(cUrl);
+ async function installMozAM(filename) {
+ await load(INSTALL_PAGE);
+
+ await ContentTask.spawn(gBrowser.selectedBrowser, `${BASE}/${filename}`, function*(url) {
+ yield content.wrappedJSObject.installMozAM(url);
});
},
- function installTrigger(url) {
- ContentTask.spawn(gBrowser.selectedBrowser, url, function*(cUrl) {
- content.wrappedJSObject.installTrigger(cUrl);
+ async function installTrigger(filename) {
+ await load(INSTALL_PAGE);
+
+ ContentTask.spawn(gBrowser.selectedBrowser, `${BASE}/${filename}`, function*(url) {
+ content.wrappedJSObject.installTrigger(url);
});
- return Promise.resolve();
+ },
+
+ async function installFile(filename) {
+ const ChromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"]
+ .getService(Ci.nsIChromeRegistry);
+ let chromeUrl = Services.io.newURI(gTestPath);
+ let fileUrl = ChromeRegistry.convertChromeURL(chromeUrl);
+ let file = fileUrl.QueryInterface(Ci.nsIFileURL).file;
+ file.leafName = filename;
+
+ let MockFilePicker = SpecialPowers.MockFilePicker;
+ MockFilePicker.init(window);
+ MockFilePicker.returnFiles = [file];
+
+ await BrowserOpenAddonsMgr("addons://list/extension");
+ let contentWin = gBrowser.selectedTab.linkedBrowser.contentWindow;
+
+ // Do the install...
+ contentWin.gViewController.doCommand("cmd_installFromFile");
+ MockFilePicker.cleanup();
},
];
add_task(function* () {
yield SpecialPowers.pushPrefEnv({set: [
["extensions.webapi.testing", true],
["extensions.install.requireBuiltInCerts", false],
// XXX remove this when prompts are enabled by default
["extensions.webextPermissionPrompts", true],
]});
- function* runOnce(installFn, url, cancel) {
- let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE);
+ function* runOnce(installFn, filename, cancel) {
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser);
let installPromise = new Promise(resolve => {
let listener = {
onDownloadCancelled() {
AddonManager.removeInstallListener(listener);
resolve(false);
},
@@ -113,20 +143,20 @@ add_task(function* () {
onInstallFailed() {
AddonManager.removeInstallListener(listener);
resolve(false);
},
};
AddonManager.addInstallListener(listener);
});
- let installMethodPromise = installFn(url);
+ let installMethodPromise = installFn(filename);
let panel = yield promisePopupNotificationShown("addon-webext-permissions");
- checkNotification(panel, url);
+ checkNotification(panel, filename);
if (cancel) {
panel.secondaryButton.click();
try {
yield installMethodPromise;
} catch (err) {}
} else {
// Look for post-install notification
@@ -135,17 +165,16 @@ add_task(function* () {
// Press OK on the post-install notification
panel = yield postInstallPromise;
panel.button.click();
yield installMethodPromise;
}
-
let result = yield installPromise;
let addon = yield promiseGetAddonByID(ID);
if (cancel) {
ok(!result, "Installation was cancelled");
is(addon, null, "Extension is not installed");
} else {
ok(result, "Installation completed");
isnot(addon, null, "Extension is installed");