Bug 1234757 - Use channel.asyncOpen2 within netwerk/test/unit/test_protocolproxyservice.js (r=mcmanus)

This commit is contained in:
Christoph Kerschbaumer 2016-01-15 11:34:34 -08:00
parent 7c8730a8f8
commit 39ea40404c

View File

@ -17,7 +17,7 @@
// run_myipaddress_test(); // run_myipaddress_test();
// run_failed_script_test(); // run_failed_script_test();
// run_isresolvable_test(); // run_isresolvable_test();
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm");
var ios = Components.classes["@mozilla.org/network/io-service;1"] var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService); .getService(Components.interfaces.nsIIOService);
@ -172,14 +172,10 @@ resolveCallback.prototype = {
}; };
function run_filter_test() { function run_filter_test() {
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Verify initial state // Verify initial state
var cb = new resolveCallback(); var cb = new resolveCallback();
@ -202,14 +198,10 @@ function filter_test0_1(pi) {
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = filter_test0_2; cb.nextFunction = filter_test0_2;
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
} }
@ -222,14 +214,10 @@ function filter_test0_2(pi)
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = filter_test0_3; cb.nextFunction = filter_test0_3;
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
} }
@ -244,14 +232,10 @@ function filter_test0_3(pi)
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = filter_test0_4; cb.nextFunction = filter_test0_4;
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
} }
@ -264,14 +248,10 @@ function filter_test0_4(pi)
pps.registerChannelFilter(filter03, 10); pps.registerChannelFilter(filter03, 10);
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = filter_test0_5; cb.nextFunction = filter_test0_5;
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
} }
@ -353,14 +333,10 @@ function run_filter_test2() {
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = filter_test1_1; cb.nextFunction = filter_test1_1;
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
} }
@ -372,14 +348,10 @@ function filter_test1_1(pi) {
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = filter_test1_2; cb.nextFunction = filter_test1_2;
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
} }
@ -392,14 +364,10 @@ function filter_test1_2(pi) {
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = filter_test1_3; cb.nextFunction = filter_test1_3;
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
} }
@ -411,15 +379,10 @@ function filter_test1_3(pi) {
var filter_3_1; var filter_3_1;
function run_filter_test3() { function run_filter_test3() {
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Push a filter and verify the results asynchronously // Push a filter and verify the results asynchronously
filter_3_1 = new TestFilter("http", "foo", 8080, 0, 10); filter_3_1 = new TestFilter("http", "foo", 8080, 0, 10);
@ -437,15 +400,10 @@ function filter_test3_1(pi) {
} }
function run_pref_test() { function run_pref_test() {
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Verify 'direct' setting // Verify 'direct' setting
prefs.setIntPref("network.proxy.type", 0); prefs.setIntPref("network.proxy.type", 0);
@ -464,14 +422,10 @@ function pref_test1_1(pi)
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = pref_test1_2; cb.nextFunction = pref_test1_2;
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
} }
@ -486,14 +440,10 @@ function pref_test1_2(pi)
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = pref_test1_3; cb.nextFunction = pref_test1_3;
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
} }
@ -510,14 +460,10 @@ function pref_test1_3(pi)
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = pref_test1_4; cb.nextFunction = pref_test1_4;
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
} }
@ -575,15 +521,10 @@ function run_pac_test() {
'function FindProxyForURL(url, host) {' + 'function FindProxyForURL(url, host) {' +
' return "PROXY foopy:8080; DIRECT";' + ' return "PROXY foopy:8080; DIRECT";' +
'}'; '}';
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Configure PAC // Configure PAC
prefs.setIntPref("network.proxy.type", 2); prefs.setIntPref("network.proxy.type", 2);
@ -596,15 +537,10 @@ function run_pac2_test() {
'function FindProxyForURL(url, host) {' + 'function FindProxyForURL(url, host) {' +
' return "HTTPS foopy:8080; DIRECT";' + ' return "HTTPS foopy:8080; DIRECT";' +
'}'; '}';
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Configure PAC // Configure PAC
originalTLSProxy = prefs.getBoolPref("network.proxy.proxy_over_tls"); originalTLSProxy = prefs.getBoolPref("network.proxy.proxy_over_tls");
@ -619,15 +555,10 @@ function run_pac3_test() {
'function FindProxyForURL(url, host) {' + 'function FindProxyForURL(url, host) {' +
' return "HTTPS foopy:8080; DIRECT";' + ' return "HTTPS foopy:8080; DIRECT";' +
'}'; '}';
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Configure PAC // Configure PAC
prefs.setCharPref("network.proxy.autoconfig_url", pac); prefs.setCharPref("network.proxy.autoconfig_url", pac);
prefs.setBoolPref("network.proxy.proxy_over_tls", false); prefs.setBoolPref("network.proxy.proxy_over_tls", false);
@ -662,14 +593,10 @@ function run_pac4_test() {
' && myAppOrigin() == "' + appOrigin + '")' + ' && myAppOrigin() == "' + appOrigin + '")' +
' return "PROXY foopy:8080; DIRECT";' + ' return "PROXY foopy:8080; DIRECT";' +
'}'; '}';
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
channel.notificationCallbacks = channel.notificationCallbacks =
AppsUtils.createLoadContext(appId, isInBrowser); AppsUtils.createLoadContext(appId, isInBrowser);
@ -713,15 +640,10 @@ TestResolveCancelationCallback.prototype = {
}; };
function run_pac_cancel_test() { function run_pac_cancel_test() {
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Configure PAC // Configure PAC
var pac = 'data:text/plain,' + var pac = 'data:text/plain,' +
'function FindProxyForURL(url, host) {' + 'function FindProxyForURL(url, host) {' +
@ -761,15 +683,10 @@ function check_host_filters_cb()
function check_host_filter(i) { function check_host_filter(i) {
var uri; var uri;
dump("*** uri=" + hostList[i] + " bShouldBeFiltered=" + bShouldBeFiltered + "\n"); dump("*** uri=" + hostList[i] + " bShouldBeFiltered=" + bShouldBeFiltered + "\n");
var channel = ios.newChannel2(hostList[i], var channel = NetUtil.newChannel({
null, uri: hostList[i],
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var cb = new resolveCallback(); var cb = new resolveCallback();
cb.nextFunction = host_filter_cb; cb.nextFunction = host_filter_cb;
var req = pps.asyncResolve(channel, 0, cb); var req = pps.asyncResolve(channel, 0, cb);
@ -872,15 +789,10 @@ function run_myipaddress_test()
// no traffic to this IP is ever sent, it is just a public IP that // no traffic to this IP is ever sent, it is just a public IP that
// does not require DNS to determine a route. // does not require DNS to determine a route.
var channel = ios.newChannel2("http://192.0.43.10/", var channel = NetUtil.newChannel({
null, uri: "http://192.0.43.10/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
prefs.setIntPref("network.proxy.type", 2); prefs.setIntPref("network.proxy.type", 2);
prefs.setCharPref("network.proxy.autoconfig_url", pac); prefs.setCharPref("network.proxy.autoconfig_url", pac);
@ -915,14 +827,10 @@ function run_myipaddress_test_2()
' return "PROXY " + myaddr + ":5678";' + ' return "PROXY " + myaddr + ":5678";' +
'}'; '}';
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
prefs.setIntPref("network.proxy.type", 2); prefs.setIntPref("network.proxy.type", 2);
prefs.setCharPref("network.proxy.autoconfig_url", pac); prefs.setCharPref("network.proxy.autoconfig_url", pac);
@ -951,15 +859,10 @@ function run_failed_script_test()
var pac = 'data:text/plain,' + var pac = 'data:text/plain,' +
'\nfor(;\n'; '\nfor(;\n';
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
prefs.setIntPref("network.proxy.type", 2); prefs.setIntPref("network.proxy.type", 2);
prefs.setCharPref("network.proxy.autoconfig_url", pac); prefs.setCharPref("network.proxy.autoconfig_url", pac);
@ -985,15 +888,11 @@ function failed_script_callback(pi)
obs = obs.QueryInterface(Components.interfaces.nsIObserverService); obs = obs.QueryInterface(Components.interfaces.nsIObserverService);
obs.addObserver(directFilterListener, "http-on-modify-request", false); obs.addObserver(directFilterListener, "http-on-modify-request", false);
var chan = ios.newChannel2("http://127.0.0.1:7247", var chan = NetUtil.newChannel({
"", uri: "http://127.0.0.1:7247",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(), chan.asyncOpen2(directFilterListener);
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
chan.asyncOpen(directFilterListener, null);
} }
var directFilterListener = { var directFilterListener = {
@ -1038,15 +937,10 @@ function run_isresolvable_test()
' return "PROXY 127.0.0.1:1234";' + ' return "PROXY 127.0.0.1:1234";' +
'}'; '}';
var channel = ios.newChannel2("http://www.mozilla.org/", var channel = NetUtil.newChannel({
null, uri: "http://www.mozilla.org/",
null, loadUsingSystemPrincipal: true
null, // aLoadingNode });
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
prefs.setIntPref("network.proxy.type", 2); prefs.setIntPref("network.proxy.type", 2);
prefs.setCharPref("network.proxy.autoconfig_url", pac); prefs.setCharPref("network.proxy.autoconfig_url", pac);