Bug 1584479 - Part 3: Use new social cookies blocked flag in protections panel category logic. r=johannh,xeonchen
☠☠ backed out by 070d360bafef ☠ ☠
authorNihanth Subramanya <nhnt11@gmail.com>
Fri, 01 Nov 2019 20:07:09 +0000
changeset 500251 d2c56bd61b08f11f9bcde957c12cb3ff45aa5148
parent 500250 0edb227865459d4fb59da0771dad10130e4d7b64
child 500252 b0d9877bd8b07ad3b77196e35c1be702ba85ba93
push id99481
push usernhnt11@gmail.com
push dateFri, 01 Nov 2019 22:03:30 +0000
treeherderautoland@b0d9877bd8b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh, xeonchen
bugs1584479
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1584479 - Part 3: Use new social cookies blocked flag in protections panel category logic. r=johannh,xeonchen Differential Revision: https://phabricator.services.mozilla.com/D47428
browser/base/content/browser-siteProtections.js
browser/base/content/test/trackingUI/browser_trackingUI_socialtracking.js
browser/base/content/test/trackingUI/trackingAPI.js
--- a/browser/base/content/browser-siteProtections.js
+++ b/browser/base/content/browser-siteProtections.js
@@ -648,16 +648,18 @@ var ThirdPartyCookies = {
 
   get enabled() {
     return this.PREF_ENABLED_VALUES.includes(this.behaviorPref);
   },
 
   isBlocking(state) {
     return (
       (state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER) != 0 ||
+      (state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_SOCIALTRACKER) !=
+        0 ||
       (state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_ALL) != 0 ||
       (state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_BY_PERMISSION) !=
         0 ||
       (state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_FOREIGN) != 0
     );
   },
 
   isDetected(state) {
@@ -665,17 +667,20 @@ var ThirdPartyCookies = {
       return true;
     }
 
     if (
       this.behaviorPref == Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER ||
       this.behaviorPref == Ci.nsICookieService.BEHAVIOR_ACCEPT
     ) {
       return (
-        (state & Ci.nsIWebProgressListener.STATE_COOKIES_LOADED_TRACKER) != 0
+        (state & Ci.nsIWebProgressListener.STATE_COOKIES_LOADED_TRACKER) != 0 ||
+        (state &
+          Ci.nsIWebProgressListener.STATE_COOKIES_LOADED_SOCIALTRACKER) !=
+          0
       );
     }
 
     // We don't have specific flags for the other cookie behaviors so just
     // fall back to STATE_COOKIES_LOADED.
     return (state & Ci.nsIWebProgressListener.STATE_COOKIES_LOADED) != 0;
   },
 
@@ -1008,34 +1013,37 @@ var SocialTracking = {
   },
 
   updateCategoryItem() {
     this.categoryItem.hidden = !this.enabled;
     this.categoryItem.classList.toggle("blocked", this.blockingEnabled);
   },
 
   isBlocking(state) {
-    let cookieTrackerBlocked =
-      (state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER) != 0;
     let socialtrackingContentBlocked =
       (state &
         Ci.nsIWebProgressListener.STATE_BLOCKED_SOCIALTRACKING_CONTENT) !=
       0;
-    let socialtrackingContentLoaded =
-      (state & Ci.nsIWebProgressListener.STATE_LOADED_SOCIALTRACKING_CONTENT) !=
+    let socialtrackingCookieBlocked =
+      (state & Ci.nsIWebProgressListener.STATE_BLOCKED_COOKIES_SOCIALTRACKER) !=
       0;
-    return (
-      (socialtrackingContentLoaded && cookieTrackerBlocked) ||
-      socialtrackingContentBlocked
-    );
+    return socialtrackingCookieBlocked || socialtrackingContentBlocked;
   },
 
   isAllowing(state) {
+    if (this.socialTrackingProtectionEnabled) {
+      return (
+        (state &
+          Ci.nsIWebProgressListener.STATE_LOADED_SOCIALTRACKING_CONTENT) !=
+        0
+      );
+    }
+
     return (
-      (state & Ci.nsIWebProgressListener.STATE_LOADED_SOCIALTRACKING_CONTENT) !=
+      (state & Ci.nsIWebProgressListener.STATE_COOKIES_LOADED_SOCIALTRACKER) !=
       0
     );
   },
 
   isDetected(state) {
     return this.isBlocking(state) || this.isAllowing(state);
   },
 
--- a/browser/base/content/test/trackingUI/browser_trackingUI_socialtracking.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_socialtracking.js
@@ -161,16 +161,17 @@ async function testSubview(hasException)
     gProtectionsHandler.enableForCurrentPage();
     await loaded;
   }
 
   BrowserTestUtils.removeTab(tab);
 }
 
 async function testCategoryItem() {
+  Services.prefs.setBoolPref(ST_PROTECTION_PREF, false);
   Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, false);
 
   let promise = BrowserTestUtils.openNewForegroundTab({
     url: TRACKING_PAGE,
     gBrowser,
   });
   let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]);
 
@@ -181,59 +182,39 @@ async function testCategoryItem() {
   ok(
     !categoryItem.classList.contains("blocked"),
     "Category not marked as blocked"
   );
   ok(
     categoryItem.classList.contains("notFound"),
     "Category marked as not found"
   );
+
+  Services.prefs.setBoolPref(ST_PROTECTION_PREF, true);
   Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, true);
+
   ok(categoryItem.classList.contains("blocked"), "Category marked as blocked");
   ok(
     categoryItem.classList.contains("notFound"),
     "Category marked as not found"
   );
-  Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, false);
-  ok(
-    !categoryItem.classList.contains("blocked"),
-    "Category not marked as blocked"
-  );
-  ok(
-    categoryItem.classList.contains("notFound"),
-    "Category marked as not found"
-  );
 
   promise = waitForContentBlockingEvent();
 
   await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
     content.postMessage("socialtracking", "*");
   });
 
   await promise;
 
-  ok(
-    !categoryItem.classList.contains("blocked"),
-    "Category not marked as blocked"
-  );
-  ok(
-    !categoryItem.classList.contains("notFound"),
-    "Category not marked as not found"
-  );
-  Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, true);
   ok(categoryItem.classList.contains("blocked"), "Category marked as blocked");
-  ok(
-    !categoryItem.classList.contains("notFound"),
-    "Category not marked as not found"
-  );
-  Services.prefs.setBoolPref(ST_BLOCK_COOKIES_PREF, false);
-  ok(
-    !categoryItem.classList.contains("blocked"),
-    "Category not marked as blocked"
-  );
+
+  await TestUtils.waitForCondition(() => {
+    return !categoryItem.classList.contains("notFound");
+  });
   ok(
     !categoryItem.classList.contains("notFound"),
     "Category not marked as not found"
   );
 
   BrowserTestUtils.removeTab(tab);
 }
 
--- a/browser/base/content/test/trackingUI/trackingAPI.js
+++ b/browser/base/content/test/trackingUI/trackingAPI.js
@@ -5,17 +5,19 @@ function createIframe(src) {
 }
 
 onmessage = event => {
   switch (event.data) {
     case "tracking":
       createIframe("https://trackertest.org/");
       break;
     case "socialtracking":
-      createIframe("https://socialtracking.example.com/");
+      createIframe(
+        "http://socialtracking.example.com/browser/browser/base/content/test/trackingUI/cookieServer.sjs"
+      );
       break;
     case "cryptomining":
       createIframe("http://cryptomining.example.com/");
       break;
     case "fingerprinting":
       createIframe("https://fingerprinting.example.com/");
       break;
     case "more-tracking":