Bug 837091 - Rename cookie-changed notification for private cookies. r=ehsan a=bajaj
authorJosh Matthews <josh@joshmatthews.net>
Tue, 05 Feb 2013 10:44:21 +0000
changeset 127477 c70f78759651a936fae17f3a098d591cf4600eef
parent 127476 f87b14a1329944a760dc243d29fca9c4936395bd
child 127478 8755cbf3acc5c4de9119370a46051f01eb0c402c
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, bajaj
bugs837091
milestone20.0a2
Bug 837091 - Rename cookie-changed notification for private cookies. r=ehsan a=bajaj
netwerk/cookie/nsCookieService.cpp
netwerk/test/unit/head_channels.js
netwerk/test/unit/test_private_cookie_changed.js
netwerk/test/unit/xpcshell.ini
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -1664,18 +1664,20 @@ nsCookieService::NotifyRejected(nsIURI *
 // "changed" means a cookie was altered. aSubject is the new cookie.
 // "cleared" means the entire cookie list was cleared. aSubject is null.
 // "batch-deleted" means a set of cookies was purged. aSubject is the list of
 // cookies.
 void
 nsCookieService::NotifyChanged(nsISupports     *aSubject,
                                const PRUnichar *aData)
 {
+  const char* topic = mDBState == mPrivateDBState ?
+      "private-cookie-changed" : "cookie-changed";
   if (mObserverService)
-    mObserverService->NotifyObservers(aSubject, "cookie-changed", aData);
+    mObserverService->NotifyObservers(aSubject, topic, aData);
 }
 
 already_AddRefed<nsIArray>
 nsCookieService::CreatePurgeList(nsICookie2* aCookie)
 {
   nsCOMPtr<nsIMutableArray> removedList =
     do_CreateInstance(NS_ARRAY_CONTRACTID);
   removedList->AppendElement(aCookie, false);
--- a/netwerk/test/unit/head_channels.js
+++ b/netwerk/test/unit/head_channels.js
@@ -214,19 +214,19 @@ function LoadContextCallback(appId, inBr
 
 LoadContextCallback.prototype = {
   associatedWindow: null,
   topWindow : null,
   isAppOfType: function(appType) {
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
   QueryInterface: function(iid) {
-    if (iid == Ci.nsILoadContext ||
-               Ci.nsIInterfaceRequestor ||
-               Ci.nsISupports) {
+    if (iid.equals(Ci.nsILoadContext) ||
+        iid.equals(Ci.nsIInterfaceRequestor) ||
+        iid.equals(Ci.nsISupports)) {
         return this;
     }
     throw Cr.NS_ERROR_NO_INTERFACE;
   },
   getInterface: function(iid) {
     if (iid.equals(Ci.nsILoadContext))
       return this;
     throw Cr.NS_ERROR_NO_INTERFACE;
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_private_cookie_changed.js
@@ -0,0 +1,31 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/NetUtil.jsm");
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+function makeChan(uri, isPrivate) {
+  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+  var chan = ios.newChannel(uri.spec, null, null)
+                .QueryInterface(Ci.nsIHttpChannel);
+  chan.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(isPrivate);
+  return chan;
+}
+
+function run_test() {
+  let publicNotifications = 0;
+  let privateNotifications = 0;
+  Services.obs.addObserver(function() {publicNotifications++;}, "cookie-changed", false);
+  Services.obs.addObserver(function() {privateNotifications++;}, "private-cookie-changed", false);
+
+  let uri = NetUtil.newURI("http://foo.com/");
+  let publicChan = makeChan(uri, false);
+  let svc = Services.cookies.QueryInterface(Ci.nsICookieService);
+  svc.setCookieString(uri, null, "oh=hai", publicChan);
+  let privateChan = makeChan(uri, true);
+  svc.setCookieString(uri, null, "oh=hai", privateChan);
+  do_check_eq(publicNotifications, 1);
+  do_check_eq(privateNotifications, 1);
+}
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -159,16 +159,17 @@ skip-if = os == "android"
 skip-if = os == "win"
 [test_nojsredir.js]
 [test_offline_status.js]
 [test_parse_content_type.js]
 [test_permmgr.js]
 [test_plaintext_sniff.js]
 [test_post.js]
 [test_private_channel.js]
+[test_private_cookie_changed.js]
 [test_progress.js]
 [test_protocolproxyservice.js]
 [test_proxy-failover_canceled.js]
 [test_proxy-failover_passing.js]
 [test_proxy-replace_canceled.js]
 [test_proxy-replace_passing.js]
 [test_psl.js]
 [test_range_requests.js]