Bug 1543022 - do not show content blocking icon on about: pages when location change isSimulated. r=johannh
authorErica Wright <ewright@mozilla.com>
Tue, 16 Apr 2019 15:26:22 +0000
changeset 469686 d245ef38503c
parent 469685 a67dae409401
child 469687 3d5e46c5fd7c
push id35879
push usernerli@mozilla.com
push dateTue, 16 Apr 2019 22:01:48 +0000
treeherdermozilla-central@12a60898fdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1543022
milestone68.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 1543022 - do not show content blocking icon on about: pages when location change isSimulated. r=johannh onLocationChange does not get the simulated events. We need to be hiding the icon from the onContentBlockingEvent as it was before, since that seems to cover all of them. Differential Revision: https://phabricator.services.mozilla.com/D27166
browser/base/content/browser-contentblocking.js
browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js
--- a/browser/base/content/browser-contentblocking.js
+++ b/browser/base/content/browser-contentblocking.js
@@ -1076,33 +1076,33 @@ var ContentBlocking = {
   // This triggers from top level location changes.
   onLocationChange() {
     // Reset blocking and exception status so that we can send telemetry
     this.hadShieldState = false;
     let baseURI = this._baseURIForChannelClassifier;
 
     // Don't deal with about:, file: etc.
     if (!baseURI) {
-      this.iconBox.removeAttribute("animate");
-      this.iconBox.removeAttribute("active");
-      this.iconBox.removeAttribute("hasException");
       return;
     }
     // Add to telemetry per page load as a baseline measurement.
     this.fingerprintersHistogramAdd("pageLoad");
     this.cryptominersHistogramAdd("pageLoad");
     this.shieldHistogramAdd(0);
   },
 
   onContentBlockingEvent(event, webProgress, isSimulated) {
     let previousState = gBrowser.securityUI.contentBlockingEvent;
     let baseURI = this._baseURIForChannelClassifier;
 
     // Don't deal with about:, file: etc.
     if (!baseURI) {
+      this.iconBox.removeAttribute("animate");
+      this.iconBox.removeAttribute("active");
+      this.iconBox.removeAttribute("hasException");
       return;
     }
 
     let anyDetected = false;
     let anyBlocking = false;
 
     for (let blocker of this.blockers) {
       // Store data on whether the blocker is activated in the current document for
--- a/browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js
@@ -1,14 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const TP_PREF = "privacy.trackingprotection.enabled";
 const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
 const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
+const ABOUT_PAGE = "about:preferences";
 
 /* This asserts that the content blocking event state is correctly reset
  * when navigating to a new location, and that the user is correctly
  * reset when switching between tabs. */
 
 add_task(async function testResetOnLocationChange() {
   Services.prefs.setBoolPref(TP_PREF, true);
 
@@ -40,8 +41,37 @@ add_task(async function testResetOnLocat
   is(browser.securityUI.contentBlockingEvent, 0, "Benign page has no content blocking event");
   ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active");
 
   gBrowser.removeTab(trackingTab);
   gBrowser.removeTab(tab);
 
   Services.prefs.clearUserPref(TP_PREF);
 });
+
+/* Test that the content blocking icon is correctly reset
+ * when changing tabs or navigating to an about: page */
+add_task(async function testResetOnTabChange() {
+  Services.prefs.setBoolPref(TP_PREF, true);
+
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, ABOUT_PAGE);
+  ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active");
+
+  await Promise.all([promiseTabLoadEvent(tab, TRACKING_PAGE),
+                     waitForContentBlockingEvent(3)]);
+  ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
+
+  await promiseTabLoadEvent(tab, ABOUT_PAGE);
+  ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active");
+
+  let contentBlockingEvent = waitForContentBlockingEvent(3);
+  let trackingTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TRACKING_PAGE);
+  await contentBlockingEvent;
+  ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
+
+  gBrowser.selectedTab = tab;
+  ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active");
+
+  gBrowser.removeTab(trackingTab);
+  gBrowser.removeTab(tab);
+
+  Services.prefs.clearUserPref(TP_PREF);
+});