extensions/cookie/test/unit/test_cookies_persistence.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // test for cookie persistence across sessions, for the cases:
     5 // 1) network.cookie.lifetimePolicy = 0 (expire naturally)
     6 // 2) network.cookie.lifetimePolicy = 2 (expire at end of session)
     8 let test_generator = do_run_test();
    10 function run_test() {
    11   do_test_pending();
    12   test_generator.next();
    13 }
    15 function finish_test() {
    16   do_execute_soon(function() {
    17     test_generator.close();
    18     do_test_finished();
    19   });
    20 }
    22 function do_run_test() {
    23   // Set up a profile.
    24   let profile = do_get_profile();
    26   // Create URIs and channels pointing to foo.com and bar.com.
    27   // We will use these to put foo.com into first and third party contexts.
    28   var spec1 = "http://foo.com/foo.html";
    29   var spec2 = "http://bar.com/bar.html";
    30   var uri1 = NetUtil.newURI(spec1);
    31   var uri2 = NetUtil.newURI(spec2);
    32   var channel1 = NetUtil.newChannel(uri1);
    33   var channel2 = NetUtil.newChannel(uri2);
    35   // Force the channel URI to be used when determining the originating URI of
    36   // the channel.
    37   var httpchannel1 = channel1.QueryInterface(Ci.nsIHttpChannelInternal);
    38   var httpchannel2 = channel1.QueryInterface(Ci.nsIHttpChannelInternal);
    39   httpchannel1.forceAllowThirdPartyCookie = true;
    40   httpchannel2.forceAllowThirdPartyCookie = true;
    42   // test with cookies enabled, and third party cookies persistent.
    43   Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
    44   Services.prefs.setBoolPref("network.cookie.thirdparty.sessionOnly", false);
    45   do_set_cookies(uri1, channel1, false, [1, 2, 3, 4]);
    46   do_set_cookies(uri2, channel2, true, [1, 2, 3, 4]);
    48   // fake a profile change
    49   do_close_profile(test_generator);
    50   yield;
    51   do_load_profile();
    52   do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 4);
    53   do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0);
    55   // Again, but don't wait for the async close to complete. This should always
    56   // work, since we blocked on close above and haven't kicked off any writes
    57   // since then.
    58   do_close_profile();
    59   do_load_profile();
    60   do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 4);
    61   do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0);
    63   // cleanse them
    64   do_close_profile(test_generator, "shutdown-cleanse");
    65   yield;
    66   do_load_profile();
    67   do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 0);
    68   do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0);
    70   // test with cookies set to session-only
    71   Services.prefs.setIntPref("network.cookie.lifetimePolicy", 2);
    72   do_set_cookies(uri1, channel1, false, [1, 2, 3, 4]);
    73   do_set_cookies(uri2, channel2, true, [1, 2, 3, 4]);
    75   // fake a profile change
    76   do_close_profile(test_generator);
    77   yield;
    78   do_load_profile();
    79   do_check_eq(Services.cookies.countCookiesFromHost(uri1.host), 0);
    80   do_check_eq(Services.cookies.countCookiesFromHost(uri2.host), 0);
    82   finish_test();
    83 }

mercurial