Bug 1232567 - Convert 10 tests within netwerk/test to use AsyncOpen2 (r=mcmanus)

This commit is contained in:
Christoph Kerschbaumer 2015-12-17 12:47:22 -08:00
Родитель bd48dbd1fc
Коммит 55c5c7efa6
10 изменённых файлов: 44 добавлений и 149 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -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"].

Просмотреть файл

@ -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"].

Просмотреть файл

@ -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

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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.

Просмотреть файл

@ -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<?xml version='1.0'?><root/>\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();
}

Просмотреть файл

@ -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) {