Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 5 | Components.utils.import("resource://gre/modules/NetUtil.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | function makeChan(uri, isPrivate) { |
michael@0 | 8 | var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); |
michael@0 | 9 | var chan = ios.newChannel(uri.spec, null, null) |
michael@0 | 10 | .QueryInterface(Ci.nsIHttpChannel); |
michael@0 | 11 | chan.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(isPrivate); |
michael@0 | 12 | return chan; |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | function run_test() { |
michael@0 | 16 | // Allow all cookies. |
michael@0 | 17 | Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); |
michael@0 | 18 | |
michael@0 | 19 | let publicNotifications = 0; |
michael@0 | 20 | let privateNotifications = 0; |
michael@0 | 21 | Services.obs.addObserver(function() {publicNotifications++;}, "cookie-changed", false); |
michael@0 | 22 | Services.obs.addObserver(function() {privateNotifications++;}, "private-cookie-changed", false); |
michael@0 | 23 | |
michael@0 | 24 | let uri = NetUtil.newURI("http://foo.com/"); |
michael@0 | 25 | let publicChan = makeChan(uri, false); |
michael@0 | 26 | let svc = Services.cookies.QueryInterface(Ci.nsICookieService); |
michael@0 | 27 | svc.setCookieString(uri, null, "oh=hai", publicChan); |
michael@0 | 28 | let privateChan = makeChan(uri, true); |
michael@0 | 29 | svc.setCookieString(uri, null, "oh=hai", privateChan); |
michael@0 | 30 | do_check_eq(publicNotifications, 1); |
michael@0 | 31 | do_check_eq(privateNotifications, 1); |
michael@0 | 32 | } |