Bug 1488809 - Correctly account for non-CB-UI tracking protection cases in browser_trackingUI_state.js. r=Ehsan a=test-only
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 06 Sep 2018 14:57:39 +0000
changeset 492372 8d1e1d1ccc2ed4995c64ec3d6e0b2acc57a4108d
parent 492371 73fc28dd555bb87d1a51ac76d86b2499d9fcc83b
child 492373 f66a7bf843803609cba0746f2faa4c60d6da50d5
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)
reviewersEhsan, test-only
bugs1488809
milestone63.0
Bug 1488809 - Correctly account for non-CB-UI tracking protection cases in browser_trackingUI_state.js. r=Ehsan a=test-only Differential Revision: https://phabricator.services.mozilla.com/D5146
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
@@ -136,63 +136,69 @@ function testTrackingPage(window) {
       "shield is" + (blockedByTP ? "" : " not") + " active");
   ok(!ContentBlocking.iconBox.hasAttribute("hasException"), "icon box shows no exception");
   is(ContentBlocking.iconBox.getAttribute("tooltiptext"),
      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)) {
+  let isWindowPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
+  let cbUIEnabled = Services.prefs.getBoolPref(CB_UI_PREF);
+  let tpEnabled = isWindowPrivate ? Services.prefs.getBoolPref(TP_PB_PREF) : Services.prefs.getBoolPref(TP_PREF);
+  let blockingEnabled = cbUIEnabled ? Services.prefs.getBoolPref(CB_PREF) : tpEnabled;
+  if (isWindowPrivate) {
     ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
-    is(hidden("#tracking-action-unblock-private"), !cbEnabled,
-       "unblockButtonPrivate is" + (cbEnabled ? "" : " not") + " visible");
+    is(!hidden("#tracking-action-unblock-private"), blockingEnabled,
+       "unblockButtonPrivate is" + (blockingEnabled ? "" : " not") + " visible");
   } else {
-    ok(!hidden("#tracking-action-unblock"), "unblockButton is visible");
-    is(hidden("#tracking-action-unblock-private"), cbEnabled,
-       "unblockButtonPrivate is" + (cbEnabled ? "" : " not") + " hidden");
+    ok(hidden("#tracking-action-unblock-private"), "unblockButtonPrivate is hidden");
+    is(!hidden("#tracking-action-unblock"), blockingEnabled,
+       "unblockButton is" + (blockingEnabled ? "" : " 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)) {
+  if (cbUIEnabled) {
     ok(!hidden("#identity-popup-content-blocking-category-list"), "category list is visible");
     let category;
     if (Services.prefs.getBoolPref(FB_PREF)) {
       category = "#identity-popup-content-blocking-category-fastblock";
     } else {
       category = Services.prefs.getIntPref(TPC_PREF) == Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER ?
                    "#identity-popup-content-blocking-category-3rdpartycookies" :
                    "#identity-popup-content-blocking-category-tracking-protection";
     }
     is(hidden(category + " > .identity-popup-content-blocking-category-add-blocking"), blockedByTP,
       "Category item is" + (blockedByTP ? " not" : "") + " showing add blocking");
     is(hidden(category + " > .identity-popup-content-blocking-category-state-label"), !blockedByTP,
       "Category item is" + (blockedByTP ? "" : " not") + " set to blocked");
   }
 }
 
-function testTrackingPageUnblocked(blockedByTP) {
+function testTrackingPageUnblocked(blockedByTP, window) {
   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);
+  let isWindowPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
+  let cbUIEnabled = Services.prefs.getBoolPref(CB_UI_PREF);
+  let tpEnabled = isWindowPrivate ? Services.prefs.getBoolPref(TP_PB_PREF) : Services.prefs.getBoolPref(TP_PREF);
+  let blockingEnabled = cbUIEnabled ? Services.prefs.getBoolPref(CB_PREF) : tpEnabled;
   ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
-  is(ContentBlocking.iconBox.hasAttribute("hasException"), cbEnabled,
-     "shield" + (cbEnabled ? " shows" : " doesn't show") + " exception");
+  is(ContentBlocking.iconBox.hasAttribute("hasException"), blockingEnabled,
+     "shield" + (blockingEnabled ? " shows" : " doesn't show") + " exception");
   is(ContentBlocking.iconBox.getAttribute("tooltiptext"),
      gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), "correct tooltip");
 
-  is(BrowserTestUtils.is_visible(ContentBlocking.iconBox), cbEnabled,
-     "icon box is" + (cbEnabled ? "" : " not") + " visible");
-  is(hidden("#tracking-action-block"), !cbEnabled,
-     "blockButton is" + (cbEnabled ? " not" : "") + " visible");
+  is(BrowserTestUtils.is_visible(ContentBlocking.iconBox), blockingEnabled,
+     "icon box is" + (blockingEnabled ? "" : " not") + " visible");
+  is(hidden("#tracking-action-block"), !blockingEnabled,
+     "blockButton is" + (blockingEnabled ? " 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");
@@ -267,17 +273,17 @@ async function testContentBlockingEnable
   await promiseTabLoadEvent(tab, gTrackingPageURL);
   testTrackingPage(tab.ownerGlobal);
 
   info("Disable CB for the page (which reloads the page)");
   let tabReloadPromise = promiseTabLoadEvent(tab);
   clickButton("#tracking-action-unblock");
   await tabReloadPromise;
   let blockedByTP = areTrackersBlocked(isPrivateBrowsing);
-  testTrackingPageUnblocked(blockedByTP);
+  testTrackingPageUnblocked(blockedByTP, tab.ownerGlobal);
 
   info("Re-enable TP for the page (which reloads the page)");
   tabReloadPromise = promiseTabLoadEvent(tab);
   clickButton("#tracking-action-block");
   await tabReloadPromise;
   testTrackingPage(tab.ownerGlobal);
 }
 
@@ -378,17 +384,17 @@ add_task(async function testPrivateBrows
      "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);
+    Services.prefs.setBoolPref(TP_PB_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);