Bug 1514070 - Ensure that the cookies subpanel will correctly show granted permissions to trackers as soon as they're granted. r=ewright, a=RyanVM
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 18 Dec 2018 16:57:13 +0000
changeset 509116 ef357d2c21405cd5c4de8129c81c6a000b651a0c
parent 509115 5c3919c84d998eab7f11b2502a518c09b8bd693c
child 509117 fef8ee3bdc39ed3171fc133f9d4215dd7228540f
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersewright, RyanVM
bugs1514070
milestone65.0
Bug 1514070 - Ensure that the cookies subpanel will correctly show granted permissions to trackers as soon as they're granted. r=ewright, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D14570
browser/base/content/browser-contentblocking.js
browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js
browser/base/content/test/trackingUI/trackingAPI.js
--- a/browser/base/content/browser-contentblocking.js
+++ b/browser/base/content/browser-contentblocking.js
@@ -424,18 +424,18 @@ var ThirdPartyCookies = {
         if (this.isDetected(state)) {
           hasCookie = true;
         }
         if (TrackingProtection.isAllowing(state)) {
           isTracker = true;
         }
         // blocked tells us whether the resource was actually blocked
         // (which it may not be in case of an exception).
-        if (this.isBlocking(state) && blocked) {
-          info.isAllowed = false;
+        if (this.isBlocking(state)) {
+          info.isAllowed = !blocked;
         }
       }
 
       if (!hasCookie) {
         continue;
       }
 
       let isFirstParty = false;
--- a/browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js
@@ -171,8 +171,74 @@ add_task(async function testCookiesSubVi
     ok(BrowserTestUtils.is_visible(button), "Permission remove button is visible");
     button.click();
     is(Services.perms.testExactPermissionFromPrincipal(principal, "cookie"), Services.perms.UNKNOWN_ACTION, "Button click should remove cookie pref.");
     ok(!listItem.classList.contains("allowed"), "Has removed the allowed class");
   });
 
   Services.prefs.clearUserPref(TPC_PREF);
 });
+
+add_task(async function testCookiesSubViewAllowedHeuristic() {
+  Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER);
+  let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin("http://not-tracking.example.com/");
+
+  // Pretend that the tracker has already been interacted with
+  let trackerPrincipal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin("http://trackertest.org/");
+  Services.perms.addFromPrincipal(trackerPrincipal, "storageAccessAPI", Services.perms.ALLOW_ACTION);
+
+  await BrowserTestUtils.withNewTab(COOKIE_PAGE, async function(browser) {
+    let popup;
+    let windowCreated = TestUtils.topicObserved("chrome-document-global-created", (subject, data) => {
+      popup = subject;
+      return true;
+    });
+    let permChanged = TestUtils.topicObserved("perm-changed",
+      (subject, data) => {
+        return subject &&
+               subject.QueryInterface(Ci.nsIPermission)
+                      .type == "3rdPartyStorage^http://trackertest.org" &&
+               subject.principal.origin == principal.origin &&
+               data == "added";
+      });
+
+    await ContentTask.spawn(browser, {}, function() {
+      content.postMessage("window-open", "*");
+    });
+    await Promise.all([windowCreated, permChanged]);
+
+    await new Promise(resolve => waitForFocus(resolve, popup));
+    await new Promise(resolve => waitForFocus(resolve, window));
+
+    await openIdentityPopup();
+
+    let categoryItem =
+      document.getElementById("identity-popup-content-blocking-category-cookies");
+    ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible");
+    let cookiesView = document.getElementById("identity-popup-cookiesView");
+    let viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown");
+    categoryItem.click();
+    await viewShown;
+
+    ok(true, "Cookies view was shown");
+
+    let listItems = cookiesView.querySelectorAll(".identity-popup-content-blocking-list-item");
+    is(listItems.length, 1, "We have 1 cookie in the list");
+
+    let listItem = listItems[0];
+    let label = listItem.querySelector(".identity-popup-content-blocking-list-host-label");
+    is(label.value, "http://trackertest.org", "Has an item for trackertest.org");
+    ok(BrowserTestUtils.is_visible(listItem), "List item is visible");
+    ok(listItem.classList.contains("allowed"), "Indicates whether the cookie was blocked or allowed");
+
+    let button = listItem.querySelector(".identity-popup-permission-remove-button");
+    ok(BrowserTestUtils.is_visible(button), "Permission remove button is visible");
+    button.click();
+    is(Services.perms.testExactPermissionFromPrincipal(principal, "3rdPartyStorage^http://trackertest.org"), Services.perms.UNKNOWN_ACTION, "Button click should remove the storage pref.");
+    ok(!listItem.classList.contains("allowed"), "Has removed the allowed class");
+
+    await ContentTask.spawn(browser, {}, function() {
+      content.postMessage("window-close", "*");
+    });
+  });
+
+  Services.prefs.clearUserPref(TPC_PREF);
+});
--- a/browser/base/content/test/trackingUI/trackingAPI.js
+++ b/browser/base/content/test/trackingUI/trackingAPI.js
@@ -28,10 +28,17 @@ onmessage = event => {
     }
     break;
   case "third-party-cookie": {
       let ifr = document.createElement("iframe");
       ifr.src = "https://test1.example.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs";
       document.body.appendChild(ifr);
     }
     break;
+  case "window-open":
+      window.win = window.open("http://trackertest.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs", "_blank", "width=100,height=100");
+    break;
+  case "window-close":
+      window.win.close();
+      window.win = null;
+    break;
   }
 };