Bug 1916813 - visibly disable the studies checkbox if telemetry upload is disabled to reflect reality, r=mossop,settings-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D221328
This commit is contained in:
Gijs Kruitbosch 2024-09-18 12:18:43 +00:00
Родитель e187818d25
Коммит cc1b561bb5
3 изменённых файлов: 58 добавлений и 17 удалений

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

@ -971,7 +971,7 @@
#endif
#ifdef MOZ_NORMANDY
<hbox align="center">
<hbox align="center" class="indent">
<checkbox id="optOutStudiesEnabled"
class="tail-with-learn-more"
data-l10n-id="collection-studies"/>

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

@ -3521,22 +3521,27 @@ var gPrivacyPane = {
const allowedByPolicy = Services.policies.isAllowed("Shield");
const checkbox = document.getElementById("optOutStudiesEnabled");
if (
allowedByPolicy &&
Services.prefs.getBoolPref(PREF_NORMANDY_ENABLED, false)
) {
if (Services.prefs.getBoolPref(PREF_OPT_OUT_STUDIES_ENABLED, false)) {
checkbox.setAttribute("checked", "true");
function updateCheckbox() {
if (
allowedByPolicy &&
Services.prefs.getBoolPref(PREF_UPLOAD_ENABLED, false) &&
Services.prefs.getBoolPref(PREF_NORMANDY_ENABLED, false)
) {
if (Services.prefs.getBoolPref(PREF_OPT_OUT_STUDIES_ENABLED, false)) {
checkbox.setAttribute("checked", "true");
} else {
checkbox.removeAttribute("checked");
}
checkbox.setAttribute("preference", PREF_OPT_OUT_STUDIES_ENABLED);
checkbox.removeAttribute("disabled");
} else {
checkbox.removeAttribute("preference");
checkbox.removeAttribute("checked");
checkbox.setAttribute("disabled", "true");
}
checkbox.setAttribute("preference", PREF_OPT_OUT_STUDIES_ENABLED);
checkbox.removeAttribute("disabled");
} else {
checkbox.removeAttribute("preference");
checkbox.removeAttribute("checked");
checkbox.setAttribute("disabled", "true");
}
Preferences.get(PREF_UPLOAD_ENABLED).on("change", updateCheckbox);
updateCheckbox();
},
initAddonRecommendationsCheckbox() {

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

@ -1,6 +1,7 @@
"use strict";
const OPT_OUT_PREF = "app.shield.optoutstudies.enabled";
const TELEMETRY_UPLOAD_PREF = "datareporting.healthreport.uploadEnabled";
function withPrivacyPrefs() {
return function (testFunc) {
@ -13,7 +14,10 @@ function withPrivacyPrefs() {
decorate_task(
withPrefEnv({
set: [[OPT_OUT_PREF, true]],
set: [
[OPT_OUT_PREF, true],
[TELEMETRY_UPLOAD_PREF, true],
],
}),
withPrivacyPrefs(),
async function testCheckedOnLoad({ browser }) {
@ -29,7 +33,33 @@ decorate_task(
decorate_task(
withPrefEnv({
set: [[OPT_OUT_PREF, false]],
set: [
[OPT_OUT_PREF, true],
[TELEMETRY_UPLOAD_PREF, false],
],
}),
withPrivacyPrefs(),
async function testCheckedOnLoadWithTelemetryDisabled({ browser }) {
const checkbox = browser.contentDocument.getElementById(
"optOutStudiesEnabled"
);
ok(
!checkbox.checked,
"Opt-out checkbox is not checked on load when telemetry is disabled."
);
ok(
checkbox.disabled,
"Opt-out checkbox is disabled on load when telemetry is disabled."
);
}
);
decorate_task(
withPrefEnv({
set: [
[OPT_OUT_PREF, false],
[TELEMETRY_UPLOAD_PREF, true],
],
}),
withPrivacyPrefs(),
async function testUncheckedOnLoad({ browser }) {
@ -45,7 +75,10 @@ decorate_task(
decorate_task(
withPrefEnv({
set: [[OPT_OUT_PREF, true]],
set: [
[OPT_OUT_PREF, true],
[TELEMETRY_UPLOAD_PREF, true],
],
}),
withPrivacyPrefs(),
async function testCheckboxes({ browser }) {
@ -68,7 +101,10 @@ decorate_task(
decorate_task(
withPrefEnv({
set: [[OPT_OUT_PREF, true]],
set: [
[OPT_OUT_PREF, true],
[TELEMETRY_UPLOAD_PREF, true],
],
}),
withPrivacyPrefs(),
async function testPrefWatchers({ browser }) {