diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/general/browser_modifiedclick_inherit_principal.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/general/browser_modifiedclick_inherit_principal.js | 42 |
1 files changed, 42 insertions, 0 deletions
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,<a href=''>Middle-click me</a>"); + +/* + * 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); + }); +}); |