Bug 1100876 - Add showOnlyOnce to MozBehavior dict. r=mhenretty, r=smaug
authorAlexandre Lissy <lissyx@lissyx.dyndns.org>
Tue, 25 Nov 2014 08:26:00 -0500
changeset 242034 9155e0c352338e772a0fa230c690213fd0328cab
parent 242033 8ad15ef85676af2ad034932a90c1ad0800795737
child 242035 fc5ea5a66624566970e2ae92e13e9c2f6d74e9e3
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhenretty, smaug
bugs1100876
milestone36.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 1100876 - Add showOnlyOnce to MozBehavior dict. r=mhenretty, r=smaug There are some notifications that we know we don't want to resend. For instance, Voicemail notifications are some, since everytime the network will be ready it will notify us of the status, so we don't have to resend it on reboot. We add a 'showOnlyOnce' key in the MozBehavior dict for this usecase.
dom/notification/ChromeNotifications.js
dom/tests/mochitest/notification/test_notification_resend.html
dom/webidl/Notification.webidl
--- a/dom/notification/ChromeNotifications.js
+++ b/dom/notification/ChromeNotifications.js
@@ -49,16 +49,21 @@ ChromeNotifications.prototype = {
 
     notifications.forEach(function(notification) {
       let behavior;
       try {
         behavior = JSON.parse(notification.mozbehavior);
       } catch(e) {
         behavior = undefined;
       }
+
+      if (behavior && behavior.showOnlyOnce === true) {
+        return;
+      }
+
       appNotifier.showAppNotification(
         notification.icon,
         notification.title,
         notification.body,
         null,
         {
           manifestURL: notification.origin,
           id: notification.alertName,
--- a/dom/tests/mochitest/notification/test_notification_resend.html
+++ b/dom/tests/mochitest/notification/test_notification_resend.html
@@ -82,16 +82,45 @@
 
       navigator.mozChromeNotifications.mozResendAllNotifications(function(number) {
         is(number, 1, "One notification resent");
         notif.close();
       });
     },
 
     function (done) {
+      info("Sending one non-resendable notification");
+      var behavior = {
+        showOnlyOnce: true
+      };
+      var notif = new Notification("title", { mozbehavior: behavior });
+      ok(notif, "Notification object is valid");
+      notifications.push(notif);
+
+      var promise = Notification.get();
+      promise.then(function (notifications) {
+        is(notifications.length, 1, "one notification has been sent");
+        done();
+      });
+    },
+
+    function (done) {
+      info("Trying to resend non-resendable notification");
+      var notif = notifications.pop();
+      notif.onclose = function() {
+        done();
+      };
+
+      navigator.mozChromeNotifications.mozResendAllNotifications(function(number) {
+        is(number, 0, "One notification not resent");
+        notif.close();
+      });
+    },
+
+    function (done) {
       info("Sending two notifications, closing one");
       var notif1 = new Notification("title1");
       ok(notif1, "Notification object is valid");
       notif1.onclose = function() {
         done();
       };
 
       var payload = NotificationTest.payload;
--- a/dom/webidl/Notification.webidl
+++ b/dom/webidl/Notification.webidl
@@ -67,16 +67,17 @@ dictionary NotificationOptions {
 
 dictionary GetNotificationOptions {
   DOMString tag;
 };
 
 dictionary NotificationBehavior {
   boolean noscreen = false;
   boolean noclear = false;
+  boolean showOnlyOnce = false;
   DOMString soundFile = "";
   sequence<unsigned long> vibrationPattern;
 };
 
 enum NotificationPermission {
   "default",
   "denied",
   "granted"