Bug 1519095 - Allow changing the text of an existing notification. r=jaws a=lizzard
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Fri, 08 Feb 2019 19:12:54 +0000
changeset 513045 f965e1e246ea
parent 513044 5da23f314b32
child 513046 59b12aa8fa46
push id10696
push usernbeleuzu@mozilla.com
push dateThu, 14 Feb 2019 00:48:15 +0000
treeherdermozilla-beta@401c1404f3b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, lizzard
bugs1519095
milestone66.0
Bug 1519095 - Allow changing the text of an existing notification. r=jaws a=lizzard This fixes the notification bar that shows how many popup windows have been blocked. Differential Revision: https://phabricator.services.mozilla.com/D17152
browser/base/content/test/popups/browser_popup_blocker.js
toolkit/content/widgets/notificationbox.js
--- a/browser/base/content/test/popups/browser_popup_blocker.js
+++ b/browser/base/content/test/popups/browser_popup_blocker.js
@@ -27,18 +27,20 @@ add_task(async function test_maximum_rep
   // Open the test page.
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, baseURL + "popup_blocker_10_popups.html");
 
   // Wait for the popup-blocked notification.
   let notification = await BrowserTestUtils.waitForCondition(() =>
     gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"));
 
   // Slightly hacky way to ensure we show the correct message in this case.
-  ok(notification.label.includes("more than"), "Notification label has 'more than'");
-  ok(notification.label.includes("5"), "Notification label shows the maximum number of popups");
+  ok(notification.messageText.textContent.includes("more than"),
+     "Notification label has 'more than'");
+  ok(notification.messageText.textContent.includes("5"),
+     "Notification label shows the maximum number of popups");
 
   gBrowser.removeTab(tab);
 
   Services.prefs.clearUserPref("privacy.popups.maxReported");
 });
 
 add_task(async function test_opening_blocked_popups() {
   // Open the test page.
--- a/toolkit/content/widgets/notificationbox.js
+++ b/toolkit/content/widgets/notificationbox.js
@@ -333,16 +333,24 @@ MozElements.Notification = class Notific
     }
   }
 
   get control() {
     return this.closest(".notificationbox-stack")._notificationBox;
   }
 
   /**
+   * Changes the text of an existing notification. If the notification was
+   * created with a custom fragment, it will be overwritten with plain text.
+   */
+  set label(value) {
+    this.messageText.textContent = value;
+  }
+
+  /**
    * This method should only be called when the user has manually closed the
    * notification. If you want to programmatically close the notification, you
    * should call close() instead.
    */
   dismiss() {
     if (this.eventCallback) {
       this.eventCallback("dismissed");
     }