Bug 1453260 - run test script in specific page only r?aswan draft
authorRob Wu <rob@robwu.nl>
Wed, 11 Apr 2018 14:25:03 +0200
changeset 780429 56ce1fd19b1533011d30c5ac704a464a9d08ddb6
parent 780394 f6c3a0a19d82db25750d8badccd5cf37e79d028e
child 780436 8adf3b2b8fca9e7a86b1ce75e9b48a864a2b1207
push id105998
push userbmo:rob@robwu.nl
push dateWed, 11 Apr 2018 12:30:30 +0000
reviewersaswan
bugs1453260
milestone61.0a1
Bug 1453260 - run test script in specific page only r?aswan Use a more specific entry point for the test than "http://mochitest.test:8888" to make sure that the test is only started once, when the test opens a tab with the entry point. MozReview-Commit-ID: 7iAFREDuACu
browser/components/extensions/test/browser/browser_ext_connect_and_move_tabs.js
--- a/browser/components/extensions/test/browser/browser_ext_connect_and_move_tabs.js
+++ b/browser/components/extensions/test/browser/browser_ext_connect_and_move_tabs.js
@@ -6,27 +6,27 @@
 // prematurely disconnected as the underlying message managers change when a
 // tab is moved between windows.
 
 function loadExtension() {
   return ExtensionTestUtils.loadExtension({
     manifest: {
       "content_scripts": [{
         "js": ["script.js"],
-        "matches": ["http://mochi.test/"],
+        "matches": ["http://mochi.test/?discoTest"],
       }],
     },
     background() {
       browser.runtime.onConnect.addListener((port) => {
         port.onDisconnect.addListener(() => {
           browser.test.fail("onDisconnect should not fire because the port is to be closed from this side");
           browser.test.sendMessage("port_disconnected");
         });
         port.onMessage.addListener(async msg => {
-          browser.test.assertEq("connect_from_contentscript", msg, "expected message");
+          browser.test.assertEq("connect_from_script", msg, "expected message");
           // Move a tab to a new window and back. Regression test for bugzil.la/1448674
           let {windowId, id: tabId, index} = port.sender.tab;
           await browser.windows.create({tabId});
           await browser.tabs.move(tabId, {index, windowId});
           await browser.windows.create({tabId});
           await browser.tabs.move(tabId, {index, windowId});
           try {
             // When the port is unexpectedly disconnected, postMessage will throw an error.
@@ -60,26 +60,26 @@ function loadExtension() {
         port.onMessage.addListener(msg => {
           browser.test.assertEq("ping", msg, "expected message");
           browser.test.sendMessage("port_ping_ponged_before_disconnect");
           port.onDisconnect.addListener(() => {
             browser.test.sendMessage("port_disconnected");
           });
           browser.runtime.sendMessage("disconnect-me");
         });
-        port.postMessage("connect_from_contentscript");
+        port.postMessage("connect_from_script");
       },
     },
   });
 }
 
 add_task(async function contentscript_connect_and_move_tabs() {
   let extension = loadExtension();
   await extension.startup();
-  await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://mochi.test:8888/");
+  await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://mochi.test:8888/?discoTest");
   await extension.awaitMessage("port_ping_ponged_before_disconnect");
   await extension.awaitMessage("port_disconnected");
   // Must use gBrowser.selectedTab instead of the return value of
   // BrowserTestUtils.openNewForegroundTab because the latter does not refer to
   // the tab because the tab is moved between windows during the test.
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
   await extension.unload();
 });