diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/test/browser/browser_103_private_window.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/browser/browser_103_private_window.js')
-rw-r--r-- | netwerk/test/browser/browser_103_private_window.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/netwerk/test/browser/browser_103_private_window.js b/netwerk/test/browser/browser_103_private_window.js new file mode 100644 index 0000000000..2d6daf9501 --- /dev/null +++ b/netwerk/test/browser/browser_103_private_window.js @@ -0,0 +1,70 @@ +/* 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"; + +Services.prefs.setBoolPref("network.early-hints.enabled", true); + +registerCleanupFunction(function () { + Services.prefs.clearUserPref("network.early-hints.enabled"); +}); + +// Test steps: +// 1. Load early_hint_asset_html.sjs with a provided uuid. +// 2. In early_hint_asset_html.sjs, a 103 response with +// a Link header<early_hint_asset.sjs> and the provided uuid is returned. +// 3. We use "http-on-opening-request" topic to observe whether the +// early hinted request is created. +// 4. Finally, we check if the request has the correct `isPrivate` value. +async function test_early_hints_load_url(usePrivateWin) { + let headers = new Headers(); + headers.append("X-Early-Hint-Count-Start", ""); + await fetch( + "https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs", + { headers } + ); + + // Open a browsing window. + const win = await BrowserTestUtils.openNewBrowserWindow({ + private: usePrivateWin, + }); + + let id = Services.uuid.generateUUID().toString(); + let expectedUrl = `https://example.com/browser/netwerk/test/browser/early_hint_asset.sjs?as=fetch&uuid=${id}`; + let observed = {}; + let observer = { + QueryInterface: ChromeUtils.generateQI(["nsIObserver"]), + observe(aSubject, aTopic, aData) { + if (aTopic == "http-on-opening-request") { + let channel = aSubject.QueryInterface(Ci.nsIHttpChannel); + if (channel.URI.spec === expectedUrl) { + observed.actrualUrl = channel.URI.spec; + let isPrivate = channel.QueryInterface( + Ci.nsIPrivateBrowsingChannel + ).isChannelPrivate; + observed.isPrivate = isPrivate; + Services.obs.removeObserver(observer, "http-on-opening-request"); + } + } + }, + }; + Services.obs.addObserver(observer, "http-on-opening-request"); + + let requestUrl = `https://example.com/browser/netwerk/test/browser/early_hint_asset_html.sjs?as=fetch&hinted=1&uuid=${id}`; + + const browser = win.gBrowser.selectedTab.linkedBrowser; + let loaded = BrowserTestUtils.browserLoaded(browser, false, requestUrl); + BrowserTestUtils.loadURIString(browser, requestUrl); + await loaded; + + Assert.equal(observed.actrualUrl, expectedUrl); + Assert.equal(observed.isPrivate, usePrivateWin); + + await BrowserTestUtils.closeWindow(win); +} + +add_task(async function test_103_private_window() { + await test_early_hints_load_url(true); + await test_early_hints_load_url(false); +}); |