Bug 1217621 - Show settings action for XUL notifications. r=jaws
authorKit Cambridge <kcambridge@mozilla.com>
Fri, 23 Oct 2015 15:53:15 -0600
changeset 304512 04d81b3992f6066a4c72503ffc91cf0826f63428
parent 304511 5c9a1a6832a6ce7b1417dfef48c5678f39e46adf
child 304513 9e60fa0fc1e313841abb7480ceed394bb8be95be
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1217621
milestone44.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 1217621 - Show settings action for XUL notifications. r=jaws
browser/base/content/test/alerts/browser_notification_open_settings.js
toolkit/components/alerts/resources/content/alert.js
toolkit/components/alerts/resources/content/alert.xul
--- a/browser/base/content/test/alerts/browser_notification_open_settings.js
+++ b/browser/base/content/test/alerts/browser_notification_open_settings.js
@@ -1,18 +1,71 @@
 "use strict";
 
-add_task(function* test_settingsOpen() {
+var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
+
+function waitForCloseWindow(window) {
+  return new Promise(function(resolve) {
+    Services.ww.registerNotification(function observer(subject, topic, data) {
+      if (topic == "domwindowclosed" && subject == window) {
+        Services.ww.unregisterNotification(observer);
+        resolve();
+      }
+    });
+  });
+}
+
+add_task(function* test_settingsOpen_observer() {
   info("Opening a dummy tab so openPreferences=>switchToTabHavingURI doesn't use the blank tab.");
   yield BrowserTestUtils.withNewTab({
     gBrowser,
     url: "about:robots"
   }, function* dummyTabTask(aBrowser) {
     let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#content");
     info("simulate a notifications-open-settings notification");
     let uri = NetUtil.newURI("https://example.com");
     let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
     Services.obs.notifyObservers(principal, "notifications-open-settings", null);
     let tab = yield tabPromise;
     ok(tab, "The notification settings tab opened");
     yield BrowserTestUtils.removeTab(tab);
   });
 });
+
+add_task(function* test_settingsOpen_button() {
+  let pm = Services.perms;
+  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");
+
+      let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
+      if (!alertWindow) {
+        ok(true, "Notifications don't use XUL windows on all platforms.");
+        notification.close();
+        return;
+      }
+
+      let closePromise = waitForCloseWindow(alertWindow);
+      let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#content");
+      let openSettingsMenuItem = alertWindow.document.getElementById("openSettingsMenuItem");
+      openSettingsMenuItem.click();
+
+      info("Waiting for notification settings tab");
+      let tab = yield tabPromise;
+      ok(tab, "The notification settings tab opened");
+
+      yield closePromise;
+      yield BrowserTestUtils.removeTab(tab);
+    });
+  } finally {
+    info("Removing notification permission");
+    pm.remove(makeURI(notificationURL), "desktop-notification");
+  }
+});
--- a/toolkit/components/alerts/resources/content/alert.js
+++ b/toolkit/components/alerts/resources/content/alert.js
@@ -57,16 +57,19 @@ function prefillAlertInfo() {
           ALERT_BUNDLE.formatStringFromName("doNotDisturb.label",
                                             [BRAND_NAME],
                                             1));
         let disableForOrigin = document.getElementById("disableForOriginMenuItem");
         disableForOrigin.setAttribute("label",
           ALERT_BUNDLE.formatStringFromName("webActions.disableForOrigin.label",
                                             [hostPort],
                                             1));
+        let openSettings = document.getElementById("openSettingsMenuItem");
+        openSettings.setAttribute("label",
+          ALERT_BUNDLE.GetStringFromName("webActions.settings.label"));
       }
     }
     case 10:
       gAlertListener = window.arguments[9];
     case 9:
       gReplacedWindow = window.arguments[8];
     case 8:
       if (window.arguments[7]) {
@@ -247,16 +250,21 @@ function doNotDisturb() {
   onAlertClose();
 }
 
 function disableForOrigin() {
   gAlertListener.observe(null, "alertdisablecallback", gAlertCookie);
   onAlertClose();
 }
 
+function openSettings() {
+  gAlertListener.observe(null, "alertsettingscallback", gAlertCookie);
+  onAlertClose();
+}
+
 function onAlertClose() {
   let alertBox = document.getElementById("alertBox");
   if (alertBox.getAttribute("animate") == "true") {
     // Closed when the animation ends.
     alertBox.setAttribute("closing", "true");
   } else {
     window.close();
   }
--- a/toolkit/components/alerts/resources/content/alert.xul
+++ b/toolkit/components/alerts/resources/content/alert.xul
@@ -46,16 +46,18 @@
           <button type="menu" id="alertSettings" tooltiptext="&settings.label;"
                   onclick="event.stopPropagation();">
             <menupopup position="after_end">
               <menuitem id="doNotDisturbMenuItem"
                         oncommand="doNotDisturb();"/>
               <menuseparator/>
               <menuitem id="disableForOriginMenuItem"
                         oncommand="disableForOrigin();"/>
+              <menuitem id="openSettingsMenuItem"
+                        oncommand="openSettings();"/>
             </menupopup>
           </button>
         </box>
       </vbox>
     </box>
   </vbox>
 
   <!-- This method is called inline because we want to make sure we establish the width