Bug 1254359 - notifications.getAll() result is not Chrome-compatible, r?kmag draft
authorbsilverberg <bsilverberg@mozilla.com>
Wed, 30 Mar 2016 09:31:37 -0400
changeset 345802 5c3b6c8cc60c5631b26e940a987f0910ec022645
parent 345578 7ce97832e03815c3f5dbe7fefcb301049b67aaf8
child 346024 c833fe88afc430710cfaaf55c4532ae6a1a912e6
child 346051 ece4f3a6dc06d3b9f0e38dce70a4b84df4afe8e8
child 346066 bff8d2c117c83d7ba0cab702b0f4a7e5a43a276a
push id14180
push userbmo:bob.silverberg@gmail.com
push dateWed, 30 Mar 2016 13:33:46 +0000
reviewerskmag
bugs1254359
milestone48.0a1
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"],
     },