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