Bug 1403349 - Split webNavigation onCreatedNavigationTarget tests to prevent timeouts on linux32 debug. r=aswan, a=ritu
authorLuca Greco <lgreco@mozilla.com>
Fri, 13 Oct 2017 18:19:47 +0200
changeset 432695 3d0ba43d0afd86b10a25213390180c8019a103c3
parent 432694 5ad5a62c35d20b99dfa7b4bcc54ccf76f67a2651
child 432696 86534d5daeef8066928eef910d6d5c60442b24b0
push id8029
push userryanvm@gmail.com
push dateMon, 23 Oct 2017 18:08:40 +0000
treeherdermozilla-beta@86534d5daeef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, ritu
bugs1403349
milestone57.0
Bug 1403349 - Split webNavigation onCreatedNavigationTarget tests to prevent timeouts on linux32 debug. r=aswan, a=ritu MozReview-Commit-ID: 50JLocTVvfu
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget.js
browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_contextmenu.js
browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_named_window.js
browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_subframe_window_open.js
browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_window_open.js
browser/components/extensions/test/browser/head_webNavigation.js
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -1,13 +1,14 @@
 [DEFAULT]
 support-files =
   head.js
   head_pageAction.js
   head_sessions.js
+  head_webNavigation.js
   profilerSymbols.sjs
   context.html
   context_frame.html
   ctxmenu-image.png
   context_tabs_onUpdated_page.html
   context_tabs_onUpdated_iframe.html
   file_clearplugindata.html
   file_find_frames.html
@@ -166,16 +167,18 @@ skip-if = true # Bug 1398514
 [browser_ext_themes_validation.js]
 [browser_ext_url_overrides_newtab.js]
 [browser_ext_user_events.js]
 [browser_ext_webRequest.js]
 [browser_ext_webNavigation_frameId0.js]
 [browser_ext_webNavigation_getFrames.js]
 [browser_ext_webNavigation_onCreatedNavigationTarget.js]
 [browser_ext_webNavigation_onCreatedNavigationTarget_contextmenu.js]
+[browser_ext_webNavigation_onCreatedNavigationTarget_named_window.js]
+[browser_ext_webNavigation_onCreatedNavigationTarget_subframe_window_open.js]
 [browser_ext_webNavigation_onCreatedNavigationTarget_window_open.js]
 [browser_ext_webNavigation_urlbar_transitions.js]
 [browser_ext_windows.js]
 [browser_ext_windows_create.js]
 tags = fullscreen
 [browser_ext_windows_create_params.js]
 [browser_ext_windows_create_tabId.js]
 [browser_ext_windows_create_url.js]
--- a/browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget.js
+++ b/browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget.js
@@ -1,15 +1,14 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-const BASE_URL = "http://mochi.test:8888/browser/browser/components/extensions/test/browser";
-const SOURCE_PAGE = `${BASE_URL}/webNav_createdTargetSource.html`;
-const OPENED_PAGE = `${BASE_URL}/webNav_createdTarget.html`;
+Services.scriptloader.loadSubScript(new URL("head_webNavigation.js", gTestPath).href,
+                                    this);
 
 async function background() {
   const tabs = await browser.tabs.query({active: true, currentWindow: true});
   const sourceTabId = tabs[0].id;
 
   const sourceTabFrames = await browser.webNavigation.getAllFrames({tabId: sourceTabId});
 
   browser.webNavigation.onCreatedNavigationTarget.addListener((msg) => {
@@ -29,83 +28,65 @@ async function background() {
     browser.test.sendMessage("tabsOnCreated", tab.id);
   });
 
   browser.test.sendMessage("expectedSourceTab", {
     sourceTabId, sourceTabFrames,
   });
 }
 
-async function runTestCase({extension, openNavTarget, expectedWebNavProps}) {
-  await openNavTarget();
-
-  const webNavMsg = await extension.awaitMessage("webNavOnCreated");
-  const createdTabId = await extension.awaitMessage("tabsOnCreated");
-  const completedNavMsg = await extension.awaitMessage("webNavOnCompleted");
-
-  let {sourceTabId, sourceFrameId, url} = expectedWebNavProps;
-
-  is(webNavMsg.tabId, createdTabId, "Got the expected tabId property");
-  is(webNavMsg.sourceTabId, sourceTabId, "Got the expected sourceTabId property");
-  is(webNavMsg.sourceFrameId, sourceFrameId, "Got the expected sourceFrameId property");
-  is(webNavMsg.url, url, "Got the expected url property");
-
-  is(completedNavMsg.tabId, createdTabId, "Got the expected webNavigation.onCompleted tabId property");
-  is(completedNavMsg.url, url, "Got the expected webNavigation.onCompleted url property");
-}
-
 add_task(async function test_on_created_navigation_target_from_mouse_click() {
   const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
 
   const extension = ExtensionTestUtils.loadExtension({
     background,
     manifest: {
       permissions: ["webNavigation"],
     },
   });
 
   await extension.startup();
 
   const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
 
   info("Open link in a new tab using Ctrl-click");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       BrowserTestUtils.synthesizeMouseAtCenter("#test-create-new-tab-from-mouse-click",
                                                {ctrlKey: true, metaKey: true},
                                                tab.linkedBrowser);
     },
     expectedWebNavProps: {
       sourceTabId: expectedSourceTab.sourceTabId,
       sourceFrameId: 0,
       url: `${OPENED_PAGE}#new-tab-from-mouse-click`,
     },
   });
 
   info("Open link in a new window using Shift-click");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       BrowserTestUtils.synthesizeMouseAtCenter("#test-create-new-window-from-mouse-click",
                                                {shiftKey: true},
                                                tab.linkedBrowser);
     },
     expectedWebNavProps: {
       sourceTabId: expectedSourceTab.sourceTabId,
       sourceFrameId: 0,
       url: `${OPENED_PAGE}#new-window-from-mouse-click`,
     },
   });
 
   info("Open link with target=\"_blank\" in a new tab using click");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       BrowserTestUtils.synthesizeMouseAtCenter("#test-create-new-tab-from-targetblank-click",
                                                {},
                                                tab.linkedBrowser);
     },
     expectedWebNavProps: {
       sourceTabId: expectedSourceTab.sourceTabId,
@@ -130,17 +111,17 @@ add_task(async function test_on_created_
   });
 
   await extension.startup();
 
   const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
 
   info("Open a subframe link in a new tab using Ctrl-click");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       BrowserTestUtils.synthesizeMouseAtCenter(function() {
         // This code runs as a framescript in the child process and it returns the
         // target link in the subframe.
         return this.content.frames[0].document // eslint-disable-line mozilla/no-cpows-in-tests
           .querySelector("#test-create-new-tab-from-mouse-click-subframe");
       }, {ctrlKey: true, metaKey: true}, tab.linkedBrowser);
@@ -149,17 +130,17 @@ add_task(async function test_on_created_
       sourceTabId: expectedSourceTab.sourceTabId,
       sourceFrameId: expectedSourceTab.sourceTabFrames[1].frameId,
       url: `${OPENED_PAGE}#new-tab-from-mouse-click-subframe`,
     },
   });
 
   info("Open a subframe link in a new window using Shift-click");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       BrowserTestUtils.synthesizeMouseAtCenter(function() {
         // This code runs as a framescript in the child process and it returns the
         // target link in the subframe.
         return this.content.frames[0].document // eslint-disable-line mozilla/no-cpows-in-tests
                       .querySelector("#test-create-new-window-from-mouse-click-subframe");
       }, {shiftKey: true}, tab.linkedBrowser);
@@ -168,17 +149,17 @@ add_task(async function test_on_created_
       sourceTabId: expectedSourceTab.sourceTabId,
       sourceFrameId: expectedSourceTab.sourceTabFrames[1].frameId,
       url: `${OPENED_PAGE}#new-window-from-mouse-click-subframe`,
     },
   });
 
   info("Open a subframe link with target=\"_blank\" in a new tab using click");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       BrowserTestUtils.synthesizeMouseAtCenter(function() {
         // This code runs as a framescript in the child process and it returns the
         // target link in the subframe.
         return this.content.frames[0].document // eslint-disable-line mozilla/no-cpows-in-tests
           .querySelector("#test-create-new-tab-from-targetblank-click-subframe");
       }, {}, tab.linkedBrowser);
@@ -189,9 +170,8 @@ add_task(async function test_on_created_
       url: `${OPENED_PAGE}#new-tab-from-targetblank-click-subframe`,
     },
   });
 
   await BrowserTestUtils.removeTab(tab);
 
   await extension.unload();
 });
-
--- a/browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_contextmenu.js
+++ b/browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_contextmenu.js
@@ -1,15 +1,22 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-const BASE_URL = "http://mochi.test:8888/browser/browser/components/extensions/test/browser";
-const SOURCE_PAGE = `${BASE_URL}/webNav_createdTargetSource.html`;
-const OPENED_PAGE = `${BASE_URL}/webNav_createdTarget.html`;
+Services.scriptloader.loadSubScript(new URL("head_webNavigation.js", gTestPath).href,
+                                    this);
+
+async function clickContextMenuItem({pageElementSelector, contextMenuItemLabel}) {
+  const contentAreaContextMenu = await openContextMenu(pageElementSelector);
+  const item = contentAreaContextMenu.getElementsByAttribute("label", contextMenuItemLabel);
+  is(item.length, 1, `found contextMenu item for "${contextMenuItemLabel}"`);
+  item[0].click();
+  await closeContextMenu();
+}
 
 async function background() {
   const tabs = await browser.tabs.query({active: true, currentWindow: true});
   const sourceTabId = tabs[0].id;
 
   const sourceTabFrames = await browser.webNavigation.getAllFrames({tabId: sourceTabId});
 
   browser.webNavigation.onCreatedNavigationTarget.addListener((msg) => {
@@ -29,76 +36,50 @@ async function background() {
     browser.test.sendMessage("tabsOnCreated", tab.id);
   });
 
   browser.test.sendMessage("expectedSourceTab", {
     sourceTabId, sourceTabFrames,
   });
 }
 
-async function runTestCase({extension, openNavTarget, expectedWebNavProps}) {
-  await openNavTarget();
-
-  const webNavMsg = await extension.awaitMessage("webNavOnCreated");
-  const createdTabId = await extension.awaitMessage("tabsOnCreated");
-  const completedNavMsg = await extension.awaitMessage("webNavOnCompleted");
-
-  let {sourceTabId, sourceFrameId, url} = expectedWebNavProps;
-
-  is(webNavMsg.tabId, createdTabId, "Got the expected tabId property");
-  is(webNavMsg.sourceTabId, sourceTabId, "Got the expected sourceTabId property");
-  is(webNavMsg.sourceFrameId, sourceFrameId, "Got the expected sourceFrameId property");
-  is(webNavMsg.url, url, "Got the expected url property");
-
-  is(completedNavMsg.tabId, createdTabId, "Got the expected webNavigation.onCompleted tabId property");
-  is(completedNavMsg.url, url, "Got the expected webNavigation.onCompleted url property");
-}
-
-async function clickContextMenuItem({pageElementSelector, contextMenuItemLabel}) {
-  const contentAreaContextMenu = await openContextMenu(pageElementSelector);
-  const item = contentAreaContextMenu.getElementsByAttribute("label", contextMenuItemLabel);
-  is(item.length, 1, `found contextMenu item for "${contextMenuItemLabel}"`);
-  item[0].click();
-  await closeContextMenu();
-}
-
 add_task(async function test_on_created_navigation_target_from_context_menu() {
   const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
 
   const extension = ExtensionTestUtils.loadExtension({
     background,
     manifest: {
       permissions: ["webNavigation"],
     },
   });
 
   await extension.startup();
 
   const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
 
   info("Open link in a new tab from the context menu");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     async openNavTarget() {
       await clickContextMenuItem({
         pageElementSelector: "#test-create-new-tab-from-context-menu",
         contextMenuItemLabel: "Open Link in New Tab",
       });
     },
     expectedWebNavProps: {
       sourceTabId: expectedSourceTab.sourceTabId,
       sourceFrameId: 0,
       url: `${OPENED_PAGE}#new-tab-from-context-menu`,
     },
   });
 
   info("Open link in a new window from the context menu");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     async openNavTarget() {
       await clickContextMenuItem({
         pageElementSelector: "#test-create-new-window-from-context-menu",
         contextMenuItemLabel: "Open Link in New Window",
       });
     },
     expectedWebNavProps: {
@@ -124,17 +105,17 @@ add_task(async function test_on_created_
   });
 
   await extension.startup();
 
   const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
 
   info("Open a subframe link in a new tab from the context menu");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     async openNavTarget() {
       await clickContextMenuItem({
         pageElementSelector: function() {
           // This code runs as a framescript in the child process and it returns the
           // target link in the subframe.
           return this.content.frames[0] // eslint-disable-line mozilla/no-cpows-in-tests
             .document.querySelector("#test-create-new-tab-from-context-menu-subframe");
@@ -146,17 +127,17 @@ add_task(async function test_on_created_
       sourceTabId: expectedSourceTab.sourceTabId,
       sourceFrameId: expectedSourceTab.sourceTabFrames[1].frameId,
       url: `${OPENED_PAGE}#new-tab-from-context-menu-subframe`,
     },
   });
 
   info("Open a subframe link in a new window from the context menu");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     async openNavTarget() {
       await clickContextMenuItem({
         pageElementSelector: function() {
           // This code runs as a framescript in the child process and it returns the
           // target link in the subframe.
           return this.content.frames[0] // eslint-disable-line mozilla/no-cpows-in-tests
             .document.querySelector("#test-create-new-window-from-context-menu-subframe");
copy from browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_window_open.js
copy to browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_named_window.js
--- a/browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_window_open.js
+++ b/browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_named_window.js
@@ -1,15 +1,14 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-const BASE_URL = "http://mochi.test:8888/browser/browser/components/extensions/test/browser";
-const SOURCE_PAGE = `${BASE_URL}/webNav_createdTargetSource.html`;
-const OPENED_PAGE = `${BASE_URL}/webNav_createdTarget.html`;
+Services.scriptloader.loadSubScript(new URL("head_webNavigation.js", gTestPath).href,
+                                    this);
 
 async function background() {
   const tabs = await browser.tabs.query({active: true, currentWindow: true});
   const sourceTabId = tabs[0].id;
 
   const sourceTabFrames = await browser.webNavigation.getAllFrames({tabId: sourceTabId});
 
   browser.webNavigation.onCreatedNavigationTarget.addListener((msg) => {
@@ -35,224 +34,16 @@ async function background() {
     }
   });
 
   browser.test.sendMessage("expectedSourceTab", {
     sourceTabId, sourceTabFrames,
   });
 }
 
-async function runTestCase({extension, openNavTarget, expectedWebNavProps}) {
-  await openNavTarget();
-
-  const webNavMsg = await extension.awaitMessage("webNavOnCreated");
-  const createdTabId = await extension.awaitMessage("tabsOnCreated");
-  const completedNavMsg = await extension.awaitMessage("webNavOnCompleted");
-
-  let {sourceTabId, sourceFrameId, url} = expectedWebNavProps;
-
-  is(webNavMsg.tabId, createdTabId, "Got the expected tabId property");
-  is(webNavMsg.sourceTabId, sourceTabId, "Got the expected sourceTabId property");
-  is(webNavMsg.sourceFrameId, sourceFrameId, "Got the expected sourceFrameId property");
-  is(webNavMsg.url, url, "Got the expected url property");
-
-  is(completedNavMsg.tabId, createdTabId, "Got the expected webNavigation.onCompleted tabId property");
-  is(completedNavMsg.url, url, "Got the expected webNavigation.onCompleted url property");
-}
-
-// Test that there are no pending createdNavigationTarget messages still tracked
-// in WebNavigation.jsm (to be called before the extension is unloaded, because
-// once the last extension which have subscribed a webNavigation event is unloaded
-// all the pending created navigation target data is completely cleared).
-function assertNoPendingCreatedNavigationTargetData() {
-  const {Manager} = Cu.import("resource://gre/modules/WebNavigation.jsm", {});
-  Assert.equal(Manager.createdNavigationTargetByOuterWindowId.size, 0,
-               "There should be no pending createdNavigationTarget messages in WebNavigation");
-}
-
-add_task(async function test_window_open() {
-  const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
-
-  gBrowser.selectedTab = tab1;
-
-  const extension = ExtensionTestUtils.loadExtension({
-    background,
-    manifest: {
-      permissions: ["webNavigation", "tabs", "<all_urls>"],
-    },
-  });
-
-  await extension.startup();
-
-  const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
-
-  info("open a url in a new tab from a window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `window.open("${OPENED_PAGE}#new-tab-from-window-open"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: 0,
-      url: `${OPENED_PAGE}#new-tab-from-window-open`,
-    },
-  });
-
-  info("open a url in a new window from a window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `window.open("${OPENED_PAGE}#new-win-from-window-open", "_blank", "toolbar=0"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: 0,
-      url: `${OPENED_PAGE}#new-win-from-window-open`,
-    },
-  });
-
-  assertNoPendingCreatedNavigationTargetData();
-
-  await BrowserTestUtils.removeTab(tab1);
-
-  await extension.unload();
-});
-
-add_task(async function test_window_open_from_subframe() {
-  const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
-
-  gBrowser.selectedTab = tab1;
-
-  const extension = ExtensionTestUtils.loadExtension({
-    background,
-    manifest: {
-      permissions: ["webNavigation", "tabs", "<all_urls>"],
-    },
-  });
-
-  await extension.startup();
-
-  const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
-
-  info("open a url in a new tab from subframe window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `document.querySelector('iframe').contentWindow.open("${OPENED_PAGE}#new-tab-from-window-open-subframe"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: expectedSourceTab.sourceTabFrames[1].frameId,
-      url: `${OPENED_PAGE}#new-tab-from-window-open-subframe`,
-    },
-  });
-
-  info("open a url in a new window from subframe window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `document.querySelector('iframe').contentWindow.open("${OPENED_PAGE}#new-win-from-window-open-subframe", "_blank", "toolbar=0"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: expectedSourceTab.sourceTabFrames[1].frameId,
-      url: `${OPENED_PAGE}#new-win-from-window-open-subframe`,
-    },
-  });
-
-  assertNoPendingCreatedNavigationTargetData();
-
-  await BrowserTestUtils.removeTab(tab1);
-
-  await extension.unload();
-});
-
-add_task(async function test_window_open_close_from_browserAction_popup() {
-  const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
-
-  gBrowser.selectedTab = tab1;
-
-  function popup() {
-    window.open("", "_self").close();
-
-    browser.test.sendMessage("browserAction_popup_executed");
-  }
-
-  const extension = ExtensionTestUtils.loadExtension({
-    background,
-    manifest: {
-      browser_action: {
-        default_popup: "popup.html",
-      },
-      permissions: ["webNavigation", "tabs", "<all_urls>"],
-    },
-    files: {
-      "popup.html": `<!DOCTYPE html>
-        <html>
-          <head>
-            <meta charset="utf-8">
-          </head>
-          <body>
-            <script src="popup.js"></script>
-          </body>
-        </html>
-      `,
-      "popup.js": popup,
-    },
-  });
-
-  await extension.startup();
-
-  const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
-
-  clickBrowserAction(extension);
-
-  await extension.awaitMessage("browserAction_popup_executed");
-
-  info("open a url in a new tab from a window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `window.open("${OPENED_PAGE}#new-tab-from-window-open"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: 0,
-      url: `${OPENED_PAGE}#new-tab-from-window-open`,
-    },
-  });
-
-  assertNoPendingCreatedNavigationTargetData();
-
-  await BrowserTestUtils.removeTab(tab1);
-
-  await extension.unload();
-});
-
 add_task(async function test_window_open_in_named_win() {
   const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
 
   gBrowser.selectedTab = tab1;
 
   const extension = ExtensionTestUtils.loadExtension({
     background,
     manifest: {
@@ -261,34 +52,34 @@ add_task(async function test_window_open
   });
 
   await extension.startup();
 
   const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
 
   info("open a url in a new named window from a window.open call");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       extension.sendMessage({
         type: "execute-contentscript",
         code: `window.open("${OPENED_PAGE}#new-named-window-open", "TestWinName"); true;`,
       });
     },
     expectedWebNavProps: {
       sourceTabId: expectedSourceTab.sourceTabId,
       sourceFrameId: 0,
       url: `${OPENED_PAGE}#new-named-window-open`,
     },
   });
 
   info("open a url in an existent named window from a window.open call");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       extension.sendMessage({
         type: "execute-contentscript",
         code: `window.open("${OPENED_PAGE}#existent-named-window-open", "TestWinName"); true;`,
       });
     },
     expectedWebNavProps: {
copy from browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_window_open.js
copy to browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_subframe_window_open.js
--- a/browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_window_open.js
+++ b/browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_subframe_window_open.js
@@ -1,15 +1,14 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-const BASE_URL = "http://mochi.test:8888/browser/browser/components/extensions/test/browser";
-const SOURCE_PAGE = `${BASE_URL}/webNav_createdTargetSource.html`;
-const OPENED_PAGE = `${BASE_URL}/webNav_createdTarget.html`;
+Services.scriptloader.loadSubScript(new URL("head_webNavigation.js", gTestPath).href,
+                                    this);
 
 async function background() {
   const tabs = await browser.tabs.query({active: true, currentWindow: true});
   const sourceTabId = tabs[0].id;
 
   const sourceTabFrames = await browser.webNavigation.getAllFrames({tabId: sourceTabId});
 
   browser.webNavigation.onCreatedNavigationTarget.addListener((msg) => {
@@ -35,101 +34,16 @@ async function background() {
     }
   });
 
   browser.test.sendMessage("expectedSourceTab", {
     sourceTabId, sourceTabFrames,
   });
 }
 
-async function runTestCase({extension, openNavTarget, expectedWebNavProps}) {
-  await openNavTarget();
-
-  const webNavMsg = await extension.awaitMessage("webNavOnCreated");
-  const createdTabId = await extension.awaitMessage("tabsOnCreated");
-  const completedNavMsg = await extension.awaitMessage("webNavOnCompleted");
-
-  let {sourceTabId, sourceFrameId, url} = expectedWebNavProps;
-
-  is(webNavMsg.tabId, createdTabId, "Got the expected tabId property");
-  is(webNavMsg.sourceTabId, sourceTabId, "Got the expected sourceTabId property");
-  is(webNavMsg.sourceFrameId, sourceFrameId, "Got the expected sourceFrameId property");
-  is(webNavMsg.url, url, "Got the expected url property");
-
-  is(completedNavMsg.tabId, createdTabId, "Got the expected webNavigation.onCompleted tabId property");
-  is(completedNavMsg.url, url, "Got the expected webNavigation.onCompleted url property");
-}
-
-// Test that there are no pending createdNavigationTarget messages still tracked
-// in WebNavigation.jsm (to be called before the extension is unloaded, because
-// once the last extension which have subscribed a webNavigation event is unloaded
-// all the pending created navigation target data is completely cleared).
-function assertNoPendingCreatedNavigationTargetData() {
-  const {Manager} = Cu.import("resource://gre/modules/WebNavigation.jsm", {});
-  Assert.equal(Manager.createdNavigationTargetByOuterWindowId.size, 0,
-               "There should be no pending createdNavigationTarget messages in WebNavigation");
-}
-
-add_task(async function test_window_open() {
-  const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
-
-  gBrowser.selectedTab = tab1;
-
-  const extension = ExtensionTestUtils.loadExtension({
-    background,
-    manifest: {
-      permissions: ["webNavigation", "tabs", "<all_urls>"],
-    },
-  });
-
-  await extension.startup();
-
-  const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
-
-  info("open a url in a new tab from a window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `window.open("${OPENED_PAGE}#new-tab-from-window-open"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: 0,
-      url: `${OPENED_PAGE}#new-tab-from-window-open`,
-    },
-  });
-
-  info("open a url in a new window from a window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `window.open("${OPENED_PAGE}#new-win-from-window-open", "_blank", "toolbar=0"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: 0,
-      url: `${OPENED_PAGE}#new-win-from-window-open`,
-    },
-  });
-
-  assertNoPendingCreatedNavigationTargetData();
-
-  await BrowserTestUtils.removeTab(tab1);
-
-  await extension.unload();
-});
-
 add_task(async function test_window_open_from_subframe() {
   const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
 
   gBrowser.selectedTab = tab1;
 
   const extension = ExtensionTestUtils.loadExtension({
     background,
     manifest: {
@@ -138,34 +52,34 @@ add_task(async function test_window_open
   });
 
   await extension.startup();
 
   const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
 
   info("open a url in a new tab from subframe window.open call");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       extension.sendMessage({
         type: "execute-contentscript",
         code: `document.querySelector('iframe').contentWindow.open("${OPENED_PAGE}#new-tab-from-window-open-subframe"); true;`,
       });
     },
     expectedWebNavProps: {
       sourceTabId: expectedSourceTab.sourceTabId,
       sourceFrameId: expectedSourceTab.sourceTabFrames[1].frameId,
       url: `${OPENED_PAGE}#new-tab-from-window-open-subframe`,
     },
   });
 
   info("open a url in a new window from subframe window.open call");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       extension.sendMessage({
         type: "execute-contentscript",
         code: `document.querySelector('iframe').contentWindow.open("${OPENED_PAGE}#new-win-from-window-open-subframe", "_blank", "toolbar=0"); true;`,
       });
     },
     expectedWebNavProps: {
@@ -221,17 +135,17 @@ add_task(async function test_window_open
   const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
 
   clickBrowserAction(extension);
 
   await extension.awaitMessage("browserAction_popup_executed");
 
   info("open a url in a new tab from a window.open call");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       extension.sendMessage({
         type: "execute-contentscript",
         code: `window.open("${OPENED_PAGE}#new-tab-from-window-open"); true;`,
       });
     },
     expectedWebNavProps: {
@@ -242,65 +156,8 @@ add_task(async function test_window_open
   });
 
   assertNoPendingCreatedNavigationTargetData();
 
   await BrowserTestUtils.removeTab(tab1);
 
   await extension.unload();
 });
-
-add_task(async function test_window_open_in_named_win() {
-  const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
-
-  gBrowser.selectedTab = tab1;
-
-  const extension = ExtensionTestUtils.loadExtension({
-    background,
-    manifest: {
-      permissions: ["webNavigation", "tabs", "<all_urls>"],
-    },
-  });
-
-  await extension.startup();
-
-  const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
-
-  info("open a url in a new named window from a window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `window.open("${OPENED_PAGE}#new-named-window-open", "TestWinName"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: 0,
-      url: `${OPENED_PAGE}#new-named-window-open`,
-    },
-  });
-
-  info("open a url in an existent named window from a window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `window.open("${OPENED_PAGE}#existent-named-window-open", "TestWinName"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: 0,
-      url: `${OPENED_PAGE}#existent-named-window-open`,
-    },
-  });
-
-  assertNoPendingCreatedNavigationTargetData();
-
-  await BrowserTestUtils.removeTab(tab1);
-
-  await extension.unload();
-});
--- a/browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_window_open.js
+++ b/browser/components/extensions/test/browser/browser_ext_webNavigation_onCreatedNavigationTarget_window_open.js
@@ -1,15 +1,14 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-const BASE_URL = "http://mochi.test:8888/browser/browser/components/extensions/test/browser";
-const SOURCE_PAGE = `${BASE_URL}/webNav_createdTargetSource.html`;
-const OPENED_PAGE = `${BASE_URL}/webNav_createdTarget.html`;
+Services.scriptloader.loadSubScript(new URL("head_webNavigation.js", gTestPath).href,
+                                    this);
 
 async function background() {
   const tabs = await browser.tabs.query({active: true, currentWindow: true});
   const sourceTabId = tabs[0].id;
 
   const sourceTabFrames = await browser.webNavigation.getAllFrames({tabId: sourceTabId});
 
   browser.webNavigation.onCreatedNavigationTarget.addListener((msg) => {
@@ -35,44 +34,16 @@ async function background() {
     }
   });
 
   browser.test.sendMessage("expectedSourceTab", {
     sourceTabId, sourceTabFrames,
   });
 }
 
-async function runTestCase({extension, openNavTarget, expectedWebNavProps}) {
-  await openNavTarget();
-
-  const webNavMsg = await extension.awaitMessage("webNavOnCreated");
-  const createdTabId = await extension.awaitMessage("tabsOnCreated");
-  const completedNavMsg = await extension.awaitMessage("webNavOnCompleted");
-
-  let {sourceTabId, sourceFrameId, url} = expectedWebNavProps;
-
-  is(webNavMsg.tabId, createdTabId, "Got the expected tabId property");
-  is(webNavMsg.sourceTabId, sourceTabId, "Got the expected sourceTabId property");
-  is(webNavMsg.sourceFrameId, sourceFrameId, "Got the expected sourceFrameId property");
-  is(webNavMsg.url, url, "Got the expected url property");
-
-  is(completedNavMsg.tabId, createdTabId, "Got the expected webNavigation.onCompleted tabId property");
-  is(completedNavMsg.url, url, "Got the expected webNavigation.onCompleted url property");
-}
-
-// Test that there are no pending createdNavigationTarget messages still tracked
-// in WebNavigation.jsm (to be called before the extension is unloaded, because
-// once the last extension which have subscribed a webNavigation event is unloaded
-// all the pending created navigation target data is completely cleared).
-function assertNoPendingCreatedNavigationTargetData() {
-  const {Manager} = Cu.import("resource://gre/modules/WebNavigation.jsm", {});
-  Assert.equal(Manager.createdNavigationTargetByOuterWindowId.size, 0,
-               "There should be no pending createdNavigationTarget messages in WebNavigation");
-}
-
 add_task(async function test_window_open() {
   const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
 
   gBrowser.selectedTab = tab1;
 
   const extension = ExtensionTestUtils.loadExtension({
     background,
     manifest: {
@@ -81,34 +52,34 @@ add_task(async function test_window_open
   });
 
   await extension.startup();
 
   const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
 
   info("open a url in a new tab from a window.open call");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       extension.sendMessage({
         type: "execute-contentscript",
         code: `window.open("${OPENED_PAGE}#new-tab-from-window-open"); true;`,
       });
     },
     expectedWebNavProps: {
       sourceTabId: expectedSourceTab.sourceTabId,
       sourceFrameId: 0,
       url: `${OPENED_PAGE}#new-tab-from-window-open`,
     },
   });
 
   info("open a url in a new window from a window.open call");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       extension.sendMessage({
         type: "execute-contentscript",
         code: `window.open("${OPENED_PAGE}#new-win-from-window-open", "_blank", "toolbar=0"); true;`,
       });
     },
     expectedWebNavProps: {
@@ -120,73 +91,16 @@ add_task(async function test_window_open
 
   assertNoPendingCreatedNavigationTargetData();
 
   await BrowserTestUtils.removeTab(tab1);
 
   await extension.unload();
 });
 
-add_task(async function test_window_open_from_subframe() {
-  const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
-
-  gBrowser.selectedTab = tab1;
-
-  const extension = ExtensionTestUtils.loadExtension({
-    background,
-    manifest: {
-      permissions: ["webNavigation", "tabs", "<all_urls>"],
-    },
-  });
-
-  await extension.startup();
-
-  const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
-
-  info("open a url in a new tab from subframe window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `document.querySelector('iframe').contentWindow.open("${OPENED_PAGE}#new-tab-from-window-open-subframe"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: expectedSourceTab.sourceTabFrames[1].frameId,
-      url: `${OPENED_PAGE}#new-tab-from-window-open-subframe`,
-    },
-  });
-
-  info("open a url in a new window from subframe window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `document.querySelector('iframe').contentWindow.open("${OPENED_PAGE}#new-win-from-window-open-subframe", "_blank", "toolbar=0"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: expectedSourceTab.sourceTabFrames[1].frameId,
-      url: `${OPENED_PAGE}#new-win-from-window-open-subframe`,
-    },
-  });
-
-  assertNoPendingCreatedNavigationTargetData();
-
-  await BrowserTestUtils.removeTab(tab1);
-
-  await extension.unload();
-});
-
 add_task(async function test_window_open_close_from_browserAction_popup() {
   const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
 
   gBrowser.selectedTab = tab1;
 
   function popup() {
     window.open("", "_self").close();
 
@@ -221,17 +135,17 @@ add_task(async function test_window_open
   const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
 
   clickBrowserAction(extension);
 
   await extension.awaitMessage("browserAction_popup_executed");
 
   info("open a url in a new tab from a window.open call");
 
-  await runTestCase({
+  await runCreatedNavigationTargetTest({
     extension,
     openNavTarget() {
       extension.sendMessage({
         type: "execute-contentscript",
         code: `window.open("${OPENED_PAGE}#new-tab-from-window-open"); true;`,
       });
     },
     expectedWebNavProps: {
@@ -242,65 +156,8 @@ add_task(async function test_window_open
   });
 
   assertNoPendingCreatedNavigationTargetData();
 
   await BrowserTestUtils.removeTab(tab1);
 
   await extension.unload();
 });
-
-add_task(async function test_window_open_in_named_win() {
-  const tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SOURCE_PAGE);
-
-  gBrowser.selectedTab = tab1;
-
-  const extension = ExtensionTestUtils.loadExtension({
-    background,
-    manifest: {
-      permissions: ["webNavigation", "tabs", "<all_urls>"],
-    },
-  });
-
-  await extension.startup();
-
-  const expectedSourceTab = await extension.awaitMessage("expectedSourceTab");
-
-  info("open a url in a new named window from a window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `window.open("${OPENED_PAGE}#new-named-window-open", "TestWinName"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: 0,
-      url: `${OPENED_PAGE}#new-named-window-open`,
-    },
-  });
-
-  info("open a url in an existent named window from a window.open call");
-
-  await runTestCase({
-    extension,
-    openNavTarget() {
-      extension.sendMessage({
-        type: "execute-contentscript",
-        code: `window.open("${OPENED_PAGE}#existent-named-window-open", "TestWinName"); true;`,
-      });
-    },
-    expectedWebNavProps: {
-      sourceTabId: expectedSourceTab.sourceTabId,
-      sourceFrameId: 0,
-      url: `${OPENED_PAGE}#existent-named-window-open`,
-    },
-  });
-
-  assertNoPendingCreatedNavigationTargetData();
-
-  await BrowserTestUtils.removeTab(tab1);
-
-  await extension.unload();
-});
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/head_webNavigation.js
@@ -0,0 +1,39 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+/* exported BASE_URL, SOURCE_PAGE, OPENED_PAGE,
+   runCreatedNavigationTargetTest, assertNoPendingCreatedNavigationTargetData */
+
+const BASE_URL = "http://mochi.test:8888/browser/browser/components/extensions/test/browser";
+const SOURCE_PAGE = `${BASE_URL}/webNav_createdTargetSource.html`;
+const OPENED_PAGE = `${BASE_URL}/webNav_createdTarget.html`;
+
+async function runCreatedNavigationTargetTest({extension, openNavTarget, expectedWebNavProps}) {
+  await openNavTarget();
+
+  const webNavMsg = await extension.awaitMessage("webNavOnCreated");
+  const createdTabId = await extension.awaitMessage("tabsOnCreated");
+  const completedNavMsg = await extension.awaitMessage("webNavOnCompleted");
+
+  let {sourceTabId, sourceFrameId, url} = expectedWebNavProps;
+
+  is(webNavMsg.tabId, createdTabId, "Got the expected tabId property");
+  is(webNavMsg.sourceTabId, sourceTabId, "Got the expected sourceTabId property");
+  is(webNavMsg.sourceFrameId, sourceFrameId, "Got the expected sourceFrameId property");
+  is(webNavMsg.url, url, "Got the expected url property");
+
+  is(completedNavMsg.tabId, createdTabId, "Got the expected webNavigation.onCompleted tabId property");
+  is(completedNavMsg.url, url, "Got the expected webNavigation.onCompleted url property");
+}
+
+
+// Test that there are no pending createdNavigationTarget messages still tracked
+// in WebNavigation.jsm (to be called before the extension is unloaded, because
+// once the last extension which have subscribed a webNavigation event is unloaded
+// all the pending created navigation target data is completely cleared).
+function assertNoPendingCreatedNavigationTargetData() {
+  const {Manager} = Cu.import("resource://gre/modules/WebNavigation.jsm", {});
+  Assert.equal(Manager.createdNavigationTargetByOuterWindowId.size, 0,
+               "There should be no pending createdNavigationTarget messages in WebNavigation");
+}