summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_private_cookie_changed.js
blob: 6c6f31de477965fa394850a566c9714f9ca4a843 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");

function makeChan(uri, isPrivate) {
  var chan = NetUtil.newChannel ({
    uri: uri.spec,
    loadUsingSystemPrincipal: true
  }).QueryInterface(Components.interfaces.nsIHttpChannel);

  chan.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(isPrivate);
  return chan;
}

function run_test() {
  // Allow all cookies.
  Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
  
  let publicNotifications = 0;
  let privateNotifications = 0;
  Services.obs.addObserver(function() {publicNotifications++;}, "cookie-changed", false);
  Services.obs.addObserver(function() {privateNotifications++;}, "private-cookie-changed", false);

  let uri = NetUtil.newURI("http://foo.com/");
  let publicChan = makeChan(uri, false);
  let svc = Services.cookies.QueryInterface(Ci.nsICookieService);
  svc.setCookieString(uri, null, "oh=hai", publicChan);
  let privateChan = makeChan(uri, true);
  svc.setCookieString(uri, null, "oh=hai", privateChan);
  do_check_eq(publicNotifications, 1);
  do_check_eq(privateNotifications, 1);
}