Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 Cu.import("resource://testing-common/httpd.js");
3 XPCOMUtils.defineLazyGetter(this, "URL", function() {
4 return "http://localhost:" + httpserver.identity.primaryPort;
5 });
7 var httpserver = new HttpServer();
8 var testpath = "/simple";
9 var httpbody = "0123456789";
11 var live_channels = [];
13 function run_test() {
14 httpserver.registerPathHandler(testpath, serverHandler);
15 httpserver.start(-1);
17 var local_channel;
19 // Opened channel that has no remaining references on shutdown
20 local_channel = setupChannel(testpath);
21 local_channel.asyncOpen(
22 new ChannelListener(checkRequest, local_channel), null);
24 // Opened channel that has no remaining references after being opened
25 setupChannel(testpath).asyncOpen(
26 new ChannelListener(function() {}, null), null);
28 // Unopened channel that has remaining references on shutdown
29 live_channels.push(setupChannel(testpath));
31 // Opened channel that has remaining references on shutdown
32 live_channels.push(setupChannel(testpath));
33 live_channels[1].asyncOpen(
34 new ChannelListener(checkRequestFinish, live_channels[1]), null);
36 do_test_pending();
37 }
39 function setupChannel(path) {
40 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
41 var chan = ios.newChannel(URL + path, "", null);
42 chan.QueryInterface(Ci.nsIHttpChannel);
43 chan.requestMethod = "GET";
44 return chan;
45 }
47 function serverHandler(metadata, response) {
48 response.setHeader("Content-Type", "text/plain", false);
49 response.bodyOutputStream.write(httpbody, httpbody.length);
50 }
52 function checkRequest(request, data, context) {
53 do_check_eq(data, httpbody);
54 }
56 function checkRequestFinish(request, data, context) {
57 checkRequest(request, data, context);
58 httpserver.stop(do_test_finished);
59 }