Bug 1956105 - Propagate data upload pref changes between profiles in a group. r=profiles-reviewers,settings-reviewers,mossop

Add a pref that we overlooked in the original patch (bug 1933264).

Differential Revision: https://phabricator.services.mozilla.com/D242863
This commit is contained in:
Jared Hirsch
2025-03-26 23:25:15 +00:00
parent 645026db0e
commit e33e0b5fd5
4 changed files with 55 additions and 5 deletions

View File

@@ -1190,11 +1190,15 @@ var gPrivacyPane = {
this.initDataCollection();
if (AppConstants.MOZ_DATA_REPORTING) {
this.initSubmitHealthReport();
this.updateSubmitHealthReportFromPref();
Preferences.get(PREF_UPLOAD_ENABLED).on(
"change",
gPrivacyPane.updateSubmitHealthReportFromPref
);
setEventListener(
"submitHealthReportBox",
"command",
gPrivacyPane.updateSubmitHealthReport
gPrivacyPane.updateSubmitHealthReportToPref
);
if (AppConstants.MOZ_NORMANDY) {
this.initOptOutStudyCheckbox();
@@ -3414,10 +3418,11 @@ var gPrivacyPane = {
},
/**
* Initialize the health report service reference and checkbox.
* Update the health report service checkbox from preference.
*/
initSubmitHealthReport() {
updateSubmitHealthReportFromPref() {
let checkbox = document.getElementById("submitHealthReportBox");
let telemetryContainer = document.getElementById("telemetry-container");
// Telemetry is only sending data if MOZ_TELEMETRY_REPORTING is defined.
// We still want to display the preferences panel if that's not the case, but
@@ -3433,12 +3438,13 @@ var gPrivacyPane = {
checkbox.checked =
Services.prefs.getBoolPref(PREF_UPLOAD_ENABLED) &&
AppConstants.MOZ_TELEMETRY_REPORTING;
telemetryContainer.hidden = checkbox.checked;
},
/**
* Update the health report preference with state from checkbox.
*/
updateSubmitHealthReport() {
updateSubmitHealthReportToPref() {
let checkbox = document.getElementById("submitHealthReportBox");
let telemetryContainer = document.getElementById("telemetry-container");

View File

@@ -196,6 +196,8 @@ skip-if = ["true"]
["browser_privacy_syncDataClearing_v2.js"]
["browser_privacy_uploadEnabled.js"]
["browser_privacypane_2.js"]
["browser_privacypane_3.js"]

View File

@@ -0,0 +1,41 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests the submitHealthReportBox checkbox is automatically updated when the
// corresponding datareporting.healthreport.uploadEnabled pref is changed.
const PREF_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
add_task(async function test_updatePageFromPref() {
if (!AppConstants.MOZ_TELEMETRY_REPORTING) {
ok(true, "Skipping test because telemetry reporting is disabled");
return;
}
await SpecialPowers.pushPrefEnv({
set: [[PREF_UPLOAD_ENABLED, false]],
});
await openPreferencesViaOpenPreferencesAPI("panePrivacy", {
leaveOpen: true,
});
const doc = gBrowser.selectedBrowser.contentDocument;
const checkbox = doc.getElementById("submitHealthReportBox");
Assert.ok(!checkbox.checked, "checkbox should match pref state on page load");
await SpecialPowers.pushPrefEnv({
set: [[PREF_UPLOAD_ENABLED, true]],
});
let checkboxUpdated = BrowserTestUtils.waitForMutationCondition(
checkbox,
{ attributeFilter: ["checked"] },
() => checkbox.checked
);
await checkboxUpdated;
Assert.ok(checkbox.checked, "pref change should trigger checkbox update");
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});

View File

@@ -113,6 +113,7 @@ class SelectableProfileServiceClass extends EventEmitter {
"browser.crashReports.unsubmittedCheck.autoSubmit2",
"browser.discovery.enabled",
"browser.urlbar.quicksuggest.dataCollection.enabled",
"datareporting.healthreport.uploadEnabled",
"datareporting.policy.currentPolicyVersion",
"datareporting.policy.dataSubmissionEnabled",
"datareporting.policy.dataSubmissionPolicyAcceptedVersion",