|
1 Cu.import("resource://testing-common/httpd.js"); |
|
2 |
|
3 var httpserver = new HttpServer(); |
|
4 var index = 0; |
|
5 var tests = [ |
|
6 {url: "/test/cegzip1", |
|
7 flags: CL_EXPECT_GZIP, |
|
8 ce: "gzip", |
|
9 body: [ |
|
10 0x1f, 0x8b, 0x08, 0x08, 0x5a, 0xa0, 0x31, 0x4f, 0x00, 0x03, 0x74, 0x78, 0x74, 0x00, 0x2b, 0xc9, |
|
11 0xc8, 0x2c, 0x56, 0x00, 0xa2, 0x92, 0xd4, 0xe2, 0x12, 0x43, 0x2e, 0x00, 0xb9, 0x23, 0xd7, 0x3b, |
|
12 0x0e, 0x00, 0x00, 0x00], |
|
13 datalen: 14 // the data length of the uncompressed document |
|
14 }, |
|
15 |
|
16 {url: "/test/cegzip2", |
|
17 flags: CL_EXPECT_GZIP, |
|
18 ce: "gzip, gzip", |
|
19 body: [ |
|
20 0x1f, 0x8b, 0x08, 0x00, 0x72, 0xa1, 0x31, 0x4f, 0x00, 0x03, 0x93, 0xef, 0xe6, 0xe0, 0x88, 0x5a, |
|
21 0x60, 0xe8, 0xcf, 0xc0, 0x5c, 0x52, 0x51, 0xc2, 0xa0, 0x7d, 0xf2, 0x84, 0x4e, 0x18, 0xc3, 0xa2, |
|
22 0x49, 0x57, 0x1e, 0x09, 0x39, 0xeb, 0x31, 0xec, 0x54, 0xbe, 0x6e, 0xcd, 0xc7, 0xc0, 0xc0, 0x00, |
|
23 0x00, 0x6e, 0x90, 0x7a, 0x85, 0x24, 0x00, 0x00, 0x00], |
|
24 datalen: 14 // the data length of the uncompressed document |
|
25 }, |
|
26 ]; |
|
27 |
|
28 function setupChannel(url) { |
|
29 var ios = Components.classes["@mozilla.org/network/io-service;1"]. |
|
30 getService(Ci.nsIIOService); |
|
31 var chan = ios.newChannel("http://localhost:" + |
|
32 httpserver.identity.primaryPort + url, "", null); |
|
33 return chan; |
|
34 } |
|
35 |
|
36 function startIter() { |
|
37 var channel = setupChannel(tests[index].url); |
|
38 channel.asyncOpen(new ChannelListener(completeIter, channel, tests[index].flags), null); |
|
39 } |
|
40 |
|
41 function completeIter(request, data, ctx) { |
|
42 do_check_true(data.length == tests[index].datalen); |
|
43 if (++index < tests.length) { |
|
44 startIter(); |
|
45 } else { |
|
46 httpserver.stop(do_test_finished); |
|
47 } |
|
48 } |
|
49 |
|
50 function run_test() { |
|
51 httpserver.registerPathHandler("/test/cegzip1", handler); |
|
52 httpserver.registerPathHandler("/test/cegzip2", handler); |
|
53 httpserver.start(-1); |
|
54 |
|
55 startIter(); |
|
56 do_test_pending(); |
|
57 } |
|
58 |
|
59 function handler(metadata, response) { |
|
60 response.setStatusLine(metadata.httpVersion, 200, "OK"); |
|
61 response.setHeader("Content-Type", "text/plain", false); |
|
62 response.setHeader("Content-Encoding", tests[index].ce, false); |
|
63 response.setHeader("Content-Length", "" + tests[index].body.length, false); |
|
64 |
|
65 var bos = Components.classes["@mozilla.org/binaryoutputstream;1"] |
|
66 .createInstance(Components.interfaces.nsIBinaryOutputStream); |
|
67 bos.setOutputStream(response.bodyOutputStream); |
|
68 |
|
69 response.processAsync(); |
|
70 bos.writeByteArray(tests[index].body, tests[index].body.length); |
|
71 response.finish(); |
|
72 } |
|
73 |