Bug 1267720 - Test that new windows opened from remote content get the right flags. r?smaug draft
authorMike Conley <mconley@mozilla.com>
Fri, 29 Apr 2016 15:28:29 -0400
changeset 363495 79ffa7a3ae0c0a7fabab507ff204f33416c0d814
parent 363494 bfbd12dd3c0e1a8942687cb2875eeb2f86ad63bb
child 363496 655a87de21ac65bae1af1a811b1c7ce9be1a0f50
push id17222
push usermconley@mozilla.com
push dateWed, 04 May 2016 21:02:55 +0000
reviewerssmaug
bugs1267720
milestone49.0a1
Bug 1267720 - Test that new windows opened from remote content get the right flags. r?smaug MozReview-Commit-ID: 3zgJrU0LeUV
embedding/components/windowwatcher/moz.build
embedding/components/windowwatcher/test/browser.ini
embedding/components/windowwatcher/test/browser_new_remote_window_flags.js
embedding/components/windowwatcher/test/head.js
embedding/components/windowwatcher/test/mochitest.ini
embedding/components/windowwatcher/test/moz.build
--- a/embedding/components/windowwatcher/moz.build
+++ b/embedding/components/windowwatcher/moz.build
@@ -1,14 +1,16 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
+TEST_DIRS += ['test']
+
 XPIDL_SOURCES += [
     'nsIDialogParamBlock.idl',
     'nsIPromptFactory.idl',
     'nsIPromptService.idl',
     'nsIPromptService2.idl',
     'nsIWindowWatcher.idl',
     'nsPIPromptService.idl',
     'nsPIWindowWatcher.idl',
new file mode 100644
--- /dev/null
+++ b/embedding/components/windowwatcher/test/browser.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+support-files =
+  head.js
+tags = openwindow
+
+[browser_new_remote_window_flags.js]
+run-if = e10s
new file mode 100644
--- /dev/null
+++ b/embedding/components/windowwatcher/test/browser_new_remote_window_flags.js
@@ -0,0 +1,76 @@
+/**
+ * Tests that when a remote browser opens a new window that the
+ * newly opened window is also remote.
+ */
+
+const ANCHOR_PAGE = `data:text/html,<a href="about:blank" target="_blank">Click me!</a>`;
+const SCRIPT_PAGE = `data:text/html,<script>window.open("about:blank", "_blank");</script>`;
+
+// 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.
+Services.prefs.setIntPref("browser.link.open_newwindow", 2);
+registerCleanupFunction(() => {
+  Services.prefs.clearUserPref("browser.link.open_newwindow");
+});
+
+function assertFlags(win) {
+  let webNav = win.QueryInterface(Ci.nsIInterfaceRequestor)
+                  .getInterface(Ci.nsIWebNavigation);
+  let loadContext = webNav.QueryInterface(Ci.nsILoadContext);
+  let chromeFlags = webNav.QueryInterface(Ci.nsIDocShellTreeItem)
+                          .treeOwner
+                          .QueryInterface(Ci.nsIInterfaceRequestor)
+                          .getInterface(Ci.nsIXULWindow)
+                          .chromeFlags;
+  Assert.ok(loadContext.useRemoteTabs,
+            "Should be using remote tabs on the load context");
+  Assert.ok(chromeFlags & Ci.nsIWebBrowserChrome.CHROME_REMOTE_WINDOW,
+            "Should have the remoteness chrome flag on the window");
+}
+
+/**
+ * Content can open a window using a target="_blank" link
+ */
+add_task(function* test_new_remote_window_flags() {
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: ANCHOR_PAGE,
+  }, function*(browser) {
+    let newWinPromise = BrowserTestUtils.waitForNewWindow();
+    yield BrowserTestUtils.synthesizeMouseAtCenter("a", {}, browser);
+    let win = yield newWinPromise;
+    assertFlags(win);
+    yield BrowserTestUtils.closeWindow(win);
+  });
+});
+
+/**
+ * Content can open a window using a target="_blank" link
+ */
+add_task(function* test_new_remote_window_flags() {
+  let newWinPromise = BrowserTestUtils.waitForNewWindow();
+
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: SCRIPT_PAGE,
+  }, function*(browser) {
+    let win = yield newWinPromise;
+    assertFlags(win);
+    yield BrowserTestUtils.closeWindow(win);
+  });
+});
+
+/**
+ * Content can open a window using a target="_blank" link
+ */
+add_task(function* test_new_remote_window_flags() {
+  let newWinPromise = BrowserTestUtils.waitForNewWindow();
+  yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
+    content.open("about:blank", "_blank");
+  });
+
+  let win = yield newWinPromise;
+  assertFlags(win);
+  yield BrowserTestUtils.closeWindow(win);
+});
new file mode 100644
--- /dev/null
+++ b/embedding/components/windowwatcher/test/head.js
@@ -0,0 +1,4 @@
+function pushPrefs(...aPrefs) {
+  return new Promise(resolve =>
+                     SpecialPowers.pushPrefEnv({"set": aPrefs}, resolve));
+}
new file mode 100644
--- /dev/null
+++ b/embedding/components/windowwatcher/test/mochitest.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+support-files =
+  head.js
+tags = openwindow
+
+[test_new_remote_window_flags.html]
+run-if = e10s
new file mode 100644
--- /dev/null
+++ b/embedding/components/windowwatcher/test/moz.build
@@ -0,0 +1,10 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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',
+]
+