michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // test for cookie persistence across sessions, for the cases: michael@0: // 1) network.cookie.lifetimePolicy = 0 (expire naturally) michael@0: // 2) network.cookie.lifetimePolicy = 2 (expire at end of session) michael@0: michael@0: let test_generator = do_run_test(); michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: test_generator.next(); michael@0: } michael@0: michael@0: function finish_test() { michael@0: do_execute_soon(function() { michael@0: test_generator.close(); michael@0: do_test_finished(); michael@0: }); michael@0: } michael@0: michael@0: function do_run_test() { michael@0: // Set up a profile. michael@0: let profile = do_get_profile(); michael@0: michael@0: // Create URIs and channels pointing to foo.com and bar.com. michael@0: // We will use these to put foo.com into first and third party contexts. michael@0: var spec1 = "http://foo.com/foo.html"; michael@0: var spec2 = "http://bar.com/bar.html"; michael@0: var uri1 = NetUtil.newURI(spec1); michael@0: var uri2 = NetUtil.newURI(spec2); michael@0: var channel1 = NetUtil.newChannel(uri1); michael@0: var channel2 = NetUtil.newChannel(uri2); michael@0: michael@0: // Force the channel URI to be used when determining the originating URI of michael@0: // the channel. michael@0: var httpchannel1 = channel1.QueryInterface(Ci.nsIHttpChannelInternal); michael@0: var httpchannel2 = channel1.QueryInterface(Ci.nsIHttpChannelInternal); michael@0: httpchannel1.forceAllowThirdPartyCookie = true; michael@0: httpchannel2.forceAllowThirdPartyCookie = true; michael@0: michael@0: // test with cookies enabled, and third party cookies persistent. michael@0: Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); michael@0: Services.prefs.setBoolPref("network.cookie.thirdparty.sessionOnly", false); michael@0: do_set_cookies(uri1, channel1, false, [1, 2, 3, 4]); michael@0: do_set_cookies(uri2, channel2, true, [1, 2, 3, 4]); michael@0: michael@0: // fake a profile change michael@0: do_close_profile(test_generator); michael@0: yield; michael@0: do_load_profile(); michael@0: do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 4); michael@0: do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); michael@0: michael@0: // Again, but don't wait for the async close to complete. This should always michael@0: // work, since we blocked on close above and haven't kicked off any writes michael@0: // since then. michael@0: do_close_profile(); michael@0: do_load_profile(); michael@0: do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 4); michael@0: do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); michael@0: michael@0: // cleanse them michael@0: do_close_profile(test_generator, "shutdown-cleanse"); michael@0: yield; michael@0: do_load_profile(); michael@0: do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 0); michael@0: do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); michael@0: michael@0: // test with cookies set to session-only michael@0: Services.prefs.setIntPref("network.cookie.lifetimePolicy", 2); michael@0: do_set_cookies(uri1, channel1, false, [1, 2, 3, 4]); michael@0: do_set_cookies(uri2, channel2, true, [1, 2, 3, 4]); michael@0: michael@0: // fake a profile change michael@0: do_close_profile(test_generator); michael@0: yield; michael@0: do_load_profile(); michael@0: do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 0); michael@0: do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0); michael@0: michael@0: finish_test(); michael@0: } michael@0: