|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // test for cookie persistence across sessions, for the cases: |
|
5 // 1) network.cookie.lifetimePolicy = 0 (expire naturally) |
|
6 // 2) network.cookie.lifetimePolicy = 2 (expire at end of session) |
|
7 |
|
8 let test_generator = do_run_test(); |
|
9 |
|
10 function run_test() { |
|
11 do_test_pending(); |
|
12 test_generator.next(); |
|
13 } |
|
14 |
|
15 function finish_test() { |
|
16 do_execute_soon(function() { |
|
17 test_generator.close(); |
|
18 do_test_finished(); |
|
19 }); |
|
20 } |
|
21 |
|
22 function do_run_test() { |
|
23 // Set up a profile. |
|
24 let profile = do_get_profile(); |
|
25 |
|
26 // Create URIs and channels pointing to foo.com and bar.com. |
|
27 // We will use these to put foo.com into first and third party contexts. |
|
28 var spec1 = "http://foo.com/foo.html"; |
|
29 var spec2 = "http://bar.com/bar.html"; |
|
30 var uri1 = NetUtil.newURI(spec1); |
|
31 var uri2 = NetUtil.newURI(spec2); |
|
32 var channel1 = NetUtil.newChannel(uri1); |
|
33 var channel2 = NetUtil.newChannel(uri2); |
|
34 |
|
35 // Force the channel URI to be used when determining the originating URI of |
|
36 // the channel. |
|
37 var httpchannel1 = channel1.QueryInterface(Ci.nsIHttpChannelInternal); |
|
38 var httpchannel2 = channel1.QueryInterface(Ci.nsIHttpChannelInternal); |
|
39 httpchannel1.forceAllowThirdPartyCookie = true; |
|
40 httpchannel2.forceAllowThirdPartyCookie = true; |
|
41 |
|
42 // test with cookies enabled, and third party cookies persistent. |
|
43 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); |
|
44 Services.prefs.setBoolPref("network.cookie.thirdparty.sessionOnly", false); |
|
45 do_set_cookies(uri1, channel1, false, [1, 2, 3, 4]); |
|
46 do_set_cookies(uri2, channel2, true, [1, 2, 3, 4]); |
|
47 |
|
48 // fake a profile change |
|
49 do_close_profile(test_generator); |
|
50 yield; |
|
51 do_load_profile(); |
|
52 do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 4); |
|
53 do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); |
|
54 |
|
55 // Again, but don't wait for the async close to complete. This should always |
|
56 // work, since we blocked on close above and haven't kicked off any writes |
|
57 // since then. |
|
58 do_close_profile(); |
|
59 do_load_profile(); |
|
60 do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 4); |
|
61 do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); |
|
62 |
|
63 // cleanse them |
|
64 do_close_profile(test_generator, "shutdown-cleanse"); |
|
65 yield; |
|
66 do_load_profile(); |
|
67 do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 0); |
|
68 do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); |
|
69 |
|
70 // test with cookies set to session-only |
|
71 Services.prefs.setIntPref("network.cookie.lifetimePolicy", 2); |
|
72 do_set_cookies(uri1, channel1, false, [1, 2, 3, 4]); |
|
73 do_set_cookies(uri2, channel2, true, [1, 2, 3, 4]); |
|
74 |
|
75 // fake a profile change |
|
76 do_close_profile(test_generator); |
|
77 yield; |
|
78 do_load_profile(); |
|
79 do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 0); |
|
80 do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); |
|
81 |
|
82 finish_test(); |
|
83 } |
|
84 |