Bug 1526793 - always prompt for restart when toggling permanent private browsing mode, r=jaws a=lizzard
Differential Revision:
https://phabricator.services.mozilla.com/D19313
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -835,20 +835,24 @@ var gPrivacyPane = {
},
// PRIVATE BROWSING
/**
* Initialize the starting state for the auto-start private browsing mode pref reverter.
*/
initAutoStartPrivateBrowsingReverter() {
+ // We determine the mode in initializeHistoryMode, which is guaranteed to have been
+ // called before now, so this is up-to-date.
let mode = document.getElementById("historyMode");
- let autoStart = document.getElementById("privateBrowsingAutoStart");
this._lastMode = mode.selectedIndex;
- this._lastCheckState = autoStart.hasAttribute("checked");
+ // The value of the autostart pref, on the other hand, is gotten from Preferences,
+ // which updates the DOM asynchronously, so we can't rely on the DOM. Get it directly
+ // from the prefs.
+ this._lastCheckState = Preferences.get("browser.privatebrowsing.autostart").value;
},
_lastMode: null,
_lastCheckState: null,
async updateAutostart() {
let mode = document.getElementById("historyMode");
let autoStart = document.getElementById("privateBrowsingAutoStart");
let pref = Preferences.get("browser.privatebrowsing.autostart");
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -86,12 +86,13 @@ skip-if = e10s
support-files =
subdialog.xul
subdialog2.xul
[browser_sync_sanitize.js]
skip-if = os == 'win' && processor == "x86_64" && bits == 64 # bug 1522821
[browser_telemetry.js]
# Skip this test on Android as FHR and Telemetry are separate systems there.
skip-if = !healthreport || !telemetry || (os == 'linux' && debug) || (os == 'android')
+[browser_warning_permanent_private_browsing.js]
[browser_containers_name_input.js]
run-if = nightly_build # Containers is enabled only on Nightly
[browser_fluent.js]
[browser_hometab_restore_defaults.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_warning_permanent_private_browsing.js
@@ -0,0 +1,45 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+function checkForPrompt(prefVal) {
+ return async function() {
+ await SpecialPowers.pushPrefEnv({set: [
+ ["privacy.history.custom", true],
+ ["browser.privatebrowsing.autostart", !prefVal],
+ ]});
+
+ await openPreferencesViaOpenPreferencesAPI("panePrivacy", { leaveOpen: true });
+ let doc = gBrowser.contentDocument;
+ is(doc.getElementById("historyMode").value, "custom", "Expect custom history mode");
+
+ // Stub out the prompt method as an easy way to check it was shown. We throw away
+ // the tab straight after so don't need to bother restoring it.
+ let promptFired = false;
+ doc.defaultView.confirmRestartPrompt = () => {
+ promptFired = true;
+ return doc.defaultView.CONFIRM_RESTART_PROMPT_RESTART_NOW;
+ };
+ // Tick the checkbox and pretend the user did it:
+ let checkbox = doc.getElementById("privateBrowsingAutoStart");
+ checkbox.checked = prefVal;
+ checkbox.doCommand();
+
+ // Now the prompt should have shown.
+ ok(promptFired,
+ `Expect a prompt when turning permanent private browsing ${prefVal ? "on" : "off"}!`);
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+ };
+}
+
+/**
+ * Check we show the prompt if the permanent private browsing pref is false
+ * and we flip the checkbox to true.
+ */
+add_task(checkForPrompt(true));
+
+/**
+ * Check it works in the other direction:
+ */
+add_task(checkForPrompt(false));