netwerk/test/unit/test_bug826063.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial