2019-01-17 21:18:31 +03:00
|
|
|
const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
|
|
|
|
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
2012-08-14 18:06:04 +04:00
|
|
|
|
2013-07-19 21:19:28 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "URL", function() {
|
|
|
|
return "http://localhost:" + httpserver.identity.primaryPort;
|
|
|
|
});
|
|
|
|
|
2012-08-14 18:06:04 +04:00
|
|
|
var httpserver = new HttpServer();
|
2010-06-27 20:44:15 +04:00
|
|
|
var testpath = "/simple";
|
|
|
|
var httpbody = "0123456789";
|
|
|
|
|
|
|
|
var live_channels = [];
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
httpserver.registerPathHandler(testpath, serverHandler);
|
2013-07-19 21:19:28 +04:00
|
|
|
httpserver.start(-1);
|
2010-06-27 20:44:15 +04:00
|
|
|
|
|
|
|
var local_channel;
|
|
|
|
|
|
|
|
// Opened channel that has no remaining references on shutdown
|
|
|
|
local_channel = setupChannel(testpath);
|
2015-12-19 00:31:16 +03:00
|
|
|
local_channel.asyncOpen2(new ChannelListener(checkRequest, local_channel));
|
2010-06-27 20:44:15 +04:00
|
|
|
|
|
|
|
// Opened channel that has no remaining references after being opened
|
2015-12-19 00:31:16 +03:00
|
|
|
setupChannel(testpath).asyncOpen2(new ChannelListener(function() {}, null));
|
2010-06-27 20:44:15 +04:00
|
|
|
|
|
|
|
// Unopened channel that has remaining references on shutdown
|
|
|
|
live_channels.push(setupChannel(testpath));
|
|
|
|
|
|
|
|
// Opened channel that has remaining references on shutdown
|
|
|
|
live_channels.push(setupChannel(testpath));
|
2015-12-19 00:31:16 +03:00
|
|
|
live_channels[1].asyncOpen2(new ChannelListener(checkRequestFinish, live_channels[1]));
|
2010-06-27 20:44:15 +04:00
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupChannel(path) {
|
2015-12-19 00:31:16 +03:00
|
|
|
var chan = NetUtil.newChannel({
|
|
|
|
uri: URL + path,
|
|
|
|
loadUsingSystemPrincipal: true
|
|
|
|
});
|
2010-06-27 20:44:15 +04:00
|
|
|
chan.QueryInterface(Ci.nsIHttpChannel);
|
|
|
|
chan.requestMethod = "GET";
|
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
|
|
|
function serverHandler(metadata, response) {
|
|
|
|
response.setHeader("Content-Type", "text/plain", false);
|
|
|
|
response.bodyOutputStream.write(httpbody, httpbody.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkRequest(request, data, context) {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(data, httpbody);
|
2010-06-27 20:44:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkRequestFinish(request, data, context) {
|
|
|
|
checkRequest(request, data, context);
|
|
|
|
httpserver.stop(do_test_finished);
|
|
|
|
}
|