Bug 1352791 - Use a pushPermissions helper for alerts b-c tests. r=MattN
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 09 Oct 2017 18:49:54 -0400
changeset 385270 314590a2d58878e952f209723153b341ea2a2d9c
parent 385269 969e0b72c2eea55d49c3dc057ab3ccad1c1a1865
child 385271 638f6196f028bfd16fb3318a2c1fe10f95d848e8
push id32650
push userarchaeopteryx@coole-files.de
push dateTue, 10 Oct 2017 09:13:16 +0000
treeherdermozilla-central@77a4c52e9987 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1352791
milestone58.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 1352791 - Use a pushPermissions helper for alerts b-c tests. r=MattN MozReview-Commit-ID: E6tsp3TioBS
browser/base/content/test/alerts/browser.ini
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_replace.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.ini
+++ b/browser/base/content/test/alerts/browser.ini
@@ -1,14 +1,12 @@
 [DEFAULT]
 support-files =
   head.js
   file_dom_notifications.html
 
 [browser_notification_close.js]
 skip-if = os == 'win' # Bug 1227785
 [browser_notification_do_not_disturb.js]
-skip-if = (os == 'win' && bits == 32) # Bug 1352791
 [browser_notification_open_settings.js]
 [browser_notification_remove_permission.js]
 [browser_notification_replace.js]
 [browser_notification_tab_switching.js]
-skip-if = os == "win" || os == "linux" # Bug 1243263
--- a/browser/base/content/test/alerts/browser_notification_close.js
+++ b/browser/base/content/test/alerts/browser_notification_close.js
@@ -2,19 +2,18 @@
 
 const {PlacesTestUtils} =
   Cu.import("resource://testing-common/PlacesTestUtils.jsm", {});
 
 let notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
 let oldShowFavicons;
 
 add_task(async function test_notificationClose() {
-  let pm = Services.perms;
   let notificationURI = makeURI(notificationURL);
-  pm.add(notificationURI, "desktop-notification", pm.ALLOW_ACTION);
+  await addNotificationPermission(notificationURL);
 
   oldShowFavicons = Services.prefs.getBoolPref("alerts.showFavicons");
   Services.prefs.setBoolPref("alerts.showFavicons", true);
 
   await PlacesTestUtils.addVisits(notificationURI);
   let faviconURI = await new Promise(resolve => {
     let uri =
       makeURI("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVQI12P4//8/AAX+Av7czFnnAAAAAElFTkSuQmCC");
--- a/browser/base/content/test/alerts/browser_notification_do_not_disturb.js
+++ b/browser/base/content/test/alerts/browser_notification_do_not_disturb.js
@@ -16,33 +16,32 @@ function test() {
     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 = BrowserTestUtils.addTab(gBrowser, notificationURL);
-  gBrowser.selectedTab = tab;
-  tab.linkedBrowser.addEventListener("load", onLoad, true);
+  addNotificationPermission(notificationURL).then(function openTab() {
+    tab = BrowserTestUtils.addTab(gBrowser, 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() {
--- a/browser/base/content/test/alerts/browser_notification_open_settings.js
+++ b/browser/base/content/test/alerts/browser_notification_open_settings.js
@@ -20,23 +20,17 @@ add_task(async function test_settingsOpe
     ok(tab, "The notification settings tab opened");
     await syncPaneLoadedPromise;
     await BrowserTestUtils.removeTab(tab);
   });
 });
 
 add_task(async function test_settingsOpen_button() {
   info("Adding notification permission");
-  await new Promise(resolve => {
-    SpecialPowers.pushPermissions([{
-      type: "desktop-notification",
-      allow: true,
-      context: notificationURL,
-    }], resolve);
-  });
+  await addNotificationPermission(notificationURL);
 
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: notificationURL
   }, async function tabTask(aBrowser) {
     // Ensure preferences is loaded before removing the tab.
     let syncPaneLoadedPromise = TestUtils.topicObserved("sync-pane-loaded", () => true);
 
--- a/browser/base/content/test/alerts/browser_notification_remove_permission.js
+++ b/browser/base/content/test/alerts/browser_notification_remove_permission.js
@@ -3,28 +3,26 @@
 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 = BrowserTestUtils.addTab(gBrowser, notificationURL);
-  gBrowser.selectedTab = tab;
-  tab.linkedBrowser.addEventListener("load", onLoad, true);
+  addNotificationPermission(notificationURL).then(function openTab() {
+    tab = BrowserTestUtils.addTab(gBrowser, 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() {
--- a/browser/base/content/test/alerts/browser_notification_replace.js
+++ b/browser/base/content/test/alerts/browser_notification_replace.js
@@ -1,15 +1,14 @@
 "use strict";
 
 let notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
 
 add_task(async function test_notificationReplace() {
-  let pm = Services.perms;
-  pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
+  await addNotificationPermission(notificationURL);
 
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: notificationURL
   }, async function dummyTabTask(aBrowser) {
     await ContentTask.spawn(aBrowser, {}, async function() {
       let win = content.window.wrappedJSObject;
       let notification = win.showNotification1();
@@ -27,12 +26,8 @@ add_task(async function test_notificatio
 
       let promiseNewCloseEvent = ContentTaskUtils.waitForEvent(newNotification, "close");
       newNotification.close();
       let newCloseEvent = await promiseNewCloseEvent;
       Assert.equal(newCloseEvent.target.body, "Test body 2", "Closed new notification");
     });
   });
 });
-
-add_task(async function cleanup() {
-  Services.perms.remove(makeURI(notificationURL), "desktop-notification");
-});
--- a/browser/base/content/test/alerts/browser_notification_tab_switching.js
+++ b/browser/base/content/test/alerts/browser_notification_tab_switching.js
@@ -5,18 +5,17 @@
 "use strict";
 
 var tab;
 var notification;
 var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
 var newWindowOpenedFromTab;
 
 add_task(async function test_notificationPreventDefaultAndSwitchTabs() {
-  let pm = Services.perms;
-  pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
+  await addNotificationPermission(notificationURL);
 
   let originalTab = gBrowser.selectedTab;
   await BrowserTestUtils.withNewTab({
     gBrowser,
     url: notificationURL
   }, async function dummyTabTask(aBrowser) {
     // Put new tab in background so it is obvious when it is re-focused.
     await BrowserTestUtils.switchTab(gBrowser, originalTab);
--- a/browser/base/content/test/alerts/head.js
+++ b/browser/base/content/test/alerts/head.js
@@ -1,8 +1,18 @@
+async function addNotificationPermission(originString) {
+  return new Promise(resolve => {
+    SpecialPowers.pushPermissions([{
+      type: "desktop-notification",
+      allow: true,
+      context: originString,
+    }], resolve);
+  });
+}
+
 /**
  * Similar to `BrowserTestUtils.closeWindow`, but
  * doesn't call `window.close()`.
  */
 function promiseWindowClosed(window) {
   return new Promise(function(resolve) {
     Services.ww.registerNotification(function observer(subject, topic, data) {
       if (topic == "domwindowclosed" && subject == window) {