Bug 1487434 - Ensure that the checkbox of the All Detected Trackers category is also disabled when TP is controlled by an extension; r=johannh
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 30 Aug 2018 11:32:29 -0400
changeset 434513 5a1f07f8ca7c538d3bcf18bfaf69383ab3e85c51
parent 434512 a3eb8e5020063cd518cb7028a0607286e01d50a0
child 434514 d14aaf65a80b3baddb193fa6707e4515e4a44609
child 434520 3c448cf1ddaf42117d9e54cc1f81bb8f05d30cc6
push id34563
push userdvarga@mozilla.com
push dateMon, 03 Sep 2018 21:54:32 +0000
treeherdermozilla-central@d14aaf65a80b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1487434
milestone63.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 1487434 - Ensure that the checkbox of the All Detected Trackers category is also disabled when TP is controlled by an extension; r=johannh This checkbox is non-functional in this state, so there is no point to it being enabled. Differential Revision: https://phabricator.services.mozilla.com/D4838
browser/components/preferences/in-content/privacy.js
browser/components/preferences/in-content/tests/browser_contentblocking.js
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -199,22 +199,23 @@ var gPrivacyPane = {
     let isLocked = TRACKING_PROTECTION_PREFS.some(
       pref => Services.prefs.prefIsLocked(pref));
 
     function setInputsDisabledState(isControlled) {
       let disabled = isLocked || isControlled;
       if (contentBlockingUiEnabled) {
         let tpCheckbox =
           document.getElementById("contentBlockingTrackingProtectionCheckbox");
-        if (!tpCheckbox.checked) {
-          disabled = true;
-        }
-        // Only enable the TP menu if content blocking is enabled.
+        // Only enable the TP menu if content blocking and Detect All Trackers
+        // are enabled.
         document.getElementById("trackingProtectionMenu").disabled = disabled ||
+          !tpCheckbox.checked ||
           !contentBlockingEnabled;
+        // Only enable the TP category checkbox if content blocking is enabled.
+        tpCheckbox.disabled = disabled || !contentBlockingEnabled;
       } else {
         document.querySelectorAll("#trackingProtectionRadioGroup > radio")
           .forEach((element) => {
             element.disabled = disabled;
           });
         document.querySelector("#trackingProtectionDesc > label")
           .disabled = disabled;
       }
--- a/browser/components/preferences/in-content/tests/browser_contentblocking.js
+++ b/browser/components/preferences/in-content/tests/browser_contentblocking.js
@@ -78,16 +78,47 @@ add_task(async function testContentBlock
 
   for (let selector of checkboxes) {
     let element = doc.querySelector(selector);
     ok(element, "checkbox " + selector + " exists");
     is(element.getAttribute("checked"), "true",
        "checkbox " + selector + " is checked");
   }
 
+  // Ensure the dependent controls of the tracking protection subsection behave properly.
+  let tpCheckbox = doc.querySelector(checkboxes[1]);
+
+  let dependentControls = [
+    "#trackingProtectionMenu",
+  ];
+  let alwaysEnabledControls = [
+    "#trackingProtectionMenuDesc",
+    ".content-blocking-category-name",
+    "#changeBlockListLink",
+  ];
+
+  tpCheckbox.checked = true;
+
+  // The first time, privacy-pane-tp-ui-updated won't be dispatched since the
+  // assignment above is a no-op.
+
+  // Ensure the dependent controls are enabled
+  checkControlStateWorker(doc, dependentControls, true);
+  checkControlStateWorker(doc, alwaysEnabledControls, true);
+
+  let promise = TestUtils.topicObserved("privacy-pane-tp-ui-updated");
+  EventUtils.synthesizeMouseAtCenter(tpCheckbox, {}, doc.defaultView);
+
+  await promise;
+  ok(!tpCheckbox.checked, "The checkbox should now be unchecked");
+
+  // Ensure the dependent controls are disabled
+  checkControlStateWorker(doc, dependentControls, false);
+  checkControlStateWorker(doc, alwaysEnabledControls, true);
+
   gBrowser.removeCurrentTab();
 });
 
 // Tests that the content blocking "Restore Defaults" button does what it's supposed to.
 add_task(async function testContentBlockingRestoreDefaults() {
   SpecialPowers.pushPrefEnv({set: [
     [CB_UI_PREF, true],
   ]});
@@ -165,16 +196,34 @@ add_task(async function testContentBlock
   for (let pref of resettable) {
     ok(Services.prefs.prefHasUserValue(pref), `modified the pref ${pref}`);
   }
 
   await extension.startup();
 
   await TestUtils.waitForCondition(() => Services.prefs.prefHasUserValue(TP_PREF));
 
+  let dependentControls = [
+    "#content-blocking-categories-label",
+    ".fast-block-ui .content-blocking-checkbox",
+    ".reject-trackers-ui .content-blocking-checkbox",
+    ".content-blocking-icon",
+    ".content-blocking-category-name",
+    "#changeBlockListLink",
+    "#contentBlockingChangeCookieSettings",
+    "#blockCookiesCB, #blockCookiesCB > radio",
+  ];
+  let alwaysDisabledControls = [
+    ".tracking-protection-ui .content-blocking-checkbox",
+    "#trackingProtectionMenu",
+    "[control=trackingProtectionMenu]",
+  ];
+
+  await doDependentControlChecks(dependentControls, alwaysDisabledControls);
+
   await openPreferencesViaOpenPreferencesAPI("privacy", {leaveOpen: true});
   let doc = gBrowser.contentDocument;
 
   let contentBlockingRestoreDefaults = doc.getElementById("contentBlockingRestoreDefaults");
   contentBlockingRestoreDefaults.click();
 
   for (let pref of resettable) {
     ok(!Services.prefs.prefHasUserValue(pref), `reset the pref ${pref}`);
@@ -306,26 +355,23 @@ add_task(async function testContentBlock
     [CB_RT_UI_PREF, true],
     [TP_PREF, false],
     [TP_PBM_PREF, false],
     [NCB_PREF, Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
   ]});
 
   let dependentControls = [
     "#content-blocking-categories-label",
-    ".content-blocking-checkbox",
-    ".content-blocking-icon",
-    ".content-blocking-category-name",
+    "[control=trackingProtectionMenu]",
     "#changeBlockListLink",
     "#contentBlockingChangeCookieSettings",
     "#blockCookiesCB, #blockCookiesCB > radio",
   ];
   let alwaysDisabledControls = [
     "#trackingProtectionMenu",
-    "[control=trackingProtectionMenu]",
   ];
 
   await doDependentControlChecks(dependentControls, alwaysDisabledControls);
 });
 
 
 // Checks that the granular controls are disabled or enabled depending on the master pref for CB
 // when the Cookies and Site Data section is set to block either "All Cookies" or "Cookies from