michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: Components.utils.import("resource://gre/modules/NetUtil.jsm"); michael@0: michael@0: function makeChan(uri, isPrivate) { michael@0: var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); michael@0: var chan = ios.newChannel(uri.spec, null, null) michael@0: .QueryInterface(Ci.nsIHttpChannel); michael@0: chan.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(isPrivate); michael@0: return chan; michael@0: } michael@0: michael@0: function run_test() { michael@0: // Allow all cookies. michael@0: Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); michael@0: michael@0: let publicNotifications = 0; michael@0: let privateNotifications = 0; michael@0: Services.obs.addObserver(function() {publicNotifications++;}, "cookie-changed", false); michael@0: Services.obs.addObserver(function() {privateNotifications++;}, "private-cookie-changed", false); michael@0: michael@0: let uri = NetUtil.newURI("http://foo.com/"); michael@0: let publicChan = makeChan(uri, false); michael@0: let svc = Services.cookies.QueryInterface(Ci.nsICookieService); michael@0: svc.setCookieString(uri, null, "oh=hai", publicChan); michael@0: let privateChan = makeChan(uri, true); michael@0: svc.setCookieString(uri, null, "oh=hai", privateChan); michael@0: do_check_eq(publicNotifications, 1); michael@0: do_check_eq(privateNotifications, 1); michael@0: }