Bug 536324 part 4 - Test to make sure 64-bit content length works. r=sworkman
authorNick Hurley <hurley@todesschaf.org>
Mon, 22 Oct 2012 10:51:07 -0700
changeset 111058 4bb51e245a4ed53ffaace1923cfa100d627b3261
parent 111057 af7e6c8e6d768e7dcf2e9f7f30fc7f4c8b37d4f5
child 111059 8141e5eb9f0b2dfc4b5e3def07b98666a10be0c2
push id23726
push userryanvm@gmail.com
push dateTue, 23 Oct 2012 01:41:58 +0000
treeherdermozilla-central@48502b61a63e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman
bugs536324
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 536324 part 4 - Test to make sure 64-bit content length works. r=sworkman
netwerk/test/unit/test_bug536324_64bit_content_length.js
netwerk/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_bug536324_64bit_content_length.js
@@ -0,0 +1,66 @@
+/* Test to ensure our 64-bit content length implementation works, at least for
+   a simple HTTP case */
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+const Cr = Components.results;
+
+Cu.import("resource://testing-common/httpd.js");
+
+// This C-L is significantly larger than (U)INT32_MAX, to make sure we do
+// 64-bit properly.
+const CONTENT_LENGTH = "1152921504606846975";
+
+var httpServer = null;
+
+var listener = {
+  onStartRequest: function (req, ctx) {
+  },
+
+  onDataAvailable: function (req, ctx, stream, off, count) {
+    do_check_eq(req.getResponseHeader("Content-Length"), CONTENT_LENGTH);
+
+    // We're done here, cancel the channel
+    req.cancel(NS_BINDING_ABORT);
+  },
+
+  onStopRequest: function (req, ctx, stat) {
+    httpServer.stop(do_test_finished);
+  }
+};
+
+function hugeContentLength(metadata, response) {
+  var text = "abcdefghijklmnopqrstuvwxyz";
+  var bytes_written = 0;
+
+  response.seizePower();
+
+  response.write("HTTP/1.1 200 OK\r\n");
+  response.write("Content-Length: " + CONTENT_LENGTH + "\r\n");
+  response.write("Connection: close\r\n");
+  response.write("\r\n");
+
+  // Write enough data to ensure onDataAvailable gets called
+  while (bytes_written < 4096) {
+    response.write(text);
+    bytes_written += text.length;
+  }
+
+  response.finish();
+}
+
+function test_hugeContentLength() {
+  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+  var chan = ios.newChannel("http://localhost:4444/", null, null)
+                .QueryInterface(Ci.nsIHttpChannel);
+  chan.asyncOpen(listener, null);
+}
+
+add_test(test_hugeContentLength);
+
+function run_test() {
+  httpServer = new HttpServer();
+  httpServer.registerPathHandler("/", hugeContentLength);
+  httpServer.start(4444);
+  run_next_test();
+}
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -52,16 +52,17 @@ skip-if = os == "android"
 [test_bug484684.js]
 [test_bug490095.js]
 [test_bug504014.js]
 [test_bug510359.js]
 # Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_bug515583.js]
 [test_bug528292.js]
+[test_bug536324_64bit_content_length.js]
 [test_bug540566.js]
 [test_bug543805.js]
 [test_bug553970.js]
 [test_bug561042.js]
 [test_bug561276.js]
 [test_bug580508.js]
 [test_bug586908.js]
 [test_bug596443.js]