Bug 1254359 - notifications.getAll() result is not Chrome-compatible, r=kmag
authorbsilverberg <bsilverberg@mozilla.com>
Wed, 30 Mar 2016 09:31:37 -0400
changeset 291338 1d794d077cb1d12228185a0b9f6bbf64c56b8513
parent 291337 642e91672f8ae6738f48c93d0846d65dbc0eb2f2
child 291339 0228e00caf591a590ac553d3ccf297c647b4c9c0
push id74545
push userkwierso@gmail.com
push dateFri, 01 Apr 2016 23:05:42 +0000
treeherdermozilla-inbound@c410d4e20586 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1254359
milestone48.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 1254359 - notifications.getAll() result is not Chrome-compatible, r=kmag MozReview-Commit-ID: EIeIZquJaIN
toolkit/components/extensions/ext-notifications.js
toolkit/components/extensions/schemas/notifications.json
toolkit/components/extensions/test/mochitest/test_ext_notifications.html
--- a/toolkit/components/extensions/ext-notifications.js
+++ b/toolkit/components/extensions/ext-notifications.js
@@ -106,17 +106,20 @@ extensions.registerSchemaAPI("notificati
         if (notifications.has(notificationId)) {
           notifications.get(notificationId).clear();
           return Promise.resolve(true);
         }
         return Promise.resolve(false);
       },
 
       getAll: function() {
-        let result = Array.from(notificationsMap.get(extension).keys());
+        let result = {};
+        notificationsMap.get(extension).forEach((value, key) => {
+          result[key] = value.options;
+        });
         return Promise.resolve(result);
       },
 
       onClosed: new EventManager(context, "notifications.onClosed", fire => {
         let listener = notification => {
           // FIXME: Support the byUser argument.
           fire(notification.id, true);
         };
--- a/toolkit/components/extensions/schemas/notifications.json
+++ b/toolkit/components/extensions/schemas/notifications.json
@@ -272,21 +272,18 @@
         "async": "callback",
         "parameters": [
           {
             "type": "function",
             "name": "callback",
             "parameters": [
               {
                 "name": "notifications",
-                "type": "array",
-                "description": "The set of notification_ids currently in the system.",
-                "items": {
-                  "type": "string"
-                }
+                "type": "object",
+                "description": "The set of notifications currently in the system."
               }
             ]
           }
         ]
       },
       {
         "name": "getPermissionLevel",
         "unsupported": true,
--- a/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
@@ -108,19 +108,18 @@ add_task(function* test_notification_cle
   is(x, true, "got correct boolean from notifications.clear");
   yield extension.awaitFinish();
   yield extension.unload();
 });
 
 add_task(function* test_notifications_empty_getAll() {
   function backgroundScript() {
     browser.notifications.getAll().then(notifications => {
-      browser.test.assertTrue(Array.isArray(notifications),
-        "getAll() returned an array");
-      browser.test.assertEq(notifications.length, 0, "the array was empty");
+      browser.test.assertEq("object", typeof notifications, "getAll() returned an object");
+      browser.test.assertEq(0, Object.keys(notifications).length, "the object has no properties");
       browser.test.notifyPass("getAll empty");
     });
   }
 
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["notifications"],
     },
@@ -139,24 +138,27 @@ add_task(function* test_notifications_po
       message: "Carry on",
     };
 
     browser.notifications.create("p1", opts).then(() => {
       return browser.notifications.create("p2", opts);
     }).then(() => {
       return browser.notifications.getAll();
     }).then(notifications => {
-      browser.test.assertTrue(Array.isArray(notifications),
-        "getAll() returned an array");
-      browser.test.assertEq(notifications.length, 2,
-        "the array contained two notification ids");
-      browser.test.assertTrue(notifications.includes("p1"),
-        "the array contains the first notification");
-      browser.test.assertTrue(notifications.includes("p2"),
-        "the array contains the second notification");
+      browser.test.assertEq("object", typeof notifications, "getAll() returned an object");
+      browser.test.assertEq(2, Object.keys(notifications).length, "the object has 2 properties");
+      for (let notificationId of ["p1", "p2"]) {
+        for (let key of Object.keys(opts)) {
+          browser.test.assertEq(
+            opts[key],
+            notifications[notificationId][key],
+            `the notification has the expected value for option: ${key}`
+          );
+        }
+      }
       browser.test.notifyPass("getAll populated");
     });
   }
 
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["notifications"],
     },