Bug 1388066 - Add test for message sender.tab when tabId is 0 on Firefox for Android. draft
authorLuca Greco <lgreco@mozilla.com>
Fri, 11 Aug 2017 16:08:50 +0200
changeset 645656 deee35958b6ff8999a3758cd1ee072d36b2beee9
parent 645655 4092ff015370ba60f56db33df08d2da69c229832
child 725958 fe31769f687790ca4e0e0f16049d8a1f3561168c
push id73818
push userluca.greco@alcacoop.it
push dateSun, 13 Aug 2017 20:45:14 +0000
bugs1388066
milestone57.0a1
Bug 1388066 - Add test for message sender.tab when tabId is 0 on Firefox for Android. MozReview-Commit-ID: LUj9y8tSCNU
mobile/android/components/extensions/test/mochitest/test_ext_tabs_sendMessage.html
--- a/mobile/android/components/extensions/test/mochitest/test_ext_tabs_sendMessage.html
+++ b/mobile/android/components/extensions/test/mochitest/test_ext_tabs_sendMessage.html
@@ -231,12 +231,57 @@ add_task(function* tabsSendMessageNoExce
 
   yield Promise.all([
     extension.startup(),
     extension.awaitFinish("tabs.sendMessage"),
   ]);
 
   yield extension.unload();
 });
+
+
+add_task(async function tabsSendAndReceiveMessageTabId0() {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "permissions": ["tabs", "<all_urls>"],
+    },
+
+    async background() {
+      function contentScriptCode() {
+        browser.runtime.onMessage.addListener(msg => {
+          browser.test.assertEq(msg, "message to tabId 0",
+                                "Got the expected message from the background page");
+
+          return Promise.resolve("reply to background page");
+        });
+        browser.runtime.sendMessage("message from tabId 0");
+      }
+
+      await browser.runtime.onMessage.addListener(async (msg, sender) => {
+        browser.test.assertEq("message from tabId 0", msg,
+                              "Got the expected message from a content script");
+        browser.test.assertTrue(sender.tab,
+                              "Got a sender.tab object as expected");
+        browser.test.assertEq(0, sender.tab.id,
+                              "Got a sender.tab object with tab.id == 0");
+
+        const reply = await browser.tabs.sendMessage(0, "message to tabId 0");
+
+        browser.test.assertEq("reply to background page", reply);
+
+        browser.test.notifyPass("tabs.messaging.tab0");
+      });
+
+      await browser.tabs.executeScript(0, {code: `new ${contentScriptCode}`});
+    },
+  });
+
+  await extension.startup();
+
+  await extension.awaitFinish("tabs.messaging.tab0");
+
+  await extension.unload();
+});
+
 </script>
 
 </body>
 </html>