toolkit/components/captivedetect/test/unit/test_captive_portal_found.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 'use strict';
     7 const kInterfaceName = 'wifi';
     9 var server;
    10 var step = 0;
    11 var loginFinished = false;
    13 function xhr_handler(metadata, response) {
    14   response.setStatusLine(metadata.httpVersion, 200, 'OK');
    15   response.setHeader('Cache-Control', 'no-cache', false);
    16   response.setHeader('Content-Type', 'text/plain', false);
    17   if (loginFinished) {
    18     response.write('true');
    19   } else {
    20     response.write('false');
    21   }
    22 }
    24 function fakeUIResponse() {
    25   Services.obs.addObserver(function observe(subject, topic, data) {
    26     if (topic === 'captive-portal-login') {
    27       let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
    28                   .createInstance(Ci.nsIXMLHttpRequest);
    29       xhr.open('GET', gServerURL + kCanonicalSitePath, true);
    30       xhr.send();
    31       loginFinished = true;
    32       do_check_eq(++step, 2);
    33     }
    34   }, 'captive-portal-login', false);
    35 }
    37 function test_portal_found() {
    38   do_test_pending();
    40   let callback = {
    41     QueryInterface: XPCOMUtils.generateQI([Ci.nsICaptivePortalCallback]),
    42     prepare: function prepare() {
    43       do_check_eq(++step, 1);
    44       gCaptivePortalDetector.finishPreparation(kInterfaceName);
    45     },
    46     complete: function complete(success) {
    47       do_check_eq(++step, 3);
    48       do_check_true(success);
    49       gServer.stop(do_test_finished);
    50     },
    51   };
    53   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
    54 }
    56 function run_test() {
    57   run_captivedetect_test(xhr_handler, fakeUIResponse, test_portal_found);
    58 }

mercurial