xpcom/tests/unit/test_pipe.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 /* vim:set ts=2 sw=2 sts=2 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 const Cc = Components.classes;
     8 const Ci = Components.interfaces;
     9 const Cr = Components.results;
    10 const CC = Components.Constructor;
    12 var Pipe = CC("@mozilla.org/pipe;1", "nsIPipe", "init");
    14 function run_test()
    15 {
    16   test_not_initialized();
    17   test_ends_are_threadsafe();
    18 }
    20 function test_not_initialized()
    21 {
    22   var p = Cc["@mozilla.org/pipe;1"]
    23             .createInstance(Ci.nsIPipe);
    24   try
    25   {
    26     var dummy = p.outputStream;
    27     throw Cr.NS_ERROR_FAILURE;
    28   }
    29   catch (e)
    30   {
    31     if (e.result != Cr.NS_ERROR_NOT_INITIALIZED)
    32       do_throw("using a pipe before initializing it should throw NS_ERROR_NOT_INITIALIZED");
    33   }
    34 }
    36 function test_ends_are_threadsafe()
    37 {
    38   var p, is, os;
    40   p = new Pipe(true, true, 1024, 1, null);
    41   is = p.inputStream.QueryInterface(Ci.nsIClassInfo);
    42   os = p.outputStream.QueryInterface(Ci.nsIClassInfo);
    43   do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE));
    44   do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE));
    46   p = new Pipe(true, false, 1024, 1, null);
    47   is = p.inputStream.QueryInterface(Ci.nsIClassInfo);
    48   os = p.outputStream.QueryInterface(Ci.nsIClassInfo);
    49   do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE));
    50   do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE));
    52   p = new Pipe(false, true, 1024, 1, null);
    53   is = p.inputStream.QueryInterface(Ci.nsIClassInfo);
    54   os = p.outputStream.QueryInterface(Ci.nsIClassInfo);
    55   do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE));
    56   do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE));
    58   p = new Pipe(false, false, 1024, 1, null);
    59   is = p.inputStream.QueryInterface(Ci.nsIClassInfo);
    60   os = p.outputStream.QueryInterface(Ci.nsIClassInfo);
    61   do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE));
    62   do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE));
    63 }

mercurial