tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug826063.js (2029B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * Test that nsIPrivateBrowsingChannel.isChannelPrivate yields the correct
      6 * result for various combinations of .setPrivate() and nsILoadContexts
      7 */
      8 
      9 "use strict";
     10 
     11 var URIs = ["http://example.org", "https://example.org"];
     12 
     13 function* getChannels() {
     14  for (let u of URIs) {
     15    yield NetUtil.newChannel({
     16      uri: u,
     17      loadUsingSystemPrincipal: true,
     18    });
     19  }
     20 }
     21 
     22 function checkPrivate(channel, shouldBePrivate) {
     23  Assert.equal(
     24    channel.QueryInterface(Ci.nsIPrivateBrowsingChannel).isChannelPrivate,
     25    shouldBePrivate
     26  );
     27 }
     28 
     29 /**
     30 * Default configuration
     31 * Default is non-private
     32 */
     33 add_test(function test_plain() {
     34  for (let c of getChannels()) {
     35    checkPrivate(c, false);
     36  }
     37  run_next_test();
     38 });
     39 
     40 /**
     41 * Explicitly setPrivate(true), no load context
     42 */
     43 add_test(function test_setPrivate_private() {
     44  for (let c of getChannels()) {
     45    c.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(true);
     46    checkPrivate(c, true);
     47  }
     48  run_next_test();
     49 });
     50 
     51 /**
     52 * Explicitly setPrivate(false), no load context
     53 */
     54 add_test(function test_setPrivate_regular() {
     55  for (let c of getChannels()) {
     56    c.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(false);
     57    checkPrivate(c, false);
     58  }
     59  run_next_test();
     60 });
     61 
     62 /**
     63 * Load context mandates private mode
     64 */
     65 add_test(function test_LoadContextPrivate() {
     66  let ctx = Cu.createPrivateLoadContext();
     67  for (let c of getChannels()) {
     68    c.notificationCallbacks = ctx;
     69    checkPrivate(c, true);
     70  }
     71  run_next_test();
     72 });
     73 
     74 /**
     75 * Load context mandates regular mode
     76 */
     77 add_test(function test_LoadContextRegular() {
     78  let ctx = Cu.createLoadContext();
     79  for (let c of getChannels()) {
     80    c.notificationCallbacks = ctx;
     81    checkPrivate(c, false);
     82  }
     83  run_next_test();
     84 });
     85 
     86 // Do not test simultanous uses of .setPrivate and load context.
     87 // There is little merit in doing so, and combining both will assert in
     88 // Debug builds anyway.