|
1 Cu.import("resource://testing-common/httpd.js"); |
|
2 |
|
3 XPCOMUtils.defineLazyGetter(this, "URL", function() { |
|
4 return "http://localhost:" + httpserver.identity.primaryPort; |
|
5 }); |
|
6 |
|
7 var httpserver = new HttpServer(); |
|
8 var testpath = "/simple"; |
|
9 var httpbody = "0123456789"; |
|
10 |
|
11 var live_channels = []; |
|
12 |
|
13 function run_test() { |
|
14 httpserver.registerPathHandler(testpath, serverHandler); |
|
15 httpserver.start(-1); |
|
16 |
|
17 var local_channel; |
|
18 |
|
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); |
|
23 |
|
24 // Opened channel that has no remaining references after being opened |
|
25 setupChannel(testpath).asyncOpen( |
|
26 new ChannelListener(function() {}, null), null); |
|
27 |
|
28 // Unopened channel that has remaining references on shutdown |
|
29 live_channels.push(setupChannel(testpath)); |
|
30 |
|
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); |
|
35 |
|
36 do_test_pending(); |
|
37 } |
|
38 |
|
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 } |
|
46 |
|
47 function serverHandler(metadata, response) { |
|
48 response.setHeader("Content-Type", "text/plain", false); |
|
49 response.bodyOutputStream.write(httpbody, httpbody.length); |
|
50 } |
|
51 |
|
52 function checkRequest(request, data, context) { |
|
53 do_check_eq(data, httpbody); |
|
54 } |
|
55 |
|
56 function checkRequestFinish(request, data, context) { |
|
57 checkRequest(request, data, context); |
|
58 httpserver.stop(do_test_finished); |
|
59 } |