extensions/cookie/test/unit/test_cookies_thirdparty_session.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial