This is an automated email from the git hooks/post-receive script.
richard pushed a commit to branch geckoview-102.3.0esr-12.0-1 in repository tor-browser.
commit f9216d71e55862903a9854660278dccaf09e6e44 Author: Kershaw Chang kershaw@mozilla.com AuthorDate: Fri Aug 19 13:10:49 2022 +0000
Bug 1779005 - Use mLoadFailureCount as an indicator for PAC laod, r=necko-reviewers,valentin a=RyanVM
Since IsLoading() is false when PAC request fails, we have to use something else to indicate that PAC is not available. mLoadFailureCount can be used in this case. It only reset when PAC request is succeeded and when reloading a PAC.
Differential Revision: https://phabricator.services.mozilla.com/D154907 --- netwerk/base/nsPACMan.cpp | 4 +- .../unit/test_pac_reload_after_network_change.js | 71 ++++++++++++++++++++++ netwerk/test/unit/xpcshell.ini | 1 + 3 files changed, 75 insertions(+), 1 deletion(-)
diff --git a/netwerk/base/nsPACMan.cpp b/netwerk/base/nsPACMan.cpp index 63908e1cf0773..7fe88b4fe097c 100644 --- a/netwerk/base/nsPACMan.cpp +++ b/netwerk/base/nsPACMan.cpp @@ -802,7 +802,9 @@ bool nsPACMan::ProcessPending() {
RefPtr<PendingPACQuery> query(dont_AddRef(mPendingQ.popFirst()));
- if (mShutdown || IsLoading()) { + // Having |mLoadFailureCount > 0| means we haven't had a sucessful PAC load + // yet. We should use DIRECT instead. + if (mShutdown || IsLoading() || mLoadFailureCount > 0) { query->Complete(NS_ERROR_NOT_AVAILABLE, ""_ns); return true; } diff --git a/netwerk/test/unit/test_pac_reload_after_network_change.js b/netwerk/test/unit/test_pac_reload_after_network_change.js new file mode 100644 index 0000000000000..2b6826730ffdd --- /dev/null +++ b/netwerk/test/unit/test_pac_reload_after_network_change.js @@ -0,0 +1,71 @@ +"use strict"; + +const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js"); +XPCOMUtils.defineLazyServiceGetter( + this, + "gProxyService", + "@mozilla.org/network/protocol-proxy-service;1", + "nsIProtocolProxyService" +); +var { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm"); + +let pacServer; +const proxyPort = 4433; + +add_setup(async function() { + pacServer = new HttpServer(); + pacServer.registerPathHandler("/proxy.pac", function handler( + metadata, + response + ) { + let content = `function FindProxyForURL(url, host) { return "HTTPS localhost:${proxyPort}"; }`; + response.setHeader("Content-Length", `${content.length}`); + response.bodyOutputStream.write(content, content.length); + }); + pacServer.start(-1); +}); + +registerCleanupFunction(async () => { + Services.prefs.clearUserPref("network.proxy.type"); + Services.prefs.clearUserPref("network.proxy.autoconfig_url"); + Services.prefs.clearUserPref("network.proxy.reload_pac_delay"); +}); + +async function getProxyInfo() { + return new Promise((resolve, reject) => { + let uri = Services.io.newURI("http://www.mozilla.org/"); + gProxyService.asyncResolve(uri, 0, { + onProxyAvailable(_req, _uri, pi, _status) { + resolve(pi); + }, + }); + }); +} + +// Test if we can successfully get PAC when the PAC server is available. +add_task(async function testPAC() { + // Configure PAC + Services.prefs.setIntPref("network.proxy.type", 2); + Services.prefs.setCharPref( + "network.proxy.autoconfig_url", + `http://localhost:$%7BpacServer.identity.primaryPort%7D/proxy.pac%60 + ); + + let pi = await getProxyInfo(); + Assert.equal(pi.port, proxyPort, "Expected proxy port to be the same"); + Assert.equal(pi.type, "https", "Expected proxy type to be https"); +}); + +// When PAC server is down, we should not use proxy at all. +add_task(async function testWhenPACServerDown() { + Services.prefs.setIntPref("network.proxy.reload_pac_delay", 0); + await new Promise(resolve => pacServer.stop(resolve)); + + Services.obs.notifyObservers(null, "network:link-status-changed", "changed"); + + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + await new Promise(resolve => setTimeout(resolve, 3000)); + + let pi = await getProxyInfo(); + Assert.equal(pi, null, "should have no proxy"); +}); diff --git a/netwerk/test/unit/xpcshell.ini b/netwerk/test/unit/xpcshell.ini index 69d73597ed0fc..dd233f7c199e9 100644 --- a/netwerk/test/unit/xpcshell.ini +++ b/netwerk/test/unit/xpcshell.ini @@ -611,3 +611,4 @@ skip-if = run-sequentially = node server exceptions dont replay well [test_http_408_retry.js] [test_brotli_decoding.js] +[test_pac_reload_after_network_change.js]