netwerk/test/unit/test_bug536324_64bit_content_length.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/test/unit/test_bug536324_64bit_content_length.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +/* Test to ensure our 64-bit content length implementation works, at least for
     1.5 +   a simple HTTP case */
     1.6 +
     1.7 +Cu.import("resource://testing-common/httpd.js");
     1.8 +
     1.9 +// This C-L is significantly larger than (U)INT32_MAX, to make sure we do
    1.10 +// 64-bit properly.
    1.11 +const CONTENT_LENGTH = "1152921504606846975";
    1.12 +
    1.13 +var httpServer = null;
    1.14 +
    1.15 +var listener = {
    1.16 +  onStartRequest: function (req, ctx) {
    1.17 +  },
    1.18 +
    1.19 +  onDataAvailable: function (req, ctx, stream, off, count) {
    1.20 +    do_check_eq(req.getResponseHeader("Content-Length"), CONTENT_LENGTH);
    1.21 +
    1.22 +    // We're done here, cancel the channel
    1.23 +    req.cancel(NS_BINDING_ABORT);
    1.24 +  },
    1.25 +
    1.26 +  onStopRequest: function (req, ctx, stat) {
    1.27 +    httpServer.stop(do_test_finished);
    1.28 +  }
    1.29 +};
    1.30 +
    1.31 +function hugeContentLength(metadata, response) {
    1.32 +  var text = "abcdefghijklmnopqrstuvwxyz";
    1.33 +  var bytes_written = 0;
    1.34 +
    1.35 +  response.seizePower();
    1.36 +
    1.37 +  response.write("HTTP/1.1 200 OK\r\n");
    1.38 +  response.write("Content-Length: " + CONTENT_LENGTH + "\r\n");
    1.39 +  response.write("Connection: close\r\n");
    1.40 +  response.write("\r\n");
    1.41 +
    1.42 +  // Write enough data to ensure onDataAvailable gets called
    1.43 +  while (bytes_written < 4096) {
    1.44 +    response.write(text);
    1.45 +    bytes_written += text.length;
    1.46 +  }
    1.47 +
    1.48 +  response.finish();
    1.49 +}
    1.50 +
    1.51 +function test_hugeContentLength() {
    1.52 +  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    1.53 +  var chan = ios.newChannel("http://localhost:" +
    1.54 +                            httpServer.identity.primaryPort + "/", null, null)
    1.55 +                .QueryInterface(Ci.nsIHttpChannel);
    1.56 +  chan.asyncOpen(listener, null);
    1.57 +}
    1.58 +
    1.59 +add_test(test_hugeContentLength);
    1.60 +
    1.61 +function run_test() {
    1.62 +  httpServer = new HttpServer();
    1.63 +  httpServer.registerPathHandler("/", hugeContentLength);
    1.64 +  httpServer.start(-1);
    1.65 +  run_next_test();
    1.66 +}

mercurial