extensions/cookie/test/unit/test_cookies_thirdparty.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 cookie blocking, for the cases:
michael@0 5 // 1) with null channel
michael@0 6 // 2) with channel, but with no docshell parent
michael@0 7
michael@0 8 function run_test() {
michael@0 9 // Create URIs and channels pointing to foo.com and bar.com.
michael@0 10 // We will use these to put foo.com into first and third party contexts.
michael@0 11 var spec1 = "http://foo.com/foo.html";
michael@0 12 var spec2 = "http://bar.com/bar.html";
michael@0 13 var uri1 = NetUtil.newURI(spec1);
michael@0 14 var uri2 = NetUtil.newURI(spec2);
michael@0 15 var channel1 = NetUtil.newChannel(uri1);
michael@0 16 var channel2 = NetUtil.newChannel(uri2);
michael@0 17
michael@0 18 // test with cookies enabled
michael@0 19 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
michael@0 20 do_set_cookies(uri1, channel1, true, [1, 2, 3, 4]);
michael@0 21 Services.cookies.removeAll();
michael@0 22 do_set_cookies(uri1, channel2, true, [1, 2, 3, 4]);
michael@0 23 Services.cookies.removeAll();
michael@0 24
michael@0 25 // test with third party cookies blocked
michael@0 26 Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
michael@0 27 do_set_cookies(uri1, channel1, true, [0, 0, 0, 0]);
michael@0 28 Services.cookies.removeAll();
michael@0 29 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
michael@0 30 Services.cookies.removeAll();
michael@0 31
michael@0 32 // Force the channel URI to be used when determining the originating URI of
michael@0 33 // the channel.
michael@0 34 var httpchannel1 = channel1.QueryInterface(Ci.nsIHttpChannelInternal);
michael@0 35 var httpchannel2 = channel2.QueryInterface(Ci.nsIHttpChannelInternal);
michael@0 36 httpchannel1.forceAllowThirdPartyCookie = true;
michael@0 37 httpchannel2.forceAllowThirdPartyCookie = true;
michael@0 38
michael@0 39 // test with cookies enabled
michael@0 40 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
michael@0 41 do_set_cookies(uri1, channel1, true, [1, 2, 3, 4]);
michael@0 42 Services.cookies.removeAll();
michael@0 43 do_set_cookies(uri1, channel2, true, [1, 2, 3, 4]);
michael@0 44 Services.cookies.removeAll();
michael@0 45
michael@0 46 // test with third party cookies blocked
michael@0 47 Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
michael@0 48 do_set_cookies(uri1, channel1, true, [0, 1, 1, 2]);
michael@0 49 Services.cookies.removeAll();
michael@0 50 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
michael@0 51 Services.cookies.removeAll();
michael@0 52
michael@0 53 // test with third party cookies limited
michael@0 54 Services.prefs.setIntPref("network.cookie.cookieBehavior", 3);
michael@0 55 do_set_cookies(uri1, channel1, true, [0, 1, 2, 3]);
michael@0 56 Services.cookies.removeAll();
michael@0 57 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
michael@0 58 Services.cookies.removeAll();
michael@0 59 do_set_single_http_cookie(uri1, channel1, 1);
michael@0 60 do_set_cookies(uri1, channel2, true, [2, 3, 4, 5]);
michael@0 61 Services.cookies.removeAll();
michael@0 62
michael@0 63 // Test per-site 3rd party cookie blocking with cookies enabled
michael@0 64 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
michael@0 65 var kPermissionType = "cookie";
michael@0 66 var ALLOW_FIRST_PARTY_ONLY = 9;
michael@0 67 // ALLOW_FIRST_PARTY_ONLY overrides
michael@0 68 Services.perms.add(uri1, kPermissionType, ALLOW_FIRST_PARTY_ONLY);
michael@0 69 do_set_cookies(uri1, channel1, true, [0, 1, 1, 2]);
michael@0 70 Services.cookies.removeAll();
michael@0 71 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
michael@0 72 Services.cookies.removeAll();
michael@0 73
michael@0 74 // Test per-site 3rd party cookie blocking with 3rd party cookies disabled
michael@0 75 Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
michael@0 76 do_set_cookies(uri1, channel1, true, [0, 1, 1, 2]);
michael@0 77 Services.cookies.removeAll();
michael@0 78 // No preference has been set for uri2, but it should act as if
michael@0 79 // ALLOW_FIRST_PARTY_ONLY has been set
michael@0 80 do_set_cookies(uri2, channel2, true, [0, 1, 1, 2]);
michael@0 81 Services.cookies.removeAll();
michael@0 82 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
michael@0 83 Services.cookies.removeAll();
michael@0 84
michael@0 85 // Test per-site 3rd party cookie blocking with 3rd party cookies limited
michael@0 86 Services.prefs.setIntPref("network.cookie.cookieBehavior", 3);
michael@0 87 do_set_cookies(uri1, channel1, true, [0, 1, 1, 2]);
michael@0 88 Services.cookies.removeAll();
michael@0 89 // No preference has been set for uri2, but it should act as if
michael@0 90 // LIMIT_THIRD_PARTY has been set
michael@0 91 do_set_cookies(uri2, channel2, true, [0, 1, 2, 3]);
michael@0 92 Services.cookies.removeAll();
michael@0 93 do_set_single_http_cookie(uri2, channel2, 1);
michael@0 94 do_set_cookies(uri2, channel2, true, [2, 3, 4, 5]);
michael@0 95 Services.cookies.removeAll();
michael@0 96 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
michael@0 97 Services.cookies.removeAll();
michael@0 98 do_set_single_http_cookie(uri1, channel1, 1);
michael@0 99 do_set_cookies(uri1, channel2, true, [1, 1, 1, 1]);
michael@0 100 Services.cookies.removeAll();
michael@0 101
michael@0 102 // Test per-site 3rd party cookie limiting with cookies enabled
michael@0 103 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
michael@0 104 var kPermissionType = "cookie";
michael@0 105 var LIMIT_THIRD_PARTY = 10;
michael@0 106 // LIMIT_THIRD_PARTY overrides
michael@0 107 Services.perms.add(uri1, kPermissionType, LIMIT_THIRD_PARTY);
michael@0 108 do_set_cookies(uri1, channel1, true, [0, 1, 2, 3]);
michael@0 109 Services.cookies.removeAll();
michael@0 110 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
michael@0 111 Services.cookies.removeAll();
michael@0 112 do_set_single_http_cookie(uri1, channel1, 1);
michael@0 113 do_set_cookies(uri1, channel2, true, [2, 3, 4, 5]);
michael@0 114 Services.cookies.removeAll();
michael@0 115
michael@0 116 // Test per-site 3rd party cookie limiting with 3rd party cookies disabled
michael@0 117 Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
michael@0 118 do_set_cookies(uri1, channel1, true, [0, 1, 2, 3]);
michael@0 119 Services.cookies.removeAll();
michael@0 120 // No preference has been set for uri2, but it should act as if
michael@0 121 // ALLOW_FIRST_PARTY_ONLY has been set
michael@0 122 do_set_cookies(uri2, channel2, true, [0, 1, 1, 2]);
michael@0 123 Services.cookies.removeAll();
michael@0 124 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
michael@0 125 Services.cookies.removeAll();
michael@0 126 do_set_single_http_cookie(uri1, channel1, 1);
michael@0 127 do_set_cookies(uri1, channel2, true, [2, 3, 4, 5]);
michael@0 128 Services.cookies.removeAll();
michael@0 129
michael@0 130 // Test per-site 3rd party cookie limiting with 3rd party cookies limited
michael@0 131 Services.prefs.setIntPref("network.cookie.cookieBehavior", 3);
michael@0 132 do_set_cookies(uri1, channel1, true, [0, 1, 2, 3]);
michael@0 133 Services.cookies.removeAll();
michael@0 134 // No preference has been set for uri2, but it should act as if
michael@0 135 // LIMIT_THIRD_PARTY has been set
michael@0 136 do_set_cookies(uri2, channel2, true, [0, 1, 2, 3]);
michael@0 137 Services.cookies.removeAll();
michael@0 138 do_set_single_http_cookie(uri2, channel2, 1);
michael@0 139 do_set_cookies(uri2, channel2, true, [2, 3, 4, 5]);
michael@0 140 Services.cookies.removeAll();
michael@0 141 do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
michael@0 142 Services.cookies.removeAll();
michael@0 143 do_set_single_http_cookie(uri1, channel1, 1);
michael@0 144 do_set_cookies(uri1, channel2, true, [2, 3, 4, 5]);
michael@0 145 Services.cookies.removeAll();
michael@0 146 }
michael@0 147

mercurial