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