summaryrefslogtreecommitdiffstats
path: root/embedding/components/windowwatcher/test
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /embedding/components/windowwatcher/test
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'embedding/components/windowwatcher/test')
-rw-r--r--embedding/components/windowwatcher/test/browser.ini9
-rw-r--r--embedding/components/windowwatcher/test/browser_new_content_window_chromeflags.js278
-rw-r--r--embedding/components/windowwatcher/test/browser_new_content_window_from_chrome_principal.js34
-rw-r--r--embedding/components/windowwatcher/test/browser_new_remote_window_flags.js78
-rw-r--r--embedding/components/windowwatcher/test/browser_new_sized_window.js67
-rw-r--r--embedding/components/windowwatcher/test/chrome.ini7
-rw-r--r--embedding/components/windowwatcher/test/file_storage_copied.html13
-rw-r--r--embedding/components/windowwatcher/test/file_test_dialog.html14
-rw-r--r--embedding/components/windowwatcher/test/mochitest.ini12
-rw-r--r--embedding/components/windowwatcher/test/moz.build18
-rw-r--r--embedding/components/windowwatcher/test/test_blank_named_window.html45
-rw-r--r--embedding/components/windowwatcher/test/test_dialog_arguments.html38
-rw-r--r--embedding/components/windowwatcher/test/test_modal_windows.html56
-rw-r--r--embedding/components/windowwatcher/test/test_named_window.html92
-rw-r--r--embedding/components/windowwatcher/test/test_storage_copied.html45
15 files changed, 806 insertions, 0 deletions
diff --git a/embedding/components/windowwatcher/test/browser.ini b/embedding/components/windowwatcher/test/browser.ini
new file mode 100644
index 000000000..925b96e34
--- /dev/null
+++ b/embedding/components/windowwatcher/test/browser.ini
@@ -0,0 +1,9 @@
+[DEFAULT]
+tags = openwindow
+
+[browser_new_content_window_chromeflags.js]
+[browser_new_remote_window_flags.js]
+run-if = e10s
+[browser_new_content_window_from_chrome_principal.js]
+[browser_new_sized_window.js]
+skip-if = os == 'win' # Bug 1276802 - Opening windows from content on Windows might not get the size right
diff --git a/embedding/components/windowwatcher/test/browser_new_content_window_chromeflags.js b/embedding/components/windowwatcher/test/browser_new_content_window_chromeflags.js
new file mode 100644
index 000000000..887f86152
--- /dev/null
+++ b/embedding/components/windowwatcher/test/browser_new_content_window_chromeflags.js
@@ -0,0 +1,278 @@
+/**
+ * Tests that chromeFlags are set properly on windows that are
+ * being opened from content.
+ */
+
+// The following features set chrome flags on new windows and are
+// supported by web content. The schema for each property on this
+// object is as follows:
+//
+// <feature string>: {
+// flag: <associated nsIWebBrowserChrome flag>,
+// defaults_to: <what this feature defaults to normally>
+// }
+const ALLOWED = {
+ "toolbar": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_TOOLBAR,
+ defaults_to: true,
+ },
+ "personalbar": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_PERSONAL_TOOLBAR,
+ defaults_to: true,
+ },
+ "menubar": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_MENUBAR,
+ defaults_to: true,
+ },
+ "scrollbars": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_SCROLLBARS,
+ defaults_to: false,
+ },
+ "minimizable": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_WINDOW_MIN,
+ defaults_to: true,
+ },
+};
+
+// Construct a features string that flips all ALLOWED features
+// to not be their defaults.
+const ALLOWED_STRING = Object.keys(ALLOWED).map(feature => {
+ let toValue = ALLOWED[feature].defaults_to ? "no" : "yes";
+ return `${feature}=${toValue}`;
+}).join(",");
+
+// The following are not allowed from web content, at least
+// in the default case (since some are disabled by default
+// via the dom.disable_window_open_feature pref branch).
+const DISALLOWED = {
+ "location": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_LOCATIONBAR,
+ defaults_to: true,
+ },
+ "chrome": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_OPENAS_CHROME,
+ defaults_to: false,
+ },
+ "dialog": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_OPENAS_DIALOG,
+ defaults_to: false,
+ },
+ "private": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_PRIVATE_WINDOW,
+ defaults_to: false,
+ },
+ "non-private": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_NON_PRIVATE_WINDOW,
+ defaults_to: false,
+ },
+ // "all":
+ // checked manually, since this is an aggregate
+ // flag.
+ //
+ // "remote":
+ // checked manually, since its default value will
+ // depend on whether or not e10s is enabled by default.
+ "popup": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_WINDOW_POPUP,
+ defaults_to: false,
+ },
+ "alwaysLowered": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_WINDOW_LOWERED,
+ defaults_to: false,
+ },
+ "z-lock": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_WINDOW_LOWERED, // Renamed to alwaysLowered
+ defaults_to: false,
+ },
+ "alwaysRaised": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_WINDOW_RAISED,
+ defaults_to: false,
+ },
+ "macsuppressanimation": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_MAC_SUPPRESS_ANIMATION,
+ defaults_to: false,
+ },
+ "extrachrome": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_EXTRA,
+ defaults_to: false,
+ },
+ "centerscreen": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_CENTER_SCREEN,
+ defaults_to: false,
+ },
+ "dependent": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_DEPENDENT,
+ defaults_to: false,
+ },
+ "modal": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_MODAL,
+ defaults_to: false,
+ },
+ "titlebar": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_TITLEBAR,
+ defaults_to: true,
+ },
+ "close": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_WINDOW_CLOSE,
+ defaults_to: true,
+ },
+ "resizable": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_WINDOW_RESIZE,
+ defaults_to: true,
+ },
+ "status": {
+ flag: Ci.nsIWebBrowserChrome.CHROME_STATUSBAR,
+ defaults_to: true,
+ },
+};
+
+// Construct a features string that flips all DISALLOWED features
+// to not be their defaults.
+const DISALLOWED_STRING = Object.keys(DISALLOWED).map(feature => {
+ let toValue = DISALLOWED[feature].defaults_to ? "no" : "yes";
+ return `${feature}=${toValue}`;
+}).join(",");
+
+const FEATURES = [ALLOWED_STRING, DISALLOWED_STRING].join(",");
+
+const SCRIPT_PAGE = `data:text/html,<script>window.open("about:blank", "_blank", "${FEATURES}");</script>`;
+const SCRIPT_PAGE_FOR_CHROME_ALL = `data:text/html,<script>window.open("about:blank", "_blank", "all");</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");
+});
+
+/**
+ * Given some nsIDOMWindow for a window running in the parent
+ * process, return the nsIWebBrowserChrome chrome flags for
+ * the associated XUL window.
+ *
+ * @param win (nsIDOMWindow)
+ * Some window in the parent process.
+ * @returns int
+ */
+function getParentChromeFlags(win) {
+ return win.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShellTreeItem)
+ .treeOwner
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIXULWindow)
+ .chromeFlags;
+}
+
+/**
+ * For some chromeFlags, ensures that flags that are in the
+ * ALLOWED group were modified, and that flags in the DISALLOWED
+ * group were not modified.
+ *
+ * @param chromeFlags (int)
+ * Some chromeFlags to check.
+ */
+function assertContentFlags(chromeFlags) {
+ for (let feature in ALLOWED) {
+ let flag = ALLOWED[feature].flag;
+
+ if (ALLOWED[feature].defaults_to) {
+ // The feature is supposed to default to true, so we should
+ // have been able to flip it off.
+ Assert.ok(!(chromeFlags & flag),
+ `Expected feature ${feature} to be disabled`);
+ } else {
+ // The feature is supposed to default to false, so we should
+ // have been able to flip it on.
+ Assert.ok((chromeFlags & flag),
+ `Expected feature ${feature} to be enabled`);
+ }
+ }
+
+ for (let feature in DISALLOWED) {
+ let flag = DISALLOWED[feature].flag;
+ if (DISALLOWED[feature].defaults_to) {
+ // The feature is supposed to default to true, so it should
+ // stay true.
+ Assert.ok((chromeFlags & flag),
+ `Expected feature ${feature} to be unchanged`);
+ } else {
+ // The feature is supposed to default to false, so it should
+ // stay false.
+ Assert.ok(!(chromeFlags & flag),
+ `Expected feature ${feature} to be unchanged`);
+ }
+ }
+}
+
+/**
+ * Opens a window from content using window.open with the
+ * features computed from ALLOWED and DISALLOWED. The computed
+ * feature string attempts to flip every feature away from their
+ * default.
+ */
+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;
+ let parentChromeFlags = getParentChromeFlags(win);
+ assertContentFlags(parentChromeFlags);
+
+ if (win.gMultiProcessBrowser) {
+ Assert.ok(parentChromeFlags &
+ Ci.nsIWebBrowserChrome.CHROME_REMOTE_WINDOW,
+ "Should be remote by default");
+ } else {
+ Assert.ok(!(parentChromeFlags &
+ Ci.nsIWebBrowserChrome.CHROME_REMOTE_WINDOW),
+ "Should not be remote by default");
+ }
+
+ // Confusingly, chromeFlags also exist in the content process
+ // as part of the TabChild, so we have to check those too.
+ let b = win.gBrowser.selectedBrowser;
+ let contentChromeFlags = yield ContentTask.spawn(b, null, function*() {
+ docShell.QueryInterface(Ci.nsIInterfaceRequestor);
+ try {
+ // This will throw if we're not a remote browser.
+ return docShell.getInterface(Ci.nsITabChild)
+ .QueryInterface(Ci.nsIWebBrowserChrome)
+ .chromeFlags;
+ } catch(e) {
+ // This must be a non-remote browser...
+ return docShell.QueryInterface(Ci.nsIDocShellTreeItem)
+ .treeOwner
+ .QueryInterface(Ci.nsIWebBrowserChrome)
+ .chromeFlags;
+ }
+ });
+
+ assertContentFlags(contentChromeFlags);
+ Assert.ok(!(contentChromeFlags &
+ Ci.nsIWebBrowserChrome.CHROME_REMOTE_WINDOW),
+ "Should not be remote in the content process.");
+
+ yield BrowserTestUtils.closeWindow(win);
+ });
+
+ // We check "all" manually, since that's an aggregate flag
+ // and doesn't fit nicely into the ALLOWED / DISALLOWED scheme
+ newWinPromise = BrowserTestUtils.waitForNewWindow();
+
+ yield BrowserTestUtils.withNewTab({
+ gBrowser,
+ url: SCRIPT_PAGE_FOR_CHROME_ALL,
+ }, function*(browser) {
+ let win = yield newWinPromise;
+ let parentChromeFlags = getParentChromeFlags(win);
+ Assert.notEqual((parentChromeFlags & Ci.nsIWebBrowserChrome.CHROME_ALL),
+ Ci.nsIWebBrowserChrome.CHROME_ALL,
+ "Should not have been able to set CHROME_ALL");
+ yield BrowserTestUtils.closeWindow(win);
+ });
+});
diff --git a/embedding/components/windowwatcher/test/browser_new_content_window_from_chrome_principal.js b/embedding/components/windowwatcher/test/browser_new_content_window_from_chrome_principal.js
new file mode 100644
index 000000000..c8a24d43e
--- /dev/null
+++ b/embedding/components/windowwatcher/test/browser_new_content_window_from_chrome_principal.js
@@ -0,0 +1,34 @@
+"use strict";
+
+/**
+ * Tests that if chrome-privileged code calls .open() on an
+ * unprivileged window, that the principal in the newly
+ * opened window is appropriately set.
+ */
+add_task(function* test_chrome_opens_window() {
+ // 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 SpecialPowers.pushPrefEnv({"set": [
+ ["browser.link.open_newwindow", 2],
+ ]});
+
+ let newWinPromise = BrowserTestUtils.waitForNewWindow(true, "http://example.com/");
+
+ yield ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
+ content.open("http://example.com/", "_blank");
+ });
+
+ let win = yield newWinPromise;
+ let browser = win.gBrowser.selectedBrowser;
+
+ yield ContentTask.spawn(browser, null, function*() {
+ Assert.ok(!content.document.nodePrincipal.isSystemPrincipal,
+ "We should not have a system principal.")
+ Assert.equal(content.document.nodePrincipal.origin,
+ "http://example.com",
+ "Should have the example.com principal");
+ });
+
+ yield BrowserTestUtils.closeWindow(win);
+}); \ No newline at end of file
diff --git a/embedding/components/windowwatcher/test/browser_new_remote_window_flags.js b/embedding/components/windowwatcher/test/browser_new_remote_window_flags.js
new file mode 100644
index 000000000..e4f3d1ddf
--- /dev/null
+++ b/embedding/components/windowwatcher/test/browser_new_remote_window_flags.js
@@ -0,0 +1,78 @@
+/**
+ * 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.
+add_task(function* setup() {
+ yield SpecialPowers.pushPrefEnv({"set": [
+ ["browser.link.open_newwindow", 2],
+ ]});
+});
+
+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_target_blank() {
+ 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 window.open
+ */
+add_task(function* test_new_remote_window_flags_window_open() {
+ let newWinPromise = BrowserTestUtils.waitForNewWindow();
+
+ yield BrowserTestUtils.withNewTab({
+ gBrowser,
+ url: SCRIPT_PAGE,
+ }, function*(browser) {
+ let win = yield newWinPromise;
+ assertFlags(win);
+ yield BrowserTestUtils.closeWindow(win);
+ });
+});
+
+/**
+ * Privileged content scripts can also open new windows
+ * using content.open.
+ */
+add_task(function* test_new_remote_window_flags_content_open() {
+ 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);
+});
diff --git a/embedding/components/windowwatcher/test/browser_new_sized_window.js b/embedding/components/windowwatcher/test/browser_new_sized_window.js
new file mode 100644
index 000000000..f4b1890b1
--- /dev/null
+++ b/embedding/components/windowwatcher/test/browser_new_sized_window.js
@@ -0,0 +1,67 @@
+"use strict";
+
+/**
+ * Tests that content can open windows at requested dimensions
+ * of height and width.
+ */
+
+/**
+ * This utility function does most of the actual testing. We
+ * construct a feature string suitable for the passed in width
+ * and height, and then run that script in content to open the
+ * new window. When the new window comes up, this function tests
+ * to ensure that the content area of the initial browser is the
+ * requested dimensions. Finally, we also ensure that we're not
+ * persisting the position, size or sizemode of the new browser
+ * window.
+ */
+function test_dimensions({ width, height}) {
+ let features = [];
+ if (width) {
+ features.push(`width=${width}`);
+ }
+ if (height) {
+ features.push(`height=${height}`);
+ }
+ const FEATURE_STR = features.join(",");
+ const SCRIPT_PAGE = `data:text/html,<script>window.open("about:blank", "_blank", "${FEATURE_STR}");</script>`;
+
+ let newWinPromise = BrowserTestUtils.waitForNewWindow();
+
+ return BrowserTestUtils.withNewTab({
+ gBrowser,
+ url: SCRIPT_PAGE,
+ }, function*(browser) {
+ let win = yield newWinPromise;
+ let rect = win.gBrowser.selectedBrowser.getBoundingClientRect();
+
+ if (width) {
+ Assert.equal(rect.width, width, "Should have the requested width");
+ }
+
+ if (height) {
+ Assert.equal(rect.height, height, "Should have the requested height");
+ }
+
+ let treeOwner = win.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDocShell)
+ .QueryInterface(Ci.nsIDocShellTreeItem)
+ .treeOwner;
+ let persistPosition = {};
+ let persistSize = {};
+ let persistSizeMode = {};
+ treeOwner.getPersistence(persistPosition, persistSize, persistSizeMode);
+
+ Assert.ok(!persistPosition.value, "Should not persist position");
+ Assert.ok(!persistSize.value, "Should not persist size");
+ Assert.ok(!persistSizeMode.value, "Should not persist size mode");
+
+ yield BrowserTestUtils.closeWindow(win);
+ });
+}
+
+add_task(function* test_new_sized_window() {
+ yield test_dimensions({ width: 100 });
+ yield test_dimensions({ height: 150 });
+ yield test_dimensions({ width: 300, height: 200 });
+});
diff --git a/embedding/components/windowwatcher/test/chrome.ini b/embedding/components/windowwatcher/test/chrome.ini
new file mode 100644
index 000000000..5f3b49433
--- /dev/null
+++ b/embedding/components/windowwatcher/test/chrome.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+tags = openwindow
+
+[test_dialog_arguments.html]
+support-files =
+ file_test_dialog.html
+[test_modal_windows.html]
diff --git a/embedding/components/windowwatcher/test/file_storage_copied.html b/embedding/components/windowwatcher/test/file_storage_copied.html
new file mode 100644
index 000000000..250c7891a
--- /dev/null
+++ b/embedding/components/windowwatcher/test/file_storage_copied.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+This page is opened in a new window by test_storage_copied.html.
+We need to return the sessionStorage value for the item "test-item",
+by way of postMessage.
+-->
+<head>
+<body>Opened!</body>
+<script>
+ window.postMessage(window.sessionStorage.getItem("test-item"), "*");
+</script>
+</html> \ No newline at end of file
diff --git a/embedding/components/windowwatcher/test/file_test_dialog.html b/embedding/components/windowwatcher/test/file_test_dialog.html
new file mode 100644
index 000000000..b323ba526
--- /dev/null
+++ b/embedding/components/windowwatcher/test/file_test_dialog.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+This page is opened in a new window by test_dialog_arguments. It is
+a dialog which expects a Symbol to be passed in the dialog arguments.
+Once we load, we call back into the opener with the argument we were
+passed.
+-->
+<head>
+<body>Opened!</body>
+<script>
+ window.opener.done(window.arguments[0]);
+</script>
+</html> \ No newline at end of file
diff --git a/embedding/components/windowwatcher/test/mochitest.ini b/embedding/components/windowwatcher/test/mochitest.ini
new file mode 100644
index 000000000..42955d496
--- /dev/null
+++ b/embedding/components/windowwatcher/test/mochitest.ini
@@ -0,0 +1,12 @@
+[DEFAULT]
+tags = openwindow
+
+[test_blank_named_window.html]
+skip-if = (os == 'android') # Fennec doesn't support web content opening new windows (See bug 1277544 for details)
+[test_named_window.html]
+skip-if = (os == 'android') # Fennec doesn't support web content opening new windows (See bug 1277544 for details)
+[test_storage_copied.html]
+support-files =
+ file_storage_copied.html
+skip-if = (os == 'android') # Fennec doesn't support web content opening new windows (See bug 1277544 for details)
+
diff --git a/embedding/components/windowwatcher/test/moz.build b/embedding/components/windowwatcher/test/moz.build
new file mode 100644
index 000000000..bd6f51aff
--- /dev/null
+++ b/embedding/components/windowwatcher/test/moz.build
@@ -0,0 +1,18 @@
+# -*- Mode: python; 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',
+]
+
+MOCHITEST_MANIFESTS += [
+ 'mochitest.ini',
+]
+
+MOCHITEST_CHROME_MANIFESTS += [
+ 'chrome.ini',
+]
+
diff --git a/embedding/components/windowwatcher/test/test_blank_named_window.html b/embedding/components/windowwatcher/test/test_blank_named_window.html
new file mode 100644
index 000000000..b45ad1f70
--- /dev/null
+++ b/embedding/components/windowwatcher/test/test_blank_named_window.html
@@ -0,0 +1,45 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that when opening a window with the reserved name _blank that the new
+window does not get that name, and that subsequent window openings with that
+name result in new windows being opened.
+-->
+<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>
+ <script type="application/javascript">
+ "use strict";
+ 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 SpecialPowers.pushPrefEnv({"set": [
+ ["browser.link.open_newwindow", 2],
+ ]});
+
+ let win1 = window.open("data:text/html,<p>This is window 1 for test_blank_named_window.html</p>", "_blank");
+
+ let name = SpecialPowers.wrap(win1)
+ .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+ .getInterface(SpecialPowers.Ci.nsIWebNavigation)
+ .QueryInterface(SpecialPowers.Ci.nsIDocShellTreeItem)
+ .name;
+
+ is(name, "", "Should have no name");
+
+ let win2 = window.open("data:text/html,<p>This is window 2 for test_blank_named_window.html</p>", "_blank");
+ isnot(win1, win2, "Should not have gotten back the same window");
+
+ win1.close();
+ win2.close();
+ });
+ </script>
+</body>
+</html> \ No newline at end of file
diff --git a/embedding/components/windowwatcher/test/test_dialog_arguments.html b/embedding/components/windowwatcher/test/test_dialog_arguments.html
new file mode 100644
index 000000000..7cde69401
--- /dev/null
+++ b/embedding/components/windowwatcher/test/test_dialog_arguments.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that arguments can be passed to dialogs.
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test a modal window</title>
+
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+ <script type="application/javascript;version=1.8">
+ const {utils: Cu, interfaces: Ci} = Components;
+
+ Cu.import("resource://gre/modules/Services.jsm");
+
+ const TEST_ITEM = Symbol("test-item");
+
+ function done(returnedItem) {
+ is(returnedItem, TEST_ITEM,
+ "Dialog should have received test item");
+ win.close();
+ SimpleTest.finish();
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ let win = window.openDialog("file_test_dialog.html", "_blank", "width=100,height=100", TEST_ITEM);
+ </script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+</pre>
+</body>
+</html> \ No newline at end of file
diff --git a/embedding/components/windowwatcher/test/test_modal_windows.html b/embedding/components/windowwatcher/test/test_modal_windows.html
new file mode 100644
index 000000000..8a2c03be0
--- /dev/null
+++ b/embedding/components/windowwatcher/test/test_modal_windows.html
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that the parent can open modal windows, and that the modal window
+that is opened reports itself as being modal.
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test a modal window</title>
+
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+ <script type="application/javascript;version=1.8">
+ const {utils: Cu, interfaces: Ci} = Components;
+
+ Cu.import("resource://gre/modules/Services.jsm");
+ Cu.import("resource://testing-common/BrowserTestUtils.jsm");
+
+ add_task(function*() {
+ BrowserTestUtils.domWindowOpened().then((win) => {
+ let treeOwner = win.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShellTreeItem)
+ .treeOwner
+ let chromeFlags = treeOwner.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIXULWindow)
+ .chromeFlags;
+ ok(chromeFlags & Ci.nsIWebBrowserChrome.CHROME_MODAL,
+ "Should have the modal chrome flag");
+
+ let wbc = treeOwner.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebBrowserChrome);
+ ok(wbc.isWindowModal(), "Should report as modal");
+
+ win.close();
+ });
+
+ let modal = window.openDialog("data:text/html,<p>This is a modal window for test_modal_windows.html</p>",
+ "_blank", "modal", null);
+ // Since the modal runs a nested event loop, just to be on the safe side,
+ // we'll wait a tick of the main event loop before resolving the task.
+ yield new Promise(resolve => setTimeout(resolve, 0));
+ });
+
+ </script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+</pre>
+</body>
+</html> \ No newline at end of file
diff --git a/embedding/components/windowwatcher/test/test_named_window.html b/embedding/components/windowwatcher/test/test_named_window.html
new file mode 100644
index 000000000..58bd8a9cf
--- /dev/null
+++ b/embedding/components/windowwatcher/test/test_named_window.html
@@ -0,0 +1,92 @@
+<!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="#" id="link">Click me</a>
+
+ <script type="application/javascript">
+ "use strict";
+
+ const NAME = "my_window";
+ const TARGET_URL = "data:text/html,<html><body>test_named_window.html new window</body></html>";
+ const TARGET_URL_2 = TARGET_URL + "#2";
+ const TARGET_URL_3 = TARGET_URL + "#3";
+
+ /**
+ * Returns a Promise that resolves once some target has had
+ * some event dispatched on it.
+ *
+ * @param target
+ * The thing to wait for the event to be dispatched
+ * through.
+ * @param eventName
+ * The name of the event to wait for.
+ * @returns Promise
+ */
+ function promiseEvent(target, eventName) {
+ return new Promise(resolve => {
+ target.addEventListener(eventName, function onEvent(e) {
+ target.removeEventListener(eventName, onEvent, true);
+ resolve(e);
+ }, true);
+ });
+ }
+
+ 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 SpecialPowers.pushPrefEnv({"set": [
+ ["browser.link.open_newwindow", 2],
+ ]});
+
+ let win1 = window.open(TARGET_URL, "my_window");
+ yield promiseEvent(win1, "load");
+
+ 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");
+ is(win1.location.href, new URL(TARGET_URL).href,
+ "Should have loaded target TARGET_URL in the original window");
+
+ let hashChange = promiseEvent(win1, "hashchange");
+ let win2 = window.open(TARGET_URL_2, "my_window");
+ yield hashChange;
+
+ is(win1, win2, "Should have gotten back the same window");
+ is(win1.location.href, new URL(TARGET_URL_2).href,
+ "Should have re-targeted pre-existing window");
+
+ hashChange = promiseEvent(win1, "hashchange");
+ let link = document.getElementById("link");
+ link.setAttribute("target", NAME);
+ link.setAttribute("href", TARGET_URL_3);
+ link.click();
+
+ yield hashChange;
+
+ is(win1.location.href, new URL(TARGET_URL_3).href,
+ "Should have re-targeted pre-existing window");
+
+ win1.close();
+ });
+ </script>
+</body>
+</html> \ No newline at end of file
diff --git a/embedding/components/windowwatcher/test/test_storage_copied.html b/embedding/components/windowwatcher/test/test_storage_copied.html
new file mode 100644
index 000000000..27aeb51a9
--- /dev/null
+++ b/embedding/components/windowwatcher/test/test_storage_copied.html
@@ -0,0 +1,45 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test sessionStorage is copied over when a new window opens to the
+same domain as the opener.
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test storage copied</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>
+ <script type="application/javascript">
+ "use strict";
+
+ function waitForMessage(win) {
+ return new Promise(resolve => {
+ win.addEventListener("message", function onMessage(event) {
+ win.removeEventListener("message", onMessage);
+ resolve(event.data);
+ });
+ });
+ }
+
+ add_task(function*() {
+ const TEST_VALUE = "test-value";
+ // 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 SpecialPowers.pushPrefEnv({"set": [
+ ["browser.link.open_newwindow", 2],
+ ]});
+
+ window.sessionStorage.setItem("test-item", TEST_VALUE);
+ let win = window.open("file_storage_copied.html", "my_window");
+ let data = yield waitForMessage(win);
+ is(data, TEST_VALUE, "Should have cloned the test value");
+ win.close();
+ });
+ </script>
+</body>
+</html> \ No newline at end of file