|
1 // |
|
2 // Simple HTTP test: fetches page |
|
3 // |
|
4 |
|
5 // Note: sets Cc and Ci variables |
|
6 |
|
7 Cu.import("resource://testing-common/httpd.js"); |
|
8 |
|
9 var httpserver = new HttpServer(); |
|
10 var testpath = "/simple"; |
|
11 var httpbody = "0123456789"; |
|
12 var buffer = ""; |
|
13 |
|
14 var dbg=0 |
|
15 if (dbg) { print("============== START =========="); } |
|
16 |
|
17 function run_test() { |
|
18 setup_test(); |
|
19 do_test_pending(); |
|
20 } |
|
21 |
|
22 function setup_test() { |
|
23 if (dbg) { print("============== setup_test: in"); } |
|
24 httpserver.registerPathHandler(testpath, serverHandler); |
|
25 httpserver.start(-1); |
|
26 var channel = setupChannel(testpath); |
|
27 // ChannelListener defined in head_channels.js |
|
28 channel.asyncOpen(new ChannelListener(checkRequest, channel), null); |
|
29 if (dbg) { print("============== setup_test: out"); } |
|
30 } |
|
31 |
|
32 function setupChannel(path) { |
|
33 var ios = Cc["@mozilla.org/network/io-service;1"]. |
|
34 getService(Ci.nsIIOService); |
|
35 var chan = ios.newChannel("http://localhost:" + |
|
36 httpserver.identity.primaryPort + path, "", null); |
|
37 chan.QueryInterface(Ci.nsIHttpChannel); |
|
38 chan.requestMethod = "GET"; |
|
39 return chan; |
|
40 } |
|
41 |
|
42 function serverHandler(metadata, response) { |
|
43 if (dbg) { print("============== serverHandler: in"); } |
|
44 response.setHeader("Content-Type", "text/plain", false); |
|
45 response.bodyOutputStream.write(httpbody, httpbody.length); |
|
46 if (dbg) { print("============== serverHandler: out"); } |
|
47 } |
|
48 |
|
49 function checkRequest(request, data, context) { |
|
50 if (dbg) { print("============== checkRequest: in"); } |
|
51 do_check_eq(data, httpbody); |
|
52 httpserver.stop(do_test_finished); |
|
53 if (dbg) { print("============== checkRequest: out"); } |
|
54 } |
|
55 |