toolkit/components/captivedetect/test/unit/test_abort_ongoing_request.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.

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

mercurial