From 23d824ce11e9c78ffe1ea29fa7b7f786c6afcc21 Mon Sep 17 00:00:00 2001 From: Noemi Erli Date: Mon, 9 Sep 2024 17:22:40 +0300 Subject: [PATCH] Backed out 2 changesets (bug 1907304) for causing failures in browser_net_offline_mode.js CLOSED TREE Backed out changeset 17ad7316a6df (bug 1907304) Backed out changeset c872b365b709 (bug 1907304) --- devtools/client/netmonitor/test/browser.toml | 2 - .../test/browser_net_throttling_cached.js | 68 ------------------- netwerk/protocol/http/nsHttpChannel.cpp | 25 +++---- 3 files changed, 10 insertions(+), 85 deletions(-) delete mode 100644 devtools/client/netmonitor/test/browser_net_throttling_cached.js diff --git a/devtools/client/netmonitor/test/browser.toml b/devtools/client/netmonitor/test/browser.toml index 39537e79fb05..957cbfec1c96 100644 --- a/devtools/client/netmonitor/test/browser.toml +++ b/devtools/client/netmonitor/test/browser.toml @@ -512,8 +512,6 @@ fail-if = ["a11y_checks"] # Bug 1849028 clicked element may not be focusable and ["browser_net_throttle.js"] -["browser_net_throttling_cached.js"] - ["browser_net_throttling_profiles.js"] ["browser_net_timeline_ticks.js"] diff --git a/devtools/client/netmonitor/test/browser_net_throttling_cached.js b/devtools/client/netmonitor/test/browser_net_throttling_cached.js deleted file mode 100644 index 47238932331a..000000000000 --- a/devtools/client/netmonitor/test/browser_net_throttling_cached.js +++ /dev/null @@ -1,68 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const { - profiles, - PROFILE_CONSTANTS, -} = require("resource://devtools/client/shared/components/throttling/profiles.js"); - -const offlineProfile = profiles.find( - profile => profile.id === PROFILE_CONSTANTS.OFFLINE -); - -const CACHED_URL = STATUS_CODES_SJS + "?sts=ok&cached&test_cached"; - -add_setup(async function () { - await pushPref("devtools.cache.disabled", false); -}); - -add_task(async function () { - const { monitor } = await initNetMonitor(SIMPLE_URL, { requestCount: 1 }); - const { connector } = monitor.panelWin; - const { updateNetworkThrottling } = connector; - - // Throttle the network before entering the content process - await updateNetworkThrottling(true, offlineProfile); - - // The request is blocked since the profile is offline - await SpecialPowers.spawn( - gBrowser.selectedBrowser, - [CACHED_URL], - async url => { - try { - await content.fetch(url); - ok(false, "Should not load since tab is offline"); - } catch (err) { - is(err.name, "TypeError", "Should fail since profile is offline"); - } - } - ); - - // Disable throttling - await updateNetworkThrottling(false); - - // Fetch to prime the cache - await SpecialPowers.spawn( - gBrowser.selectedBrowser, - [CACHED_URL], - async url => { - await content.fetch(url); - } - ); - - // Set profile to offline again - await updateNetworkThrottling(true, offlineProfile); - - // Check that cached resource loaded - await SpecialPowers.spawn( - gBrowser.selectedBrowser, - [CACHED_URL], - async url => { - await content.fetch(url); - } - ); - - await teardown(monitor); -}); diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 61d038fbf5cb..b968ed0943eb 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -665,6 +665,12 @@ nsresult nsHttpChannel::OnBeforeConnect() { // SecurityInfo.sys.mjs mLoadInfo->SetHstsStatus(isSecureURI); + RefPtr bc; + mLoadInfo->GetBrowsingContext(getter_AddRefs(bc)); + if (bc && bc->Top()->GetForceOffline()) { + return NS_ERROR_OFFLINE; + } + // At this point it is no longer possible to call // HttpBaseChannel::UpgradeToSecure. StoreUpgradableToSecure(false); @@ -767,12 +773,7 @@ nsresult nsHttpChannel::MaybeUseHTTPSRRForUpgrade(bool aShouldUpgrade, return aStatus; } - RefPtr bc; - mLoadInfo->GetBrowsingContext(getter_AddRefs(bc)); - bool forceOffline = bc && bc->Top()->GetForceOffline(); - - if (mURI->SchemeIs("https") || aShouldUpgrade || !LoadUseHTTPSSVC() || - forceOffline) { + if (mURI->SchemeIs("https") || aShouldUpgrade || !LoadUseHTTPSSVC()) { return ContinueOnBeforeConnect(aShouldUpgrade, aStatus); } @@ -1225,12 +1226,6 @@ nsresult nsHttpChannel::ContinueConnect() { return NS_ERROR_DOCUMENT_NOT_CACHED; } - RefPtr bc; - mLoadInfo->GetBrowsingContext(getter_AddRefs(bc)); - if (bc && bc->Top()->GetForceOffline()) { - return NS_ERROR_OFFLINE; - } - // hit the net... nsresult rv = DoConnect(mTransactionSticky); mTransactionSticky = nullptr; @@ -4139,10 +4134,10 @@ nsresult nsHttpChannel::OpenCacheEntryInternal(bool isHttps) { return NS_OK; } - bool forceOffline = bc && bc->Top()->GetForceOffline(); - if (offline || (mLoadFlags & INHIBIT_CACHING) || forceOffline) { + if (offline || (mLoadFlags & INHIBIT_CACHING) || + (bc && bc->Top()->GetForceOffline())) { if (BYPASS_LOCAL_CACHE(mLoadFlags, LoadPreferCacheLoadOverBypass()) && - !offline && !forceOffline) { + !offline) { return NS_OK; } cacheEntryOpenFlags = nsICacheStorage::OPEN_READONLY;