Bug 1023638 - Fix test_captive_portal_found_303.js to not redirect to example.org. r=schien, a=test-only
authorNathan Froyd <froydnj@mozilla.com>
Tue, 10 Jun 2014 20:24:05 -0400
changeset 206993 e59ad1a713fa997cb69501360f5860987a4a463e
parent 206992 d360f03adf66ab8aa339fcc1b7bf144fff6487e3
child 206994 8415553664fdb087817d28de7d33b8e6dd203980
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersschien, test-only
bugs1023638
milestone32.0a2
Bug 1023638 - Fix test_captive_portal_found_303.js to not redirect to example.org. r=schien, a=test-only
toolkit/components/captivedetect/test/unit/test_captive_portal_found_303.js
--- a/toolkit/components/captivedetect/test/unit/test_captive_portal_found_303.js
+++ b/toolkit/components/captivedetect/test/unit/test_captive_portal_found_303.js
@@ -1,29 +1,31 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 'use strict';
 
 const kInterfaceName = 'wifi';
 
-var server;
 var step = 0;
 var loginFinished = false;
 
+var gRedirectServer;
+var gRedirectServerURL;
+
 function xhr_handler(metadata, response) {
   if (loginFinished) {
     response.setStatusLine(metadata.httpVersion, 200, 'OK');
     response.setHeader('Cache-Control', 'no-cache', false);
     response.setHeader('Content-Type', 'text/plain', false);
     response.write('true');
   } else {
     response.setStatusLine(metadata.httpVersion, 303, "See Other");
-    response.setHeader("Location", "http://example.org/", false);
+    response.setHeader("Location", gRedirectServerURL, false);
     response.setHeader("Content-Type", "text/html", false);
   }
 }
 
 function fakeUIResponse() {
   Services.obs.addObserver(function observe(subject, topic, data) {
     if (topic === 'captive-portal-login') {
       let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
@@ -33,17 +35,19 @@ function fakeUIResponse() {
       loginFinished = true;
       do_check_eq(++step, 2);
     }
   }, 'captive-portal-login', false);
 
   Services.obs.addObserver(function observe(subject, topic, data) {
     if (topic === 'captive-portal-login-success') {
       do_check_eq(++step, 4);
-      gServer.stop(do_test_finished);
+      gServer.stop(function () {
+        gRedirectServer.stop(do_test_finished);
+      });
     }
   }, 'captive-portal-login-success', false);
 }
 
 function test_portal_found() {
   do_test_pending();
 
   let callback = {
@@ -57,10 +61,14 @@ function test_portal_found() {
       do_check_true(success);
     },
   };
 
   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
 }
 
 function run_test() {
+  gRedirectServer = new HttpServer();
+  gRedirectServer.start(-1);
+  gRedirectServerURL = 'http://localhost:' + gRedirectServer.identity.primaryPort;
+
   run_captivedetect_test(xhr_handler, fakeUIResponse, test_portal_found);
 }