1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_private_cookie_changed.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,32 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.8 +Components.utils.import("resource://gre/modules/NetUtil.jsm"); 1.9 + 1.10 +function makeChan(uri, isPrivate) { 1.11 + var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); 1.12 + var chan = ios.newChannel(uri.spec, null, null) 1.13 + .QueryInterface(Ci.nsIHttpChannel); 1.14 + chan.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(isPrivate); 1.15 + return chan; 1.16 +} 1.17 + 1.18 +function run_test() { 1.19 + // Allow all cookies. 1.20 + Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); 1.21 + 1.22 + let publicNotifications = 0; 1.23 + let privateNotifications = 0; 1.24 + Services.obs.addObserver(function() {publicNotifications++;}, "cookie-changed", false); 1.25 + Services.obs.addObserver(function() {privateNotifications++;}, "private-cookie-changed", false); 1.26 + 1.27 + let uri = NetUtil.newURI("http://foo.com/"); 1.28 + let publicChan = makeChan(uri, false); 1.29 + let svc = Services.cookies.QueryInterface(Ci.nsICookieService); 1.30 + svc.setCookieString(uri, null, "oh=hai", publicChan); 1.31 + let privateChan = makeChan(uri, true); 1.32 + svc.setCookieString(uri, null, "oh=hai", privateChan); 1.33 + do_check_eq(publicNotifications, 1); 1.34 + do_check_eq(privateNotifications, 1); 1.35 +}