From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- .../components/windowwatcher/test/browser.ini | 9 + .../test/browser_new_content_window_chromeflags.js | 278 +++++++++++++++++++++ ...ser_new_content_window_from_chrome_principal.js | 34 +++ .../test/browser_new_remote_window_flags.js | 78 ++++++ .../windowwatcher/test/browser_new_sized_window.js | 67 +++++ embedding/components/windowwatcher/test/chrome.ini | 7 + .../windowwatcher/test/file_storage_copied.html | 13 + .../windowwatcher/test/file_test_dialog.html | 14 ++ .../components/windowwatcher/test/mochitest.ini | 12 + embedding/components/windowwatcher/test/moz.build | 18 ++ .../test/test_blank_named_window.html | 45 ++++ .../windowwatcher/test/test_dialog_arguments.html | 38 +++ .../windowwatcher/test/test_modal_windows.html | 56 +++++ .../windowwatcher/test/test_named_window.html | 92 +++++++ .../windowwatcher/test/test_storage_copied.html | 45 ++++ 15 files changed, 806 insertions(+) create mode 100644 embedding/components/windowwatcher/test/browser.ini create mode 100644 embedding/components/windowwatcher/test/browser_new_content_window_chromeflags.js create mode 100644 embedding/components/windowwatcher/test/browser_new_content_window_from_chrome_principal.js create mode 100644 embedding/components/windowwatcher/test/browser_new_remote_window_flags.js create mode 100644 embedding/components/windowwatcher/test/browser_new_sized_window.js create mode 100644 embedding/components/windowwatcher/test/chrome.ini create mode 100644 embedding/components/windowwatcher/test/file_storage_copied.html create mode 100644 embedding/components/windowwatcher/test/file_test_dialog.html create mode 100644 embedding/components/windowwatcher/test/mochitest.ini create mode 100644 embedding/components/windowwatcher/test/moz.build create mode 100644 embedding/components/windowwatcher/test/test_blank_named_window.html create mode 100644 embedding/components/windowwatcher/test/test_dialog_arguments.html create mode 100644 embedding/components/windowwatcher/test/test_modal_windows.html create mode 100644 embedding/components/windowwatcher/test/test_named_window.html create mode 100644 embedding/components/windowwatcher/test/test_storage_copied.html (limited to 'embedding/components/windowwatcher/test') 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: +// +// : { +// flag: , +// defaults_to: +// } +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,`; +const SCRIPT_PAGE_FOR_CHROME_ALL = `data:text/html,`; + +// 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,Click me!`; +const SCRIPT_PAGE = `data:text/html,`; + +// 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,`; + + 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 @@ + + + + +Opened! + + \ 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 @@ + + + + +Opened! + + \ 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 @@ + + + + + + Test named windows + + + + + + + + + \ 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 @@ + + + + + + Test a modal window + + + + + + + +

+ +
+
+ + \ 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 @@ + + + + + + Test a modal window + + + + + + + + +

+ +
+
+ + \ 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 @@ + + + + + + Test named windows + + + + + + + Click me + + + + \ 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 @@ + + + + + + Test storage copied + + + + + + + + + \ No newline at end of file -- cgit v1.2.3