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 188034 46cbab3faf7d4809a970d8b6335cae36ec8205c1
parent 188033 9c086482429557c72f3011ae834ebe81942ebae6
child 188035 d5cb21f510f4b16fa27296bfb5b5184419c4fcdd
push id361
push userryanvm@gmail.com
push dateFri, 13 Jun 2014 15:45:05 +0000
treeherdermozilla-b2g30_v1_4@46cbab3faf7d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersschien, test-only
bugs1023638
milestone30.0
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']
@@ -43,24 +45,30 @@ 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);
-      gServer.stop(do_test_finished);
+      gServer.stop(function () {
+        gRedirectServer.stop(do_test_finished);
+      });
     },
   };
 
   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);
 
   server = new HttpServer();
   server.registerPathHandler(kCanonicalSitePath, xhr_handler);
   server.start(4444);
 
   fakeUIResponse();