mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 13:48:23 +02:00
Differential Revision: https://phabricator.services.mozilla.com/D29115 --HG-- rename : extensions/cookie/test/unit/head_cookies.js => netwerk/test/unit/head_cookies.js rename : extensions/cookie/test/unit/test_bug526789.js => netwerk/test/unit/test_bug526789.js rename : extensions/cookie/test/unit/test_bug650522.js => netwerk/test/unit/test_bug650522.js rename : extensions/cookie/test/unit/test_bug667087.js => netwerk/test/unit/test_bug667087.js rename : extensions/cookie/test/unit/test_cookies_async_failure.js => netwerk/test/unit/test_cookies_async_failure.js rename : extensions/cookie/test/unit/test_cookies_persistence.js => netwerk/test/unit/test_cookies_persistence.js rename : extensions/cookie/test/unit/test_cookies_privatebrowsing.js => netwerk/test/unit/test_cookies_privatebrowsing.js rename : extensions/cookie/test/unit/test_cookies_profile_close.js => netwerk/test/unit/test_cookies_profile_close.js rename : extensions/cookie/test/unit/test_cookies_read.js => netwerk/test/unit/test_cookies_read.js rename : extensions/cookie/test/unit/test_cookies_sync_failure.js => netwerk/test/unit/test_cookies_sync_failure.js rename : extensions/cookie/test/unit/test_cookies_thirdparty.js => netwerk/test/unit/test_cookies_thirdparty.js rename : extensions/cookie/test/unit/test_cookies_thirdparty_nonsecure_session.js => netwerk/test/unit/test_cookies_thirdparty_nonsecure_session.js rename : extensions/cookie/test/unit/test_cookies_thirdparty_session.js => netwerk/test/unit/test_cookies_thirdparty_session.js rename : extensions/cookie/test/unit/test_domain_eviction.js => netwerk/test/unit/test_domain_eviction.js rename : extensions/cookie/test/unit/test_eviction.js => netwerk/test/unit/test_eviction.js rename : extensions/cookie/test/unit/test_schema_2_migration.js => netwerk/test/unit/test_schema_2_migration.js rename : extensions/cookie/test/unit/test_schema_3_migration.js => netwerk/test/unit/test_schema_3_migration.js extra : moz-landing-system : lando
152 lines
5.4 KiB
JavaScript
152 lines
5.4 KiB
JavaScript
"use strict";
|
|
|
|
const {MockRegistrar} = ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gProxyService",
|
|
"@mozilla.org/network/protocol-proxy-service;1",
|
|
"nsIProtocolProxyService");
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "systemSettings", function() {
|
|
return {
|
|
QueryInterface: function (iid) {
|
|
if (iid.equals(Ci.nsISupports) ||
|
|
iid.equals(Ci.nsISystemProxySettings))
|
|
return this;
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
|
},
|
|
|
|
mainThreadOnly: true,
|
|
PACURI: null,
|
|
|
|
getProxyForURI: function(aSpec, aScheme, aHost, aPort) {
|
|
if (aPort != -1) {
|
|
return 'SOCKS5 http://localhost:9050'
|
|
}
|
|
if (aScheme == 'http' ||
|
|
aScheme == 'https' ||
|
|
aScheme == 'ftp') {
|
|
return 'PROXY http://localhost:8080';
|
|
}
|
|
return 'DIRECT';
|
|
}
|
|
};
|
|
});
|
|
|
|
let gMockProxy = MockRegistrar.register("@mozilla.org/system-proxy-settings;1",
|
|
systemSettings);
|
|
|
|
registerCleanupFunction(() => {
|
|
MockRegistrar.unregister(gMockProxy);
|
|
});
|
|
|
|
function makeChannel(uri) {
|
|
return NetUtil.newChannel({
|
|
uri: uri,
|
|
loadUsingSystemPrincipal: true,
|
|
});
|
|
}
|
|
|
|
async function TestProxyType(chan, flags) {
|
|
const prefs = Cc["@mozilla.org/preferences-service;1"]
|
|
.getService(Ci.nsIPrefBranch);
|
|
prefs.setIntPref(
|
|
"network.proxy.type",
|
|
Ci.nsIProtocolProxyService.PROXYCONFIG_SYSTEM);
|
|
|
|
return await new Promise((resolve, reject) => {
|
|
gProxyService.asyncResolve(chan, flags, {
|
|
onProxyAvailable(req, uri, pi, status) {
|
|
resolve(pi);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
async function TestProxyTypeByURI(uri) {
|
|
return await TestProxyType(makeChannel(uri), 0);
|
|
}
|
|
|
|
add_task(async function testHttpProxy() {
|
|
let pi = await TestProxyTypeByURI("http://www.mozilla.org/");
|
|
equal(pi.host, "localhost", "Expected proxy host to be localhost");
|
|
equal(pi.port, 8080, "Expected proxy port to be 8080");
|
|
equal(pi.type, "http", "Expected proxy type to be http");
|
|
});
|
|
|
|
add_task(async function testHttpsProxy() {
|
|
let pi = await TestProxyTypeByURI("https://www.mozilla.org/");
|
|
equal(pi.host, "localhost", "Expected proxy host to be localhost");
|
|
equal(pi.port, 8080, "Expected proxy port to be 8080");
|
|
equal(pi.type, "http", "Expected proxy type to be http");
|
|
});
|
|
|
|
add_task(async function testFtpProxy() {
|
|
let pi = await TestProxyTypeByURI("ftp://ftp.mozilla.org/");
|
|
equal(pi.host, "localhost", "Expected proxy host to be localhost");
|
|
equal(pi.port, 8080, "Expected proxy port to be 8080");
|
|
equal(pi.type, "http", "Expected proxy type to be http");
|
|
});
|
|
|
|
add_task(async function testSocksProxy() {
|
|
let pi = await TestProxyTypeByURI("http://www.mozilla.org:1234/");
|
|
equal(pi.host, "localhost", "Expected proxy host to be localhost");
|
|
equal(pi.port, 9050, "Expected proxy port to be 8080");
|
|
equal(pi.type, "socks", "Expected proxy type to be http");
|
|
});
|
|
|
|
add_task(async function testDirectProxy() {
|
|
// Do what |WebSocketChannel::AsyncOpen| do, but do not prefer https proxy.
|
|
let proxyURI = Cc["@mozilla.org/network/standard-url-mutator;1"]
|
|
.createInstance(Ci.nsIURIMutator)
|
|
.setSpec("wss://ws.mozilla.org/")
|
|
.finalize();
|
|
let uri = proxyURI.mutate()
|
|
.setScheme("https")
|
|
.finalize();
|
|
|
|
let ioService = Cc["@mozilla.org/network/io-service;1"].
|
|
getService(Ci.nsIIOService);
|
|
let chan = ioService.
|
|
newChannelFromURIWithProxyFlags(uri,
|
|
proxyURI,
|
|
0,
|
|
null,
|
|
Services.scriptSecurityManager.getSystemPrincipal(),
|
|
null,
|
|
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
|
Ci.nsIContentPolicy.TYPE_OTHER);
|
|
|
|
let pi = await TestProxyType(chan, 0);
|
|
equal(pi, null, "Expected proxy host to be null");
|
|
});
|
|
|
|
add_task(async function testWebSocketProxy() {
|
|
// Do what |WebSocketChannel::AsyncOpen| do
|
|
let proxyURI = Cc["@mozilla.org/network/standard-url-mutator;1"]
|
|
.createInstance(Ci.nsIURIMutator)
|
|
.setSpec("wss://ws.mozilla.org/")
|
|
.finalize();
|
|
let uri = proxyURI.mutate()
|
|
.setScheme("https")
|
|
.finalize();
|
|
|
|
let proxyFlags = Ci.nsIProtocolProxyService.RESOLVE_PREFER_HTTPS_PROXY |
|
|
Ci.nsIProtocolProxyService.RESOLVE_ALWAYS_TUNNEL;
|
|
|
|
let ioService = Cc["@mozilla.org/network/io-service;1"].
|
|
getService(Ci.nsIIOService);
|
|
let chan = ioService.
|
|
newChannelFromURIWithProxyFlags(uri,
|
|
proxyURI,
|
|
proxyFlags,
|
|
null,
|
|
Services.scriptSecurityManager.getSystemPrincipal(),
|
|
null,
|
|
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
|
Ci.nsIContentPolicy.TYPE_OTHER);
|
|
|
|
let pi = await TestProxyType(chan, proxyFlags);
|
|
equal(pi.host, "localhost", "Expected proxy host to be localhost");
|
|
equal(pi.port, 8080, "Expected proxy port to be 8080");
|
|
equal(pi.type, "http", "Expected proxy type to be http");
|
|
});
|