diff --git a/netwerk/test/unit/test_304_responses.js b/netwerk/test/unit/test_304_responses.js index ace151b2ff33..033c337b7fe5 100644 --- a/netwerk/test/unit/test_304_responses.js +++ b/netwerk/test/unit/test_304_responses.js @@ -2,7 +2,7 @@ // https://bugzilla.mozilla.org/show_bug.cgi?id=761228 Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); XPCOMUtils.defineLazyGetter(this, "URL", function() { return "http://localhost:" + httpServer.identity.primaryPort; @@ -26,16 +26,8 @@ function make_uri(url) { } function make_channel(url) { - var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - var chan = ios.newChannel2(url, - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER).QueryInterface(Ci.nsIHttpChannel); - return chan; + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}) + .QueryInterface(Ci.nsIHttpChannel); } function clearCache() { @@ -76,7 +68,7 @@ function consume304(request, buffer) { // a 304 response (i.e. when the server shouldn't have sent us one). add_test(function test_unexpected_304() { var chan = make_channel(baseURI + unexpected304); - chan.asyncOpen(new ChannelListener(consume304, null), null); + chan.asyncOpen2(new ChannelListener(consume304, null)); }); // Test that we can cope with a 304 response that was (erroneously) stored in @@ -98,6 +90,6 @@ add_test(function test_304_stored_in_cache() { chan.QueryInterface(Components.interfaces.nsIHttpChannel); chan.setRequestHeader("If-None-Match", '"foo"', false); - chan.asyncOpen(new ChannelListener(consume304, null), null); + chan.asyncOpen2(new ChannelListener(consume304, null)); }); }); diff --git a/netwerk/test/unit/test_bug248970_cookie.js b/netwerk/test/unit/test_bug248970_cookie.js index c4e6da153314..41c45e10593f 100644 --- a/netwerk/test/unit/test_bug248970_cookie.js +++ b/netwerk/test/unit/test_bug248970_cookie.js @@ -4,6 +4,7 @@ Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpserver; @@ -13,23 +14,16 @@ function inChildProcess() { .processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT; } function makeChan(path) { - var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - var chan = ios.newChannel2("http://localhost:" + httpserver.identity.primaryPort + "/" + path, - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER) - .QueryInterface(Ci.nsIHttpChannel); - return chan; + return NetUtil.newChannel({ + uri: "http://localhost:" + httpserver.identity.primaryPort + "/" + path, + loadUsingSystemPrincipal: true + }).QueryInterface(Ci.nsIHttpChannel); } function setup_chan(path, isPrivate, callback) { var chan = makeChan(path); chan.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(isPrivate); - chan.asyncOpen(new ChannelListener(callback), null); + chan.asyncOpen2(new ChannelListener(callback)); } function set_cookie(value, callback) { diff --git a/netwerk/test/unit/test_bug282432.js b/netwerk/test/unit/test_bug282432.js index 9d294e5a088e..f8da54356ad2 100644 --- a/netwerk/test/unit/test_bug282432.js +++ b/netwerk/test/unit/test_bug282432.js @@ -1,4 +1,4 @@ -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); function run_test() { do_test_pending(); @@ -34,12 +34,9 @@ function run_test() { // This file does not exist. let file = do_get_file("_NOT_EXIST_.txt", true); do_check_false(file.exists()); - - let channel = ios.newChannelFromURI2(ios.newFileURI(file), - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - channel.asyncOpen(listener, null); + let channel = NetUtil.newChannel({ + uri: ios.newFileURI(file), + loadUsingSystemPrincipal: true + }); + channel.asyncOpen2(listener); } diff --git a/netwerk/test/unit/test_bug369787.js b/netwerk/test/unit/test_bug369787.js index 32e682a34065..d59bef005c7a 100644 --- a/netwerk/test/unit/test_bug369787.js +++ b/netwerk/test/unit/test_bug369787.js @@ -1,5 +1,5 @@ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); const BUGID = "369787"; var server = null; @@ -55,21 +55,12 @@ function run_test() { server.start(-1); // make request - channel = - Components.classes["@mozilla.org/network/io-service;1"]. - getService(Components.interfaces.nsIIOService). - newChannel2("http://localhost:" + - server.identity.primaryPort + "/bug" + BUGID, - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - + channel = NetUtil.newChannel({ + uri: "http://localhost:" + server.identity.primaryPort + "/bug" + BUGID, + loadUsingSystemPrincipal: true + }); channel.QueryInterface(Components.interfaces.nsIHttpChannel); - channel.asyncOpen(new TestListener(), null); + channel.asyncOpen2(new TestListener()); do_test_pending(); } diff --git a/netwerk/test/unit/test_bug376660.js b/netwerk/test/unit/test_bug376660.js index bdc30aff9734..8208eef6a6cb 100644 --- a/netwerk/test/unit/test_bug376660.js +++ b/netwerk/test/unit/test_bug376660.js @@ -1,4 +1,4 @@ -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var Cc = Components.classes; var Ci = Components.interfaces; @@ -45,17 +45,11 @@ function test1() { createInstance(Ci.nsIUnicharStreamLoader); f.init(listener); - var ios = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); - var chan = ios.newChannel2("data:text/plain,", - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - chan.asyncOpen(f, null); + var chan = NetUtil.newChannel({ + uri: "data:text/plain,", + loadUsingSystemPrincipal: true + }); + chan.asyncOpen2(f); do_test_pending(); } @@ -65,18 +59,12 @@ function test2() { createInstance(Ci.nsIUnicharStreamLoader); f.init(listener); - var ios = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); - var chan = ios.newChannel2("http://localhost:0/", - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + var chan = NetUtil.newChannel({ + uri: "http://localhost:0/", + loadUsingSystemPrincipal: true + }); listener.expect_failure = true; - chan.asyncOpen(f, null); + chan.asyncOpen2(f); do_test_pending(); } diff --git a/netwerk/test/unit/test_bug468594.js b/netwerk/test/unit/test_bug468594.js index 81c333ae1dde..66d463190e09 100644 --- a/netwerk/test/unit/test_bug468594.js +++ b/netwerk/test/unit/test_bug468594.js @@ -14,7 +14,7 @@ // definition of "explicit expiration time" being used here. Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpserver = new HttpServer(); var index = 0; @@ -57,16 +57,10 @@ function logit(i, data) { } function setupChannel(suffix, value) { - var ios = Components.classes["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - var chan = ios.newChannel2("http://localhost:" + httpserver.identity.primaryPort + suffix, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + var chan = NetUtil.newChannel({ + uri: "http://localhost:" + httpserver.identity.primaryPort + suffix, + loadUsingSystemPrincipal: true + }); var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); httpChan.requestMethod = "GET"; httpChan.setRequestHeader("x-request", value, false); @@ -75,7 +69,7 @@ function setupChannel(suffix, value) { function triggerNextTest() { var channel = setupChannel(tests[index].url, tests[index].server); - channel.asyncOpen(new ChannelListener(checkValueAndTrigger, null),null); + channel.asyncOpen2(new ChannelListener(checkValueAndTrigger, null)); } function checkValueAndTrigger(request, data, ctx) { diff --git a/netwerk/test/unit/test_bug536324_64bit_content_length.js b/netwerk/test/unit/test_bug536324_64bit_content_length.js index dea7e52f7797..1dcb475be75d 100644 --- a/netwerk/test/unit/test_bug536324_64bit_content_length.js +++ b/netwerk/test/unit/test_bug536324_64bit_content_length.js @@ -2,7 +2,7 @@ a simple HTTP case */ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); // This C-L is significantly larger than (U)INT32_MAX, to make sure we do // 64-bit properly. @@ -47,18 +47,11 @@ function hugeContentLength(metadata, response) { } function test_hugeContentLength() { - var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - var chan = ios.newChannel2("http://localhost:" + - httpServer.identity.primaryPort + "/", - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER) - .QueryInterface(Ci.nsIHttpChannel); - chan.asyncOpen(listener, null); + var chan = NetUtil.newChannel({ + uri: "http://localhost:" + httpServer.identity.primaryPort + "/", + loadUsingSystemPrincipal: true + }).QueryInterface(Ci.nsIHttpChannel); + chan.asyncOpen2(listener); } add_test(test_hugeContentLength); diff --git a/netwerk/test/unit/test_bug669001.js b/netwerk/test/unit/test_bug669001.js index a0a038d132f1..bbb376f8f60f 100644 --- a/netwerk/test/unit/test_bug669001.js +++ b/netwerk/test/unit/test_bug669001.js @@ -1,5 +1,5 @@ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpServer = null; var path = "/bug699001"; @@ -9,16 +9,7 @@ XPCOMUtils.defineLazyGetter(this, "URI", function() { }); function make_channel(url) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - return ios.newChannel2(url, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); } var fetched; @@ -117,7 +108,7 @@ function nextTest() // Give the old channel a chance to close the cache entry first. // XXX This is actually a race condition that might be considered a bug... do_execute_soon(function() { - chan.asyncOpen(new ChannelListener(checkAndShiftTest, null), null); + chan.asyncOpen2(new ChannelListener(checkAndShiftTest, null)); }); } diff --git a/netwerk/test/unit/test_bug770243.js b/netwerk/test/unit/test_bug770243.js index 389e8e5ce5b2..8fd7abcea426 100644 --- a/netwerk/test/unit/test_bug770243.js +++ b/netwerk/test/unit/test_bug770243.js @@ -8,7 +8,7 @@ */ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpserv; @@ -28,19 +28,10 @@ function clearCreds() } function makeChan() { - var ios = Cc["@mozilla.org/network/io-service;1"] - .getService(Ci.nsIIOService); - var chan = ios.newChannel2("http://localhost:" + - httpserv.identity.primaryPort + "/", - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER) - .QueryInterface(Ci.nsIHttpChannel); - return chan; + return NetUtil.newChannel({ + uri: "http://localhost:" + httpserv.identity.primaryPort + "/", + loadUsingSystemPrincipal: true + }).QueryInterface(Ci.nsIHttpChannel); } // Array of handlers that are called one by one in response to expected requests @@ -148,46 +139,46 @@ var tests = [ // Test 1: 200 (cacheable) function() { var ch = makeChan(); - ch.asyncOpen(new ChannelListener(function(req, body) { + ch.asyncOpen2(new ChannelListener(function(req, body) { do_check_eq(body, "Response body 1"); sync_and_run_next_test(); - }, null, CL_NOT_FROM_CACHE), null); + }, null, CL_NOT_FROM_CACHE)); }, // Test 2: 401 and 200 + new content function() { var ch = makeChan(); - ch.asyncOpen(new ChannelListener(function(req, body) { + ch.asyncOpen2(new ChannelListener(function(req, body) { do_check_eq(body, "Response body 2"); sync_and_run_next_test(); - }, null, CL_NOT_FROM_CACHE), null); + }, null, CL_NOT_FROM_CACHE)); }, // Test 3: 401 and 304 function() { var ch = makeChan(); - ch.asyncOpen(new ChannelListener(function(req, body) { + ch.asyncOpen2(new ChannelListener(function(req, body) { do_check_eq(body, "Response body 2"); sync_and_run_next_test(); - }, null, CL_FROM_CACHE), null); + }, null, CL_FROM_CACHE)); }, // Test 4: 407 and 200 + new content function() { var ch = makeChan(); - ch.asyncOpen(new ChannelListener(function(req, body) { + ch.asyncOpen2(new ChannelListener(function(req, body) { do_check_eq(body, "Response body 3"); sync_and_run_next_test(); - }, null, CL_NOT_FROM_CACHE), null); + }, null, CL_NOT_FROM_CACHE)); }, // Test 5: 407 and 304 function() { var ch = makeChan(); - ch.asyncOpen(new ChannelListener(function(req, body) { + ch.asyncOpen2(new ChannelListener(function(req, body) { do_check_eq(body, "Response body 3"); sync_and_run_next_test(); - }, null, CL_FROM_CACHE), null); + }, null, CL_FROM_CACHE)); }, // End of test run diff --git a/netwerk/test/unit/test_cacheForOfflineUse_no-store.js b/netwerk/test/unit/test_cacheForOfflineUse_no-store.js index e6a7884ca3af..8a49242eee91 100644 --- a/netwerk/test/unit/test_cacheForOfflineUse_no-store.js +++ b/netwerk/test/unit/test_cacheForOfflineUse_no-store.js @@ -2,7 +2,7 @@ // https://bugzilla.mozilla.org/show_bug.cgi?id=760955 Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpServer = null; const testFileName = "test_nsHttpChannel_CacheForOfflineUse-no-store"; @@ -20,17 +20,8 @@ var cacheUpdateObserver = null; var appCache = null; function make_channel_for_offline_use(url, callback, ctx) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - var chan = ios.newChannel2(url, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - + var chan = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); + var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"]. getService(Components.interfaces.nsIApplicationCacheService); appCache = cacheService.getApplicationCache(cacheClientID); @@ -62,7 +53,7 @@ function checkNormal(request, buffer) } add_test(function test_normal() { var chan = make_channel_for_offline_use(baseURI + normalEntry); - chan.asyncOpen(new ChannelListener(checkNormal, chan), null); + chan.asyncOpen2(new ChannelListener(checkNormal, chan)); }); // An HTTP channel for updating the offline cache should fail when it gets a @@ -82,8 +73,7 @@ function checkNoStore(request, buffer) add_test(function test_noStore() { var chan = make_channel_for_offline_use(baseURI + noStoreEntry); // The no-store should cause the channel to fail to load. - chan.asyncOpen(new ChannelListener(checkNoStore, chan, CL_EXPECT_FAILURE), - null); + chan.asyncOpen2(new ChannelListener(checkNoStore, chan, CL_EXPECT_FAILURE)); }); function run_test() diff --git a/netwerk/test/unit/test_cache_jar.js b/netwerk/test/unit/test_cache_jar.js index e8fddfc48807..df16c8b2a460 100644 --- a/netwerk/test/unit/test_cache_jar.js +++ b/netwerk/test/unit/test_cache_jar.js @@ -1,5 +1,6 @@ Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyGetter(this, "URL", function() { @@ -19,15 +20,8 @@ function cached_handler(metadata, response) { } function makeChan(url, appId, inBrowser) { - var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - var chan = ios.newChannel2(url, - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER).QueryInterface(Ci.nsIHttpChannel); + var chan = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}) + .QueryInterface(Ci.nsIHttpChannel); chan.notificationCallbacks = { appId: appId, isInBrowserElement: inBrowser, @@ -53,7 +47,7 @@ function run_all_tests() { for (let test of firstTests) { handlers_called = 0; var chan = makeChan(URL, test[0], test[1]); - chan.asyncOpen(new ChannelListener(doneFirstLoad, test[2]), null); + chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[2])); yield undefined; } @@ -71,7 +65,7 @@ function run_all_tests() { for (let test of secondTests) { handlers_called = 0; var chan = makeChan(URL, test[0], test[1]); - chan.asyncOpen(new ChannelListener(doneFirstLoad, test[2]), null); + chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[2])); yield undefined; } @@ -81,7 +75,7 @@ function run_all_tests() { for (let test of thirdTests) { handlers_called = 0; var chan = makeChan(URL, test[0], test[1]); - chan.asyncOpen(new ChannelListener(doneFirstLoad, test[2]), null); + chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[2])); yield undefined; } } @@ -105,7 +99,7 @@ function doneFirstLoad(req, buffer, expected) { // Load it again, make sure it hits the cache var nc = req.notificationCallbacks.getInterface(Ci.nsILoadContext); var chan = makeChan(URL, nc.appId, nc.isInBrowserElement); - chan.asyncOpen(new ChannelListener(doneSecondLoad, expected), null); + chan.asyncOpen2(new ChannelListener(doneSecondLoad, expected)); } function doneSecondLoad(req, buffer, expected) { diff --git a/netwerk/test/unit/test_event_sink.js b/netwerk/test/unit/test_event_sink.js index 691dced70d61..45c01683a79f 100644 --- a/netwerk/test/unit/test_event_sink.js +++ b/netwerk/test/unit/test_event_sink.js @@ -1,7 +1,7 @@ // This file tests channel event sinks (bug 315598 et al) Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); XPCOMUtils.defineLazyGetter(this, "URL", function() { return "http://localhost:" + httpserv.identity.primaryPort; @@ -97,19 +97,7 @@ var listener = { }; function makeChan(url) { - var ios = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); - var chan = ios.newChannel2(url, - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER) - .QueryInterface(Components.interfaces.nsIHttpChannel); - - return chan; + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); } var httpserv = null; @@ -127,7 +115,7 @@ function run_test() { var chan = makeChan(URL + "/redirect"); chan.notificationCallbacks = eventsink; - chan.asyncOpen(listener, null); + chan.asyncOpen2(listener); do_test_pending(); } @@ -153,7 +141,7 @@ function run_test_continued() { } listener._iteration++; - chan.asyncOpen(listener, null); + chan.asyncOpen2(listener); do_test_pending(); } diff --git a/netwerk/test/unit/test_fallback_request-error_canceled.js b/netwerk/test/unit/test_fallback_request-error_canceled.js index 2f7c40295537..02129e6b4e16 100644 --- a/netwerk/test/unit/test_fallback_request-error_canceled.js +++ b/netwerk/test/unit/test_fallback_request-error_canceled.js @@ -1,5 +1,6 @@ Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpServer = null; // Need to randomize, because apparently no one clears our cache @@ -10,19 +11,9 @@ XPCOMUtils.defineLazyGetter(this, "randomURI", function() { }); var cacheUpdateObserver = null; -var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal(); function make_channel(url, callback, ctx) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - return ios.newChannel2(url, - "", - null, - null, // aLoadingNode - systemPrincipal, - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); } function make_uri(url) { @@ -108,7 +99,7 @@ function run_test() chan.notificationCallbacks = new ChannelEventSink(ES_ABORT_REDIRECT); var chanac = chan.QueryInterface(Ci.nsIApplicationCacheChannel); chanac.chooseApplicationCache = true; - chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE), null); + chan.asyncOpen2(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE)); }); }} @@ -123,7 +114,7 @@ function run_test() httpServer.identity.primaryPort + "/manifest"), make_uri("http://localhost:" + httpServer.identity.primaryPort + "/masterEntry"), - systemPrincipal, + Services.scriptSecurityManager.getSystemPrincipal(), null); do_test_pending(); diff --git a/netwerk/test/unit/test_httpResponseTimeout.js b/netwerk/test/unit/test_httpResponseTimeout.js index c676ac2f7ea4..3a40b0a0899d 100644 --- a/netwerk/test/unit/test_httpResponseTimeout.js +++ b/netwerk/test/unit/test_httpResponseTimeout.js @@ -7,7 +7,7 @@ "use strict"; Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var baseURL; const kResponseTimeoutPref = "network.http.response.timeout"; @@ -56,19 +56,10 @@ function testTimeout(timeoutEnabled, expectResponse) { prefService.setIntPref(kResponseTimeoutPref, 0); } - var ios = Cc["@mozilla.org/network/io-service;1"] - .getService(Ci.nsIIOService); - var chan = ios.newChannel2(baseURL, - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER) - .QueryInterface(Ci.nsIHttpChannel); + var chan = NetUtil.newChannel({uri: baseURL, loadUsingSystemPrincipal: true}) + .QueryInterface(Ci.nsIHttpChannel); var listener = new TimeoutListener(expectResponse); - chan.asyncOpen(listener, null); + chan.asyncOpen2(listener); } function testTimeoutEnabled() { diff --git a/netwerk/test/unit/test_httpcancel.js b/netwerk/test/unit/test_httpcancel.js index 5aed90017359..49188ca1ee24 100644 --- a/netwerk/test/unit/test_httpcancel.js +++ b/netwerk/test/unit/test_httpcancel.js @@ -5,7 +5,7 @@ // expected: see comments that start with ENSURE_CALLED_BEFORE_CONNECT: Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var ios = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); @@ -73,15 +73,8 @@ var listener = { }; function makeChan(url) { - var chan = ios.newChannel2(url, - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER) - .QueryInterface(Components.interfaces.nsIHttpChannel); + var chan = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}) + .QueryInterface(Components.interfaces.nsIHttpChannel); // ENSURE_CALLED_BEFORE_CONNECT: set original value var uri = ios.newURI("http://site1.com", null, null); @@ -100,7 +93,7 @@ function execute_test() { obs = obs.QueryInterface(Components.interfaces.nsIObserverService); obs.addObserver(observer, "http-on-modify-request", false); - chan.asyncOpen(listener, null); + chan.asyncOpen2(listener); } function run_test() { diff --git a/netwerk/test/unit/test_mismatch_last-modified.js b/netwerk/test/unit/test_mismatch_last-modified.js index 6c3489a35137..f675a123fbba 100644 --- a/netwerk/test/unit/test_mismatch_last-modified.js +++ b/netwerk/test/unit/test_mismatch_last-modified.js @@ -1,5 +1,5 @@ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpserver = new HttpServer(); var ios; @@ -69,18 +69,11 @@ XPCOMUtils.defineLazyGetter(this, "listener_2", function() { onStopRequest: function test_onStopR(request, ctx, status) { var channel = request.QueryInterface(Ci.nsIHttpChannel); - - var chan = ios.newChannel2("http://localhost:" + - httpserver.identity.primaryPort + - "/test1", - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - chan.asyncOpen(listener_3, null); + var chan = NetUtil.newChannel({ + uri: "http://localhost:" + httpserver.identity.primaryPort + "/test1", + loadUsingSystemPrincipal: true + }); + chan.asyncOpen2(listener_3); } }; }); @@ -107,19 +100,12 @@ XPCOMUtils.defineLazyGetter(this, "listener_1", function() { }, onStopRequest: function test_onStopR(request, ctx, status) { - var channel = request.QueryInterface(Ci.nsIHttpChannel); - - var chan = ios.newChannel2("http://localhost:" + - httpserver.identity.primaryPort + - "/test1", - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - chan.asyncOpen(listener_2, null); + var channel = request.QueryInterface(Ci.nsIHttpChannel); + var chan = NetUtil.newChannel({ + uri: "http://localhost:" + httpserver.identity.primaryPort + "/test1", + loadUsingSystemPrincipal: true + }); + chan.asyncOpen2(listener_2); } }; }); @@ -135,16 +121,11 @@ function run_test() { httpserver.start(-1); var port = httpserver.identity.primaryPort; - - var chan = ios.newChannel2("http://localhost:" + port + "/test1", - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - chan.asyncOpen(listener_1, null); + var chan = NetUtil.newChannel({ + uri: "http://localhost:" + port + "/test1", + loadUsingSystemPrincipal: true + }); + chan.asyncOpen2(listener_1); do_test_pending(); } diff --git a/netwerk/test/unit/test_multipart_byteranges.js b/netwerk/test/unit/test_multipart_byteranges.js index 0a6ee48d93f1..367615fff9f8 100644 --- a/netwerk/test/unit/test_multipart_byteranges.js +++ b/netwerk/test/unit/test_multipart_byteranges.js @@ -1,5 +1,5 @@ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpserver = null; @@ -8,16 +8,7 @@ XPCOMUtils.defineLazyGetter(this, "uri", function() { }); function make_channel(url) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - return ios.newChannel2(url, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); } var multipartBody = "--boundary\r\n"+ @@ -39,19 +30,6 @@ var multipartBody = "--boundary\r\n"+ "\r\n"+ "--boundary--"; -function make_channel(url) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - return ios.newChannel2(url, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); -} - function contentHandler(metadata, response) { response.setHeader("Content-Type", 'multipart/byteranges; boundary="boundary"'); @@ -130,6 +108,6 @@ function run_test() null); var chan = make_channel(uri); - chan.asyncOpen(conv, null); + chan.asyncOpen2(conv, null); do_test_pending(); } diff --git a/netwerk/test/unit/test_packaged_app_channel.js b/netwerk/test/unit/test_packaged_app_channel.js index bc399f9de76e..b7740db826b1 100644 --- a/netwerk/test/unit/test_packaged_app_channel.js +++ b/netwerk/test/unit/test_packaged_app_channel.js @@ -6,6 +6,8 @@ Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); + XPCOMUtils.defineLazyGetter(this, "uri", function() { return "http://localhost:" + httpserver.identity.primaryPort; @@ -18,16 +20,7 @@ const nsIBinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstr function make_channel(url) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - return ios.newChannel2(url, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); } function Listener(callback) { @@ -231,10 +224,10 @@ function run_test() function test_channel_with_bad_signature() { var channel = make_channel(uri+"/package_with_bad_signature!//index.html"); channel.notificationCallbacks = new LoadContextCallback(1024, false, false, false); - channel.asyncOpen(new Listener(function(l) { + channel.asyncOpen2(new Listener(function(l) { do_check_true(l.gotFileNotFound); run_next_test(); - }), null); + })); } function test_channel_with_bad_signature_from_trusted_origin() { @@ -245,20 +238,20 @@ function test_channel_with_bad_signature_from_trusted_origin() { Services.prefs.setComplexValue(pref, Ci.nsISupportsString, origin); var channel = make_channel(uri+"/package_with_bad_signature!//index.html"); channel.notificationCallbacks = new LoadContextCallback(1024, false, false, false); - channel.asyncOpen(new Listener(function(l) { + channel.asyncOpen2(new Listener(function(l) { do_check_true(l.gotStopRequestOK); Services.prefs.clearUserPref(pref); run_next_test(); - }), null); + })); } function test_channel_with_good_signature() { var channel = make_channel(uri+"/package_with_good_signature!//index.html"); channel.notificationCallbacks = new LoadContextCallback(1024, false, false, false); - channel.asyncOpen(new Listener(function(l) { + channel.asyncOpen2(new Listener(function(l) { do_check_true(l.gotStopRequestOK); run_next_test(); - }), null); + })); } function test_channel(aNullNotificationCallbacks) { @@ -268,13 +261,13 @@ function test_channel(aNullNotificationCallbacks) { channel.notificationCallbacks = new LoadContextCallback(1024, false, false, false); } - channel.asyncOpen(new Listener(function(l) { + channel.asyncOpen2(new Listener(function(l) { // XXX: no content length available for this resource //do_check_true(channel.contentLength > 0); do_check_true(l.gotStartRequest); do_check_true(l.gotStopRequestOK); run_next_test(); - }), null); + })); } function test_channel_no_notificationCallbacks() { @@ -284,7 +277,7 @@ function test_channel_no_notificationCallbacks() { function test_channel_uris() { // A `!//` in the query or ref should not be handled as a packaged app resource var channel = make_channel(uri+"/regular?bla!//bla#bla!//bla"); - channel.asyncOpen(new ChannelListener(check_regular_response, null), null); + channel.asyncOpen2(new ChannelListener(check_regular_response, null)); } function check_regular_response(request, buffer) { diff --git a/netwerk/test/unit/test_partial_response_entry_size_smart_shrink.js b/netwerk/test/unit/test_partial_response_entry_size_smart_shrink.js index ff4335a9c0ff..fed8094834a4 100644 --- a/netwerk/test/unit/test_partial_response_entry_size_smart_shrink.js +++ b/netwerk/test/unit/test_partial_response_entry_size_smart_shrink.js @@ -9,6 +9,7 @@ Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); XPCOMUtils.defineLazyGetter(this, "URL", function() { return "http://localhost:" + httpServer.identity.primaryPort; @@ -17,16 +18,7 @@ XPCOMUtils.defineLazyGetter(this, "URL", function() { var httpServer = null; function make_channel(url, callback, ctx) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - return ios.newChannel2(url, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); } // Have 2kb response (8 * 2 ^ 8) @@ -71,7 +63,7 @@ function run_test() httpServer.start(-1); var chan = make_channel(URL + "/content"); - chan.asyncOpen(new ChannelListener(firstTimeThrough, null, CL_IGNORE_CL), null); + chan.asyncOpen2(new ChannelListener(firstTimeThrough, null, CL_IGNORE_CL)); do_test_pending(); } @@ -81,7 +73,7 @@ function firstTimeThrough(request, buffer) Services.prefs.setIntPref("browser.cache.disk.max_entry_size", 1); var chan = make_channel(URL + "/content"); - chan.asyncOpen(new ChannelListener(finish_test, null), null); + chan.asyncOpen2(new ChannelListener(finish_test, null)); } function finish_test(request, buffer) diff --git a/netwerk/test/unit/test_post.js b/netwerk/test/unit/test_post.js index 687a2ea7b50a..934719e7dfb1 100644 --- a/netwerk/test/unit/test_post.js +++ b/netwerk/test/unit/test_post.js @@ -3,7 +3,7 @@ // Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); XPCOMUtils.defineLazyGetter(this, "URL", function() { return "http://localhost:" + httpserver.identity.primaryPort; @@ -89,21 +89,13 @@ function run_test() { .setUploadStream(mime, "", mime.available()); channel.requestMethod = "POST"; channel.notificationCallbacks = listenerCallback; - channel.asyncOpen(new ChannelListener(checkRequest, channel), null); + channel.asyncOpen2(new ChannelListener(checkRequest, channel)); do_test_pending(); } function setupChannel(path) { - var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - return chan = ios.newChannel2(URL + path, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER) - .QueryInterface(Ci.nsIHttpChannel); + return NetUtil.newChannel({uri: URL + path, loadUsingSystemPrincipal: true}) + .QueryInterface(Ci.nsIHttpChannel); } function serverHandler(metadata, response) { diff --git a/netwerk/test/unit/test_private_necko_channel.js b/netwerk/test/unit/test_private_necko_channel.js index 88da76a01657..530d4e7e6608 100644 --- a/netwerk/test/unit/test_private_necko_channel.js +++ b/netwerk/test/unit/test_private_necko_channel.js @@ -3,7 +3,7 @@ // Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpserver = new HttpServer(); var testpath = "/simple"; @@ -25,23 +25,16 @@ function run_test() { channel.QueryInterface(Ci.nsIPrivateBrowsingChannel); channel.setPrivate(true); - channel.asyncOpen(new ChannelListener(checkRequest, channel), null); + channel.asyncOpen2(new ChannelListener(checkRequest, channel)); do_test_pending(); } function setupChannel(path) { - var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - return chan = ios.newChannel2("http://localhost:" + - httpserver.identity.primaryPort + path, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER) - .QueryInterface(Ci.nsIHttpChannel); + return NetUtil.newChannel({ + uri: "http://localhost:" + httpserver.identity.primaryPort + path, + loadUsingSystemPrincipal: true + }).QueryInterface(Ci.nsIHttpChannel); } function serverHandler(metadata, response) { diff --git a/netwerk/test/unit/test_progress.js b/netwerk/test/unit/test_progress.js index 97a7b2e7317c..e2dae9c09b89 100644 --- a/netwerk/test/unit/test_progress.js +++ b/netwerk/test/unit/test_progress.js @@ -1,5 +1,5 @@ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); XPCOMUtils.defineLazyGetter(this, "URL", function() { return "http://localhost:" + httpserver.identity.primaryPort; @@ -100,21 +100,15 @@ function run_test() { httpserver.registerPathHandler(testpath, serverHandler); httpserver.start(-1); var channel = setupChannel(testpath); - channel.asyncOpen(progressCallback, null); + channel.asyncOpen2(progressCallback); do_test_pending(); } function setupChannel(path) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - var chan = ios.newChannel2(URL + path, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + var chan = NetUtil.newChannel({ + uri: URL + path, + loadUsingSystemPrincipal: true + }); chan.QueryInterface(Ci.nsIHttpChannel); chan.requestMethod = "GET"; chan.notificationCallbacks = progressCallback; diff --git a/netwerk/test/unit/test_proxy-failover_passing.js b/netwerk/test/unit/test_proxy-failover_passing.js index 1eb41f51d291..b2bf198dd78b 100644 --- a/netwerk/test/unit/test_proxy-failover_passing.js +++ b/netwerk/test/unit/test_proxy-failover_passing.js @@ -1,19 +1,10 @@ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpServer = null; function make_channel(url, callback, ctx) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - return ios.newChannel2(url, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); } const responseBody = "response body"; @@ -47,6 +38,6 @@ function run_test() var chan = make_channel("http://localhost:" + httpServer.identity.primaryPort + "/content"); - chan.asyncOpen(new ChannelListener(finish_test, null), null); + chan.asyncOpen2(new ChannelListener(finish_test, null)); do_test_pending(); } diff --git a/netwerk/test/unit/test_redirect_different-protocol.js b/netwerk/test/unit/test_redirect_different-protocol.js index 89114d686c07..73aea57ca128 100644 --- a/netwerk/test/unit/test_redirect_different-protocol.js +++ b/netwerk/test/unit/test_redirect_different-protocol.js @@ -1,5 +1,5 @@ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); XPCOMUtils.defineLazyGetter(this, "URL", function() { return "http://localhost:" + httpServer.identity.primaryPort; @@ -20,16 +20,7 @@ function inChildProcess() { } function make_channel(url, callback, ctx) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - return ios.newChannel2(url, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); } const redirectTargetBody = "response body"; @@ -55,6 +46,6 @@ function run_test() httpServer.start(-1); var chan = make_channel(randomURI); - chan.asyncOpen(new ChannelListener(finish_test, null, 0), null); + chan.asyncOpen2(new ChannelListener(finish_test, null, 0)); do_test_pending(); } diff --git a/netwerk/test/unit/test_redirect_loop.js b/netwerk/test/unit/test_redirect_loop.js index e0ffbbd511a9..9efcecadb8c2 100644 --- a/netwerk/test/unit/test_redirect_loop.js +++ b/netwerk/test/unit/test_redirect_loop.js @@ -1,5 +1,5 @@ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); /* * This xpcshell test checks whether we detect infinite HTTP redirect loops. @@ -23,16 +23,7 @@ var emptyLoopPath = "/empty/"; var emptyLoopURI = "http://localhost:" + PORT + emptyLoopPath; function make_channel(url, callback, ctx) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - return ios.newChannel2(url, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); } function fullLoopHandler(metadata, response) @@ -65,8 +56,7 @@ function testFullLoop(request, buffer) do_check_eq(request.status, Components.results.NS_ERROR_REDIRECT_LOOP); var chan = make_channel(relativeLoopURI); - chan.asyncOpen(new ChannelListener(testRelativeLoop, null, CL_EXPECT_FAILURE), - null); + chan.asyncOpen2(new ChannelListener(testRelativeLoop, null, CL_EXPECT_FAILURE)); } function testRelativeLoop(request, buffer) @@ -74,8 +64,7 @@ function testRelativeLoop(request, buffer) do_check_eq(request.status, Components.results.NS_ERROR_REDIRECT_LOOP); var chan = make_channel(emptyLoopURI); - chan.asyncOpen(new ChannelListener(testEmptyLoop, null, CL_EXPECT_FAILURE), - null); + chan.asyncOpen2(new ChannelListener(testEmptyLoop, null, CL_EXPECT_FAILURE)); } function testEmptyLoop(request, buffer) @@ -92,7 +81,6 @@ function run_test() httpServer.registerPathHandler(emptyLoopPath, emptyLoopHandler); var chan = make_channel(fullLoopURI); - chan.asyncOpen(new ChannelListener(testFullLoop, null, CL_EXPECT_FAILURE), - null); + chan.asyncOpen2(new ChannelListener(testFullLoop, null, CL_EXPECT_FAILURE)); do_test_pending(); } diff --git a/netwerk/test/unit/test_redirect_passing.js b/netwerk/test/unit/test_redirect_passing.js index 7f38a161cb73..a9a515b5eb9e 100644 --- a/netwerk/test/unit/test_redirect_passing.js +++ b/netwerk/test/unit/test_redirect_passing.js @@ -1,5 +1,5 @@ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); XPCOMUtils.defineLazyGetter(this, "URL", function() { return "http://localhost:" + httpServer.identity.primaryPort; @@ -14,16 +14,7 @@ XPCOMUtils.defineLazyGetter(this, "randomURI", function() { }); function make_channel(url, callback, ctx) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - return ios.newChannel2(url, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}); } const responseBody = "response body"; @@ -44,7 +35,7 @@ function firstTimeThrough(request, buffer) { do_check_eq(buffer, responseBody); var chan = make_channel(randomURI); - chan.asyncOpen(new ChannelListener(finish_test, null), null); + chan.asyncOpen2(new ChannelListener(finish_test, null)); } function finish_test(request, buffer) @@ -61,6 +52,6 @@ function run_test() httpServer.start(-1); var chan = make_channel(randomURI); - chan.asyncOpen(new ChannelListener(firstTimeThrough, null), null); + chan.asyncOpen2(new ChannelListener(firstTimeThrough, null)); do_test_pending(); } diff --git a/netwerk/test/unit/test_reentrancy.js b/netwerk/test/unit/test_reentrancy.js index b7b1ecb69b07..2f8eec30f5b2 100644 --- a/netwerk/test/unit/test_reentrancy.js +++ b/netwerk/test/unit/test_reentrancy.js @@ -1,5 +1,5 @@ Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); XPCOMUtils.defineLazyGetter(this, "URL", function() { return "http://localhost:" + httpserver.identity.primaryPort; @@ -77,23 +77,15 @@ var listener = { }; function makeChan(url) { - var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - var chan = ios.newChannel2(url, - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER).QueryInterface(Ci.nsIHttpChannel); - return chan; + return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}) + .QueryInterface(Ci.nsIHttpChannel); } function next_test() { var chan = makeChan(URL + testpath); chan.QueryInterface(Ci.nsIRequest); - chan.asyncOpen(listener, null); + chan.asyncOpen2(listener); } function run_test() diff --git a/netwerk/test/unit/test_reply_without_content_type.js b/netwerk/test/unit/test_reply_without_content_type.js index 09c88db22866..7fda87209c99 100644 --- a/netwerk/test/unit/test_reply_without_content_type.js +++ b/netwerk/test/unit/test_reply_without_content_type.js @@ -5,7 +5,7 @@ // Note: sets Cc and Ci variables Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpserver = new HttpServer(); var testpath = "/simple_plainText"; @@ -29,7 +29,7 @@ add_test(function test_plainText() { httpserver.start(-1); var channel = setupChannel(testpath); // ChannelListener defined in head_channels.js - channel.asyncOpen(new ChannelListener(checkRequest, channel), null); + channel.asyncOpen2(new ChannelListener(checkRequest, channel)); do_test_pending(); if (dbg) { print("============== test_plainText: out"); } }); @@ -40,25 +40,18 @@ add_test(function test_GZip() { httpserver.start(-1); var channel = setupChannel(testpathGZip); // ChannelListener defined in head_channels.js - channel.asyncOpen(new ChannelListener(checkRequest, channel, - CL_EXPECT_GZIP), null); + channel.asyncOpen2(new ChannelListener(checkRequest, channel, + CL_EXPECT_GZIP)); do_test_pending(); if (dbg) { print("============== test_GZip: out"); } }); function setupChannel(path) { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - var chan = ios.newChannel2("http://localhost:" + - httpserver.identity.primaryPort + path, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + var chan = NetUtil.newChannel({ + uri: "http://localhost:" + httpserver.identity.primaryPort + path, + loadUsingSystemPrincipal: true + }); chan.QueryInterface(Ci.nsIHttpChannel); chan.requestMethod = "GET"; return chan; diff --git a/netwerk/test/unit/test_suspend_channel_before_connect.js b/netwerk/test/unit/test_suspend_channel_before_connect.js index 9d519d49aa35..f41932a46700 100644 --- a/netwerk/test/unit/test_suspend_channel_before_connect.js +++ b/netwerk/test/unit/test_suspend_channel_before_connect.js @@ -1,7 +1,7 @@ var CC = Components.Constructor; -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); const ServerSocket = CC("@mozilla.org/network/server-socket;1", "nsIServerSocket", @@ -88,17 +88,11 @@ add_test(function testNoConnectChannelCanceledEarly() { serv = new TestServer(); obs.addObserver(requestListenerObserver, "http-on-modify-request", false); - - var chan = ios.newChannel2("http://localhost:" + serv.port, - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - - chan.asyncOpen(listener, chan); + var chan = NetUtil.newChannel({ + uri:"http://localhost:" + serv.port, + loadUsingSystemPrincipal: true + }); + chan.asyncOpen2(listener); do_register_cleanup(function(){ serv.stop(); }); });