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
--- 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();
});