From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../browser_modifiedclick_inherit_principal.js | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 browser/base/content/test/general/browser_modifiedclick_inherit_principal.js (limited to 'browser/base/content/test/general/browser_modifiedclick_inherit_principal.js') diff --git a/browser/base/content/test/general/browser_modifiedclick_inherit_principal.js b/browser/base/content/test/general/browser_modifiedclick_inherit_principal.js new file mode 100644 index 0000000000..be3de519d6 --- /dev/null +++ b/browser/base/content/test/general/browser_modifiedclick_inherit_principal.js @@ -0,0 +1,42 @@ +"use strict"; + +const kURL = + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://example.com/browser/browser/base/content/test/general/dummy_page.html"; +("data:text/html,Middle-click me"); + +/* + * Check that when manually opening content JS links in new tabs/windows, + * we use the correct principal, and we don't clear the URL bar. + */ +add_task(async function () { + await BrowserTestUtils.withNewTab(kURL, async function (browser) { + let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser); + await SpecialPowers.spawn(browser, [], async function () { + let a = content.document.createElement("a"); + // newTabPromise won't resolve until it has a URL that's not "about:blank". + // But doing document.open() from inside that same document does not change + // the URL of the docshell. So we need to do some URL change to cause + // newTabPromise to resolve, since the document is at about:blank the whole + // time, URL-wise. Navigating to '#' should do the trick without changing + // anything else about the document involved. + a.href = + "javascript:document.write('spoof'); location.href='#'; void(0);"; + a.textContent = "Some link"; + content.document.body.appendChild(a); + }); + info("Added element"); + await BrowserTestUtils.synthesizeMouseAtCenter("a", { button: 1 }, browser); + let newTab = await newTabPromise; + is( + newTab.linkedBrowser.contentPrincipal.origin, + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://example.com", + "Principal should be for example.com" + ); + await BrowserTestUtils.switchTab(gBrowser, newTab); + info(gURLBar.value); + isnot(gURLBar.value, "", "URL bar should not be empty."); + BrowserTestUtils.removeTab(newTab); + }); +}); -- cgit v1.2.3