test_private_cookie_changed.js (1313B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ 3 */ 4 5 "use strict"; 6 7 function makeChan(uri, isPrivate) { 8 var chan = NetUtil.newChannel({ 9 uri: uri.spec, 10 loadUsingSystemPrincipal: true, 11 }).QueryInterface(Ci.nsIHttpChannel); 12 13 chan.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(isPrivate); 14 return chan; 15 } 16 17 function run_test() { 18 // We don't want to have CookieJarSettings blocking this test. 19 Services.prefs.setBoolPref( 20 "network.cookieJarSettings.unblocked_for_testing", 21 true 22 ); 23 24 // Allow all cookies. 25 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); 26 27 let publicNotifications = 0; 28 let privateNotifications = 0; 29 Services.obs.addObserver(function () { 30 publicNotifications++; 31 }, "cookie-changed"); 32 Services.obs.addObserver(function () { 33 privateNotifications++; 34 }, "private-cookie-changed"); 35 36 let uri = NetUtil.newURI("http://foo.com/"); 37 let publicChan = makeChan(uri, false); 38 let svc = Services.cookies.QueryInterface(Ci.nsICookieService); 39 svc.setCookieStringFromHttp(uri, "oh=hai", publicChan); 40 let privateChan = makeChan(uri, true); 41 svc.setCookieStringFromHttp(uri, "oh=hai", privateChan); 42 Assert.equal(publicNotifications, 1); 43 Assert.equal(privateNotifications, 1); 44 }