netwerk/test/unit/test_bug536324_64bit_content_length.js

changeset 1
ca08bd8f51b2
equal deleted inserted replaced
-1:000000000000 0:8d4d36bcfbec
1 /* Test to ensure our 64-bit content length implementation works, at least for
2 a simple HTTP case */
3
4 Cu.import("resource://testing-common/httpd.js");
5
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";
9
10 var httpServer = null;
11
12 var listener = {
13 onStartRequest: function (req, ctx) {
14 },
15
16 onDataAvailable: function (req, ctx, stream, off, count) {
17 do_check_eq(req.getResponseHeader("Content-Length"), CONTENT_LENGTH);
18
19 // We're done here, cancel the channel
20 req.cancel(NS_BINDING_ABORT);
21 },
22
23 onStopRequest: function (req, ctx, stat) {
24 httpServer.stop(do_test_finished);
25 }
26 };
27
28 function hugeContentLength(metadata, response) {
29 var text = "abcdefghijklmnopqrstuvwxyz";
30 var bytes_written = 0;
31
32 response.seizePower();
33
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");
38
39 // Write enough data to ensure onDataAvailable gets called
40 while (bytes_written < 4096) {
41 response.write(text);
42 bytes_written += text.length;
43 }
44
45 response.finish();
46 }
47
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 }
55
56 add_test(test_hugeContentLength);
57
58 function run_test() {
59 httpServer = new HttpServer();
60 httpServer.registerPathHandler("/", hugeContentLength);
61 httpServer.start(-1);
62 run_next_test();
63 }

mercurial