Bug 1476317 - Fix identity popup display for pages with exceptions that have blocked content. r=nhnt11 draft
authorJohann Hofmann <jhofmann@mozilla.com>
Wed, 18 Jul 2018 16:33:06 +0200
changeset 819757 3ace3cd4f99094edf3c678c56a39adebdc37d1f3
parent 819645 8dab948a10f073a46f13f55f94d1f6514c7360ac
push id116644
push userjhofmann@mozilla.com
push dateWed, 18 Jul 2018 14:34:01 +0000
reviewersnhnt11
bugs1476317
milestone63.0a1
Bug 1476317 - Fix identity popup display for pages with exceptions that have blocked content. r=nhnt11 The identity popup will now show that there's an exception on the site instead of being confused. We previously didn't handle this state because I assumed it wouldn't be possible to enter. Turns out if you open the same (tracking) site in two tabs and then add an exception in one tab, the other tab will be in this state until reload. MozReview-Commit-ID: GVVdNpsAm6h
browser/base/content/browser-trackingprotection.js
browser/base/content/test/trackingUI/browser_trackingUI_state.js
browser/themes/shared/controlcenter/panel.inc.css
browser/themes/shared/identity-block/identity-block.inc.css
--- a/browser/base/content/browser-trackingprotection.js
+++ b/browser/base/content/browser-trackingprotection.js
@@ -204,18 +204,20 @@ var TrackingProtection = {
     if (PrivateBrowsingUtils.isBrowserPrivate(gBrowser.selectedBrowser)) {
       hasException = PrivateBrowsingUtils.existsInTrackingAllowlist(baseURI);
     } else {
       hasException = Services.perms.testExactPermission(baseURI,
         "trackingprotection") == Services.perms.ALLOW_ACTION;
     }
 
     if (hasException) {
+      this.iconBox.setAttribute("hasException", "true");
       this.content.setAttribute("hasException", "true");
     } else {
+      this.iconBox.removeAttribute("hasException");
       this.content.removeAttribute("hasException");
     }
 
     if (isBlocking && this.enabled) {
       if (isSimulated) {
         this.cancelAnimation();
       } else if (webProgress.isTopLevel) {
         this.iconBox.setAttribute("animate", "true");
--- a/browser/base/content/test/trackingUI/browser_trackingUI_state.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_state.js
@@ -67,16 +67,17 @@ function testBenignPage() {
   ok(hidden("#tracking-blocked"), "labelTrackingBlocked is hidden");
 }
 
 function testBenignPageWithException() {
   info("Non-tracking content must not be blocked");
   ok(!TrackingProtection.container.hidden, "The container is visible");
   ok(!TrackingProtection.content.hasAttribute("state"), "content: no state");
   ok(TrackingProtection.content.hasAttribute("hasException"), "content has exception attribute");
+  ok(TrackingProtection.iconBox.hasAttribute("hasException"), "icon box has exception attribute");
   ok(!TrackingProtection.iconBox.hasAttribute("state"), "icon box: no state");
   ok(!TrackingProtection.iconBox.hasAttribute("tooltiptext"), "icon box: no tooltip");
 
   let doc = tabbrowser.ownerGlobal.document;
   ok(BrowserTestUtils.is_hidden(doc.getElementById("tracking-protection-icon-box")), "icon box is hidden");
   is(!hidden("#tracking-action-block"), TrackingProtection.enabled,
      "blockButton is visible if TP is on");
   ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
@@ -94,16 +95,18 @@ function testTrackingPage(window) {
   info("Tracking content must be blocked");
   ok(!TrackingProtection.container.hidden, "The container is visible");
   is(TrackingProtection.content.getAttribute("state"), "blocked-tracking-content",
       'content: state="blocked-tracking-content"');
   is(TrackingProtection.iconBox.getAttribute("state"), "blocked-tracking-content",
       'icon box: state="blocked-tracking-content"');
   is(TrackingProtection.iconBox.getAttribute("tooltiptext"),
      gNavigatorBundle.getString("trackingProtection.icon.activeTooltip"), "correct tooltip");
+  ok(!TrackingProtection.content.hasAttribute("hasException"), "content has no exception attribute");
+  ok(!TrackingProtection.iconBox.hasAttribute("hasException"), "icon box has no exception attribute");
 
   let doc = tabbrowser.ownerGlobal.document;
   ok(BrowserTestUtils.is_visible(doc.getElementById("tracking-protection-icon-box")), "icon box is visible");
   ok(hidden("#tracking-action-block"), "blockButton is hidden");
   ok(!hidden("#tracking-protection-preferences-button"), "preferences button is visible");
 
 
   if (PrivateBrowsingUtils.isWindowPrivate(window)) {
@@ -118,16 +121,20 @@ function testTrackingPage(window) {
   ok(hidden("#tracking-not-detected"), "labelNoTracking is hidden");
   ok(hidden("#tracking-loaded"), "labelTrackingLoaded is hidden");
   ok(hidden("#tracking-loaded-exception"), "labelTrackingLoadedException is hidden");
   ok(!hidden("#tracking-blocked"), "labelTrackingBlocked is visible");
 }
 
 function testTrackingPageUnblocked() {
   info("Tracking content must be white-listed and not blocked");
+  is(TrackingProtection.content.hasAttribute("hasException"), TrackingProtection.enabled,
+    "content has exception attribute if TP is on");
+  is(TrackingProtection.iconBox.hasAttribute("hasException"), TrackingProtection.enabled,
+    "icon box has exception attribute if TP is on");
   ok(!TrackingProtection.container.hidden, "The container is visible");
   is(TrackingProtection.content.getAttribute("state"), "loaded-tracking-content",
       'content: state="loaded-tracking-content"');
   if (TrackingProtection.enabled) {
     is(TrackingProtection.iconBox.getAttribute("state"), "loaded-tracking-content",
         'icon box: state="loaded-tracking-content"');
     is(TrackingProtection.iconBox.getAttribute("tooltiptext"),
        gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), "correct tooltip");
--- a/browser/themes/shared/controlcenter/panel.inc.css
+++ b/browser/themes/shared/controlcenter/panel.inc.css
@@ -337,25 +337,25 @@ description#identity-popup-content-verif
 }
 
 /* Show the right tracking descriptions and buttons for the corresponding state. */
 
 /* Default state / Tracking not detected */
 #tracking-protection-content:not([state]):-moz-any([enabled="false"], :not([hasException])) > #tracking-not-detected,
 #tracking-protection-content:not([state])[enabled="true"][hasException] > #tracking-not-detected-exception,
 /* Blocking tracking, offer buttons to unblock (depending on PBM). */
-#tracking-protection-content[state="blocked-tracking-content"] > #tracking-blocked,
-#main-window:not([privatebrowsingmode]) #tracking-protection-content[state="blocked-tracking-content"] > #tracking-action-unblock,
+#tracking-protection-content:not([hasException])[state="blocked-tracking-content"] > #tracking-blocked,
+#main-window:not([privatebrowsingmode]) #tracking-protection-content:not([hasException])[state="blocked-tracking-content"] > #tracking-action-unblock,
 #main-window[privatebrowsingmode] #tracking-protection-content[state="blocked-tracking-content"] > #tracking-action-unblock-private,
 /* Enabled and no exception but trackers loaded, probably needs a reload */
 #tracking-protection-content[enabled="true"]:not([hasException])[state="loaded-tracking-content"] > #tracking-reload-required,
 #tracking-protection-content[enabled="true"]:not([hasException])[state="loaded-tracking-content"] > #tracking-action-reload,
 /* Tracking Loaded */
 #tracking-protection-content[state="loaded-tracking-content"][enabled="false"] > #tracking-loaded,
-#tracking-protection-content[state="loaded-tracking-content"][enabled="true"][hasException] > #tracking-loaded-exception,
+#tracking-protection-content[enabled="true"][hasException] > #tracking-loaded-exception,
 /* Has an exception, offer to block the site again. */
 #tracking-protection-content[enabled="true"][hasException] > #tracking-action-block {
   display: -moz-box;
 }
 
 /* PERMISSIONS */
 
 #identity-popup-permissions-content {
--- a/browser/themes/shared/identity-block/identity-block.inc.css
+++ b/browser/themes/shared/identity-block/identity-block.inc.css
@@ -158,31 +158,31 @@
   margin-inline-end: 0px;
   visibility: visible;
 }
 
 #tracking-protection-icon-box[animationsenabled][animate] {
   transition: margin-left 200ms ease-out, margin-right 200ms ease-out;
 }
 
-#tracking-protection-icon-box[state="blocked-tracking-content"][animationsenabled] > #tracking-protection-icon,
+#tracking-protection-icon-box:not([hasException])[state="blocked-tracking-content"][animationsenabled] > #tracking-protection-icon,
 #tracking-protection-icon-box:not([animationsenabled]) > #tracking-protection-icon-animatable-box {
   display: none;
 }
 
 #tracking-protection-icon-box > #tracking-protection-icon-animatable-box {
   position: absolute;
   overflow: hidden;
   top: calc(50% - 10px); /* half the height of the sprite */
   margin-inline-start: 4px;
   width: 16px;
   height: 20px;
 }
 
-#tracking-protection-icon-box[state="blocked-tracking-content"] #tracking-protection-icon-animatable-image {
+#tracking-protection-icon-box:not([hasException])[state="blocked-tracking-content"] #tracking-protection-icon-animatable-image {
   background-image: url(chrome://browser/skin/tracking-protection-animation.svg);
   transform: translateX(-1232px);
   width: 1248px;
   background-size: auto;
   height: 16px;
   min-height: 20px;
   -moz-context-properties: fill, fill-opacity;
 }
@@ -201,16 +201,19 @@
 #tracking-protection-icon-box[state="blocked-tracking-content"][animate] #tracking-protection-icon-animatable-image:-moz-locale-dir(rtl) {
   animation-name: tp-icon-animation-rtl;
 }
 
 #tracking-protection-icon-box[state="blocked-tracking-content"] > #tracking-protection-icon {
   list-style-image: url(chrome://browser/skin/tracking-protection.svg);
 }
 
+/* Override the blocked tracking content rule for cases when the user has added an exception
+ * on a different tab to signify that protection is disabled now */
+#tracking-protection-icon-box[hasException][state="blocked-tracking-content"] > #tracking-protection-icon,
 #tracking-protection-icon-box[state="loaded-tracking-content"] > #tracking-protection-icon {
   list-style-image: url(chrome://browser/skin/tracking-protection-disabled.svg);
 }
 
 #urlbar[pageproxystate="invalid"] > #identity-box > #extension-icon,
 #urlbar[pageproxystate="invalid"] > #identity-box > #tracking-protection-icon-box {
   visibility: collapse;
 }