Bug 1524995 - update privacy pane history mode dependent control checkboxes correctly in permanent private browsing mode, r=jaws a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 08 Feb 2019 15:43:58 +0000
changeset 515883 a61f757afab3036bd346a8e1dff36fadafb12fc3
parent 515882 49a04a5d8d979f1d8b90352c675d22a91f17fcdb
child 515884 d9a3fc93437f01530bc58ddf984e75837994cd57
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, lizzard
bugs1524995
milestone66.0
Bug 1524995 - update privacy pane history mode dependent control checkboxes correctly in permanent private browsing mode, r=jaws a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D19144
browser/components/preferences/in-content/privacy.js
browser/components/preferences/in-content/privacy.xul
browser/components/preferences/in-content/tests/privacypane_tests_perwindow.js
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -733,52 +733,55 @@ var gPrivacyPane = {
     // Check the "Delete cookies when Firefox is closed" checkbox and disable the setting
     // when we're in auto private mode (or reset it back otherwise).
     document.getElementById("deleteOnClose").checked = this.readDeleteOnClose();
 
     let clearDataSettings = document.getElementById("clearDataSettings");
 
     if (document.getElementById("historyMode").value == "custom") {
       let disabled = Preferences.get("browser.privatebrowsing.autostart").value;
-      this.dependentControls.forEach(function(aElement) {
+      this.dependentControls.forEach(aElement => {
         let control = document.getElementById(aElement);
         let preferenceId = control.getAttribute("preference");
         if (!preferenceId) {
           let dependentControlId = control.getAttribute("control");
           if (dependentControlId) {
             let dependentControl = document.getElementById(dependentControlId);
             preferenceId = dependentControl.getAttribute("preference");
           }
         }
 
         let preference = preferenceId ? Preferences.get(preferenceId) : {};
         control.disabled = disabled || preference.locked;
+        if (control != clearDataSettings) {
+          this.ensurePrivacyMicroControlUncheckedWhenDisabled(control);
+        }
       });
 
       clearDataSettings.removeAttribute("hidden");
 
-      // adjust the checked state of the sanitizeOnShutdown checkbox
-      document.getElementById("alwaysClear").checked = disabled ? false :
-        Preferences.get("privacy.sanitize.sanitizeOnShutdown").value;
-
-      // adjust the checked state of the remember history checkboxes
-      document.getElementById("rememberHistory").checked = disabled ? false :
-        Preferences.get("places.history.enabled").value;
-      document.getElementById("rememberForms").checked = disabled ? false :
-        Preferences.get("browser.formfill.enable").value;
-
       if (!disabled) {
         // adjust the Settings button for sanitizeOnShutdown
         this._updateSanitizeSettingsButton();
       }
     } else {
       clearDataSettings.setAttribute("hidden", "true");
     }
   },
 
+  ensurePrivacyMicroControlUncheckedWhenDisabled(el) {
+    if (Preferences.get("browser.privatebrowsing.autostart").value) {
+      // Set checked to false when called from updatePrivacyMicroControls
+      el.checked = false;
+      // return false for the onsyncfrompreference case:
+      return false;
+    }
+    return undefined; // tell preferencesBindings to assign the 'right' value.
+  },
+
   // CLEAR PRIVATE DATA
 
   /*
    * Preferences:
    *
    * privacy.sanitize.sanitizeOnShutdown
    * - true if the user's private data is cleared on startup according to the
    *   Clear Private Data settings, false otherwise
--- a/browser/components/preferences/in-content/privacy.xul
+++ b/browser/components/preferences/in-content/privacy.xul
@@ -376,24 +376,27 @@
       <vbox id="historyCustomPane">
         <vbox>
           <checkbox id="privateBrowsingAutoStart"
                     data-l10n-id="history-private-browsing-permanent"
                     preference="browser.privatebrowsing.autostart"/>
           <vbox class="indent">
             <checkbox id="rememberHistory"
                       data-l10n-id="history-remember-browser-option"
+                      onsyncfrompreference="return gPrivacyPane.ensurePrivacyMicroControlUncheckedWhenDisabled(this)"
                       preference="places.history.enabled"/>
             <checkbox id="rememberForms"
                       data-l10n-id="history-remember-search-option"
+                      onsyncfrompreference="return gPrivacyPane.ensurePrivacyMicroControlUncheckedWhenDisabled(this)"
                       preference="browser.formfill.enable"/>
             <hbox id="clearDataBox"
                   align="center">
               <checkbox id="alwaysClear"
                         preference="privacy.sanitize.sanitizeOnShutdown"
+                        onsyncfrompreference="return gPrivacyPane.ensurePrivacyMicroControlUncheckedWhenDisabled(this)"
                         data-l10n-id="history-clear-on-close-option"
                         flex="1" />
             </hbox>
           </vbox>
         </vbox>
       </vbox>
     </deck>
     <vbox id="historyButtons" align="end">
--- a/browser/components/preferences/in-content/tests/privacypane_tests_perwindow.js
+++ b/browser/components/preferences/in-content/tests/privacypane_tests_perwindow.js
@@ -3,17 +3,17 @@
 
 async function runTestOnPrivacyPrefPane(testFunc) {
   info("runTestOnPrivacyPrefPane entered");
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:preferences", true, true);
   let browser = tab.linkedBrowser;
   info("loaded about:preferences");
   browser.contentWindow.gotoPref("panePrivacy");
   info("viewing privacy pane, executing testFunc");
-  testFunc(browser.contentWindow);
+  await testFunc(browser.contentWindow);
   BrowserTestUtils.removeTab(tab);
 }
 
 function controlChanged(element) {
   element.doCommand();
 }
 
 // We can only test the panes that don't trigger a preference update
@@ -200,17 +200,17 @@ function test_dependent_clearonclose_ele
   controlChanged(alwaysclear);
   expect_disabled(false);
 
   alwaysclear.checked = false;
   controlChanged(alwaysclear);
   expect_disabled(true);
 }
 
-function test_dependent_prefs(win) {
+async function test_dependent_prefs(win) {
   let historymode = win.document.getElementById("historyMode");
   ok(historymode, "history mode menulist should exist");
   let controls = [
     win.document.getElementById("rememberHistory"),
     win.document.getElementById("rememberForms"),
   ];
   controls.forEach(function(control) {
     ok(control, "the micro-management controls should exist");
@@ -221,16 +221,18 @@ function test_dependent_prefs(win) {
       is(control.checked, checked,
         control.getAttribute("id") + " should " + (checked ? "" : "not ") + "be checked");
     });
   }
 
   // controls should be checked in remember mode
   historymode.value = "remember";
   controlChanged(historymode);
+  // Initial updates from prefs are not sync, so wait:
+  await TestUtils.waitForCondition(() => controls[0].getAttribute("checked") == "true");
   expect_checked(true);
 
   // even if they're unchecked in custom mode
   historymode.value = "custom";
   controlChanged(historymode);
   controls.forEach(function(control) {
     control.checked = false;
     controlChanged(control);