Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Test to ensure our 64-bit content length implementation works, at least for |
michael@0 | 2 | a simple HTTP case */ |
michael@0 | 3 | |
michael@0 | 4 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 5 | |
michael@0 | 6 | // This C-L is significantly larger than (U)INT32_MAX, to make sure we do |
michael@0 | 7 | // 64-bit properly. |
michael@0 | 8 | const CONTENT_LENGTH = "1152921504606846975"; |
michael@0 | 9 | |
michael@0 | 10 | var httpServer = null; |
michael@0 | 11 | |
michael@0 | 12 | var listener = { |
michael@0 | 13 | onStartRequest: function (req, ctx) { |
michael@0 | 14 | }, |
michael@0 | 15 | |
michael@0 | 16 | onDataAvailable: function (req, ctx, stream, off, count) { |
michael@0 | 17 | do_check_eq(req.getResponseHeader("Content-Length"), CONTENT_LENGTH); |
michael@0 | 18 | |
michael@0 | 19 | // We're done here, cancel the channel |
michael@0 | 20 | req.cancel(NS_BINDING_ABORT); |
michael@0 | 21 | }, |
michael@0 | 22 | |
michael@0 | 23 | onStopRequest: function (req, ctx, stat) { |
michael@0 | 24 | httpServer.stop(do_test_finished); |
michael@0 | 25 | } |
michael@0 | 26 | }; |
michael@0 | 27 | |
michael@0 | 28 | function hugeContentLength(metadata, response) { |
michael@0 | 29 | var text = "abcdefghijklmnopqrstuvwxyz"; |
michael@0 | 30 | var bytes_written = 0; |
michael@0 | 31 | |
michael@0 | 32 | response.seizePower(); |
michael@0 | 33 | |
michael@0 | 34 | response.write("HTTP/1.1 200 OK\r\n"); |
michael@0 | 35 | response.write("Content-Length: " + CONTENT_LENGTH + "\r\n"); |
michael@0 | 36 | response.write("Connection: close\r\n"); |
michael@0 | 37 | response.write("\r\n"); |
michael@0 | 38 | |
michael@0 | 39 | // Write enough data to ensure onDataAvailable gets called |
michael@0 | 40 | while (bytes_written < 4096) { |
michael@0 | 41 | response.write(text); |
michael@0 | 42 | bytes_written += text.length; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | response.finish(); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function test_hugeContentLength() { |
michael@0 | 49 | var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); |
michael@0 | 50 | var chan = ios.newChannel("http://localhost:" + |
michael@0 | 51 | httpServer.identity.primaryPort + "/", null, null) |
michael@0 | 52 | .QueryInterface(Ci.nsIHttpChannel); |
michael@0 | 53 | chan.asyncOpen(listener, null); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | add_test(test_hugeContentLength); |
michael@0 | 57 | |
michael@0 | 58 | function run_test() { |
michael@0 | 59 | httpServer = new HttpServer(); |
michael@0 | 60 | httpServer.registerPathHandler("/", hugeContentLength); |
michael@0 | 61 | httpServer.start(-1); |
michael@0 | 62 | run_next_test(); |
michael@0 | 63 | } |