browser_modifiedclick_inherit_principal.js (1998B)
1 "use strict"; 2 3 const kURL = 4 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 5 "http://example.com/browser/browser/base/content/test/general/dummy_page.html"; 6 ("data:text/html,<a href=''>Middle-click me</a>"); 7 8 /* 9 * Check that when manually opening content JS links in new tabs/windows, 10 * we use the correct principal, and we don't clear the URL bar. 11 */ 12 add_task(async function () { 13 await SpecialPowers.pushPrefEnv({ 14 set: [ 15 ["browser.link.alternative_click.block_javascript", false], 16 ["dom.navigation.webidl.enabled", false], 17 ], 18 }); 19 20 await BrowserTestUtils.withNewTab(kURL, async function (browser) { 21 let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser); 22 await SpecialPowers.spawn(browser, [], async function () { 23 let a = content.document.createElement("a"); 24 // newTabPromise won't resolve until it has a URL that's not "about:blank". 25 // But doing document.open() from inside that same document does not change 26 // the URL of the docshell. So we need to do some URL change to cause 27 // newTabPromise to resolve, since the document is at about:blank the whole 28 // time, URL-wise. Navigating to '#' should do the trick without changing 29 // anything else about the document involved. 30 a.href = 31 "javascript:document.write('spoof'); location.href='#'; void(0);"; 32 a.textContent = "Some link"; 33 content.document.body.appendChild(a); 34 }); 35 info("Added element"); 36 await BrowserTestUtils.synthesizeMouseAtCenter("a", { button: 1 }, browser); 37 let newTab = await newTabPromise; 38 is( 39 newTab.linkedBrowser.contentPrincipal.origin, 40 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 41 "http://example.com", 42 "Principal should be for example.com" 43 ); 44 await BrowserTestUtils.switchTab(gBrowser, newTab); 45 info(gURLBar.value); 46 isnot(gURLBar.value, "", "URL bar should not be empty."); 47 BrowserTestUtils.removeTab(newTab); 48 }); 49 });