Bug 1487300 - Restore the state of the tracking protection menu when All Detected Trackers is checked after being previously unchecked; r=johannh

Differential Revision: https://phabricator.services.mozilla.com/D4993
This commit is contained in:
Ehsan Akhgari 2018-09-04 19:41:59 -04:00
Родитель 316ef3ba2c
Коммит ed6f913e5d
2 изменённых файлов: 43 добавлений и 0 удалений

Просмотреть файл

@ -76,6 +76,11 @@ Preferences.addAll([
// Tracking Protection
{ id: "privacy.trackingprotection.enabled", type: "bool" },
{ id: "privacy.trackingprotection.pbmode.enabled", type: "bool" },
// This isn't a configuration pref, rather it's for saving the previous state
// of the UI when we turn off the TP controls when the user checks off the
// All Detected Trackers under Content Blocking. This pref isn't listed in
// all.js/firefox.js to make sure it doesn't appear in about:config by default.
{ id: "browser.privacy.trackingprotection.menu", type: "string" },
// Button prefs
{ id: "pref.privacy.disable_button.cookie_exceptions", type: "bool" },
@ -703,6 +708,7 @@ var gPrivacyPane = {
trackingProtectionReadPrefs() {
let enabledPref = Preferences.get("privacy.trackingprotection.enabled");
let pbmPref = Preferences.get("privacy.trackingprotection.pbmode.enabled");
let btpmPref = Preferences.get("browser.privacy.trackingprotection.menu");
let tpControl,
tpCheckbox;
if (contentBlockingUiEnabled) {
@ -712,6 +718,16 @@ var gPrivacyPane = {
tpControl = document.getElementById("trackingProtectionRadioGroup");
}
let savedMenuValue;
if (contentBlockingUiEnabled) {
// Only look at the backup pref when restoring the checkbox next to
// "All Detected Trackers".
if (["always", "private"].includes(btpmPref.value) &&
tpCheckbox.checked) {
savedMenuValue = btpmPref.value;
}
}
this._updateTrackingProtectionUI();
// Global enable takes precedence over enabled in Private Browsing.
@ -728,6 +744,9 @@ var gPrivacyPane = {
} else if (!tpCheckbox) {
tpControl.value = "never";
} else {
if (savedMenuValue) {
tpControl.value = savedMenuValue;
}
tpCheckbox.checked = false;
}
},
@ -785,6 +804,7 @@ var gPrivacyPane = {
trackingProtectionWritePrefs() {
let enabledPref = Preferences.get("privacy.trackingprotection.enabled");
let pbmPref = Preferences.get("privacy.trackingprotection.pbmode.enabled");
let btpmPref = Preferences.get("browser.privacy.trackingprotection.menu");
let tpControl,
tpCheckbox;
if (contentBlockingUiEnabled) {
@ -798,6 +818,7 @@ var gPrivacyPane = {
if (tpCheckbox) {
if (tpCheckbox.checked) {
value = tpControl.value;
btpmPref.value = value;
} else {
value = "never";
}

Просмотреть файл

@ -111,6 +111,13 @@ add_task(async function testContentBlockingMainCategory() {
tpCheckbox.checked = true;
// Select "Always" under "All Detected Trackers".
let always = doc.querySelector("#trackingProtectionMenu > radio[value=always]");
let private = doc.querySelector("#trackingProtectionMenu > radio[value=private]");
always.radioGroup.selectedItem = always;
ok(!private.selected, "The Only in private windows item should not be selected");
ok(always.selected, "The Always item should be selected");
// The first time, privacy-pane-tp-ui-updated won't be dispatched since the
// assignment above is a no-op.
@ -128,6 +135,21 @@ add_task(async function testContentBlockingMainCategory() {
checkControlStateWorker(doc, dependentControls, false);
checkControlStateWorker(doc, alwaysEnabledControls, true);
// Make sure the selection in the tracking protection submenu persists after
// a few times of checking and unchecking All Detected Trackers.
// Doing this in a loop in order to avoid typing in the unrolled version manually.
// We need to go from the checked state of the checkbox to unchecked back to
// checked again...
for (let i = 0; i < 3; ++i) {
promise = TestUtils.topicObserved("privacy-pane-tp-ui-updated");
EventUtils.synthesizeMouseAtCenter(tpCheckbox, {}, doc.defaultView);
await promise;
is(tpCheckbox.checked, i % 2 == 0, "The checkbox should now be unchecked");
ok(!private.selected, "The Only in private windows item should still not be selected");
ok(always.selected, "The Always item should still be selected");
}
gBrowser.removeCurrentTab();
for (let pref of prefs) {