bug 1124717 - 4/4 test r=hurley draft
authorPatrick McManus <mcmanus@ducksong.com>
Mon, 26 Jan 2015 16:41:47 -0500
changeset 239228 812395cc0e3ed08aa5051683021caabd181cfcd2
parent 239227 0dfd56e1bc81d5b34ad7f2bb3b48c34f804cd544
child 505166 3b1c18bf0d999008eb8684bd6c70593af3ecbbc6
push id489
push usermcmanus@ducksong.com
push dateTue, 27 Jan 2015 01:44:53 +0000
reviewershurley
bugs1124717
milestone38.0a1
bug 1124717 - 4/4 test r=hurley
netwerk/test/unit/test_http2.js
testing/xpcshell/moz-http2/moz-http2.js
--- a/netwerk/test/unit/test_http2.js
+++ b/netwerk/test/unit/test_http2.js
@@ -10,16 +10,17 @@ function generateContent(size) {
     content += "0";
   }
   return content;
 }
 
 var posts = [];
 posts.push(generateContent(10));
 posts.push(generateContent(250000));
+posts.push(generateContent(128000));
 
 // pre-calculated md5sums (in hex) of the above posts
 var md5s = ['f1b708bba17f1ce948dc979f4d7092bc',
             '2ef8d3b6c8f329318eb1a119b12622b6'];
 
 var bigListenerData = generateContent(128 * 1024);
 var bigListenerMD5 = '8f607cfdd2c87d6a7eedb657dafbd836';
 
@@ -272,36 +273,68 @@ function test_http2_xhr() {
 
 var concurrent_channels = [];
 
 var Http2ConcurrentListener = function() {};
 
 Http2ConcurrentListener.prototype = new Http2CheckListener();
 Http2ConcurrentListener.prototype.count = 0;
 Http2ConcurrentListener.prototype.target = 0;
+Http2ConcurrentListener.prototype.reset = 0;
+Http2ConcurrentListener.prototype.recvdHdr = 0;
 
 Http2ConcurrentListener.prototype.onStopRequest = function(request, ctx, status) {
   this.count++;
   do_check_true(this.isHttp2Connection);
+  if (this.recvdHdr > 0) {
+    do_check_eq(request.getResponseHeader("X-Recvd"), this.recvdHdr);
+  }
+
   if (this.count == this.target) {
+    if (this.reset > 0) {
+      prefs.setIntPref("network.http.spdy.default-concurrent", this.reset);
+    }
     run_next_test();
     do_test_finished();
   }
 };
 
 function test_http2_concurrent() {
   var concurrent_listener = new Http2ConcurrentListener();
   concurrent_listener.target = 201;
+  concurrent_listener.reset = prefs.getIntPref("network.http.spdy.default-concurrent");
+  prefs.setIntPref("network.http.spdy.default-concurrent", 100);
+
   for (var i = 0; i < concurrent_listener.target; i++) {
     concurrent_channels[i] = makeChan("https://localhost:" + serverPort + "/750ms");
     concurrent_channels[i].loadFlags = Ci.nsIRequest.LOAD_BYPASS_CACHE;
     concurrent_channels[i].asyncOpen(concurrent_listener, null);
   }
 }
 
+function test_http2_concurrent_post() {
+  var concurrent_listener = new Http2ConcurrentListener();
+  concurrent_listener.target = 8;
+  concurrent_listener.recvdHdr = posts[2].length;
+  concurrent_listener.reset = prefs.getIntPref("network.http.spdy.default-concurrent");
+  prefs.setIntPref("network.http.spdy.default-concurrent", 3);
+
+  for (var i = 0; i < concurrent_listener.target; i++) {
+    concurrent_channels[i] = makeChan("https://localhost:" + serverPort + "/750msPost");
+    concurrent_channels[i].loadFlags = Ci.nsIRequest.LOAD_BYPASS_CACHE;
+    var stream = Cc["@mozilla.org/io/string-input-stream;1"]
+               .createInstance(Ci.nsIStringInputStream);
+    stream.data = posts[2];
+    var uchan = concurrent_channels[i].QueryInterface(Ci.nsIUploadChannel);
+    uchan.setUploadStream(stream, "text/plain", stream.available());
+    concurrent_channels[i].requestMethod = "POST";
+    concurrent_channels[i].asyncOpen(concurrent_listener, null);
+  }
+}
+
 // Test to make sure we get multiplexing right
 function test_http2_multiplex() {
   var chan1 = makeChan("https://localhost:" + serverPort + "/multiplex1");
   var chan2 = makeChan("https://localhost:" + serverPort + "/multiplex2");
   var listener1 = new Http2MultiplexListener();
   var listener2 = new Http2MultiplexListener();
   chan1.asyncOpen(listener1, null);
   chan2.asyncOpen(listener2, null);
@@ -620,16 +653,17 @@ function test_complete() {
 // hack - the header test resets the multiplex object on the server,
 // so make sure header is always run before the multiplex test.
 //
 // make sure post_big runs first to test race condition in restarting
 // a stalled stream when a SETTINGS frame arrives
 var tests = [ test_http2_post_big
             , test_http2_basic
             , test_http2_concurrent
+            , test_http2_concurrent_post
             , test_http2_basic_unblocked_dep
             , test_http2_nospdy
             , test_http2_push1
             , test_http2_push2
             , test_http2_push3
             , test_http2_push4
 	    , test_http2_altsvc
             , test_http2_doubleheader
--- a/testing/xpcshell/moz-http2/moz-http2.js
+++ b/testing/xpcshell/moz-http2/moz-http2.js
@@ -278,16 +278,39 @@ function handleRequest(req, res) {
       res.setHeader('X-Calculated-MD5', md5);
       res.writeHead(200);
       res.end(content);
     });
 
     return;
   }
 
+  else if (u.pathname === "/750msPost") {
+    if (req.method != "POST") {
+      res.writeHead(405);
+      res.end('Unexpected method: ' + req.method);
+      return;
+    }
+
+    var accum = 0;
+    req.on('data', function receivePostData(chunk) {
+      accum += chunk.length;
+    });
+    req.on('end', function finishPost() {
+      res.setHeader('X-Recvd', accum);
+      var rl = new runlater();
+      rl.req = req;
+      rl.resp = res;
+      setTimeout(executeRunLater, 750, rl);
+      return;
+    });
+
+    return;
+  }
+
   else if (u.pathname === "/h11required_stream") {
     if (req.httpVersionMajor === 2) {
       h11required_conn = req.stream.connection;
       res.stream.reset('HTTP_1_1_REQUIRED');
       return;
     }
   }