netwerk/test/unit/test_private_cookie_changed.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/
     3  */
     4 Components.utils.import("resource://gre/modules/Services.jsm");
     5 Components.utils.import("resource://gre/modules/NetUtil.jsm");
     7 function makeChan(uri, isPrivate) {
     8   var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
     9   var chan = ios.newChannel(uri.spec, null, null)
    10                 .QueryInterface(Ci.nsIHttpChannel);
    11   chan.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(isPrivate);
    12   return chan;
    13 }
    15 function run_test() {
    16   // Allow all cookies.
    17   Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
    19   let publicNotifications = 0;
    20   let privateNotifications = 0;
    21   Services.obs.addObserver(function() {publicNotifications++;}, "cookie-changed", false);
    22   Services.obs.addObserver(function() {privateNotifications++;}, "private-cookie-changed", false);
    24   let uri = NetUtil.newURI("http://foo.com/");
    25   let publicChan = makeChan(uri, false);
    26   let svc = Services.cookies.QueryInterface(Ci.nsICookieService);
    27   svc.setCookieString(uri, null, "oh=hai", publicChan);
    28   let privateChan = makeChan(uri, true);
    29   svc.setCookieString(uri, null, "oh=hai", privateChan);
    30   do_check_eq(publicNotifications, 1);
    31   do_check_eq(privateNotifications, 1);
    32 }

mercurial