extensions/cookie/test/unit/test_cookies_thirdparty.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:4930af8134e4
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 // test third party cookie blocking, for the cases:
5 // 1) with null channel
6 // 2) with channel, but with no docshell parent
7
8 function run_test() {
9 // Create URIs and channels pointing to foo.com and bar.com.
10 // We will use these to put foo.com into first and third party contexts.
11 var spec1 = "http://foo.com/foo.html";
12 var spec2 = "http://bar.com/bar.html";
13 var uri1 = NetUtil.newURI(spec1);
14 var uri2 = NetUtil.newURI(spec2);
15 var channel1 = NetUtil.newChannel(uri1);
16 var channel2 = NetUtil.newChannel(uri2);
17
18 // test with cookies enabled
19 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
20 do_set_cookies(uri1, channel1, true, [1, 2, 3, 4]);
21 Services.cookies.removeAll();
22 do_set_cookies(uri1, channel2, true, [1, 2, 3, 4]);
23 Services.cookies.removeAll();
24
25 // test with third party cookies blocked
26 Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
27 do_set_cookies(uri1, channel1, true, [0, 0, 0, 0]);
28 Services.cookies.removeAll();
29 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
30 Services.cookies.removeAll();
31
32 // Force the channel URI to be used when determining the originating URI of
33 // the channel.
34 var httpchannel1 = channel1.QueryInterface(Ci.nsIHttpChannelInternal);
35 var httpchannel2 = channel2.QueryInterface(Ci.nsIHttpChannelInternal);
36 httpchannel1.forceAllowThirdPartyCookie = true;
37 httpchannel2.forceAllowThirdPartyCookie = true;
38
39 // test with cookies enabled
40 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
41 do_set_cookies(uri1, channel1, true, [1, 2, 3, 4]);
42 Services.cookies.removeAll();
43 do_set_cookies(uri1, channel2, true, [1, 2, 3, 4]);
44 Services.cookies.removeAll();
45
46 // test with third party cookies blocked
47 Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
48 do_set_cookies(uri1, channel1, true, [0, 1, 1, 2]);
49 Services.cookies.removeAll();
50 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
51 Services.cookies.removeAll();
52
53 // test with third party cookies limited
54 Services.prefs.setIntPref("network.cookie.cookieBehavior", 3);
55 do_set_cookies(uri1, channel1, true, [0, 1, 2, 3]);
56 Services.cookies.removeAll();
57 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
58 Services.cookies.removeAll();
59 do_set_single_http_cookie(uri1, channel1, 1);
60 do_set_cookies(uri1, channel2, true, [2, 3, 4, 5]);
61 Services.cookies.removeAll();
62
63 // Test per-site 3rd party cookie blocking with cookies enabled
64 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
65 var kPermissionType = "cookie";
66 var ALLOW_FIRST_PARTY_ONLY = 9;
67 // ALLOW_FIRST_PARTY_ONLY overrides
68 Services.perms.add(uri1, kPermissionType, ALLOW_FIRST_PARTY_ONLY);
69 do_set_cookies(uri1, channel1, true, [0, 1, 1, 2]);
70 Services.cookies.removeAll();
71 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
72 Services.cookies.removeAll();
73
74 // Test per-site 3rd party cookie blocking with 3rd party cookies disabled
75 Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
76 do_set_cookies(uri1, channel1, true, [0, 1, 1, 2]);
77 Services.cookies.removeAll();
78 // No preference has been set for uri2, but it should act as if
79 // ALLOW_FIRST_PARTY_ONLY has been set
80 do_set_cookies(uri2, channel2, true, [0, 1, 1, 2]);
81 Services.cookies.removeAll();
82 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
83 Services.cookies.removeAll();
84
85 // Test per-site 3rd party cookie blocking with 3rd party cookies limited
86 Services.prefs.setIntPref("network.cookie.cookieBehavior", 3);
87 do_set_cookies(uri1, channel1, true, [0, 1, 1, 2]);
88 Services.cookies.removeAll();
89 // No preference has been set for uri2, but it should act as if
90 // LIMIT_THIRD_PARTY has been set
91 do_set_cookies(uri2, channel2, true, [0, 1, 2, 3]);
92 Services.cookies.removeAll();
93 do_set_single_http_cookie(uri2, channel2, 1);
94 do_set_cookies(uri2, channel2, true, [2, 3, 4, 5]);
95 Services.cookies.removeAll();
96 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
97 Services.cookies.removeAll();
98 do_set_single_http_cookie(uri1, channel1, 1);
99 do_set_cookies(uri1, channel2, true, [1, 1, 1, 1]);
100 Services.cookies.removeAll();
101
102 // Test per-site 3rd party cookie limiting with cookies enabled
103 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
104 var kPermissionType = "cookie";
105 var LIMIT_THIRD_PARTY = 10;
106 // LIMIT_THIRD_PARTY overrides
107 Services.perms.add(uri1, kPermissionType, LIMIT_THIRD_PARTY);
108 do_set_cookies(uri1, channel1, true, [0, 1, 2, 3]);
109 Services.cookies.removeAll();
110 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
111 Services.cookies.removeAll();
112 do_set_single_http_cookie(uri1, channel1, 1);
113 do_set_cookies(uri1, channel2, true, [2, 3, 4, 5]);
114 Services.cookies.removeAll();
115
116 // Test per-site 3rd party cookie limiting with 3rd party cookies disabled
117 Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
118 do_set_cookies(uri1, channel1, true, [0, 1, 2, 3]);
119 Services.cookies.removeAll();
120 // No preference has been set for uri2, but it should act as if
121 // ALLOW_FIRST_PARTY_ONLY has been set
122 do_set_cookies(uri2, channel2, true, [0, 1, 1, 2]);
123 Services.cookies.removeAll();
124 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
125 Services.cookies.removeAll();
126 do_set_single_http_cookie(uri1, channel1, 1);
127 do_set_cookies(uri1, channel2, true, [2, 3, 4, 5]);
128 Services.cookies.removeAll();
129
130 // Test per-site 3rd party cookie limiting with 3rd party cookies limited
131 Services.prefs.setIntPref("network.cookie.cookieBehavior", 3);
132 do_set_cookies(uri1, channel1, true, [0, 1, 2, 3]);
133 Services.cookies.removeAll();
134 // No preference has been set for uri2, but it should act as if
135 // LIMIT_THIRD_PARTY has been set
136 do_set_cookies(uri2, channel2, true, [0, 1, 2, 3]);
137 Services.cookies.removeAll();
138 do_set_single_http_cookie(uri2, channel2, 1);
139 do_set_cookies(uri2, channel2, true, [2, 3, 4, 5]);
140 Services.cookies.removeAll();
141 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
142 Services.cookies.removeAll();
143 do_set_single_http_cookie(uri1, channel1, 1);
144 do_set_cookies(uri1, channel2, true, [2, 3, 4, 5]);
145 Services.cookies.removeAll();
146 }
147

mercurial