michael@0: /* Test to ensure our 64-bit content length implementation works, at least for michael@0: a simple HTTP case */ michael@0: michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: // This C-L is significantly larger than (U)INT32_MAX, to make sure we do michael@0: // 64-bit properly. michael@0: const CONTENT_LENGTH = "1152921504606846975"; michael@0: michael@0: var httpServer = null; michael@0: michael@0: var listener = { michael@0: onStartRequest: function (req, ctx) { michael@0: }, michael@0: michael@0: onDataAvailable: function (req, ctx, stream, off, count) { michael@0: do_check_eq(req.getResponseHeader("Content-Length"), CONTENT_LENGTH); michael@0: michael@0: // We're done here, cancel the channel michael@0: req.cancel(NS_BINDING_ABORT); michael@0: }, michael@0: michael@0: onStopRequest: function (req, ctx, stat) { michael@0: httpServer.stop(do_test_finished); michael@0: } michael@0: }; michael@0: michael@0: function hugeContentLength(metadata, response) { michael@0: var text = "abcdefghijklmnopqrstuvwxyz"; michael@0: var bytes_written = 0; michael@0: michael@0: response.seizePower(); michael@0: michael@0: response.write("HTTP/1.1 200 OK\r\n"); michael@0: response.write("Content-Length: " + CONTENT_LENGTH + "\r\n"); michael@0: response.write("Connection: close\r\n"); michael@0: response.write("\r\n"); michael@0: michael@0: // Write enough data to ensure onDataAvailable gets called michael@0: while (bytes_written < 4096) { michael@0: response.write(text); michael@0: bytes_written += text.length; michael@0: } michael@0: michael@0: response.finish(); michael@0: } michael@0: michael@0: function test_hugeContentLength() { michael@0: var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); michael@0: var chan = ios.newChannel("http://localhost:" + michael@0: httpServer.identity.primaryPort + "/", null, null) michael@0: .QueryInterface(Ci.nsIHttpChannel); michael@0: chan.asyncOpen(listener, null); michael@0: } michael@0: michael@0: add_test(test_hugeContentLength); michael@0: michael@0: function run_test() { michael@0: httpServer = new HttpServer(); michael@0: httpServer.registerPathHandler("/", hugeContentLength); michael@0: httpServer.start(-1); michael@0: run_next_test(); michael@0: }