Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 // test third party persistence across sessions, for the cases:
5 // 1) network.cookie.thirdparty.sessionOnly = false
6 // 2) network.cookie.thirdparty.sessionOnly = true
8 let test_generator = do_run_test();
10 function run_test() {
11 do_test_pending();
12 test_generator.next();
13 }
15 function finish_test() {
16 do_execute_soon(function() {
17 test_generator.close();
18 do_test_finished();
19 });
20 }
22 function do_run_test() {
23 // Set up a profile.
24 let profile = do_get_profile();
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);
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 = channel2.QueryInterface(Ci.nsIHttpChannelInternal);
39 httpchannel1.forceAllowThirdPartyCookie = true;
40 httpchannel2.forceAllowThirdPartyCookie = true;
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, channel2, false, [1, 2, 3, 4]);
46 do_set_cookies(uri2, channel1, true, [1, 2, 3, 4]);
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);
55 // cleanse them
56 do_close_profile(test_generator, "shutdown-cleanse");
57 yield;
58 do_load_profile();
59 do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 0);
60 do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0);
62 // test with third party cookies for session only.
63 Services.prefs.setBoolPref("network.cookie.thirdparty.sessionOnly", true);
64 do_set_cookies(uri1, channel2, false, [1, 2, 3, 4]);
65 do_set_cookies(uri2, channel1, true, [1, 2, 3, 4]);
67 // fake a profile change
68 do_close_profile(test_generator);
69 yield;
70 do_load_profile();
71 do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 0);
72 do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0);
74 finish_test();
75 }