Bug 1398491 - Use SpecialPowers.pushPermissions instead of Services.perms.add. r?mattn draft
authorEdouard Oger <eoger@fastmail.com>
Fri, 06 Oct 2017 14:51:56 -0400
changeset 676170 78bf0456acdcd6d78e3738cee131bdddb30796d1
parent 675689 19b32a138d08f73961df878a29de6f0aad441683
child 734864 9f95dfc20a4491be395252b2560cffdf98b6d9f3
push id83409
push userbmo:eoger@fastmail.com
push dateFri, 06 Oct 2017 18:54:21 +0000
reviewersmattn
bugs1398491
milestone58.0a1
Bug 1398491 - Use SpecialPowers.pushPermissions instead of Services.perms.add. r?mattn MozReview-Commit-ID: NzlSA8Kt2t
browser/base/content/test/alerts/browser_notification_open_settings.js
--- a/browser/base/content/test/alerts/browser_notification_open_settings.js
+++ b/browser/base/content/test/alerts/browser_notification_open_settings.js
@@ -19,48 +19,44 @@ add_task(async function test_settingsOpe
     let tab = await tabPromise;
     ok(tab, "The notification settings tab opened");
     await syncPaneLoadedPromise;
     await BrowserTestUtils.removeTab(tab);
   });
 });
 
 add_task(async function test_settingsOpen_button() {
-  let pm = Services.perms;
   info("Adding notification permission");
-  pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
+  await new Promise(res => {
+    SpecialPowers.pushPermissions([{'type': 'desktop-notification', 'allow': true, 'context': notificationURL}], res);
+  });
 
-  try {
-    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);
+  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);
 
-      info("Waiting for notification");
-      await openNotification(aBrowser, "showNotification2");
+    info("Waiting for notification");
+    await openNotification(aBrowser, "showNotification2");
 
-      let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
-      if (!alertWindow) {
-        ok(true, "Notifications don't use XUL windows on all platforms.");
-        await closeNotification(aBrowser);
-        return;
-      }
-
-      let closePromise = promiseWindowClosed(alertWindow);
-      let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, expectedURL);
-      let openSettingsMenuItem = alertWindow.document.getElementById("openSettingsMenuItem");
-      openSettingsMenuItem.click();
+    let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
+    if (!alertWindow) {
+      ok(true, "Notifications don't use XUL windows on all platforms.");
+      await closeNotification(aBrowser);
+      return;
+    }
 
-      info("Waiting for notification settings tab");
-      let tab = await tabPromise;
-      ok(tab, "The notification settings tab opened");
+    let closePromise = promiseWindowClosed(alertWindow);
+    let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, expectedURL);
+    let openSettingsMenuItem = alertWindow.document.getElementById("openSettingsMenuItem");
+    openSettingsMenuItem.click();
 
-      await syncPaneLoadedPromise;
-      await closePromise;
-      await BrowserTestUtils.removeTab(tab);
-    });
-  } finally {
-    info("Removing notification permission");
-    pm.remove(makeURI(notificationURL), "desktop-notification");
-  }
+    info("Waiting for notification settings tab");
+    let tab = await tabPromise;
+    ok(tab, "The notification settings tab opened");
+
+    await syncPaneLoadedPromise;
+    await closePromise;
+    await BrowserTestUtils.removeTab(tab);
+  });
 });