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