fune/browser/base/content/test/general/browser_bug592338.js
Kris Maglione 918ed6c474 Bug 1431533: Part 5a - Auto-rewrite code to use ChromeUtils import methods. r=florian
This was done using the following script:
37e3803c7a/processors/chromeutils-import.jsm

MozReview-Commit-ID: 1Nc3XDu0wGl

--HG--
extra : source : 12fc4dee861c812fd2bd032c63ef17af61800c70
extra : intermediate-source : 34c999fa006bffe8705cf50c54708aa21a962e62
extra : histedit_source : b2be2c5e5d226e6c347312456a6ae339c1e634b0
2018-01-29 15:20:18 -08:00

121 lines
3.8 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/";
const {LightweightThemeManager} = ChromeUtils.import("resource://gre/modules/LightweightThemeManager.jsm", {});
/**
* Wait for the given PopupNotification to display
*
* @param {string} name
* The name of the notification to wait for.
*
* @returns {Promise}
* Resolves with the notification window.
*/
function promisePopupNotificationShown(name) {
return new Promise(resolve => {
function popupshown() {
let notification = PopupNotifications.getNotification(name);
if (!notification) { return; }
ok(notification, `${name} notification shown`);
ok(PopupNotifications.isPanelOpen, "notification panel open");
PopupNotifications.panel.removeEventListener("popupshown", popupshown);
resolve(PopupNotifications.panel.firstChild);
}
PopupNotifications.panel.addEventListener("popupshown", popupshown);
});
}
var TESTS = [
function test_install_http() {
is(LightweightThemeManager.currentTheme, null, "Should be no lightweight theme selected");
var pm = Services.perms;
pm.add(makeURI("http://example.org/"), "install", pm.ALLOW_ACTION);
// NB: Not https so no installs allowed.
const URL = "http://example.org/browser/browser/base/content/test/general/bug592338.html";
BrowserTestUtils.openNewForegroundTab({ gBrowser, url: URL }).then(async function() {
let prompted = promisePopupNotificationShown("addon-webext-permissions");
BrowserTestUtils.synthesizeMouse("#theme-install", 2, 2, {}, gBrowser.selectedBrowser);
await prompted;
is(LightweightThemeManager.currentTheme, null, "Should not have installed the test theme");
gBrowser.removeTab(gBrowser.selectedTab);
pm.remove(makeURI("http://example.org/"), "install");
runNextTest();
});
},
function test_install_lwtheme() {
is(LightweightThemeManager.currentTheme, null, "Should be no lightweight theme selected");
var pm = Services.perms;
pm.add(makeURI("https://example.com/"), "install", pm.ALLOW_ACTION);
const URL = "https://example.com/browser/browser/base/content/test/general/bug592338.html";
BrowserTestUtils.openNewForegroundTab({ gBrowser, url: URL }).then(() => {
let promise = promisePopupNotificationShown("addon-installed");
BrowserTestUtils.synthesizeMouse("#theme-install", 2, 2, {}, gBrowser.selectedBrowser);
promise.then(() => {
is(LightweightThemeManager.currentTheme.id, "test", "Should have installed the test theme");
LightweightThemeManager.currentTheme = null;
gBrowser.removeTab(gBrowser.selectedTab);
Services.perms.remove(makeURI("http://example.com/"), "install");
runNextTest();
});
});
}
];
function runNextTest() {
AddonManager.getAllInstalls(function(aInstalls) {
is(aInstalls.length, 0, "Should be no active installs");
if (TESTS.length == 0) {
AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) {
aAddon.uninstall();
Services.prefs.setBoolPref("extensions.logging.enabled", false);
finish();
});
return;
}
info("Running " + TESTS[0].name);
TESTS.shift()();
});
}
function test() {
waitForExplicitFinish();
Services.prefs.setBoolPref("extensions.logging.enabled", true);
AddonManager.getInstallForURL(TESTROOT + "theme.xpi", function(aInstall) {
aInstall.addListener({
onInstallEnded() {
AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) {
isnot(aAddon, null, "Should have installed the test theme.");
runNextTest();
});
}
});
aInstall.install();
}, "application/x-xpinstall");
}