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/browser_usercontextid_new_window.js | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 browser/components/contextualidentity/test/browser/browser_usercontextid_new_window.js (limited to 'browser/components/contextualidentity/test/browser/browser_usercontextid_new_window.js') diff --git a/browser/components/contextualidentity/test/browser/browser_usercontextid_new_window.js b/browser/components/contextualidentity/test/browser/browser_usercontextid_new_window.js new file mode 100644 index 0000000000..5fd4c6f3c2 --- /dev/null +++ b/browser/components/contextualidentity/test/browser/browser_usercontextid_new_window.js @@ -0,0 +1,93 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test that the content of new browser windows have the expected +// userContextId when it passed as the window arguments. + +const TEST_URI = + getRootDirectory(gTestPath).replace( + "chrome://mochitests/content", + "http://mochi.test:8888" + ) + "empty_file.html"; + +function openWindowWithUserContextId(userContextId, isPrivate) { + let flags = "chrome,dialog=no,all"; + if (isPrivate) { + flags += ",private"; + } + + let args = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); + + let urlSupports = Cc["@mozilla.org/supports-string;1"].createInstance( + Ci.nsISupportsString + ); + urlSupports.data = TEST_URI; + args.appendElement(urlSupports); + + args.appendElement(null); + args.appendElement(null); + args.appendElement(null); + args.appendElement(null); + + let userContextIdSupports = Cc[ + "@mozilla.org/supports-PRUint32;1" + ].createInstance(Ci.nsISupportsPRUint32); + userContextIdSupports.data = userContextId; + args.appendElement(userContextIdSupports); + + args.appendElement(Services.scriptSecurityManager.getSystemPrincipal()); + args.appendElement(Services.scriptSecurityManager.getSystemPrincipal()); + args.appendElement(Services.scriptSecurityManager.getSystemPrincipal()); + + let windowPromise = BrowserTestUtils.waitForNewWindow({ url: TEST_URI }); + Services.ww.openWindow( + null, + AppConstants.BROWSER_CHROME_URL, + "_blank", + flags, + args + ); + return windowPromise; +} + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.userContext.enabled", true]], + }); +}); + +add_task(async function test_new_window() { + let win = await openWindowWithUserContextId(1, false); + + await SpecialPowers.spawn(win.gBrowser.selectedBrowser, [TEST_URI], url => { + Assert.equal(content.document.URL, url, "expected document URL"); + let { originAttributes } = content.document.nodePrincipal; + Assert.equal(originAttributes.userContextId, 1, "expected userContextId"); + Assert.equal( + originAttributes.privateBrowsingId, + 0, + "expected non-private context" + ); + }); + + await BrowserTestUtils.closeWindow(win); +}); + +add_task(async function test_new_private_window() { + let win = await openWindowWithUserContextId(1, true); + + await SpecialPowers.spawn(win.gBrowser.selectedBrowser, [TEST_URI], url => { + Assert.equal(content.document.URL, url, "expected document URL"); + let { originAttributes } = content.document.nodePrincipal; + Assert.equal(originAttributes.userContextId, 1, "expected userContextId"); + Assert.equal( + originAttributes.privateBrowsingId, + 1, + "expected private context" + ); + }); + + await BrowserTestUtils.closeWindow(win); +}); -- cgit v1.2.3