Bug 1365032 - Part 2: Add a test for propagating properties of windows across window.open, r=smaug
authorMichael Layzell <michael@thelayzells.com>
Tue, 06 Jun 2017 14:24:00 -0400
changeset 410851 7df7e414a2be891a6bd039ae92e4507337bfc389
parent 410850 77154e843ebc364a9dba989f8ebc71e29e1cb08c
child 410852 b84707ac2dfeec9de7d16ccf17d8a703844a59e7
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1365032
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1365032 - Part 2: Add a test for propagating properties of windows across window.open, r=smaug MozReview-Commit-ID: i7cW9rd0eO
dom/tests/browser/browser.ini
dom/tests/browser/browser_noopener.js
dom/tests/browser/test_noopener_source.html
dom/tests/browser/test_noopener_target.html
--- a/dom/tests/browser/browser.ini
+++ b/dom/tests/browser/browser.ini
@@ -66,8 +66,12 @@ support-files =
 support-files =
   test_new_window_from_content_child.html
 [browser_xhr_sandbox.js]
 [browser_prerendering.js]
 support-files =
   prerender.html
   prerender_target.html
 skip-if = true || !e10s # Prerendering requires e10s, turned off for e10s-multi Bug 1315042
+[browser_noopener.js]
+support-files =
+  test_noopener_source.html
+  test_noopener_target.html
new file mode 100644
--- /dev/null
+++ b/dom/tests/browser/browser_noopener.js
@@ -0,0 +1,128 @@
+
+const TESTS = [
+  {id: "#test1", name: "", opener: true, newWindow: false},
+  {id: "#test2", name: "", opener: false, newWindow: false},
+  {id: "#test3", name: "", opener: false, newWindow: false},
+
+  {id: "#test4", name: "uniquename1", opener: true, newWindow: false},
+  {id: "#test5", name: "uniquename2", opener: false, newWindow: false},
+  {id: "#test6", name: "uniquename3", opener: false, newWindow: false},
+
+  {id: "#test7", name: "", opener: true, newWindow: false},
+  {id: "#test8", name: "", opener: false, newWindow: true},
+  {id: "#test9", name: "", opener: true, newWindow: true},
+
+  {id: "#test10", name: "uniquename1", opener: true, newWindow: false},
+  {id: "#test11", name: "uniquename2", opener: false, newWindow: true},
+  {id: "#test12", name: "uniquename3", opener: true, newWindow: true},
+];
+
+const TEST_URL = "http://mochi.test:8888/browser/dom/tests/browser/test_noopener_source.html";
+const TARGET_URL = "http://mochi.test:8888/browser/dom/tests/browser/test_noopener_target.html";
+
+const OPEN_NEWWINDOW_PREF = "browser.link.open_newwindow";
+const OPEN_NEWWINDOW = 2;
+const OPEN_NEWTAB = 3;
+
+const NOOPENER_NEWPROC_PREF = "dom.noopener.newprocess.enabled";
+
+async function doTests(private, container) {
+  let alwaysNewWindow = SpecialPowers.getIntPref(OPEN_NEWWINDOW_PREF) == OPEN_NEWWINDOW;
+
+  let window = await BrowserTestUtils.openNewBrowserWindow({ private });
+
+  let tabOpenOptions = {};
+  if (container) {
+    tabOpenOptions.userContextId = 1;
+  }
+
+  for (let test of TESTS) {
+    const testid = `${test.id} (private=${private}, container=${container}, alwaysNewWindow=${alwaysNewWindow})`;
+    let originalTab = BrowserTestUtils.addTab(window.gBrowser, TEST_URL, tabOpenOptions);
+    await BrowserTestUtils.browserLoaded(originalTab.linkedBrowser);
+    await BrowserTestUtils.switchTab(window.gBrowser, originalTab);
+
+    let waitFor;
+    if (test.newWindow || alwaysNewWindow) {
+      waitFor = BrowserTestUtils.waitForNewWindow(window.gBrowser, TARGET_URL, true);
+      // Confirm that this window has private browsing set if we're doing a private browsing test
+    } else {
+      waitFor = BrowserTestUtils.waitForNewTab(window.gBrowser, TARGET_URL, true);
+    }
+
+    BrowserTestUtils.synthesizeMouseAtCenter(test.id, {}, window.gBrowser.getBrowserForTab(originalTab));
+
+    let tab;
+    if (test.newWindow || alwaysNewWindow) {
+      let window = await waitFor;
+      is(PrivateBrowsingUtils.isWindowPrivate(window), private, "Private status should match for " + testid);
+      tab = window.gBrowser.selectedTab;
+    } else {
+      tab = await waitFor;
+    }
+
+    if (container) {
+      is(tab.linkedBrowser.getAttribute("usercontextid"), 1, "Should have usercontextid set for " + testid);
+    } else {
+      ok(!tab.linkedBrowser.hasAttribute("usercontextid"), "Should have usercontextid set for " + testid);
+    }
+
+    // Check that the name matches.
+    await ContentTask.spawn(tab.linkedBrowser, [test, testid], async ([test, testid]) => {
+      is(content.window.name, test.name, "Name should match for " + testid);
+      if (test.opener) {
+        ok(content.window.opener, "Opener should have been set for " + testid);
+      } else {
+        ok(!content.window.opener, "Opener should not have been set for " + testid);
+      }
+    });
+
+    await BrowserTestUtils.removeTab(tab);
+    await BrowserTestUtils.removeTab(originalTab);
+  }
+
+  window.close();
+}
+
+async function doAllTests() {
+  // Non-private window
+  await doTests(false, false);
+
+  // Private window
+  await doTests(true, false);
+
+  // Non-private window with container
+  await doTests(false, true);
+}
+
+// This test takes a really long time, especially in debug builds, as it is
+// constant starting and stopping processes, and opens a new window ~144 times.
+requestLongerTimeout(15);
+
+add_task(async function newtab_sameproc() {
+  await SpecialPowers.pushPrefEnv({set: [[OPEN_NEWWINDOW_PREF, OPEN_NEWTAB],
+                                         [NOOPENER_NEWPROC_PREF, false]]});
+  await doAllTests();
+});
+
+add_task(async function newtab_newproc() {
+  await SpecialPowers.pushPrefEnv({set: [[OPEN_NEWWINDOW_PREF, OPEN_NEWTAB],
+                                         [NOOPENER_NEWPROC_PREF, true]]});
+  await doAllTests();
+});
+
+add_task(async function newwindow_sameproc() {
+  await SpecialPowers.pushPrefEnv({set: [[OPEN_NEWWINDOW_PREF, OPEN_NEWWINDOW],
+                                         [NOOPENER_NEWPROC_PREF, false]]});
+  await doAllTests();
+});
+
+add_task(async function newwindow_newproc() {
+  await SpecialPowers.pushPrefEnv({set: [[OPEN_NEWWINDOW_PREF, OPEN_NEWWINDOW],
+                                         [NOOPENER_NEWPROC_PREF, true]]});
+  await doAllTests();
+});
+
+// add_task(async function() {
+//   await doTests(false, true);
+// })
new file mode 100644
--- /dev/null
+++ b/dom/tests/browser/test_noopener_source.html
@@ -0,0 +1,16 @@
+<a id="test1" href="test_noopener_target.html" target="_blank">1</a>
+<a id="test2" href="test_noopener_target.html" target="_blank" rel="noopener">2</a>
+<a id="test3" href="test_noopener_target.html" target="_blank" rel="noreferrer">3</a>
+
+<a id="test4" href="test_noopener_target.html" target="uniquename1">4</a>
+<a id="test5" href="test_noopener_target.html" target="uniquename2" rel="noopener">5</a>
+<a id="test6" href="test_noopener_target.html" target="uniquename3" rel="noreferrer">6</a>
+
+<a id="test7" onclick="window.open('test_noopener_target.html', '_blank')">7</a>
+<a id="test8" onclick="window.open('test_noopener_target.html', '_blank', 'noopener')">8</a>
+<a id="test9" onclick="window.open('test_noopener_target.html', '_blank', 'noreferrer')">9</a>
+
+<a id="test10" onclick="window.open('test_noopener_target.html', 'uniquename1')">10</a>
+<a id="test11" onclick="window.open('test_noopener_target.html', 'uniquename2', 'noopener')">11</a>
+<a id="test12" onclick="window.open('test_noopener_target.html', 'uniquename3', 'noreferrer')">12</a>
+
new file mode 100644
--- /dev/null
+++ b/dom/tests/browser/test_noopener_target.html
@@ -0,0 +1,9 @@
+
+<h2>name</h2>
+<div id="window_name"></div>
+
+<script>
+  document.querySelector("#window_name").textContent =
+    window.name;
+
+</script>