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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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';
     8 const kOtherInterfaceName = 'ril';
    10 var server;
    11 var step = 0;
    12 var loginFinished = false;
    14 function xhr_handler(metadata, response) {
    15   response.setStatusLine(metadata.httpVersion, 200, 'OK');
    16   response.setHeader('Cache-Control', 'no-cache', false);
    17   response.setHeader('Content-Type', 'text/plain', false);
    18   if (loginFinished) {
    19     response.write('true');
    20   } else {
    21     response.write('false');
    22   }
    23 }
    25 function fakeUIResponse() {
    26   Services.obs.addObserver(function observe(subject, topic, data) {
    27     if (topic === 'captive-portal-login') {
    28       let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1']
    29                   .createInstance(Ci.nsIXMLHttpRequest);
    30       xhr.open('GET', gServerURL + kCanonicalSitePath, true);
    31       xhr.send();
    32       loginFinished = true;
    33       do_check_eq(++step, 2);
    34     }
    35   }, 'captive-portal-login', false);
    36 }
    38 function test_multiple_requests() {
    39   do_test_pending();
    41   let callback = {
    42     QueryInterface: XPCOMUtils.generateQI([Ci.nsICaptivePortalCallback]),
    43     prepare: function prepare() {
    44       do_check_eq(++step, 1);
    45       gCaptivePortalDetector.finishPreparation(kInterfaceName);
    46     },
    47     complete: function complete(success) {
    48       do_check_eq(++step, 3);
    49       do_check_true(success);
    50     },
    51   };
    53   let otherCallback = {
    54     QueryInterface: XPCOMUtils.generateQI([Ci.nsICaptivePortalCallback]),
    55     prepare: function prepare() {
    56       do_check_eq(++step, 4);
    57       gCaptivePortalDetector.finishPreparation(kOtherInterfaceName);
    58     },
    59     complete: function complete(success) {
    60       do_check_eq(++step, 5);
    61       do_check_true(success);
    62       gServer.stop(do_test_finished);
    63     }
    64   };
    66   gCaptivePortalDetector.checkCaptivePortal(kInterfaceName, callback);
    67   gCaptivePortalDetector.checkCaptivePortal(kOtherInterfaceName, otherCallback);
    68 }
    70 function run_test() {
    71   run_captivedetect_test(xhr_handler, fakeUIResponse, test_multiple_requests);
    72 }

mercurial