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/tabs/helper_origin_attrs_testing.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/tabs/helper_origin_attrs_testing.js | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/browser/base/content/test/tabs/helper_origin_attrs_testing.js b/browser/base/content/test/tabs/helper_origin_attrs_testing.js new file mode 100644 index 0000000000..10ef8248c8 --- /dev/null +++ b/browser/base/content/test/tabs/helper_origin_attrs_testing.js @@ -0,0 +1,158 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const NUM_USER_CONTEXTS = 3; + +var xulFrameLoaderCreatedListenerInfo; + +function initXulFrameLoaderListenerInfo() { + xulFrameLoaderCreatedListenerInfo = {}; + xulFrameLoaderCreatedListenerInfo.numCalledSoFar = 0; +} + +function handleEvent(aEvent) { + if (aEvent.type != "XULFrameLoaderCreated") { + return; + } + // Ignore <browser> element in about:preferences and any other special pages + if ("gBrowser" in aEvent.target.ownerGlobal) { + xulFrameLoaderCreatedListenerInfo.numCalledSoFar++; + } +} + +async function openURIInRegularTab(uri, win = window) { + info(`Opening url ${uri} in a regular tab`); + + initXulFrameLoaderListenerInfo(); + win.gBrowser.addEventListener("XULFrameLoaderCreated", handleEvent); + + let tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, uri); + info( + `XULFrameLoaderCreated was fired ${xulFrameLoaderCreatedListenerInfo.numCalledSoFar} time(s) for ${uri} in regular tab` + ); + + is( + xulFrameLoaderCreatedListenerInfo.numCalledSoFar, + 1, + "XULFrameLoaderCreated fired correct number of times" + ); + + win.gBrowser.removeEventListener("XULFrameLoaderCreated", handleEvent); + return { tab, uri }; +} + +async function openURIInContainer(uri, win, userContextId) { + info(`Opening url ${uri} in user context ${userContextId}`); + initXulFrameLoaderListenerInfo(); + win.gBrowser.addEventListener("XULFrameLoaderCreated", handleEvent); + + let tab = BrowserTestUtils.addTab(win.gBrowser, uri, { + userContextId, + }); + is( + tab.getAttribute("usercontextid"), + userContextId.toString(), + "New tab has correct user context id" + ); + + let browser = tab.linkedBrowser; + + await BrowserTestUtils.browserLoaded(browser, false, uri); + info( + `XULFrameLoaderCreated was fired ${xulFrameLoaderCreatedListenerInfo.numCalledSoFar} + time(s) for ${uri} in container tab ${userContextId}` + ); + + is( + xulFrameLoaderCreatedListenerInfo.numCalledSoFar, + 1, + "XULFrameLoaderCreated fired correct number of times" + ); + + win.gBrowser.removeEventListener("XULFrameLoaderCreated", handleEvent); + + return { tab, user_context_id: userContextId, uri }; +} + +async function openURIInPrivateTab(uri) { + info( + `Opening url ${ + uri ? uri : "about:privatebrowsing" + } in a private browsing tab` + ); + let win = await BrowserTestUtils.openNewBrowserWindow({ + private: true, + waitForTabURL: "about:privatebrowsing", + }); + if (!uri) { + return { tab: win.gBrowser.selectedTab, uri: "about:privatebrowsing" }; + } + initXulFrameLoaderListenerInfo(); + win.gBrowser.addEventListener("XULFrameLoaderCreated", handleEvent); + + const browser = win.gBrowser.selectedTab.linkedBrowser; + let prevRemoteType = browser.remoteType; + let loaded = BrowserTestUtils.browserLoaded(browser, false, uri); + BrowserTestUtils.startLoadingURIString(browser, uri); + await loaded; + let currRemoteType = browser.remoteType; + + info( + `XULFrameLoaderCreated was fired ${xulFrameLoaderCreatedListenerInfo.numCalledSoFar} time(s) for ${uri} in private tab` + ); + + if ( + SpecialPowers.Services.appinfo.sessionHistoryInParent && + currRemoteType == prevRemoteType && + uri == "about:blank" + ) { + // about:blank page gets flagged for being eligible to go into bfcache + // and thus we create a new XULFrameLoader for these pages + is( + xulFrameLoaderCreatedListenerInfo.numCalledSoFar, + 1, + "XULFrameLoaderCreated fired correct number of times" + ); + } else { + is( + xulFrameLoaderCreatedListenerInfo.numCalledSoFar, + currRemoteType == prevRemoteType ? 0 : 1, + "XULFrameLoaderCreated fired correct number of times" + ); + } + + win.gBrowser.removeEventListener("XULFrameLoaderCreated", handleEvent); + return { tab: win.gBrowser.selectedTab, uri }; +} + +function initXulFrameLoaderCreatedCounter(aXulFrameLoaderCreatedListenerInfo) { + aXulFrameLoaderCreatedListenerInfo.numCalledSoFar = 0; +} + +// Expected remote types for the following tests: +// browser/base/content/test/tabs/browser_navigate_through_urls_origin_attributes.js +// browser/base/content/test/tabs/browser_origin_attrs_in_remote_type.js +function getExpectedRemoteTypes(gFissionBrowser, numPagesOpen) { + var remoteTypes; + if (gFissionBrowser) { + remoteTypes = [ + "webIsolated=https://example.com", + "webIsolated=https://example.com^userContextId=1", + "webIsolated=https://example.com^userContextId=2", + "webIsolated=https://example.com^userContextId=3", + "webIsolated=https://example.com^privateBrowsingId=1", + "webIsolated=https://example.org", + "webIsolated=https://example.org^userContextId=1", + "webIsolated=https://example.org^userContextId=2", + "webIsolated=https://example.org^userContextId=3", + "webIsolated=https://example.org^privateBrowsingId=1", + ]; + } else { + remoteTypes = Array(numPagesOpen * 2).fill("web"); // example.com and example.org + } + remoteTypes = remoteTypes.concat(Array(numPagesOpen * 2).fill(null)); // about: pages + return remoteTypes; +} |