Bug 1350053 - Part 2 - Update tests to check the arrow panel to appear, instead of the notification bar. r?Mossop
MozReview-Commit-ID: G4Hkb7KQ79X
--- a/browser/base/content/test/general/browser_bug592338.js
+++ b/browser/base/content/test/general/browser_bug592338.js
@@ -1,24 +1,43 @@
/* 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/";
-var tempScope = {};
-Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", tempScope);
-var LightweightThemeManager = tempScope.LightweightThemeManager;
+const {LightweightThemeManager} = Cu.import("resource://gre/modules/LightweightThemeManager.jsm", {});
-function wait_for_notification(aCallback) {
- PopupNotifications.panel.addEventListener("popupshown", function() {
- aCallback(PopupNotifications.panel);
- }, {once: true});
+/**
+ * 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);
gBrowser.selectedTab = gBrowser.addTab("http://example.org/browser/browser/base/content/test/general/bug592338.html");
@@ -50,30 +69,27 @@ function test_install_lwtheme() {
gBrowser.selectedTab = gBrowser.addTab("https://example.com/browser/browser/base/content/test/general/bug592338.html");
gBrowser.selectedBrowser.addEventListener("pageshow", function() {
if (gBrowser.contentDocument.location.href == "about:blank")
return;
gBrowser.selectedBrowser.removeEventListener("pageshow", arguments.callee);
+ let promise = promisePopupNotificationShown("addon-installed");
BrowserTestUtils.synthesizeMouse("#theme-install", 2, 2, {}, gBrowser.selectedBrowser);
- let notificationBox = gBrowser.getNotificationBox(gBrowser.selectedBrowser);
- waitForCondition(
- () => notificationBox.getNotificationWithValue("lwtheme-install-notification"),
- () => {
- is(LightweightThemeManager.currentTheme.id, "test", "Should have installed the test theme");
+ 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");
+ LightweightThemeManager.currentTheme = null;
+ gBrowser.removeTab(gBrowser.selectedTab);
+ Services.perms.remove(makeURI("http://example.com/"), "install");
- runNextTest();
- }
- );
+ runNextTest();
+ });
});
}
];
function runNextTest() {
AddonManager.getAllInstalls(function(aInstalls) {
is(aInstalls.length, 0, "Should be no active installs");