1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/extensions/cookie/test/unit/test_cookies_thirdparty_session.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// test third party persistence across sessions, for the cases: 1.8 +// 1) network.cookie.thirdparty.sessionOnly = false 1.9 +// 2) network.cookie.thirdparty.sessionOnly = true 1.10 + 1.11 +let test_generator = do_run_test(); 1.12 + 1.13 +function run_test() { 1.14 + do_test_pending(); 1.15 + test_generator.next(); 1.16 +} 1.17 + 1.18 +function finish_test() { 1.19 + do_execute_soon(function() { 1.20 + test_generator.close(); 1.21 + do_test_finished(); 1.22 + }); 1.23 +} 1.24 + 1.25 +function do_run_test() { 1.26 + // Set up a profile. 1.27 + let profile = do_get_profile(); 1.28 + 1.29 + // Create URIs and channels pointing to foo.com and bar.com. 1.30 + // We will use these to put foo.com into first and third party contexts. 1.31 + var spec1 = "http://foo.com/foo.html"; 1.32 + var spec2 = "http://bar.com/bar.html"; 1.33 + var uri1 = NetUtil.newURI(spec1); 1.34 + var uri2 = NetUtil.newURI(spec2); 1.35 + var channel1 = NetUtil.newChannel(uri1); 1.36 + var channel2 = NetUtil.newChannel(uri2); 1.37 + 1.38 + // Force the channel URI to be used when determining the originating URI of 1.39 + // the channel. 1.40 + var httpchannel1 = channel1.QueryInterface(Ci.nsIHttpChannelInternal); 1.41 + var httpchannel2 = channel2.QueryInterface(Ci.nsIHttpChannelInternal); 1.42 + httpchannel1.forceAllowThirdPartyCookie = true; 1.43 + httpchannel2.forceAllowThirdPartyCookie = true; 1.44 + 1.45 + // test with cookies enabled, and third party cookies persistent. 1.46 + Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); 1.47 + Services.prefs.setBoolPref("network.cookie.thirdparty.sessionOnly", false); 1.48 + do_set_cookies(uri1, channel2, false, [1, 2, 3, 4]); 1.49 + do_set_cookies(uri2, channel1, true, [1, 2, 3, 4]); 1.50 + 1.51 + // fake a profile change 1.52 + do_close_profile(test_generator); 1.53 + yield; 1.54 + do_load_profile(); 1.55 + do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 4); 1.56 + do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); 1.57 + 1.58 + // cleanse them 1.59 + do_close_profile(test_generator, "shutdown-cleanse"); 1.60 + yield; 1.61 + do_load_profile(); 1.62 + do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 0); 1.63 + do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); 1.64 + 1.65 + // test with third party cookies for session only. 1.66 + Services.prefs.setBoolPref("network.cookie.thirdparty.sessionOnly", true); 1.67 + do_set_cookies(uri1, channel2, false, [1, 2, 3, 4]); 1.68 + do_set_cookies(uri2, channel1, true, [1, 2, 3, 4]); 1.69 + 1.70 + // fake a profile change 1.71 + do_close_profile(test_generator); 1.72 + yield; 1.73 + do_load_profile(); 1.74 + do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 0); 1.75 + do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); 1.76 + 1.77 + finish_test(); 1.78 +}