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.

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

mercurial