Bug 1233350 - Fix TypeError in notifications.getAll(). r=kmag
authorSami Jaktholm <sjakthol@outlook.com>
Tue, 22 Dec 2015 11:29:22 +0200
changeset 317399 25a0f896c1861a961adaf6ff70f45904e9b9ea27
parent 317398 f51c6ba540f42d5789fe36385142820f9b6b1bae
child 317400 e1d9312025cc7d7e4dcbfcb070957246dc6d3448
push id8691
push userbmo:vivekb.balakrishnan@gmail.com
push dateWed, 23 Dec 2015 21:07:27 +0000
reviewerskmag
bugs1233350
milestone46.0a1
Bug 1233350 - Fix TypeError in notifications.getAll(). r=kmag This also adds some tests for the method.
toolkit/components/extensions/ext-notifications.js
toolkit/components/extensions/test/mochitest/test_ext_notifications.html
--- a/toolkit/components/extensions/ext-notifications.js
+++ b/toolkit/components/extensions/ext-notifications.js
@@ -119,17 +119,17 @@ extensions.registerPrivilegedAPI("notifi
 
         if (callback) {
           runSafe(context, callback, cleared);
         }
       },
 
       getAll: function(callback) {
         let notifications = notificationsMap.get(extension);
-        notifications = notifications.map(notification => notification.id);
+        notifications = Array.from(notifications, notification => notification.id);
         runSafe(context, callback, notifications);
       },
 
       onClosed: new EventManager(context, "notifications.onClosed", fire => {
         let listener = notification => {
           // FIXME: Support the byUser argument.
           fire(notification.id, true);
         };
--- a/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
@@ -40,12 +40,80 @@ add_task(function* test_notifications() 
   let x = yield extension.awaitMessage("running");
   is(x, "5", "got correct value from extension");
   yield extension.awaitFinish();
   info("test complete");
   yield extension.unload();
   info("extension unloaded successfully");
 });
 
+add_task(function* test_notifications_empty_getAll() {
+  function backgroundScript() {
+    browser.test.log("running background script");
+
+    browser.notifications.getAll(notifications => {
+      browser.test.assertTrue(Array.isArray(notifications),
+        "getAll() returned an array");
+      browser.test.assertEq(notifications.length, 0, "the array was empty");
+      browser.test.notifyPass("getAll empty");
+    });
+  }
+
+  let extensionData = {
+    manifest: {
+      permissions: ["notifications"]
+    },
+    background: "(" + backgroundScript.toString() + ")()"
+  };
+
+  let extension = ExtensionTestUtils.loadExtension(extensionData);
+  info("load complete");
+  yield extension.startup();
+  info("startup complete");
+  yield extension.awaitFinish("getAll empty");
+  info("test complete");
+  yield extension.unload();
+  info("extension unloaded successfully");
+});
+
+add_task(function* test_notifications_populated_getAll() {
+  function backgroundScript() {
+    browser.test.log("running background script");
+
+    var opts = {title: "Testing Notification", message: "Carry on"};
+    browser.notifications.create("p1", opts, () => {
+      browser.notifications.create("p2", opts, () => {
+        browser.notifications.getAll(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.notifyPass("getAll populated");
+        });
+      });
+    });
+  }
+
+  let extensionData = {
+    manifest: {
+      permissions: ["notifications"]
+    },
+    background: "(" + backgroundScript.toString() + ")()"
+  };
+
+  let extension = ExtensionTestUtils.loadExtension(extensionData);
+  info("load complete");
+  yield extension.startup();
+  info("startup complete");
+  yield extension.awaitFinish("getAll populated");
+  info("test complete");
+  yield extension.unload();
+  info("extension unloaded successfully");
+});
+
 </script>
 
 </body>
 </html>