bug 1102923 - move spdy/h2 tests off fixed port r=hurley r=ted
authorPatrick McManus <mcmanus@ducksong.com>
Thu, 15 Jan 2015 11:12:05 -0500
changeset 224721 19e54c63c4c2321408fdd7a56ef94ac8c8f204a4
parent 224720 5c93233e6aeb406ae6c9a9816b1d22f7431cdb3b
child 224722 6f6632cabb36901e981ebabb8ce96b108a146252
push id28143
push userryanvm@gmail.com
push dateWed, 21 Jan 2015 03:14:12 +0000
treeherdermozilla-central@540077a30866 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershurley, ted
bugs1102923
milestone38.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 1102923 - move spdy/h2 tests off fixed port r=hurley r=ted
netwerk/test/unit/test_http2.js
netwerk/test/unit/test_spdy.js
testing/xpcshell/moz-http2/moz-http2.js
testing/xpcshell/moz-spdy/moz-spdy.js
testing/xpcshell/runxpcshelltests.py
--- a/netwerk/test/unit/test_http2.js
+++ b/netwerk/test/unit/test_http2.js
@@ -42,35 +42,34 @@ var Http2CheckListener = function() {};
 Http2CheckListener.prototype = {
   onStartRequestFired: false,
   onDataAvailableFired: false,
   isHttp2Connection: false,
   shouldBeHttp2 : true,
 
   onStartRequest: function testOnStartRequest(request, ctx) {
     this.onStartRequestFired = true;
-
     if (!Components.isSuccessCode(request.status))
       do_throw("Channel should have a success code! (" + request.status + ")");
-    if (!(request instanceof Components.interfaces.nsIHttpChannel))
-      do_throw("Expecting an HTTP channel");
 
+    do_check_true(request instanceof Components.interfaces.nsIHttpChannel);
     do_check_eq(request.responseStatus, 200);
     do_check_eq(request.requestSucceeded, true);
   },
 
   onDataAvailable: function testOnDataAvailable(request, ctx, stream, off, cnt) {
     this.onDataAvailableFired = true;
     this.isHttp2Connection = checkIsHttp2(request);
 
     read_stream(stream, cnt);
   },
 
   onStopRequest: function testOnStopRequest(request, ctx, status) {
     do_check_true(this.onStartRequestFired);
+    do_check_true(Components.isSuccessCode(status));
     do_check_true(this.onDataAvailableFired);
     do_check_true(this.isHttp2Connection == this.shouldBeHttp2);
 
     run_next_test();
     do_test_finished();
   }
 };
 
@@ -135,18 +134,18 @@ Http2HeaderListener.prototype.onDataAvai
 
 var Http2PushListener = function() {};
 
 Http2PushListener.prototype = new Http2CheckListener();
 
 Http2PushListener.prototype.onDataAvailable = function(request, ctx, stream, off, cnt) {
   this.onDataAvailableFired = true;
   this.isHttp2Connection = checkIsHttp2(request);
-  if (ctx.originalURI.spec == "https://localhost:6944/push.js" ||
-      ctx.originalURI.spec == "https://localhost:6944/push2.js") {
+  if (ctx.originalURI.spec == "https://localhost:" + serverPort + "/push.js" ||
+      ctx.originalURI.spec == "https://localhost:" + serverPort + "/push2.js") {
     do_check_eq(request.getResponseHeader("pushed"), "yes");
   }
   read_stream(stream, cnt);
 };
 
 // Does the appropriate checks for a large GET response
 var Http2BigListener = function() {};
 
@@ -221,32 +220,32 @@ function makeChan(url) {
                              Ci.nsILoadInfo.SEC_NORMAL,
                              Ci.nsIContentPolicy.TYPE_OTHER).QueryInterface(Ci.nsIHttpChannel);
 
   return chan;
 }
 
 // Make sure we make a HTTP2 connection and both us and the server mark it as such
 function test_http2_basic() {
-  var chan = makeChan("https://localhost:6944/");
+  var chan = makeChan("https://localhost:" + serverPort + "/");
   var listener = new Http2CheckListener();
   chan.asyncOpen(listener, null);
 }
 
 function test_http2_basic_unblocked_dep() {
-  var chan = makeChan("https://localhost:6944/basic_unblocked_dep");
+  var chan = makeChan("https://localhost:" + serverPort + "/basic_unblocked_dep");
   var cos = chan.QueryInterface(Ci.nsIClassOfService);
   cos.addClassFlags(Ci.nsIClassOfService.Unblocked);
   var listener = new Http2CheckListener();
   chan.asyncOpen(listener, null);
 }
 
 // make sure we don't use h2 when disallowed
 function test_http2_nospdy() {
-  var chan = makeChan("https://localhost:6944/");
+  var chan = makeChan("https://localhost:" + serverPort + "/");
   var listener = new Http2CheckListener();
   var internalChannel = chan.QueryInterface(Ci.nsIHttpChannelInternal);
   internalChannel.allowSpdy = false;
   listener.shouldBeHttp2 = false;
   chan.asyncOpen(listener, null);
 }
 
 // Support for making sure XHR works over SPDY
@@ -260,17 +259,17 @@ function checkXhr(xhr) {
   run_next_test();
   do_test_finished();
 }
 
 // Fires off an XHR request over SPDY
 function test_http2_xhr() {
   var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
             .createInstance(Ci.nsIXMLHttpRequest);
-  req.open("GET", "https://localhost:6944/", true);
+  req.open("GET", "https://localhost:" + serverPort + "/", true);
   req.addEventListener("readystatechange", function (evt) { checkXhr(req); },
                        false);
   req.send(null);
 }
 
 var concurrent_channels = [];
 
 var Http2ConcurrentListener = function() {};
@@ -287,46 +286,46 @@ Http2ConcurrentListener.prototype.onStop
     do_test_finished();
   }
 };
 
 function test_http2_concurrent() {
   var concurrent_listener = new Http2ConcurrentListener();
   concurrent_listener.target = 201;
   for (var i = 0; i < concurrent_listener.target; i++) {
-    concurrent_channels[i] = makeChan("https://localhost:6944/750ms");
+    concurrent_channels[i] = makeChan("https://localhost:" + serverPort + "/750ms");
     concurrent_channels[i].loadFlags = Ci.nsIRequest.LOAD_BYPASS_CACHE;
     concurrent_channels[i].asyncOpen(concurrent_listener, null);
   }
 }
 
 // Test to make sure we get multiplexing right
 function test_http2_multiplex() {
-  var chan1 = makeChan("https://localhost:6944/multiplex1");
-  var chan2 = makeChan("https://localhost:6944/multiplex2");
+  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);
 }
 
 // Test to make sure we gateway non-standard headers properly
 function test_http2_header() {
-  var chan = makeChan("https://localhost:6944/header");
+  var chan = makeChan("https://localhost:" + serverPort + "/header");
   var hvalue = "Headers are fun";
   chan.setRequestHeader("X-Test-Header", hvalue, false);
   var listener = new Http2HeaderListener("X-Received-Test-Header", function(received_hvalue) {
     do_check_eq(received_hvalue, hvalue);
   });
   chan.asyncOpen(listener, null);
 }
 
 // Test to make sure cookies are split into separate fields before compression
 function test_http2_cookie_crumbling() {
-  var chan = makeChan("https://localhost:6944/cookie_crumbling");
+  var chan = makeChan("https://localhost:" + serverPort + "/cookie_crumbling");
   var cookiesSent = ['a=b', 'c=d01234567890123456789', 'e=f'].sort();
   chan.setRequestHeader("Cookie", cookiesSent.join('; '), false);
   var listener = new Http2HeaderListener("X-Received-Header-Pairs", function(pairsReceived) {
     var cookiesReceived = JSON.parse(pairsReceived).filter(function(pair) {
       return pair[0] == 'cookie';
     }).map(function(pair) {
       return pair[1];
     }).sort();
@@ -334,60 +333,60 @@ function test_http2_cookie_crumbling() {
     cookiesReceived.forEach(function(cookieReceived, index) {
       do_check_eq(cookiesSent[index], cookieReceived)
     });
   });
   chan.asyncOpen(listener, null);
 }
 
 function test_http2_push1() {
-  var chan = makeChan("https://localhost:6944/push");
+  var chan = makeChan("https://localhost:" + serverPort + "/push");
   chan.loadGroup = loadGroup;
   var listener = new Http2PushListener();
   chan.asyncOpen(listener, chan);
 }
 
 function test_http2_push2() {
-  var chan = makeChan("https://localhost:6944/push.js");
+  var chan = makeChan("https://localhost:" + serverPort + "/push.js");
   chan.loadGroup = loadGroup;
   var listener = new Http2PushListener();
   chan.asyncOpen(listener, chan);
 }
 
 function test_http2_push3() {
-  var chan = makeChan("https://localhost:6944/push2");
+  var chan = makeChan("https://localhost:" + serverPort + "/push2");
   chan.loadGroup = loadGroup;
   var listener = new Http2PushListener();
   chan.asyncOpen(listener, chan);
 }
 
 function test_http2_push4() {
-  var chan = makeChan("https://localhost:6944/push2.js");
+  var chan = makeChan("https://localhost:" + serverPort + "/push2.js");
   chan.loadGroup = loadGroup;
   var listener = new Http2PushListener();
   chan.asyncOpen(listener, chan);
 }
 
 // this is a basic test where the server sends a simple document with 2 header
 // blocks. bug 1027364
 function test_http2_doubleheader() {
-  var chan = makeChan("https://localhost:6944/doubleheader");
+  var chan = makeChan("https://localhost:" + serverPort + "/doubleheader");
   var listener = new Http2CheckListener();
   chan.asyncOpen(listener, null);
 }
 
 // Make sure we handle GETs that cover more than 2 frames properly
 function test_http2_big() {
-  var chan = makeChan("https://localhost:6944/big");
+  var chan = makeChan("https://localhost:" + serverPort + "/big");
   var listener = new Http2BigListener();
   chan.asyncOpen(listener, null);
 }
 
 function test_http2_huge_suspended() {
-  var chan = makeChan("https://localhost:6944/huge");
+  var chan = makeChan("https://localhost:" + serverPort + "/huge");
   var listener = new Http2HugeSuspendedListener();
   chan.asyncOpen(listener, null);
   chan.suspend();
   do_timeout(500, chan.resume);
 }
 
 // Support for doing a POST
 function do_post(content, chan, listener) {
@@ -400,24 +399,24 @@ function do_post(content, chan, listener
 
   chan.requestMethod = "POST";
 
   chan.asyncOpen(listener, null);
 }
 
 // Make sure we can do a simple POST
 function test_http2_post() {
-  var chan = makeChan("https://localhost:6944/post");
+  var chan = makeChan("https://localhost:" + serverPort + "/post");
   var listener = new Http2PostListener(md5s[0]);
   do_post(posts[0], chan, listener);
 }
 
 // Make sure we can do a POST that covers more than 2 frames
 function test_http2_post_big() {
-  var chan = makeChan("https://localhost:6944/post");
+  var chan = makeChan("https://localhost:" + serverPort + "/post");
   var listener = new Http2PostListener(md5s[1]);
   do_post(posts[1], chan, listener);
 }
 
 Cu.import("resource://testing-common/httpd.js");
 Cu.import("resource://gre/modules/Services.jsm");
 
 var httpserv = null;
@@ -453,17 +452,17 @@ var altsvcClientListener = {
 	run_next_test();
     }
   }
 };
 
 function altsvcHttp1Server(metadata, response) {
   response.setStatusLine(metadata.httpVersion, 200, "OK");
   response.setHeader("Content-Type", "text/plain", false);
-  response.setHeader("Alt-Svc", 'h2-16=":6944"', false);
+  response.setHeader("Alt-Svc", 'h2-16=":' + serverPort + '"', false);
   var body = "this is where a cool kid would write something neat.\n";
   response.bodyOutputStream.write(body, body.length);
 }
 
 function test_http2_altsvc() {
   httpserv = new HttpServer();
   httpserv.registerPathHandler("/altsvc1", altsvcHttp1Server);
   httpserv.start(-1);
@@ -493,50 +492,50 @@ Http2PushApiListener.prototype = {
     if (aIID.equals(Ci.nsIHttpPushListener) ||
         aIID.equals(Ci.nsIStreamListener))
       return this;
     throw Components.results.NS_ERROR_NO_INTERFACE;
   },
 
   // nsIHttpPushListener
   onPush: function onPush(associatedChannel, pushChannel) {
-    do_check_eq(associatedChannel.originalURI.spec, "https://localhost:6944/pushapi1");
+    do_check_eq(associatedChannel.originalURI.spec, "https://localhost:" + serverPort + "/pushapi1");
     do_check_eq (pushChannel.getRequestHeader("x-pushed-request"), "true");
 
     pushChannel.asyncOpen(this, pushChannel);
-    if (pushChannel.originalURI.spec == "https://localhost:6944/pushapi1/2") {
+    if (pushChannel.originalURI.spec == "https://localhost:" + serverPort + "/pushapi1/2") {
 	pushChannel.cancel(Components.results.NS_ERROR_ABORT);
     }
   },
 
  // normal Channel listeners
   onStartRequest: function pushAPIOnStart(request, ctx) {
   },
 
   onDataAvailable: function pushAPIOnDataAvailable(request, ctx, stream, offset, cnt) {
-    do_check_neq(ctx.originalURI.spec, "https://localhost:6944/pushapi1/2");
+    do_check_neq(ctx.originalURI.spec, "https://localhost:" + serverPort + "/pushapi1/2");
 
     var data = read_stream(stream, cnt);
 
-    if (ctx.originalURI.spec == "https://localhost:6944/pushapi1") {
+    if (ctx.originalURI.spec == "https://localhost:" + serverPort + "/pushapi1") {
 	do_check_eq(data[0], '0');
 	--this.checksPending;
-    } else if (ctx.originalURI.spec == "https://localhost:6944/pushapi1/1") {
+    } else if (ctx.originalURI.spec == "https://localhost:" + serverPort + "/pushapi1/1") {
 	do_check_eq(data[0], '1');
 	--this.checksPending; // twice
-    } else if (ctx.originalURI.spec == "https://localhost:6944/pushapi1/3") {
+    } else if (ctx.originalURI.spec == "https://localhost:" + serverPort + "/pushapi1/3") {
 	do_check_eq(data[0], '3');
 	--this.checksPending;
     } else {
 	do_check_eq(true, false);
     }
   },
 
   onStopRequest: function test_onStopR(request, ctx, status) {
-    if (ctx.originalURI.spec == "https://localhost:6944/pushapi1/2") {
+    if (ctx.originalURI.spec == "https://localhost:" + serverPort + "/pushapi1/2") {
 	do_check_eq(request.status, Components.results.NS_ERROR_ABORT);
     } else {
 	do_check_eq(request.status, Components.results.NS_OK);
     }
 
     --this.checksPending; // 5 times - one for each push plus the pull
     if (!this.checksPending) {
 	run_next_test();
@@ -548,17 +547,17 @@ Http2PushApiListener.prototype = {
 // pushAPI testcase 1 expects
 // 1 to pull /pushapi1 with 0
 // 2 to see /pushapi1/1 with 1
 // 3 to see /pushapi1/1 with 1 (again)
 // 4 to see /pushapi1/2 that it will cancel
 // 5 to see /pushapi1/3 with 3
 
 function test_http2_pushapi_1() {
-  var chan = makeChan("https://localhost:6944/pushapi1");
+  var chan = makeChan("https://localhost:" + serverPort + "/pushapi1");
   chan.loadGroup = loadGroup;
   var listener = new Http2PushApiListener();
   chan.notificationCallbacks = listener;
   chan.asyncOpen(listener, chan);
 }
 
 var WrongSuiteListener = function() {};
 WrongSuiteListener.prototype = new Http2CheckListener();
@@ -566,24 +565,24 @@ WrongSuiteListener.prototype.shouldBeHtt
 WrongSuiteListener.prototype.onStopRequest = function(request, ctx, status) {
   prefs.setBoolPref("security.ssl3.ecdhe_rsa_aes_128_gcm_sha256", true);
   Http2CheckListener.prototype.onStopRequest.call(this);
 };
 
 // test that we use h1 without the mandatory cipher suite available
 function test_http2_wrongsuite() {
   prefs.setBoolPref("security.ssl3.ecdhe_rsa_aes_128_gcm_sha256", false);
-  var chan = makeChan("https://localhost:6944/wrongsuite");
+  var chan = makeChan("https://localhost:" + serverPort + "/wrongsuite");
   chan.loadFlags = Ci.nsIRequest.LOAD_FRESH_CONNECTION | Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
   var listener = new WrongSuiteListener();
   chan.asyncOpen(listener, null);
 }
 
 function test_http2_h11required_stream() {
-  var chan = makeChan("https://localhost:6944/h11required_stream");
+  var chan = makeChan("https://localhost:" + serverPort + "/h11required_stream");
   var listener = new Http2CheckListener();
   listener.shouldBeHttp2 = false;
   chan.asyncOpen(listener, null);
 }
 
 function H11RequiredSessionListener () { }
 H11RequiredSessionListener.prototype = new Http2CheckListener();
 
@@ -595,24 +594,24 @@ H11RequiredSessionListener.prototype.onS
   do_check_true(this.onDataAvailableFired);
   do_check_true(this.isHttp2Connection == this.shouldBeHttp2);
 
   run_next_test();
   do_test_finished();
 };
 
 function test_http2_h11required_session() {
-  var chan = makeChan("https://localhost:6944/h11required_session");
+  var chan = makeChan("https://localhost:" + serverPort + "/h11required_session");
   var listener = new H11RequiredSessionListener();
   listener.shouldBeHttp2 = false;
   chan.asyncOpen(listener, null);
 }
 
 function test_http2_retry_rst() {
-  var chan = makeChan("https://localhost:6944/rstonce");
+  var chan = makeChan("https://localhost:" + serverPort + "/rstonce");
   var listener = new Http2CheckListener();
   chan.asyncOpen(listener, null);
 }
 
 function test_complete() {
   resetPrefs();
   do_test_finished();
   do_timeout(0,run_next_test);
@@ -687,16 +686,17 @@ CertOverrideListener.prototype = {
     throw Components.results.NS_ERROR_NO_INTERFACE;
   },
 
   notifyCertProblem: function(socketInfo, sslStatus, targetHost) {
     var cert = sslStatus.QueryInterface(Ci.nsISSLStatus).serverCert;
     var cos = Cc["@mozilla.org/security/certoverride;1"].
               getService(Ci.nsICertOverrideService);
     cos.rememberValidityOverride(this.host, this.port, cert, this.bits, false);
+    dump("Certificate Override in place\n");
     return true;
   },
 };
 
 function addCertOverride(host, port, bits) {
   var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
             .createInstance(Ci.nsIXMLHttpRequest);
   try {
@@ -717,37 +717,42 @@ function addCertOverride(host, port, bit
 var prefs;
 var spdypref;
 var spdy3pref;
 var spdypush;
 var http2pref;
 var tlspref;
 var altsvcpref1;
 var altsvcpref2;
-
 var loadGroup;
+var serverPort;
 
 function resetPrefs() {
   prefs.setBoolPref("network.http.spdy.enabled", spdypref);
   prefs.setBoolPref("network.http.spdy.enabled.v3-1", spdy3pref);
   prefs.setBoolPref("network.http.spdy.allow-push", spdypush);
   prefs.setBoolPref("network.http.spdy.enabled.http2draft", http2pref);
   prefs.setBoolPref("network.http.spdy.enforce-tls-profile", tlspref);
   prefs.setBoolPref("network.http.altsvc.enabled", altsvcpref1);
   prefs.setBoolPref("network.http.altsvc.oe", altsvcpref2);
 }
 
 function run_test() {
+  var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
+  serverPort = env.get("MOZHTTP2-PORT");
+  do_check_neq(serverPort, null);
+  dump("using port " + serverPort + "\n");
+
   // Set to allow the cert presented by our SPDY server
   do_get_profile();
   prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
   var oldPref = prefs.getIntPref("network.http.speculative-parallel-limit");
   prefs.setIntPref("network.http.speculative-parallel-limit", 0);
 
-  addCertOverride("localhost", 6944,
+  addCertOverride("localhost", serverPort,
                   Ci.nsICertOverrideService.ERROR_UNTRUSTED |
                   Ci.nsICertOverrideService.ERROR_MISMATCH |
                   Ci.nsICertOverrideService.ERROR_TIME);
 
   prefs.setIntPref("network.http.speculative-parallel-limit", oldPref);
 
   // Enable all versions of spdy to see that we auto negotiate http/2
   spdypref = prefs.getBoolPref("network.http.spdy.enabled");
--- a/netwerk/test/unit/test_spdy.js
+++ b/netwerk/test/unit/test_spdy.js
@@ -44,37 +44,36 @@ var SpdyCheckListener = function() {};
 
 SpdyCheckListener.prototype = {
   onStartRequestFired: false,
   onDataAvailableFired: false,
   isSpdyConnection: false,
 
   onStartRequest: function testOnStartRequest(request, ctx) {
     this.onStartRequestFired = true;
-
     if (!Components.isSuccessCode(request.status))
       do_throw("Channel should have a success code! (" + request.status + ")");
-    if (!(request instanceof Components.interfaces.nsIHttpChannel))
-      do_throw("Expecting an HTTP channel");
 
+    do_check_true(request instanceof Components.interfaces.nsIHttpChannel);
     do_check_eq(request.responseStatus, 200);
     do_check_eq(request.requestSucceeded, true);
   },
 
   onDataAvailable: function testOnDataAvailable(request, ctx, stream, off, cnt) {
     this.onDataAvailableFired = true;
     this.isSpdyConnection = checkIsSpdy(request);
 
     read_stream(stream, cnt);
   },
 
   onStopRequest: function testOnStopRequest(request, ctx, status) {
     do_check_true(this.onStartRequestFired);
+    do_check_true(Components.isSuccessCode(status));
+    do_check_true(this.isSpdyConnection);
     do_check_true(this.onDataAvailableFired);
-    do_check_true(this.isSpdyConnection);
 
     run_next_test();
     do_test_finished();
   }
 };
 
 /*
  * Support for testing valid multiplexing of streams
@@ -134,18 +133,18 @@ SpdyHeaderListener.prototype.onDataAvail
 
 var SpdyPushListener = function() {};
 
 SpdyPushListener.prototype = new SpdyCheckListener();
 
 SpdyPushListener.prototype.onDataAvailable = function(request, ctx, stream, off, cnt) {
   this.onDataAvailableFired = true;
   this.isSpdyConnection = checkIsSpdy(request);
-  if (ctx.originalURI.spec == "https://localhost:4443/push.js" ||
-      ctx.originalURI.spec == "https://localhost:4443/push2.js") {
+  if (ctx.originalURI.spec == "https://localhost:" + serverPort + "/push.js" ||
+      ctx.originalURI.spec == "https://localhost:" + serverPort + "/push2.js") {
     do_check_eq(request.getResponseHeader("pushed"), "yes");
   }
   read_stream(stream, cnt);
 };
 
 // Does the appropriate checks for a large GET response
 var SpdyBigListener = function() {};
 
@@ -199,17 +198,17 @@ function makeChan(url) {
                              Ci.nsILoadInfo.SEC_NORMAL,
                              Ci.nsIContentPolicy.TYPE_OTHER).QueryInterface(Ci.nsIHttpChannel);
 
   return chan;
 }
 
 // Make sure we make a spdy connection and both us and the server mark it as such
 function test_spdy_basic() {
-  var chan = makeChan("https://localhost:4443/");
+  var chan = makeChan("https://localhost:" + serverPort + "/");
   var listener = new SpdyCheckListener();
   chan.asyncOpen(listener, null);
 }
 
 // Support for making sure XHR works over SPDY
 function checkXhr(xhr) {
   if (xhr.readyState != 4) {
     return;
@@ -220,17 +219,17 @@ function checkXhr(xhr) {
   run_next_test();
   do_test_finished();
 }
 
 // Fires off an XHR request over SPDY
 function test_spdy_xhr() {
   var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
             .createInstance(Ci.nsIXMLHttpRequest);
-  req.open("GET", "https://localhost:4443/", true);
+  req.open("GET", "https://localhost:" + serverPort + "/", true);
   req.addEventListener("readystatechange", function (evt) { checkXhr(req); },
                        false);
   req.send(null);
 }
 
 var concurrent_channels = [];
 
 var SpdyConcurrentListener = function() {};
@@ -247,72 +246,72 @@ SpdyConcurrentListener.prototype.onStopR
     do_test_finished();
   }
 };
 
 function test_spdy_concurrent() {
   var concurrent_listener = new SpdyConcurrentListener();
   concurrent_listener.target = 201;
   for (var i = 0; i < concurrent_listener.target; i++) {
-    concurrent_channels[i] = makeChan("https://localhost:4443/750ms");
+    concurrent_channels[i] = makeChan("https://localhost:" + serverPort + "/750ms");
     concurrent_channels[i].loadFlags = Ci.nsIRequest.LOAD_BYPASS_CACHE;
     concurrent_channels[i].asyncOpen(concurrent_listener, null);
   }
 }
 
 // Test to make sure we get multiplexing right
 function test_spdy_multiplex() {
-  var chan1 = makeChan("https://localhost:4443/multiplex1");
-  var chan2 = makeChan("https://localhost:4443/multiplex2");
+  var chan1 = makeChan("https://localhost:" + serverPort + "/multiplex1");
+  var chan2 = makeChan("https://localhost:" + serverPort + "/multiplex2");
   var listener1 = new SpdyMultiplexListener();
   var listener2 = new SpdyMultiplexListener();
   chan1.asyncOpen(listener1, null);
   chan2.asyncOpen(listener2, null);
 }
 
 // Test to make sure we gateway non-standard headers properly
 function test_spdy_header() {
-  var chan = makeChan("https://localhost:4443/header");
+  var chan = makeChan("https://localhost:" + serverPort + "/header");
   var hvalue = "Headers are fun";
   var listener = new SpdyHeaderListener(hvalue);
   chan.setRequestHeader("X-Test-Header", hvalue, false);
   chan.asyncOpen(listener, null);
 }
 
 function test_spdy_push1() {
-  var chan = makeChan("https://localhost:4443/push");
+  var chan = makeChan("https://localhost:" + serverPort + "/push");
   chan.loadGroup = loadGroup;
   var listener = new SpdyPushListener();
   chan.asyncOpen(listener, chan);
 }
 
 function test_spdy_push2() {
-  var chan = makeChan("https://localhost:4443/push.js");
+  var chan = makeChan("https://localhost:" + serverPort + "/push.js");
   chan.loadGroup = loadGroup;
   var listener = new SpdyPushListener();
   chan.asyncOpen(listener, chan);
 }
 
 function test_spdy_push3() {
-  var chan = makeChan("https://localhost:4443/push2");
+  var chan = makeChan("https://localhost:" + serverPort + "/push2");
   chan.loadGroup = loadGroup;
   var listener = new SpdyPushListener();
   chan.asyncOpen(listener, chan);
 }
 
 function test_spdy_push4() {
-  var chan = makeChan("https://localhost:4443/push2.js");
+  var chan = makeChan("https://localhost:" + serverPort + "/push2.js");
   chan.loadGroup = loadGroup;
   var listener = new SpdyPushListener();
   chan.asyncOpen(listener, chan);
 }
 
 // Make sure we handle GETs that cover more than 2 frames properly
 function test_spdy_big() {
-  var chan = makeChan("https://localhost:4443/big");
+  var chan = makeChan("https://localhost:" + serverPort + "/big");
   var listener = new SpdyBigListener();
   chan.asyncOpen(listener, null);
 }
 
 // Support for doing a POST
 function do_post(content, chan, listener) {
   var stream = Cc["@mozilla.org/io/string-input-stream;1"]
                .createInstance(Ci.nsIStringInputStream);
@@ -323,24 +322,24 @@ function do_post(content, chan, listener
 
   chan.requestMethod = "POST";
 
   chan.asyncOpen(listener, null);
 }
 
 // Make sure we can do a simple POST
 function test_spdy_post() {
-  var chan = makeChan("https://localhost:4443/post");
+  var chan = makeChan("https://localhost:" + serverPort + "/post");
   var listener = new SpdyPostListener(md5s[0]);
   do_post(posts[0], chan, listener);
 }
 
 // Make sure we can do a POST that covers more than 2 frames
 function test_spdy_post_big() {
-  var chan = makeChan("https://localhost:4443/post");
+  var chan = makeChan("https://localhost:" + serverPort + "/post");
   var listener = new SpdyPostListener(md5s[1]);
   do_post(posts[1], chan, listener);
 }
 
 // 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
@@ -394,16 +393,17 @@ CertOverrideListener.prototype = {
     throw Components.results.NS_ERROR_NO_INTERFACE;
   },
 
   notifyCertProblem: function(socketInfo, sslStatus, targetHost) {
     var cert = sslStatus.QueryInterface(Ci.nsISSLStatus).serverCert;
     var cos = Cc["@mozilla.org/security/certoverride;1"].
               getService(Ci.nsICertOverrideService);
     cos.rememberValidityOverride(this.host, this.port, cert, this.bits, false);
+    dump("Certificate Override in place\n");
     return true;
   },
 };
 
 function addCertOverride(host, port, bits) {
   var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
             .createInstance(Ci.nsIXMLHttpRequest);
   try {
@@ -420,44 +420,47 @@ function addCertOverride(host, port, bit
     // This will fail since the server is not trusted yet
   }
 }
 
 var prefs;
 var spdypref;
 var spdy3pref;
 var spdypush;
-
 var loadGroup;
+var serverPort;
 
 function resetPrefs() {
   prefs.setBoolPref("network.http.spdy.enabled", spdypref);
   prefs.setBoolPref("network.http.spdy.enabled.v3-1", spdy3pref);
   prefs.setBoolPref("network.http.spdy.allow-push", spdypush);
 }
 
 function run_test() {
+  var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
+  serverPort = env.get("MOZSPDY-PORT");
+  do_check_neq(serverPort, null);
+  dump("using port " + serverPort + "\n");
+
   // Set to allow the cert presented by our SPDY server
   do_get_profile();
-  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-  var oldPref = prefs.getIntPref("network.http.speculative-parallel-limit");
+  prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
+  var oldParallel = prefs.getIntPref("network.http.speculative-parallel-limit");
   prefs.setIntPref("network.http.speculative-parallel-limit", 0);
 
-  addCertOverride("localhost", 4443,
+  addCertOverride("localhost", serverPort,
                   Ci.nsICertOverrideService.ERROR_UNTRUSTED |
                   Ci.nsICertOverrideService.ERROR_MISMATCH |
                   Ci.nsICertOverrideService.ERROR_TIME);
-
-  prefs.setIntPref("network.http.speculative-parallel-limit", oldPref);
+  prefs.setIntPref("network.http.speculative-parallel-limit", oldParallel);
 
   // Enable all versions of spdy to see that we auto negotiate spdy/3.1
   spdypref = prefs.getBoolPref("network.http.spdy.enabled");
   spdy3pref = prefs.getBoolPref("network.http.spdy.enabled.v3-1");
   spdypush = prefs.getBoolPref("network.http.spdy.allow-push");
   prefs.setBoolPref("network.http.spdy.enabled", true);
   prefs.setBoolPref("network.http.spdy.enabled.v3-1", true);
   prefs.setBoolPref("network.http.spdy.allow-push", true);
 
   loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance(Ci.nsILoadGroup);
 
-  // And make go!
   run_next_test();
 }
--- a/testing/xpcshell/moz-http2/moz-http2.js
+++ b/testing/xpcshell/moz-http2/moz-http2.js
@@ -191,50 +191,50 @@ function handleRequest(req, res) {
       'X-Connection-Http2': 'yes'
     });
     push.end('// comments');
     content = '<head> <script src="push2.js"/></head>body text';
   }
 
   else if (u.pathname === "/pushapi1") {
     push1 = res.push(
-	{ hostname: 'localhost:6944', port: 6944, path : '/pushapi1/1', method : 'GET',
+	{ hostname: 'localhost:' + serverPort, port: serverPort, path : '/pushapi1/1', method : 'GET',
 	  headers: {'x-pushed-request': 'true', 'x-foo' : 'bar'}});
     push1.writeHead(200, {
       'pushed' : 'yes',
       'content-length' : 1,
       'subresource' : '1',
       'X-Connection-Http2': 'yes'
       });
     push1.end('1');
 
     push1a = res.push(
-	{ hostname: 'localhost:6944', port: 6944, path : '/pushapi1/1', method : 'GET',
+	{ hostname: 'localhost:' + serverPort, port: serverPort, path : '/pushapi1/1', method : 'GET',
 	  headers: {'x-foo' : 'bar', 'x-pushed-request': 'true'}});
     push1a.writeHead(200, {
       'pushed' : 'yes',
       'content-length' : 1,
       'subresource' : '1a',
       'X-Connection-Http2': 'yes'
       });
     push1a.end('1');
 
     push2 = res.push(
-	{ hostname: 'localhost:6944', port: 6944, path : '/pushapi1/2', method : 'GET',
+	{ hostname: 'localhost:' + serverPort, port: serverPort, path : '/pushapi1/2', method : 'GET',
 	  headers: {'x-pushed-request': 'true'}});
     push2.writeHead(200, {
 	  'pushed' : 'yes',
 	  'subresource' : '2',
 	  'content-length' : 1,
 	  'X-Connection-Http2': 'yes'
       });
     push2.end('2');
 
     push3 = res.push(
-	{ hostname: 'localhost:6944', port: 6944, path : '/pushapi1/3', method : 'GET',
+	{ hostname: 'localhost:' + serverPort, port: serverPort, path : '/pushapi1/3', method : 'GET',
 	  headers: {'x-pushed-request': 'true'}});
     push3.writeHead(200, {
 	  'pushed' : 'yes',
 	  'content-length' : 1,
 	  'subresource' : '3',
 	  'X-Connection-Http2': 'yes'
       });
      push3.end('3');
@@ -339,17 +339,23 @@ function handleRequest(req, res) {
 var options = {
   key: fs.readFileSync(__dirname + '/../moz-spdy/spdy-key.pem'),
   cert: fs.readFileSync(__dirname + '/../moz-spdy/spdy-cert.pem'),
   ca: fs.readFileSync(__dirname + '/../moz-spdy/spdy-ca.pem'),
   //, log: require('../node-http2/test/util').createLogger('server')
 };
 
 var server = http2.createServer(options, handleRequest);
+
 server.on('connection', function(socket) {
   socket.on('error', function() {
     // Ignoring SSL socket errors, since they usually represent a connection that was tore down
     // by the browser because of an untrusted certificate. And this happens at least once, when
     // the first test case if done.
   });
 });
-server.listen(6944);
-console.log('HTTP2 server listening on port 6944');
+
+var serverPort;
+function listenok() {
+  serverPort = server._server.address().port;
+  console.log('HTTP2 server listening on port ' + serverPort);
+}
+server.listen(-1, "0.0.0.0", 200, listenok);
--- a/testing/xpcshell/moz-spdy/moz-spdy.js
+++ b/testing/xpcshell/moz-spdy/moz-spdy.js
@@ -183,16 +183,19 @@ console.log(u.pathname);
 // Set up the SSL certs for our server
 var options = {
   key: fs.readFileSync(__dirname + '/spdy-key.pem'),
   cert: fs.readFileSync(__dirname + '/spdy-cert.pem'),
   ca: fs.readFileSync(__dirname + '/spdy-ca.pem'),
   windowSize: 16000000,
 };
 
-spdy.createServer(options, handleRequest).listen(4443);
-console.log('SPDY server listening on port 4443');
+function listenok() {
+  console.log('SPDY server listening on port ' + webServer.address().port);
+}
+
+var webServer = spdy.createServer(options, handleRequest).listen(-1, "0.0.0.0", 200, listenok);
 
 // Set up to exit when the user finishes our stdin
 process.stdin.resume();
 process.stdin.on('end', function () {
   process.exit();
 });
--- a/testing/xpcshell/runxpcshelltests.py
+++ b/testing/xpcshell/runxpcshelltests.py
@@ -952,16 +952,22 @@ class XPCShellTests(object):
                                 stderr=STDOUT, env=self.env, cwd=os.getcwd())
                         self.nodeProc[name] = process
 
                         # Check to make sure the server starts properly by waiting for it to
                         # tell us it's started
                         msg = process.stdout.readline()
                         if 'server listening' in msg:
                             nodeMozInfo['hasNode'] = True
+                            searchObj = re.search( r'SPDY server listening on port (.*)', msg, 0)
+                            if searchObj:
+                              self.env["MOZSPDY-PORT"] = searchObj.group(1)
+                            searchObj = re.search( r'HTTP2 server listening on port (.*)', msg, 0)
+                            if searchObj:
+                              self.env["MOZHTTP2-PORT"] = searchObj.group(1)
                     except OSError, e:
                         # This occurs if the subprocess couldn't be started
                         self.log.error('Could not run %s server: %s' % (name, str(e)))
 
             myDir = os.path.split(os.path.abspath(__file__))[0]
             startServer('moz-spdy', os.path.join(myDir, 'moz-spdy', 'moz-spdy.js'))
             startServer('moz-http2', os.path.join(myDir, 'moz-http2', 'moz-http2.js'))