зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1779005 - Use mLoadFailureCount as an indicator for PAC laod, r=necko-reviewers,valentin
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
This commit is contained in:
Родитель
468f9cd2e5
Коммит
d4b82c3973
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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:${pacServer.identity.primaryPort}/proxy.pac`
|
||||
);
|
||||
|
||||
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");
|
||||
});
|
|
@ -636,3 +636,4 @@ run-sequentially = node server exceptions dont replay well
|
|||
run-sequentially = node server exceptions dont replay well
|
||||
[test_h2proxy_connection_limit.js]
|
||||
run-sequentially = node server exceptions dont replay well
|
||||
[test_pac_reload_after_network_change.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче