Bug 1233350 - Fix TypeError in notifications.getAll(). r?kmag draft
authorSami Jaktholm <sjakthol@outlook.com>
Tue, 22 Dec 2015 11:29:22 +0200
changeset 317012 669f4ee52cfe7d944b23061adc40dc9844c217bd
parent 317010 3cc8559d0d65d5704eedc72238a82c09b4b630cd
child 512238 2db1793623695a7b34410e2ae1bf770db48715ab
push id8633
push usersjakthol@outlook.com
push dateTue, 22 Dec 2015 14:07:53 +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>