Bug 1487396 - Part 3: Test that before enabling tracking protection, the shield doesn't show up unless tracking elements are blocked; r=johannh
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 31 Aug 2018 23:36:16 -0400
changeset 492368 a58913ee3875e57a398f09ed822f7da576c37ea6
parent 492367 71ebf84e6d78808a129b7d4972a5f7f097001dba
child 492369 7897af38e4650329ab5e7b85fda7dccf067d0391
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1487396
milestone63.0
Bug 1487396 - Part 3: Test that before enabling tracking protection, the shield doesn't show up unless tracking elements are blocked; r=johannh Differential Revision: https://phabricator.services.mozilla.com/D4814
browser/base/content/test/trackingUI/browser_trackingUI_state.js
--- a/browser/base/content/test/trackingUI/browser_trackingUI_state.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_state.js
@@ -93,71 +93,91 @@ function testBenignPageWithException() {
   ok(!hidden("#identity-popup-content-blocking-not-detected"), "blocking not detected label is visible");
   ok(hidden("#identity-popup-content-blocking-detected"), "blocking detected label is hidden");
 
   if (Services.prefs.getBoolPref(CB_UI_PREF)) {
     ok(hidden("#identity-popup-content-blocking-category-list"), "category list is hidden");
   }
 }
 
+function areTrackersBlocked(isPrivateBrowsing) {
+  let cbEnabled = Services.prefs.getBoolPref(CB_PREF);
+  let blockedByTP = cbEnabled &&
+                    Services.prefs.getBoolPref(isPrivateBrowsing ? TP_PB_PREF : TP_PREF);
+  return blockedByTP;
+}
+
 function testTrackingPage(window) {
   info("Tracking content must be blocked");
   ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
   ok(!ContentBlocking.content.hasAttribute("hasException"), "content shows no exception");
 
-  ok(BrowserTestUtils.is_visible(ContentBlocking.iconBox), "icon box is visible");
-  ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
+  let isPrivateBrowsing = PrivateBrowsingUtils.isWindowPrivate(window);
+  let blockedByTP = areTrackersBlocked(isPrivateBrowsing);
+  is(BrowserTestUtils.is_visible(ContentBlocking.iconBox), blockedByTP,
+     "icon box is" + (blockedByTP ? "" : " not") + " visible");
+  is(ContentBlocking.iconBox.hasAttribute("active"), blockedByTP,
+      "shield is" + (blockedByTP ? "" : " not") + " active");
   ok(!ContentBlocking.iconBox.hasAttribute("hasException"), "icon box shows no exception");
   is(ContentBlocking.iconBox.getAttribute("tooltiptext"),
-     gNavigatorBundle.getString("trackingProtection.icon.activeTooltip"), "correct tooltip");
+     blockedByTP ? gNavigatorBundle.getString("trackingProtection.icon.activeTooltip") : "",
+     "correct tooltip");
 
   ok(hidden("#tracking-action-block"), "blockButton is hidden");
 
+  let cbEnabled = Services.prefs.getBoolPref(CB_PREF);
   if (PrivateBrowsingUtils.isWindowPrivate(window)) {
     ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
-    ok(!hidden("#tracking-action-unblock-private"), "unblockButtonPrivate is visible");
+    is(hidden("#tracking-action-unblock-private"), !cbEnabled,
+       "unblockButtonPrivate is" + (cbEnabled ? "" : " not") + " visible");
   } else {
     ok(!hidden("#tracking-action-unblock"), "unblockButton is visible");
-    ok(hidden("#tracking-action-unblock-private"), "unblockButtonPrivate is hidden");
+    is(hidden("#tracking-action-unblock-private"), cbEnabled,
+       "unblockButtonPrivate is" + (cbEnabled ? "" : " not") + " hidden");
   }
 
   ok(hidden("#identity-popup-content-blocking-not-detected"), "blocking not detected label is hidden");
   ok(!hidden("#identity-popup-content-blocking-detected"), "blocking detected label is visible");
 
   if (Services.prefs.getBoolPref(CB_UI_PREF)) {
     ok(!hidden("#identity-popup-content-blocking-category-list"), "category list is visible");
-    ok(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-add-blocking"),
-      "TP category item is not showing add blocking");
-    ok(!hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-state-label"),
-      "TP category item is set to blocked");
+    is(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-add-blocking"), blockedByTP,
+      "TP category item is" + (blockedByTP ? " not" : "") + " showing add blocking");
+    is(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-state-label"), !blockedByTP,
+      "TP category item is" + (blockedByTP ? "" : " not") + " set to blocked");
   }
 }
 
-function testTrackingPageUnblocked() {
+function testTrackingPageUnblocked(blockedByTP) {
   info("Tracking content must be white-listed and not blocked");
   ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
   ok(ContentBlocking.content.hasAttribute("hasException"), "content shows exception");
 
+  let cbEnabled = Services.prefs.getBoolPref(CB_PREF);
   ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
-  ok(ContentBlocking.iconBox.hasAttribute("hasException"), "shield shows exception");
+  is(ContentBlocking.iconBox.hasAttribute("hasException"), cbEnabled,
+     "shield" + (cbEnabled ? " shows" : " doesn't show") + " exception");
   is(ContentBlocking.iconBox.getAttribute("tooltiptext"),
      gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), "correct tooltip");
 
-  ok(BrowserTestUtils.is_visible(ContentBlocking.iconBox), "icon box is visible");
-  ok(!hidden("#tracking-action-block"), "blockButton is visible");
+  is(BrowserTestUtils.is_visible(ContentBlocking.iconBox), cbEnabled,
+     "icon box is" + (cbEnabled ? "" : " not") + " visible");
+  is(hidden("#tracking-action-block"), !cbEnabled,
+     "blockButton is" + (cbEnabled ? " not" : "") + " visible");
   ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
   ok(!hidden("#identity-popup-content-blocking-disabled-label"), "disabled label is visible");
 
   ok(hidden("#identity-popup-content-blocking-not-detected"), "blocking not detected label is hidden");
   ok(!hidden("#identity-popup-content-blocking-detected"), "blocking detected label is visible");
 
   if (Services.prefs.getBoolPref(CB_UI_PREF)) {
     ok(!hidden("#identity-popup-content-blocking-category-list"), "category list is visible");
-    ok(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-add-blocking"),
-      "TP category item is not showing add blocking");
+    is(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-add-blocking"), blockedByTP,
+      "TP category item is" + (blockedByTP ? " not" : "") + " showing add blocking");
+    // Always hidden no matter if blockedByTP or not, since we have an exception.
     ok(hidden("#identity-popup-content-blocking-category-tracking-protection > .identity-popup-content-blocking-category-state-label"),
       "TP category item is not set to blocked");
   }
 }
 
 function testTrackingPageWithCBDisabled() {
   info("Tracking content must be white-listed and not blocked");
   ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
@@ -212,17 +232,18 @@ async function testContentBlockingEnable
   info("Load a test page containing tracking elements");
   await promiseTabLoadEvent(tab, TRACKING_PAGE);
   testTrackingPage(tab.ownerGlobal);
 
   info("Disable CB for the page (which reloads the page)");
   let tabReloadPromise = promiseTabLoadEvent(tab);
   clickButton("#tracking-action-unblock");
   await tabReloadPromise;
-  testTrackingPageUnblocked();
+  let blockedByTP = areTrackersBlocked(isPrivateBrowsing);
+  testTrackingPageUnblocked(blockedByTP);
 
   info("Re-enable TP for the page (which reloads the page)");
   tabReloadPromise = promiseTabLoadEvent(tab);
   clickButton("#tracking-action-block");
   await tabReloadPromise;
   testTrackingPage(tab.ownerGlobal);
 }
 
@@ -264,16 +285,28 @@ add_task(async function testNormalBrowsi
 
   ContentBlocking = gBrowser.ownerGlobal.ContentBlocking;
   ok(ContentBlocking, "CB is attached to the browser window");
   TrackingProtection = gBrowser.ownerGlobal.TrackingProtection;
   ok(TrackingProtection, "TP is attached to the browser window");
   is(TrackingProtection.enabled, Services.prefs.getBoolPref(TP_PREF),
      "TP.enabled is based on the original pref value");
 
+  await testContentBlockingEnabled(tab);
+
+  if (Services.prefs.getBoolPref(CB_UI_PREF)) {
+    Services.prefs.setBoolPref(CB_PREF, false);
+    ok(!ContentBlocking.enabled, "CB is disabled after setting the pref");
+  } else {
+    Services.prefs.setBoolPref(TP_PREF, false);
+    ok(!TrackingProtection.enabled, "TP is disabled after setting the pref");
+  }
+
+  await testContentBlockingDisabled(tab);
+
   Services.prefs.setBoolPref(TP_PREF, true);
   ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
   Services.prefs.setBoolPref(CB_PREF, true);
   ok(ContentBlocking.enabled, "CB is enabled after setting the pref");
 
   await testContentBlockingEnabled(tab);
 
   if (Services.prefs.getBoolPref(CB_UI_PREF)) {
@@ -299,16 +332,28 @@ add_task(async function testPrivateBrows
 
   ContentBlocking = tabbrowser.ownerGlobal.ContentBlocking;
   ok(ContentBlocking, "CB is attached to the private window");
   TrackingProtection = tabbrowser.ownerGlobal.TrackingProtection;
   ok(TrackingProtection, "TP is attached to the private window");
   is(TrackingProtection.enabled, Services.prefs.getBoolPref(TP_PB_PREF),
      "TP.enabled is based on the pb pref value");
 
+  await testContentBlockingEnabled(tab);
+
+  if (Services.prefs.getBoolPref(CB_UI_PREF)) {
+    Services.prefs.setBoolPref(CB_PREF, false);
+    ok(!ContentBlocking.enabled, "CB is disabled after setting the pref");
+  } else {
+    Services.prefs.setBoolPref(TP_PREF, false);
+    ok(!TrackingProtection.enabled, "TP is disabled after setting the pref");
+  }
+
+  await testContentBlockingDisabled(tab);
+
   Services.prefs.setBoolPref(TP_PB_PREF, true);
   ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
   Services.prefs.setBoolPref(CB_PREF, true);
   ok(TrackingProtection.enabled, "CB is enabled after setting the pref");
 
   await testContentBlockingEnabled(tab);
 
   if (Services.prefs.getBoolPref(CB_UI_PREF)) {