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_firstPartyIsolation_about_newtab.js | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 browser/components/originattributes/test/browser/browser_firstPartyIsolation_about_newtab.js (limited to 'browser/components/originattributes/test/browser/browser_firstPartyIsolation_about_newtab.js') diff --git a/browser/components/originattributes/test/browser/browser_firstPartyIsolation_about_newtab.js b/browser/components/originattributes/test/browser/browser_firstPartyIsolation_about_newtab.js new file mode 100644 index 0000000000..b3e175c6a1 --- /dev/null +++ b/browser/components/originattributes/test/browser/browser_firstPartyIsolation_about_newtab.js @@ -0,0 +1,55 @@ +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.newtab.preload", false], + ["privacy.firstparty.isolate", true], + ], + }); +}); + +/** + * Test about:newtab will have firstPartytDomain set when we enable the pref. + * + * We split about:newtab from browser_firstPartyIsolation_aboutPages.js because + * about:newtab needs special care. + * + * In the original test browser_firstPartyIsolation_aboutPages.js, when calling + * tabbrowser.addTab, if it found out the uri is about:newtab, it will use + * the preloaded browser, however the preloaded browser is loaded before when we + * turn on the firstPartyIsolation pref, which won't have the pref set. + * + * To prevent to use the preloaded browser, a simple trick is open a window + * first. + **/ +add_task(async function test_aboutNewTab() { + // In Fission, we cannot open a non-remote window. + let win = await BrowserTestUtils.openNewBrowserWindow({ + remote: SpecialPowers.useRemoteSubframes, + }); + let gbrowser = win.gBrowser; + let tab = BrowserTestUtils.addTab(gbrowser, "about:newtab"); + await BrowserTestUtils.browserLoaded(tab.linkedBrowser); + + let attrs = { + firstPartyDomain: "about.ef2a7dd5-93bc-417f-a698-142c3116864f.mozilla", + }; + await SpecialPowers.spawn( + tab.linkedBrowser, + [{ attrs }], + async function (args) { + Assert.ok(true, "principal " + content.document.nodePrincipal.origin); + Assert.equal( + content.document.nodePrincipal.originAttributes.firstPartyDomain, + args.attrs.firstPartyDomain, + "about:newtab should have firstPartyDomain set" + ); + Assert.ok( + content.document.nodePrincipal.isContentPrincipal, + "The principal should be a content principal." + ); + } + ); + + gbrowser.removeTab(tab); + win.close(); +}); -- cgit v1.2.3