Bug 1267720 - Test that named windows work properly. r?smaug draft
authorMike Conley <mconley@mozilla.com>
Fri, 29 Apr 2016 17:24:20 -0400
changeset 363496 655a87de21ac65bae1af1a811b1c7ce9be1a0f50
parent 363495 79ffa7a3ae0c0a7fabab507ff204f33416c0d814
child 363497 bd5a485aa8ef187c3c70e692660304b49e3c796f
push id17222
push usermconley@mozilla.com
push dateWed, 04 May 2016 21:02:55 +0000
reviewerssmaug
bugs1267720
milestone49.0a1
Bug 1267720 - Test that named windows work properly. r?smaug MozReview-Commit-ID: 80uzqBvPmOA
embedding/components/windowwatcher/test/mochitest.ini
embedding/components/windowwatcher/test/moz.build
embedding/components/windowwatcher/test/test_named_window.html
--- a/embedding/components/windowwatcher/test/mochitest.ini
+++ b/embedding/components/windowwatcher/test/mochitest.ini
@@ -1,7 +1,6 @@
 [DEFAULT]
 support-files =
   head.js
 tags = openwindow
 
-[test_new_remote_window_flags.html]
-run-if = e10s
+[test_named_window.html]
--- a/embedding/components/windowwatcher/test/moz.build
+++ b/embedding/components/windowwatcher/test/moz.build
@@ -3,8 +3,11 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 BROWSER_CHROME_MANIFESTS += [
     'browser.ini',
 ]
 
+MOCHITEST_MANIFESTS += [
+    'mochitest.ini',
+]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/embedding/components/windowwatcher/test/test_named_window.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that when content opens a new window with a name, that the
+newly opened window actually gets that name, and that subsequent
+attempts to open a window with that name will target the same
+window.
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test named windows</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+  <script src="head.js" type="application/javascript;version=1.8"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+  <a href="about:blank#3" target="my_window" id="link">Click me</a>
+
+  <script type="application/javascript">
+    "use strict";
+
+    const NAME = "my_window";
+
+    add_task(function*() {
+      // This magic value of 2 means that by default, when content tries
+      // to open a new window, it'll actually open in a new window instead
+      // of a new tab.
+      yield pushPrefs(["browser.link.open_newwindow", 2]);
+
+      let win1 = window.open("about:blank#1", "my_window");
+
+      let name = SpecialPowers.wrap(win1)
+                 .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+                 .getInterface(SpecialPowers.Ci.nsIWebNavigation)
+                 .QueryInterface(SpecialPowers.Ci.nsIDocShellTreeItem)
+                 .name;
+
+      is(name, NAME, "Should have the expected name");
+
+      let win2 = window.open("about:blank#2", "my_window");
+      is(win1, win2, "Should have gotten back the same window");
+
+      let link = document.getElementById("link");
+      link.setAttribute("target", NAME);
+      link.click();
+
+      yield new Promise(resolve => SimpleTest.executeSoon(resolve));
+
+      is(win1.location.href, "about:blank#3",
+         "Should have re-targeted pre-existing window");
+
+      win1.close();
+    });
+  </script>
+</body>
+</html>
\ No newline at end of file