michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "URL", function() { michael@0: return "http://localhost:" + httpserver.identity.primaryPort; michael@0: }); michael@0: michael@0: var httpserver = new HttpServer(); michael@0: var testpath = "/simple"; michael@0: var httpbody = "0123456789"; michael@0: michael@0: var live_channels = []; michael@0: michael@0: function run_test() { michael@0: httpserver.registerPathHandler(testpath, serverHandler); michael@0: httpserver.start(-1); michael@0: michael@0: var local_channel; michael@0: michael@0: // Opened channel that has no remaining references on shutdown michael@0: local_channel = setupChannel(testpath); michael@0: local_channel.asyncOpen( michael@0: new ChannelListener(checkRequest, local_channel), null); michael@0: michael@0: // Opened channel that has no remaining references after being opened michael@0: setupChannel(testpath).asyncOpen( michael@0: new ChannelListener(function() {}, null), null); michael@0: michael@0: // Unopened channel that has remaining references on shutdown michael@0: live_channels.push(setupChannel(testpath)); michael@0: michael@0: // Opened channel that has remaining references on shutdown michael@0: live_channels.push(setupChannel(testpath)); michael@0: live_channels[1].asyncOpen( michael@0: new ChannelListener(checkRequestFinish, live_channels[1]), null); michael@0: michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function setupChannel(path) { michael@0: var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); michael@0: var chan = ios.newChannel(URL + path, "", null); michael@0: chan.QueryInterface(Ci.nsIHttpChannel); michael@0: chan.requestMethod = "GET"; michael@0: return chan; michael@0: } michael@0: michael@0: function serverHandler(metadata, response) { michael@0: response.setHeader("Content-Type", "text/plain", false); michael@0: response.bodyOutputStream.write(httpbody, httpbody.length); michael@0: } michael@0: michael@0: function checkRequest(request, data, context) { michael@0: do_check_eq(data, httpbody); michael@0: } michael@0: michael@0: function checkRequestFinish(request, data, context) { michael@0: checkRequest(request, data, context); michael@0: httpserver.stop(do_test_finished); michael@0: }