Bug 1584479 - Part 3: Use new social cookies blocked flag in protections panel category logic. r=johannh,xeonchen
authorNihanth Subramanya <nhnt11@gmail.com>
Fri, 01 Nov 2019 23:24:29 +0000
changeset 500281 8da9387aac08174fd17e968351423d24e28ace91
parent 500280 d0f91ad7450c157ed94c5fd70b51f80d8ad3303b
child 500282 16aac90f6572f363d2b5c8205e13115ac818869d
push id99500
push usernhnt11@gmail.com
push dateSat, 02 Nov 2019 09:56:01 +0000
treeherderautoland@16aac90f6572 [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":