Bug 892765 - part 3 - run captivedetect test http server on OS-determined port; r=schien
authorNathan Froyd <froydnj@mozilla.com>
Sat, 22 Jun 2013 16:59:16 -0400
changeset 138394 332c413c55e8326f86872a48809c16ee020b1266
parent 138393 8dfaa3d620fb89228fd434224560a02766f67ccf
child 138395 69062da2609388168a99a8b510b5d9ecdaaaf70d
push id30954
push usernfroyd@mozilla.com
push dateFri, 12 Jul 2013 21:18:05 +0000
treeherdermozilla-inbound@332c413c55e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersschien
bugs892765
milestone25.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 892765 - part 3 - run captivedetect test http server on OS-determined port; r=schien
toolkit/components/captivedetect/test/unit/head_setprefs.js
toolkit/components/captivedetect/test/unit/test_abort_during_user_login.js
toolkit/components/captivedetect/test/unit/test_abort_ongoing_request.js
toolkit/components/captivedetect/test/unit/test_abort_pending_request.js
toolkit/components/captivedetect/test/unit/test_captive_portal_found.js
toolkit/components/captivedetect/test/unit/test_captive_portal_found_303.js
toolkit/components/captivedetect/test/unit/test_multiple_requests.js
toolkit/components/captivedetect/test/unit/test_user_cancel.js
--- a/toolkit/components/captivedetect/test/unit/head_setprefs.js
+++ b/toolkit/components/captivedetect/test/unit/head_setprefs.js
@@ -9,40 +9,41 @@ const {classes: Cc, interfaces: Ci, util
 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
 Cu.import('resource://gre/modules/Services.jsm');
 Cu.import('resource://testing-common/httpd.js');
 
 XPCOMUtils.defineLazyServiceGetter(this, 'gCaptivePortalDetector',
                                    '@mozilla.org/toolkit/captive-detector;1',
                                    'nsICaptivePortalDetector');
 
-const kServerURL = 'http://localhost:4444';
 const kCanonicalSitePath = '/canonicalSite.html';
 const kCanonicalSiteContent = 'true';
 const kPrefsCanonicalURL = 'captivedetect.canonicalURL';
 const kPrefsCanonicalContent = 'captivedetect.canonicalContent';
 const kPrefsMaxWaitingTime = 'captivedetect.maxWaitingTime';
 const kPrefsPollingTime = 'captivedetect.pollingTime';
 
 var gServer;
+var gServerURL;
 
 function setupPrefs() {
   let prefs = Components.classes["@mozilla.org/preferences-service;1"]
                 .getService(Components.interfaces.nsIPrefService)
                 .QueryInterface(Components.interfaces.nsIPrefBranch);
-  prefs.setCharPref(kPrefsCanonicalURL, kServerURL + kCanonicalSitePath);
+  prefs.setCharPref(kPrefsCanonicalURL, gServerURL + kCanonicalSitePath);
   prefs.setCharPref(kPrefsCanonicalContent, kCanonicalSiteContent);
   prefs.setIntPref(kPrefsMaxWaitingTime, 0);
   prefs.setIntPref(kPrefsPollingTime, 1);
 }
 
 function run_captivedetect_test(xhr_handler, fakeUIResponse, testfun)
 {
   gServer = new HttpServer();
   gServer.registerPathHandler(kCanonicalSitePath, xhr_handler);
-  gServer.start(4444);
+  gServer.start(-1);
+  gServerURL = 'http://localhost:' + gServer.identity.primaryPort;
 
   setupPrefs();
 
   fakeUIResponse();
 
   testfun();
 }
--- a/toolkit/components/captivedetect/test/unit/test_abort_during_user_login.js
+++ b/toolkit/components/captivedetect/test/unit/test_abort_during_user_login.js
@@ -22,17 +22,17 @@ function xhr_handler(metadata, response)
 }
 
 function fakeUIResponse() {
   let requestId;
   Services.obs.addObserver(function observe(subject, topic, data) {
     if (topic === 'captive-portal-login') {
       let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
                   .createInstance(Ci.nsIXMLHttpRequest);
-      xhr.open('GET', kServerURL + kCanonicalSitePath, true);
+      xhr.open('GET', gServerURL + kCanonicalSitePath, true);
       xhr.send();
       loginFinished = true;
       do_check_eq(++step, 2);
       requestId = JSON.parse(data).id;
       gCaptivePortalDetector.abort(kInterfaceName);
     }
   }, 'captive-portal-login', false);
   Services.obs.addObserver(function observe(subject, topic, data) {
--- a/toolkit/components/captivedetect/test/unit/test_abort_ongoing_request.js
+++ b/toolkit/components/captivedetect/test/unit/test_abort_ongoing_request.js
@@ -22,17 +22,17 @@ function xhr_handler(metadata, response)
   }
 }
 
 function fakeUIResponse() {
   Services.obs.addObserver(function observe(subject, topic, data) {
     if (topic === 'captive-portal-login') {
       let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
                   .createInstance(Ci.nsIXMLHttpRequest);
-      xhr.open('GET', kServerURL + kCanonicalSitePath, true);
+      xhr.open('GET', gServerURL + kCanonicalSitePath, true);
       xhr.send();
       loginFinished = true;
       do_check_eq(++step, 3);
     }
   }, 'captive-portal-login', false);
 }
 
 function test_multiple_requests_abort() {
--- a/toolkit/components/captivedetect/test/unit/test_abort_pending_request.js
+++ b/toolkit/components/captivedetect/test/unit/test_abort_pending_request.js
@@ -22,17 +22,17 @@ function xhr_handler(metadata, response)
   }
 }
 
 function fakeUIResponse() {
   Services.obs.addObserver(function observe(subject, topic, data) {
     if (topic === 'captive-portal-login') {
       let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
                   .createInstance(Ci.nsIXMLHttpRequest);
-      xhr.open('GET', kServerURL + kCanonicalSitePath, true);
+      xhr.open('GET', gServerURL + kCanonicalSitePath, true);
       xhr.send();
       loginFinished = true;
       do_check_eq(++step, 2);
     }
   }, 'captive-portal-login', false);
 }
 
 function test_abort() {
--- a/toolkit/components/captivedetect/test/unit/test_captive_portal_found.js
+++ b/toolkit/components/captivedetect/test/unit/test_captive_portal_found.js
@@ -21,17 +21,17 @@ function xhr_handler(metadata, response)
   }
 }
 
 function fakeUIResponse() {
   Services.obs.addObserver(function observe(subject, topic, data) {
     if (topic === 'captive-portal-login') {
       let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
                   .createInstance(Ci.nsIXMLHttpRequest);
-      xhr.open('GET', kServerURL + kCanonicalSitePath, true);
+      xhr.open('GET', gServerURL + kCanonicalSitePath, true);
       xhr.send();
       loginFinished = true;
       do_check_eq(++step, 2);
     }
   }, 'captive-portal-login', false);
 }
 
 function test_portal_found() {
--- a/toolkit/components/captivedetect/test/unit/test_captive_portal_found_303.js
+++ b/toolkit/components/captivedetect/test/unit/test_captive_portal_found_303.js
@@ -23,17 +23,17 @@ function xhr_handler(metadata, response)
   }
 }
 
 function fakeUIResponse() {
   Services.obs.addObserver(function observe(subject, topic, data) {
     if (topic === 'captive-portal-login') {
       let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
                   .createInstance(Ci.nsIXMLHttpRequest);
-      xhr.open('GET', kServerURL + kCanonicalSitePath, true);
+      xhr.open('GET', gServerURL + kCanonicalSitePath, true);
       xhr.send();
       loginFinished = true;
       do_check_eq(++step, 2);
     }
   }, 'captive-portal-login', false);
 }
 
 function test_portal_found() {
--- a/toolkit/components/captivedetect/test/unit/test_multiple_requests.js
+++ b/toolkit/components/captivedetect/test/unit/test_multiple_requests.js
@@ -22,17 +22,17 @@ function xhr_handler(metadata, response)
   }
 }
 
 function fakeUIResponse() {
   Services.obs.addObserver(function observe(subject, topic, data) {
     if (topic === 'captive-portal-login') {
       let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
                   .createInstance(Ci.nsIXMLHttpRequest);
-      xhr.open('GET', kServerURL + kCanonicalSitePath, true);
+      xhr.open('GET', gServerURL + kCanonicalSitePath, true);
       xhr.send();
       loginFinished = true;
       do_check_eq(++step, 2);
     }
   }, 'captive-portal-login', false);
 }
 
 function test_multiple_requests() {
--- a/toolkit/components/captivedetect/test/unit/test_user_cancel.js
+++ b/toolkit/components/captivedetect/test/unit/test_user_cancel.js
@@ -16,17 +16,17 @@ function xhr_handler(metadata, response)
   response.write('false');
 }
 
 function fakeUIResponse() {
   Services.obs.addObserver(function observe(subject, topic, data) {
     if (topic === 'captive-portal-login') {
       let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
                   .createInstance(Ci.nsIXMLHttpRequest);
-      xhr.open('GET', kServerURL + kCanonicalSitePath, true);
+      xhr.open('GET', gServerURL + kCanonicalSitePath, true);
       xhr.send();
       do_check_eq(++step, 2);
       let details = JSON.parse(data);
       gCaptivePortalDetector.cancelLogin(details.id);
     }
   }, 'captive-portal-login', false);
 }