Bug 1350053 - Part 2 - Update tests to check the arrow panel to appear, instead of the notification bar. r=mossop
authorMike de Boer <mdeboer@mozilla.com>
Mon, 10 Apr 2017 16:17:36 +0200
changeset 352255 74d44ad1533ecb0c924da862171e8b9dcee56e83
parent 352254 5c0565ed332fd9fb97ba28b0196a608f30ecf426
child 352256 67ed44b3f67e2855bc4998adf70c3054975d70d5
push id31634
push usercbook@mozilla.com
push dateTue, 11 Apr 2017 08:14:14 +0000
treeherdermozilla-central@596ea55fa962 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1350053
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1350053 - Part 2 - Update tests to check the arrow panel to appear, instead of the notification bar. r=mossop MozReview-Commit-ID: G4Hkb7KQ79X
browser/base/content/test/general/browser_bug592338.js
--- 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");