Bug 1219097 - Stop using incorrect CPOWs in these tests. r=felipe
☠☠ backed out by bb8104dd89ae ☠ ☠
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 24 Feb 2016 00:13:16 -0800
changeset 321701 fe6d5add734ec6bf779ccbca267e33b4d26f63ff
parent 321700 f1ee875a249c025d60d29fcc01a991e07df8f0db
child 321702 e66d7c87d51a978cb1327ea21eaf1a64a52af8a0
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs1219097
milestone47.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 1219097 - Stop using incorrect CPOWs in these tests. r=felipe
browser/base/content/test/alerts/browser_notification_close.js
browser/base/content/test/alerts/browser_notification_do_not_disturb.js
browser/base/content/test/alerts/browser_notification_open_settings.js
browser/base/content/test/alerts/browser_notification_remove_permission.js
browser/base/content/test/alerts/browser_notification_tab_switching.js
browser/base/content/test/alerts/head.js
--- a/browser/base/content/test/alerts/browser_notification_close.js
+++ b/browser/base/content/test/alerts/browser_notification_close.js
@@ -1,53 +1,50 @@
-"use strict";
-
-let tab;
-let notification;
-let notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
-
-add_task(function* test_notificationClose() {
-  let pm = Services.perms;
-  pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
-
-  yield BrowserTestUtils.withNewTab({
-    gBrowser,
-    url: notificationURL
-  }, function* dummyTabTask(aBrowser) {
-    let win = aBrowser.contentWindow.wrappedJSObject;
-    notification = win.showNotification2();
-    yield BrowserTestUtils.waitForEvent(notification, "show");
-
-    info("Notification alert showing");
-
-    let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
-    if (!alertWindow) {
-      ok(true, "Notifications don't use XUL windows on all platforms.");
-      notification.close();
-      return;
-    }
-
-    let alertTitleLabel = alertWindow.document.getElementById("alertTitleLabel");
-    is(alertTitleLabel.value, "Test title", "Title text of notification should be present");
-    let alertTextLabel = alertWindow.document.getElementById("alertTextLabel");
-    is(alertTextLabel.textContent, "Test body", "Body text of notification should be present");
-
-    let alertCloseButton = alertWindow.document.querySelector(".alertCloseButton");
-    is(alertCloseButton.localName, "toolbarbutton", "close button found");
-    let promiseBeforeUnloadEvent =
-      BrowserTestUtils.waitForEvent(alertWindow, "beforeunload");
-    let closedTime = alertWindow.Date.now();
-    alertCloseButton.click();
-    info("Clicked on close button");
-    let beforeUnloadEvent = yield promiseBeforeUnloadEvent;
-
-    ok(true, "Alert should close when the close button is clicked");
-    let currentTime = alertWindow.Date.now();
-    // The notification will self-close at 12 seconds, so this checks
-    // that the notification closed before the timeout.
-    ok(currentTime - closedTime < 5000,
-       "Close requested at " + closedTime + ", actually closed at " + currentTime);
-  });
-});
-
-add_task(function* cleanup() {
-  Services.perms.remove(makeURI(notificationURL), "desktop-notification");
-});
+"use strict";
+
+let tab;
+let notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
+
+add_task(function* test_notificationClose() {
+  let pm = Services.perms;
+  pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
+
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: notificationURL
+  }, function* dummyTabTask(aBrowser) {
+    yield openNotification(aBrowser, "showNotification2");
+
+    info("Notification alert showing");
+
+    let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
+    if (!alertWindow) {
+      ok(true, "Notifications don't use XUL windows on all platforms.");
+      yield closeNotification(aBrowser);
+      return;
+    }
+
+    let alertTitleLabel = alertWindow.document.getElementById("alertTitleLabel");
+    is(alertTitleLabel.value, "Test title", "Title text of notification should be present");
+    let alertTextLabel = alertWindow.document.getElementById("alertTextLabel");
+    is(alertTextLabel.textContent, "Test body", "Body text of notification should be present");
+
+    let alertCloseButton = alertWindow.document.querySelector(".alertCloseButton");
+    is(alertCloseButton.localName, "toolbarbutton", "close button found");
+    let promiseBeforeUnloadEvent =
+      BrowserTestUtils.waitForEvent(alertWindow, "beforeunload");
+    let closedTime = alertWindow.Date.now();
+    alertCloseButton.click();
+    info("Clicked on close button");
+    let beforeUnloadEvent = yield promiseBeforeUnloadEvent;
+
+    ok(true, "Alert should close when the close button is clicked");
+    let currentTime = alertWindow.Date.now();
+    // The notification will self-close at 12 seconds, so this checks
+    // that the notification closed before the timeout.
+    ok(currentTime - closedTime < 5000,
+       "Close requested at " + closedTime + ", actually closed at " + currentTime);
+  });
+});
+
+add_task(function* cleanup() {
+  Services.perms.remove(makeURI(notificationURL), "desktop-notification");
+});
--- a/browser/base/content/test/alerts/browser_notification_do_not_disturb.js
+++ b/browser/base/content/test/alerts/browser_notification_do_not_disturb.js
@@ -1,91 +1,80 @@
-"use strict";
-
-var tab;
-var notification;
-var notification2;
-var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
-
-const ALERT_SERVICE = Cc["@mozilla.org/alerts-service;1"]
-                        .getService(Ci.nsIAlertsService)
-                        .QueryInterface(Ci.nsIAlertsDoNotDisturb);
-
-function test () {
-  waitForExplicitFinish();
-
-  try {
-    // Only run the test if the do-not-disturb
-    // interface has been implemented.
-    ALERT_SERVICE.manualDoNotDisturb;
-    ok(true, "Alert service implements do-not-disturb interface");
-  } catch (e) {
-    ok(true, "Alert service doesn't implement do-not-disturb interface, exiting test");
-    finish();
-    return;
-  }
-
-  let pm = Services.perms;
-  registerCleanupFunction(function() {
-    ALERT_SERVICE.manualDoNotDisturb = false;
-    pm.remove(makeURI(notificationURL), "desktop-notification");
-    gBrowser.removeTab(tab);
-    window.restore();
-  });
-
-  pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
-
-  // Make sure that do-not-disturb is not enabled.
-  ok(!ALERT_SERVICE.manualDoNotDisturb, "Alert service should not be disabled when test starts");
-  ALERT_SERVICE.manualDoNotDisturb = false;
-
-  tab = gBrowser.addTab(notificationURL);
-  gBrowser.selectedTab = tab;
-  tab.linkedBrowser.addEventListener("load", onLoad, true);
-}
-
-function onLoad() {
-  tab.linkedBrowser.removeEventListener("load", onLoad, true);
-  let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
-  notification = win.showNotification2();
-  notification.addEventListener("show", onAlertShowing);
-}
-
-function onAlertShowing() {
-  info("Notification alert showing");
-  notification.removeEventListener("show", onAlertShowing);
-
-  let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
-  if (!alertWindow) {
-    ok(true, "Notifications don't use XUL windows on all platforms.");
-    notification.close();
-    finish();
-    return;
-  }
-  let doNotDisturbMenuItem = alertWindow.document.getElementById("doNotDisturbMenuItem");
-  is(doNotDisturbMenuItem.localName, "menuitem", "menuitem found");
-  alertWindow.addEventListener("beforeunload", onAlertClosing);
-  doNotDisturbMenuItem.click();
-  info("Clicked on do-not-disturb menuitem");
-}
-
-function onAlertClosing(event) {
-  event.target.removeEventListener("beforeunload", onAlertClosing);
-
-  ok(ALERT_SERVICE.manualDoNotDisturb, "Alert service should be disabled after clicking menuitem");
-  let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
-  notification2 = win.showNotification2();
-  notification2.addEventListener("show", onAlert2Showing);
-
-  // The notification should not appear, but there is
-  // no way from the client-side to know that it was
-  // blocked, except for waiting some time and realizing
-  // that the "onshow" event never fired.
-  setTimeout(function() {
-    notification2.removeEventListener("show", onAlert2Showing);
-    finish();
-  }, 2000);
-}
-
-function onAlert2Showing() {
-  ok(false, "the second alert should not have been shown");
-  notification2.close();
-}
+"use strict";
+
+var tab;
+var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
+
+const ALERT_SERVICE = Cc["@mozilla.org/alerts-service;1"]
+                        .getService(Ci.nsIAlertsService)
+                        .QueryInterface(Ci.nsIAlertsDoNotDisturb);
+
+function test () {
+  waitForExplicitFinish();
+
+  try {
+    // Only run the test if the do-not-disturb
+    // interface has been implemented.
+    ALERT_SERVICE.manualDoNotDisturb;
+    ok(true, "Alert service implements do-not-disturb interface");
+  } catch (e) {
+    ok(true, "Alert service doesn't implement do-not-disturb interface, exiting test");
+    finish();
+    return;
+  }
+
+  let pm = Services.perms;
+  registerCleanupFunction(function() {
+    ALERT_SERVICE.manualDoNotDisturb = false;
+    pm.remove(makeURI(notificationURL), "desktop-notification");
+    gBrowser.removeTab(tab);
+    window.restore();
+  });
+
+  pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
+
+  // Make sure that do-not-disturb is not enabled.
+  ok(!ALERT_SERVICE.manualDoNotDisturb, "Alert service should not be disabled when test starts");
+  ALERT_SERVICE.manualDoNotDisturb = false;
+
+  tab = gBrowser.addTab(notificationURL);
+  gBrowser.selectedTab = tab;
+  tab.linkedBrowser.addEventListener("load", onLoad, true);
+}
+
+function onLoad() {
+  tab.linkedBrowser.removeEventListener("load", onLoad, true);
+  openNotification(tab.linkedBrowser, "showNotification2").then(onAlertShowing);
+}
+
+function onAlertShowing() {
+  info("Notification alert showing");
+
+  let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
+  if (!alertWindow) {
+    ok(true, "Notifications don't use XUL windows on all platforms.");
+    closeNotification(tab.linkedBrowser).then(finish);
+    return;
+  }
+  let doNotDisturbMenuItem = alertWindow.document.getElementById("doNotDisturbMenuItem");
+  is(doNotDisturbMenuItem.localName, "menuitem", "menuitem found");
+  alertWindow.addEventListener("beforeunload", onAlertClosing);
+  doNotDisturbMenuItem.click();
+  info("Clicked on do-not-disturb menuitem");
+}
+
+function onAlertClosing(event) {
+  event.target.removeEventListener("beforeunload", onAlertClosing);
+
+  ok(ALERT_SERVICE.manualDoNotDisturb, "Alert service should be disabled after clicking menuitem");
+
+  // The notification should not appear, but there is
+  // no way from the client-side to know that it was
+  // blocked, except for waiting some time and realizing
+  // that the "onshow" event never fired.
+  openNotification(tab.linkedBrowser, "showNotification2", 2000)
+    .then(onAlert2Showing, finish);
+}
+
+function onAlert2Showing() {
+  ok(false, "the second alert should not have been shown");
+  closeNotification(tab.linkedBrowser).then(finish);
+}
--- a/browser/base/content/test/alerts/browser_notification_open_settings.js
+++ b/browser/base/content/test/alerts/browser_notification_open_settings.js
@@ -24,25 +24,23 @@ add_task(function* test_settingsOpen_but
   info("Adding notification permission");
   pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
 
   try {
     yield BrowserTestUtils.withNewTab({
       gBrowser,
       url: notificationURL
     }, function* tabTask(aBrowser) {
-      let notification = aBrowser.contentWindow.wrappedJSObject.showNotification2();
-
       info("Waiting for notification");
-      yield BrowserTestUtils.waitForEvent(notification, "show");
+      yield openNotification(aBrowser, "showNotification2");
 
       let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
       if (!alertWindow) {
         ok(true, "Notifications don't use XUL windows on all platforms.");
-        notification.close();
+        yield closeNotification(aBrowser);
         return;
       }
 
       let closePromise = promiseWindowClosed(alertWindow);
       let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#content");
       let openSettingsMenuItem = alertWindow.document.getElementById("openSettingsMenuItem");
       openSettingsMenuItem.click();
 
--- a/browser/base/content/test/alerts/browser_notification_remove_permission.js
+++ b/browser/base/content/test/alerts/browser_notification_remove_permission.js
@@ -1,79 +1,74 @@
-"use strict";
-
-var tab;
-var notification;
-var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
-var alertWindowClosed = false;
-var permRemoved = false;
-
-function test () {
-  waitForExplicitFinish();
-
-  let pm = Services.perms;
-  registerCleanupFunction(function() {
-    pm.remove(makeURI(notificationURL), "desktop-notification");
-    gBrowser.removeTab(tab);
-    window.restore();
-  });
-
-  pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
-
-  tab = gBrowser.addTab(notificationURL);
-  gBrowser.selectedTab = tab;
-  tab.linkedBrowser.addEventListener("load", onLoad, true);
-}
-
-function onLoad() {
-  tab.linkedBrowser.removeEventListener("load", onLoad, true);
-  let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
-  notification = win.showNotification2();
-  notification.addEventListener("show", onAlertShowing);
-}
-
-function onAlertShowing() {
-  info("Notification alert showing");
-  notification.removeEventListener("show", onAlertShowing);
-
-  let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
-  if (!alertWindow) {
-    ok(true, "Notifications don't use XUL windows on all platforms.");
-    notification.close();
-    finish();
-    return;
-  }
-  ok(Services.perms.testExactPermission(makeURI(notificationURL), "desktop-notification"),
-     "Permission should exist prior to removal");
-  let disableForOriginMenuItem = alertWindow.document.getElementById("disableForOriginMenuItem");
-  is(disableForOriginMenuItem.localName, "menuitem", "menuitem found");
-  Services.obs.addObserver(permObserver, "perm-changed", false);
-  alertWindow.addEventListener("beforeunload", onAlertClosing);
-  disableForOriginMenuItem.click();
-  info("Clicked on disable-for-origin menuitem")
-}
-
-function permObserver(subject, topic, data) {
-  if (topic != "perm-changed") {
-    return;
-  }
-
-  let permission = subject.QueryInterface(Ci.nsIPermission);
-  is(permission.type, "desktop-notification", "desktop-notification permission changed");
-  is(data, "deleted", "desktop-notification permission deleted");
-
-  Services.obs.removeObserver(permObserver, "perm-changed");
-  permRemoved = true;
-  if (alertWindowClosed) {
-    finish();
-  }
-}
-
-function onAlertClosing(event) {
-  event.target.removeEventListener("beforeunload", onAlertClosing);
-
-  alertWindowClosed = true;
-  if (permRemoved) {
-    finish();
-  }
-}
-
-
+"use strict";
+
+var tab;
+var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
+var alertWindowClosed = false;
+var permRemoved = false;
+
+function test () {
+  waitForExplicitFinish();
+
+  let pm = Services.perms;
+  registerCleanupFunction(function() {
+    pm.remove(makeURI(notificationURL), "desktop-notification");
+    gBrowser.removeTab(tab);
+    window.restore();
+  });
+
+  pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
+
+  tab = gBrowser.addTab(notificationURL);
+  gBrowser.selectedTab = tab;
+  tab.linkedBrowser.addEventListener("load", onLoad, true);
+}
+
+function onLoad() {
+  tab.linkedBrowser.removeEventListener("load", onLoad, true);
+  openNotification(tab.linkedBrowser, "showNotification2").then(onAlertShowing);
+}
+
+function onAlertShowing() {
+  info("Notification alert showing");
+
+  let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
+  if (!alertWindow) {
+    ok(true, "Notifications don't use XUL windows on all platforms.");
+    closeNotification(tab.linkedBrowser).then(finish);
+    return;
+  }
+  ok(Services.perms.testExactPermission(makeURI(notificationURL), "desktop-notification"),
+     "Permission should exist prior to removal");
+  let disableForOriginMenuItem = alertWindow.document.getElementById("disableForOriginMenuItem");
+  is(disableForOriginMenuItem.localName, "menuitem", "menuitem found");
+  Services.obs.addObserver(permObserver, "perm-changed", false);
+  alertWindow.addEventListener("beforeunload", onAlertClosing);
+  disableForOriginMenuItem.click();
+  info("Clicked on disable-for-origin menuitem")
+}
+
+function permObserver(subject, topic, data) {
+  if (topic != "perm-changed") {
+    return;
+  }
+
+  let permission = subject.QueryInterface(Ci.nsIPermission);
+  is(permission.type, "desktop-notification", "desktop-notification permission changed");
+  is(data, "deleted", "desktop-notification permission deleted");
+
+  Services.obs.removeObserver(permObserver, "perm-changed");
+  permRemoved = true;
+  if (alertWindowClosed) {
+    finish();
+  }
+}
+
+function onAlertClosing(event) {
+  event.target.removeEventListener("beforeunload", onAlertClosing);
+
+  alertWindowClosed = true;
+  if (permRemoved) {
+    finish();
+  }
+}
+
+
--- a/browser/base/content/test/alerts/browser_notification_tab_switching.js
+++ b/browser/base/content/test/alerts/browser_notification_tab_switching.js
@@ -18,48 +18,63 @@ add_task(function* test_notificationPrev
     gBrowser,
     url: notificationURL
   }, function* dummyTabTask(aBrowser) {
     // Put new tab in background so it is obvious when it is re-focused.
     yield BrowserTestUtils.switchTab(gBrowser, originalTab);
     isnot(gBrowser.selectedBrowser, aBrowser, "Notification page loaded as a background tab");
 
     // First, show a notification that will be have the tab-switching prevented.
-    let win = aBrowser.contentWindow.wrappedJSObject;
-    let notification = win.showNotification1();
-    yield BrowserTestUtils.waitForEvent(notification, "show");
+    function promiseNotificationEvent(evt) {
+      return ContentTask.spawn(aBrowser, evt, function* (evt) {
+        return yield new Promise(resolve => {
+          let notification = content.wrappedJSObject._notification;
+          notification.addEventListener(evt, function l(event) {
+            notification.removeEventListener(evt, l);
+            resolve({ defaultPrevented: event.defaultPrevented });
+          });
+        });
+      });
+    }
+    yield openNotification(aBrowser, "showNotification1");
     info("Notification alert showing");
     let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
     if (!alertWindow) {
       ok(true, "Notifications don't use XUL windows on all platforms.");
-      notification.close();
+      yield closeNotification(aBrowser);
       return;
     }
     info("Clicking on notification");
-    let promiseClickEvent = BrowserTestUtils.waitForEvent(notification, "click");
-    EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"),
-                                       {},
-                                       alertWindow);
+    let promiseClickEvent = promiseNotificationEvent("click");
+
+    // NB: This executeSoon is needed to allow the non-e10s runs of this test
+    // a chance to set the event listener on the page. Otherwise, we
+    // synchronously fire the click event before we listen for the event.
+    executeSoon(() => {
+      EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"),
+                                         {}, alertWindow);
+    });
     let clickEvent = yield promiseClickEvent;
     ok(clickEvent.defaultPrevented, "The event handler for the first notification cancels the event");
     isnot(gBrowser.selectedBrowser, aBrowser, "Notification page still a background tab");
-    notification.close();
-    yield BrowserTestUtils.waitForEvent(notification, "close");
+    let notificationClosed = promiseNotificationEvent("close");
+    yield closeNotification(aBrowser);
+    yield notificationClosed;
 
     // Second, show a notification that will cause the tab to get switched.
-    let notification2 = win.showNotification2();
-    yield BrowserTestUtils.waitForEvent(notification2, "show");
+    yield openNotification(aBrowser, "showNotification2");
     alertWindow = Services.wm.getMostRecentWindow("alert:alert");
     let promiseTabSelect = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabSelect");
     EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"),
                                        {},
                                        alertWindow);
     yield promiseTabSelect;
     is(gBrowser.selectedBrowser.currentURI.spec, notificationURL,
        "Clicking on the second notification should select its originating tab");
-    notification2.close();
-    yield BrowserTestUtils.waitForEvent(notification2, "close");
+    notificationClosed = promiseNotificationEvent("close");
+    yield closeNotification(aBrowser);
+    yield notificationClosed;
   });
 });
 
 add_task(function* cleanup() {
   Services.perms.remove(makeURI(notificationURL), "desktop-notification");
 });
--- a/browser/base/content/test/alerts/head.js
+++ b/browser/base/content/test/alerts/head.js
@@ -27,8 +27,42 @@ function promiseWindowClosed(window) {
     Services.ww.registerNotification(function observer(subject, topic, data) {
       if (topic == "domwindowclosed" && subject == window) {
         Services.ww.unregisterNotification(observer);
         resolve();
       }
     });
   });
 }
+
+/**
+ * These two functions work with file_dom_notifications.html to open the
+ * notification and close it.
+ *
+ * whichFunction can be showNotification1 or showNotification2.
+ */
+function openNotification(aBrowser, fn, timeout) {
+  return ContentTask.spawn(aBrowser, { fn, timeout }, function* ({ fn, timeout }) {
+    let win = content.wrappedJSObject;
+    let notification = win[fn]();
+    win._notification = notification;
+    yield new Promise((resolve, reject) => {
+      let l = () => {
+        notification.removeEventListener("show", l);
+        resolve();
+      };
+
+      notification.addEventListener("show", l);
+
+      if (timeout) {
+        content.setTimeout(() => {
+          notification.removeEventListener("show", l);
+          reject("timed out");
+        }, timeout);
+      }
+    });
+  });
+}
+function closeNotification(aBrowser) {
+  return ContentTask.spawn(aBrowser, null, function() {
+    content.wrappedJSObject._notification.close();
+  });
+}