Bug 892765 - part 2 - rewrite captivedetect tests in terms of run_captivedetect_test; r=schien
authorNathan Froyd <froydnj@mozilla.com>
Fri, 12 Jul 2013 17:03:11 -0400
changeset 138393 8dfaa3d620fb89228fd434224560a02766f67ccf
parent 138392 0b8c0b71c5568b490192faa430a1c5f0d96d484f
child 138394 332c413c55e8326f86872a48809c16ee020b1266
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 2 - rewrite captivedetect tests in terms of run_captivedetect_test; r=schien
toolkit/components/captivedetect/test/unit/head_setprefs.js
toolkit/components/captivedetect/test/unit/test_abort.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_captive_portal_not_found.js
toolkit/components/captivedetect/test/unit/test_captive_portal_not_found_404.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
@@ -17,19 +17,32 @@ XPCOMUtils.defineLazyServiceGetter(this,
 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;
+
 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(kPrefsCanonicalContent, kCanonicalSiteContent);
   prefs.setIntPref(kPrefsMaxWaitingTime, 0);
   prefs.setIntPref(kPrefsPollingTime, 1);
 }
 
-setupPrefs();
+function run_captivedetect_test(xhr_handler, fakeUIResponse, testfun)
+{
+  gServer = new HttpServer();
+  gServer.registerPathHandler(kCanonicalSitePath, xhr_handler);
+  gServer.start(4444);
+
+  setupPrefs();
+
+  fakeUIResponse();
+
+  testfun();
+}
--- a/toolkit/components/captivedetect/test/unit/test_abort.js
+++ b/toolkit/components/captivedetect/test/unit/test_abort.js
@@ -40,20 +40,14 @@ function test_abort() {
     },
     complete: function complete(success) {
       do_throw('should not execute |complete| callback');
     },
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
   gCaptivePortalDetector.abort(kInterfaceName);
-  server.stop(do_test_finished);
+  gServer.stop(do_test_finished);
 }
 
 function run_test() {
-  server = new HttpServer();
-  server.registerPathHandler(kCanonicalSitePath, xhr_handler);
-  server.start(4444);
-
-  fakeUIResponse();
-
-  test_abort();
+  run_captivedetect_test(xhr_handler, fakeUIResponse, test_abort);
 }
--- a/toolkit/components/captivedetect/test/unit/test_abort_during_user_login.js
+++ b/toolkit/components/captivedetect/test/unit/test_abort_during_user_login.js
@@ -34,17 +34,17 @@ function fakeUIResponse() {
       requestId = JSON.parse(data).id;
       gCaptivePortalDetector.abort(kInterfaceName);
     }
   }, 'captive-portal-login', false);
   Services.obs.addObserver(function observe(subject, topic, data) {
     if (topic === 'captive-portal-login-abort') {
       do_check_eq(++step, 3);
       do_check_eq(JSON.parse(data).id, requestId);
-      server.stop(do_test_finished);
+      gServer.stop(do_test_finished);
     }
   }, 'captive-portal-login-abort', false);
 }
 
 function test_abort() {
   do_test_pending();
 
   let callback = {
@@ -57,16 +57,10 @@ function test_abort() {
       do_throw('should not execute |complete| callback');
     },
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
 }
 
 function run_test() {
-  server = new HttpServer();
-  server.registerPathHandler(kCanonicalSitePath, xhr_handler);
-  server.start(4444);
-
-  fakeUIResponse();
-
-  test_abort();
+  run_captivedetect_test(xhr_handler, fakeUIResponse, test_abort);
 }
--- a/toolkit/components/captivedetect/test/unit/test_abort_ongoing_request.js
+++ b/toolkit/components/captivedetect/test/unit/test_abort_ongoing_request.js
@@ -53,26 +53,20 @@ function test_multiple_requests_abort() 
     QueryInterface: XPCOMUtils.generateQI([Ci.nsICaptivePortalCallback]),
     prepare: function prepare() {
       do_check_eq(++step, 2);
       gCaptivePortalDetector.finishPreparation(kOtherInterfaceName);
     },
     complete: function complete(success) {
       do_check_eq(++step, 4);
       do_check_true(success);
-      server.stop(do_test_finished);
+      gServer.stop(do_test_finished);
     }
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
   gCaptivePortalDetector.checkCaptivePortal(kOtherInterfaceName, otherCallback);
   gCaptivePortalDetector.abort(kInterfaceName);
 }
 
 function run_test() {
-  server = new HttpServer();
-  server.registerPathHandler(kCanonicalSitePath, xhr_handler);
-  server.start(4444);
-
-  fakeUIResponse();
-
-  test_multiple_requests_abort();
+  run_captivedetect_test(xhr_handler, fakeUIResponse, 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
@@ -42,17 +42,17 @@ function test_abort() {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsICaptivePortalCallback]),
     prepare: function prepare() {
       do_check_eq(++step, 1);
       gCaptivePortalDetector.finishPreparation(kInterfaceName);
     },
     complete: function complete(success) {
       do_check_eq(++step, 3);
       do_check_true(success);
-      server.stop(do_test_finished);
+      gServer.stop(do_test_finished);
     },
   };
 
   let otherCallback = {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsICaptivePortalCallback]),
     prepare: function prepare() {
       do_throw('should not execute |prepare| callback for ' + kOtherInterfaceName);
     },
@@ -62,16 +62,10 @@ function test_abort() {
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
   gCaptivePortalDetector.checkCaptivePortal(kOtherInterfaceName, otherCallback);
   gCaptivePortalDetector.abort(kOtherInterfaceName);
 }
 
 function run_test() {
-  server = new HttpServer();
-  server.registerPathHandler(kCanonicalSitePath, xhr_handler);
-  server.start(4444);
-
-  fakeUIResponse();
-
-  test_abort();
+  run_captivedetect_test(xhr_handler, fakeUIResponse, test_abort);
 }
--- a/toolkit/components/captivedetect/test/unit/test_captive_portal_found.js
+++ b/toolkit/components/captivedetect/test/unit/test_captive_portal_found.js
@@ -41,24 +41,18 @@ function test_portal_found() {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsICaptivePortalCallback]),
     prepare: function prepare() {
       do_check_eq(++step, 1);
       gCaptivePortalDetector.finishPreparation(kInterfaceName);
     },
     complete: function complete(success) {
       do_check_eq(++step, 3);
       do_check_true(success);
-      server.stop(do_test_finished);
+      gServer.stop(do_test_finished);
     },
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
 }
 
 function run_test() {
-  server = new HttpServer();
-  server.registerPathHandler(kCanonicalSitePath, xhr_handler);
-  server.start(4444);
-
-  fakeUIResponse();
-
-  test_portal_found();
+  run_captivedetect_test(xhr_handler, fakeUIResponse, 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
@@ -43,24 +43,26 @@ function test_portal_found() {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsICaptivePortalCallback]),
     prepare: function prepare() {
       do_check_eq(++step, 1);
       gCaptivePortalDetector.finishPreparation(kInterfaceName);
     },
     complete: function complete(success) {
       do_check_eq(++step, 3);
       do_check_true(success);
-      server.stop(do_test_finished);
+      gServer.stop(do_test_finished);
     },
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
 }
 
 function run_test() {
+  run_captivedetect_test(xhr_handler, fakeUIResponse, test_portal_found);
+
   server = new HttpServer();
   server.registerPathHandler(kCanonicalSitePath, xhr_handler);
   server.start(4444);
 
   fakeUIResponse();
 
   test_portal_found();
 }
--- a/toolkit/components/captivedetect/test/unit/test_captive_portal_not_found.js
+++ b/toolkit/components/captivedetect/test/unit/test_captive_portal_not_found.js
@@ -35,24 +35,18 @@ function test_portal_not_found() {
     prepare: function prepare() {
       do_check_eq(++step, 1);
       gCaptivePortalDetector.finishPreparation(kInterfaceName);
     },
     complete: function complete(success) {
       do_check_eq(++step, 2);
       do_check_true(success);
       do_check_eq(attempt, 1);
-      server.stop(function(){dump('server stop\n'); do_test_finished(); });
+      gServer.stop(function(){dump('server stop\n'); do_test_finished(); });
     }
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
 }
 
 function run_test() {
-  server = new HttpServer();
-  server.registerPathHandler(kCanonicalSitePath, xhr_handler);
-  server.start(4444);
-
-  fakeUIResponse();
-
-  test_portal_not_found();
+  run_captivedetect_test(xhr_handler, fakeUIResponse, test_portal_not_found);
 }
--- a/toolkit/components/captivedetect/test/unit/test_captive_portal_not_found_404.js
+++ b/toolkit/components/captivedetect/test/unit/test_captive_portal_not_found_404.js
@@ -32,24 +32,18 @@ function test_portal_not_found() {
     prepare: function prepare() {
       do_check_eq(++step, 1);
       gCaptivePortalDetector.finishPreparation(kInterfaceName);
     },
     complete: function complete(success) {
       do_check_eq(++step, 2);
       do_check_true(success);
       do_check_eq(attempt, 6);
-      server.stop(do_test_finished);
+      gServer.stop(do_test_finished);
     },
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
 }
 
 function run_test() {
-  server = new HttpServer();
-  server.registerPathHandler(kCanonicalSitePath, xhr_handler);
-  server.start(4444);
-
-  fakeUIResponse();
-
-  test_portal_not_found();
+  run_captivedetect_test(xhr_handler, fakeUIResponse, test_portal_not_found);
 }
--- a/toolkit/components/captivedetect/test/unit/test_multiple_requests.js
+++ b/toolkit/components/captivedetect/test/unit/test_multiple_requests.js
@@ -54,25 +54,19 @@ function test_multiple_requests() {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsICaptivePortalCallback]),
     prepare: function prepare() {
       do_check_eq(++step, 4);
       gCaptivePortalDetector.finishPreparation(kOtherInterfaceName);
     },
     complete: function complete(success) {
       do_check_eq(++step, 5);
       do_check_true(success);
-      server.stop(do_test_finished);
+      gServer.stop(do_test_finished);
     }
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
   gCaptivePortalDetector.checkCaptivePortal(kOtherInterfaceName, otherCallback);
 }
 
 function run_test() {
-  server = new HttpServer();
-  server.registerPathHandler(kCanonicalSitePath, xhr_handler);
-  server.start(4444);
-
-  fakeUIResponse();
-
-  test_multiple_requests();
+  run_captivedetect_test(xhr_handler, fakeUIResponse, test_multiple_requests);
 }
--- a/toolkit/components/captivedetect/test/unit/test_user_cancel.js
+++ b/toolkit/components/captivedetect/test/unit/test_user_cancel.js
@@ -37,24 +37,18 @@ function test_cancel() {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsICaptivePortalCallback]),
     prepare: function prepare() {
       do_check_eq(++step, 1);
       gCaptivePortalDetector.finishPreparation(kInterfaceName);
     },
     complete: function complete(success) {
       do_check_eq(++step, 3);
       do_check_false(success);
-      server.stop(do_test_finished);
+      gServer.stop(do_test_finished);
     },
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
 }
 
 function run_test() {
-  server = new HttpServer();
-  server.registerPathHandler(kCanonicalSitePath, xhr_handler);
-  server.start(4444);
-
-  fakeUIResponse();
-
-  test_cancel();
+  run_captivedetect_test(xhr_handler, fakeUIResponse, test_cancel);
 }