diff --git a/netwerk/test/unit/test_421.js b/netwerk/test/unit/test_421.js index 17658641ed8d..7a9e07029102 100644 --- a/netwerk/test/unit/test_421.js +++ b/netwerk/test/unit/test_421.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; @@ -22,19 +22,11 @@ function setup_test() { channel = setupChannel(testpath); - channel.asyncOpen(new ChannelListener(checkRequestResponse, channel), null); + channel.asyncOpen2(new ChannelListener(checkRequestResponse, channel)); } function setupChannel(path) { - 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"; return chan; diff --git a/netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js b/netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js index 8bc4fbe7eb08..d291b5f665c2 100644 --- a/netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js +++ b/netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js @@ -13,6 +13,8 @@ This test is using a resumable response. 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; @@ -21,16 +23,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}); } const responseBody = "response body"; @@ -60,9 +53,9 @@ function run_test() httpServer.start(-1); var chan1 = make_channel(URL + "/content"); - chan1.asyncOpen(new ChannelListener(firstTimeThrough, null), null); + chan1.asyncOpen2(new ChannelListener(firstTimeThrough, null)); var chan2 = make_channel(URL + "/content"); - chan2.asyncOpen(new ChannelListener(secondTimeThrough, null), null); + chan2.asyncOpen2(new ChannelListener(secondTimeThrough, null)); do_test_pending(); } diff --git a/netwerk/test/unit/test_cache2-29b-concurrent_read_non-resumable_entry_size_zero.js b/netwerk/test/unit/test_cache2-29b-concurrent_read_non-resumable_entry_size_zero.js index 7589841824a9..67f6467bb235 100644 --- a/netwerk/test/unit/test_cache2-29b-concurrent_read_non-resumable_entry_size_zero.js +++ b/netwerk/test/unit/test_cache2-29b-concurrent_read_non-resumable_entry_size_zero.js @@ -15,6 +15,7 @@ This test is using a non-resumable response. 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; @@ -23,16 +24,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}); } const responseBody = "c\r\ndata reached\r\n3\r\nhej\r\n0\r\n\r\n"; @@ -60,9 +52,9 @@ function run_test() httpServer.start(-1); var chan1 = make_channel(URL + "/content"); - chan1.asyncOpen(new ChannelListener(firstTimeThrough, null, CL_ALLOW_UNKNOWN_CL), null); + chan1.asyncOpen2(new ChannelListener(firstTimeThrough, null, CL_ALLOW_UNKNOWN_CL)); var chan2 = make_channel(URL + "/content"); - chan2.asyncOpen(new ChannelListener(secondTimeThrough, null, CL_ALLOW_UNKNOWN_CL), null); + chan2.asyncOpen2(new ChannelListener(secondTimeThrough, null, CL_ALLOW_UNKNOWN_CL)); do_test_pending(); } diff --git a/netwerk/test/unit/test_fallback_response-error_canceled.js b/netwerk/test/unit/test_fallback_response-error_canceled.js index 8886e5fd3cf9..e025f29678f3 100644 --- a/netwerk/test/unit/test_fallback_response-error_canceled.js +++ b/netwerk/test/unit/test_fallback_response-error_canceled.js @@ -1,5 +1,7 @@ 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 @@ -13,16 +15,7 @@ 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) { @@ -103,7 +96,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)); }} var os = Cc["@mozilla.org/observer-service;1"]. diff --git a/netwerk/test/unit/test_fallback_response-error_passing.js b/netwerk/test/unit/test_fallback_response-error_passing.js index 43b198f429d9..e59fad7d09c5 100644 --- a/netwerk/test/unit/test_fallback_response-error_passing.js +++ b/netwerk/test/unit/test_fallback_response-error_passing.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 @@ -13,16 +14,7 @@ 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) { @@ -102,7 +94,7 @@ function run_test() var chan = make_channel(randomURI); var chanac = chan.QueryInterface(Ci.nsIApplicationCacheChannel); chanac.chooseApplicationCache = true; - chan.asyncOpen(new ChannelListener(finish_test), null); + chan.asyncOpen2(new ChannelListener(finish_test)); }} var os = Cc["@mozilla.org/observer-service;1"]. diff --git a/netwerk/test/unit/test_inhibit_caching.js b/netwerk/test/unit/test_inhibit_caching.js index 5fa7c2972043..7e81eb69684c 100644 --- a/netwerk/test/unit/test_inhibit_caching.js +++ b/netwerk/test/unit/test_inhibit_caching.js @@ -1,6 +1,6 @@ Cu.import('resource://gre/modules/LoadContextInfo.jsm'); Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var first = true; function contentHandler(metadata, response) @@ -35,18 +35,8 @@ function run_test() // Makes a regular request function test_first_response() { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - var chan = ios.newChannel2(uri+"/test", - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - - chan.asyncOpen(new ChannelListener(check_first_response, null), null); + var chan = NetUtil.newChannel({uri: uri+"/test", loadUsingSystemPrincipal: true}); + chan.asyncOpen2(new ChannelListener(check_first_response, null)); } // Checks that we got the appropriate response @@ -71,19 +61,9 @@ function cache_entry_callback(status, entry) { // Makes a request with the INHIBIT_CACHING load flag function test_inhibit_caching() { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - var chan = ios.newChannel2(uri+"/test", - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - + var chan = NetUtil.newChannel({uri: uri+"/test", loadUsingSystemPrincipal: true}); chan.QueryInterface(Ci.nsIRequest).loadFlags |= Ci.nsIRequest.INHIBIT_CACHING; - chan.asyncOpen(new ChannelListener(check_second_response, null), null); + chan.asyncOpen2(new ChannelListener(check_second_response, null)); } // Checks that we got a different response from the first request diff --git a/netwerk/test/unit/test_invalidport.js b/netwerk/test/unit/test_invalidport.js index 08aafbf7584f..70d401c84c54 100644 --- a/netwerk/test/unit/test_invalidport.js +++ b/netwerk/test/unit/test_invalidport.js @@ -2,7 +2,7 @@ // Perform the async open several times in order to induce exponential // scheduling behavior bugs. -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var CC = Components.Constructor; @@ -31,17 +31,8 @@ function run_test() { } function execute_test() { - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - var chan = ios.newChannel2("http://localhost:75000", - "", - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); + var chan = NetUtil.newChannel({uri: "http://localhost:75000", loadUsingSystemPrincipal: true}); chan.QueryInterface(Ci.nsIHttpChannel); - chan.asyncOpen(listener, null); + chan.asyncOpen2(listener); } diff --git a/netwerk/test/unit/test_multipart_streamconv_application_package.js b/netwerk/test/unit/test_multipart_streamconv_application_package.js index ca7907159a31..9d9f0011bc3b 100644 --- a/netwerk/test/unit/test_multipart_streamconv_application_package.js +++ b/netwerk/test/unit/test_multipart_streamconv_application_package.js @@ -21,7 +21,7 @@ // - checks that the headers for each part is set correctly Cu.import("resource://testing-common/httpd.js"); -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); var httpserver = null; @@ -30,16 +30,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}); } function contentHandler(metadata, response) @@ -210,7 +201,7 @@ function test_multipart() { null); var chan = make_channel(uri + "/multipart"); - chan.asyncOpen(conv, null); + chan.asyncOpen2(conv); } function test_multipart_with_boundary() { @@ -222,7 +213,7 @@ function test_multipart_with_boundary() { null); var chan = make_channel(uri + "/multipart2"); - chan.asyncOpen(conv, null); + chan.asyncOpen2(conv); } function test_multipart_chunked_headers() { @@ -234,7 +225,7 @@ function test_multipart_chunked_headers() { null); var chan = make_channel(uri + "/multipart3"); - chan.asyncOpen(conv, null); + chan.asyncOpen2(conv); } function test_multipart_content_type_other() { @@ -247,7 +238,7 @@ function test_multipart_content_type_other() { null); var chan = make_channel(uri + "/multipart4"); - chan.asyncOpen(conv, null); + chan.asyncOpen2(conv); } function test_multipart_package_header(aChunkSize) { @@ -260,7 +251,7 @@ function test_multipart_package_header(aChunkSize) { null); var chan = make_channel(uri + "/multipart5_" + aChunkSize); - chan.asyncOpen(conv, null); + chan.asyncOpen2(conv); } // Bug 1212223 - Test multipart with package header and different chunk size. diff --git a/netwerk/test/unit/test_multipart_streamconv_missing_lead_boundary.js b/netwerk/test/unit/test_multipart_streamconv_missing_lead_boundary.js index 46f46cab0703..97924ccb16ab 100644 --- a/netwerk/test/unit/test_multipart_streamconv_missing_lead_boundary.js +++ b/netwerk/test/unit/test_multipart_streamconv_missing_lead_boundary.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,33 +8,11 @@ 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 = "\r\nSome text\r\n--boundary\r\n\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/mixed; boundary="boundary"'); @@ -106,6 +84,6 @@ function run_test() null); var chan = make_channel(uri); - chan.asyncOpen(conv, null); + chan.asyncOpen2(conv); do_test_pending(); } diff --git a/netwerk/test/unit_ipc/child_app_offline.js b/netwerk/test/unit_ipc/child_app_offline.js index a2c5e5003f59..ded06701bbcd 100644 --- a/netwerk/test/unit_ipc/child_app_offline.js +++ b/netwerk/test/unit_ipc/child_app_offline.js @@ -1,4 +1,4 @@ -Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); function inChildProcess() { return Cc["@mozilla.org/xre/app-info;1"] @@ -7,15 +7,8 @@ function inChildProcess() { } 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, @@ -37,28 +30,28 @@ function makeChan(url, appId, inBrowser) { function run_test() { do_test_pending(); var chan = makeChan("http://localhost:12345/first", 14, false); - chan.asyncOpen(new ChannelListener(checkResponse, "response0"), null); + chan.asyncOpen2(new ChannelListener(checkResponse, "response0")); } // Should return cached result function test1() { do_test_pending(); var chan = makeChan("http://localhost:12345/first", 14, false); - chan.asyncOpen(new ChannelListener(checkResponse, "response0"), null); + chan.asyncOpen2(new ChannelListener(checkResponse, "response0")); } // This request should fail function test2() { do_test_pending(); var chan = makeChan("http://localhost:12345/second", 14, false); - chan.asyncOpen(new ChannelListener(checkResponse, "", CL_EXPECT_FAILURE), null); + chan.asyncOpen2(new ChannelListener(checkResponse, "", CL_EXPECT_FAILURE)); } // This request should succeed function test3() { do_test_pending(); var chan = makeChan("http://localhost:12345/second", 14, false); - chan.asyncOpen(new ChannelListener(checkResponse, "response3"), null); + chan.asyncOpen2(new ChannelListener(checkResponse, "response3")); } function checkResponse(req, buffer, expected) {