Bug 1352791 - Use a pushPermissions helper for alerts b-c tests. r=MattN draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 09 Oct 2017 18:49:54 -0400
changeset 677046 0838676cb13b47f87b7ecf0d4c3fbcc510448954
parent 677036 6fe7c6bdbb5b4699d234d636ae502d70b4fa702a
child 735100 ccad67c06fae7ec770c39925e8851026b558cfa6
push id83675
push usermozilla@noorenberghe.ca
push dateMon, 09 Oct 2017 22:50:18 +0000
reviewersMattN
bugs1352791
milestone58.0a1
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) {