1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_bug826063.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Test that nsIPrivateBrowsingChannel.isChannelPrivate yields the correct 1.9 + * result for various combinations of .setPrivate() and nsILoadContexts 1.10 + */ 1.11 + 1.12 +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.13 +Cu.import("resource://gre/modules/Services.jsm"); 1.14 + 1.15 +var URIs = [ 1.16 + "http://example.org", 1.17 + "https://example.org", 1.18 + "ftp://example.org" 1.19 + ]; 1.20 + 1.21 +function LoadContext(usePrivateBrowsing) { 1.22 + this.usePrivateBrowsing = usePrivateBrowsing; 1.23 +} 1.24 +LoadContext.prototype = { 1.25 + QueryInterface: XPCOMUtils.generateQI([Ci.nsILoadContext, Ci.nsIInterfaceRequestor]), 1.26 + getInterface: XPCOMUtils.generateQI([Ci.nsILoadContext]) 1.27 +}; 1.28 + 1.29 +function getChannels() { 1.30 + for (let u of URIs) { 1.31 + yield Services.io.newChannel(u, null, null); 1.32 + } 1.33 +} 1.34 + 1.35 +function checkPrivate(channel, shouldBePrivate) { 1.36 + do_check_eq(channel.QueryInterface(Ci.nsIPrivateBrowsingChannel).isChannelPrivate, 1.37 + shouldBePrivate); 1.38 +} 1.39 + 1.40 +/** 1.41 + * Default configuration 1.42 + * Default is non-private 1.43 + */ 1.44 +add_test(function test_plain() { 1.45 + for (let c of getChannels()) { 1.46 + checkPrivate(c, false); 1.47 + } 1.48 + run_next_test(); 1.49 +}); 1.50 + 1.51 +/** 1.52 + * Explicitly setPrivate(true), no load context 1.53 + */ 1.54 +add_test(function test_setPrivate_private() { 1.55 + for (let c of getChannels()) { 1.56 + c.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(true); 1.57 + checkPrivate(c, true); 1.58 + } 1.59 + run_next_test(); 1.60 +}); 1.61 + 1.62 +/** 1.63 + * Explicitly setPrivate(false), no load context 1.64 + */ 1.65 +add_test(function test_setPrivate_regular() { 1.66 + for (let c of getChannels()) { 1.67 + c.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(false); 1.68 + checkPrivate(c, false); 1.69 + } 1.70 + run_next_test(); 1.71 +}); 1.72 + 1.73 +/** 1.74 + * Load context mandates private mode 1.75 + */ 1.76 +add_test(function test_LoadContextPrivate() { 1.77 + let ctx = new LoadContext(true); 1.78 + for (let c of getChannels()) { 1.79 + c.notificationCallbacks = ctx; 1.80 + checkPrivate(c, true); 1.81 + } 1.82 + run_next_test(); 1.83 +}); 1.84 + 1.85 +/** 1.86 + * Load context mandates regular mode 1.87 + */ 1.88 +add_test(function test_LoadContextRegular() { 1.89 + let ctx = new LoadContext(false); 1.90 + for (let c of getChannels()) { 1.91 + c.notificationCallbacks = ctx; 1.92 + checkPrivate(c, false); 1.93 + } 1.94 + run_next_test(); 1.95 +}); 1.96 + 1.97 + 1.98 +// Do not test simultanous uses of .setPrivate and load context. 1.99 +// There is little merit in doing so, and combining both will assert in 1.100 +// Debug builds anyway. 1.101 + 1.102 + 1.103 +function run_test() { 1.104 + run_next_test(); 1.105 +}