From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../test/browser_new_remote_window_flags.js | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 toolkit/components/windowwatcher/test/browser_new_remote_window_flags.js (limited to 'toolkit/components/windowwatcher/test/browser_new_remote_window_flags.js') diff --git a/toolkit/components/windowwatcher/test/browser_new_remote_window_flags.js b/toolkit/components/windowwatcher/test/browser_new_remote_window_flags.js new file mode 100644 index 0000000000..06a15d123c --- /dev/null +++ b/toolkit/components/windowwatcher/test/browser_new_remote_window_flags.js @@ -0,0 +1,85 @@ +/** + * 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_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [["browser.link.open_newwindow", 2]], + }); +}); + +function assertFlags(win) { + let docShell = win.docShell; + let loadContext = docShell.QueryInterface(Ci.nsILoadContext); + let chromeFlags = docShell.treeOwner + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIAppWindow).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(async function test_new_remote_window_flags_target_blank() { + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: ANCHOR_PAGE, + }, + async function (browser) { + let newWinPromise = BrowserTestUtils.waitForNewWindow(); + await BrowserTestUtils.synthesizeMouseAtCenter("a", {}, browser); + let win = await newWinPromise; + assertFlags(win); + await BrowserTestUtils.closeWindow(win); + } + ); +}); + +/** + * Content can open a window using window.open + */ +add_task(async function test_new_remote_window_flags_window_open() { + let newWinPromise = BrowserTestUtils.waitForNewWindow(); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: SCRIPT_PAGE, + }, + async function (browser) { + let win = await newWinPromise; + assertFlags(win); + await BrowserTestUtils.closeWindow(win); + } + ); +}); + +/** + * Privileged content scripts can also open new windows + * using content.open. + */ +add_task(async function test_new_remote_window_flags_content_open() { + let newWinPromise = BrowserTestUtils.waitForNewWindow(); + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { + content.open("about:blank", "_blank"); + }); + + let win = await newWinPromise; + assertFlags(win); + await BrowserTestUtils.closeWindow(win); +}); -- cgit v1.2.3