|
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"); |
|
6 |
|
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 } |
|
14 |
|
15 function run_test() { |
|
16 // Allow all cookies. |
|
17 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); |
|
18 |
|
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); |
|
23 |
|
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 } |