--- a/toolkit/components/telemetry/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm
@@ -143,16 +143,17 @@ this.TelemetryEnvironment = {
shutdown() {
return getGlobal().shutdown();
},
// Policy to use when saving preferences. Exported for using them in tests.
RECORD_PREF_STATE: 1, // Don't record the preference value
RECORD_PREF_VALUE: 2, // We only record user-set prefs.
RECORD_DEFAULTPREF_VALUE: 3, // We only record default pref if set
+ RECORD_DEFAULTPREF_STATE: 4, // We only record if the pref exists
// Testing method
testWatchPreferences(prefMap) {
return getGlobal()._watchPreferences(prefMap);
},
/**
* Intended for use in tests only.
@@ -175,16 +176,17 @@ this.TelemetryEnvironment = {
gActiveExperimentStartupBuffer = new Map();
return getGlobal();
},
};
const RECORD_PREF_STATE = TelemetryEnvironment.RECORD_PREF_STATE;
const RECORD_PREF_VALUE = TelemetryEnvironment.RECORD_PREF_VALUE;
const RECORD_DEFAULTPREF_VALUE = TelemetryEnvironment.RECORD_DEFAULTPREF_VALUE;
+const RECORD_DEFAULTPREF_STATE = TelemetryEnvironment.RECORD_DEFAULTPREF_STATE;
const DEFAULT_ENVIRONMENT_PREFS = new Map([
["app.feedback.baseURL", {what: RECORD_PREF_VALUE}],
["app.support.baseURL", {what: RECORD_PREF_VALUE}],
["accessibility.browsewithcaret", {what: RECORD_PREF_VALUE}],
["accessibility.force_disabled", {what: RECORD_PREF_VALUE}],
["app.update.auto", {what: RECORD_PREF_VALUE}],
["app.update.enabled", {what: RECORD_PREF_VALUE}],
["app.update.interval", {what: RECORD_PREF_VALUE}],
@@ -222,16 +224,17 @@ const DEFAULT_ENVIRONMENT_PREFS = new Ma
["extensions.formautofill.addresses.enabled", {what: RECORD_PREF_VALUE}],
["extensions.formautofill.creditCards.enabled", {what: RECORD_PREF_VALUE}],
["extensions.legacy.enabled", {what: RECORD_PREF_VALUE}],
["extensions.strictCompatibility", {what: RECORD_PREF_VALUE}],
["extensions.update.enabled", {what: RECORD_PREF_VALUE}],
["extensions.update.url", {what: RECORD_PREF_VALUE}],
["extensions.update.background.url", {what: RECORD_PREF_VALUE}],
["extensions.screenshots.disabled", {what: RECORD_PREF_VALUE}],
+ ["general.config.filename", {what: RECORD_DEFAULTPREF_STATE}],
["general.smoothScroll", {what: RECORD_PREF_VALUE}],
["gfx.direct2d.disabled", {what: RECORD_PREF_VALUE}],
["gfx.direct2d.force-enabled", {what: RECORD_PREF_VALUE}],
["gfx.direct2d.use1_1", {what: RECORD_PREF_VALUE}],
["layers.acceleration.disabled", {what: RECORD_PREF_VALUE}],
["layers.acceleration.force-enabled", {what: RECORD_PREF_VALUE}],
["layers.async-pan-zoom.enabled", {what: RECORD_PREF_VALUE}],
["layers.async-video-oop.enabled", {what: RECORD_PREF_VALUE}],
@@ -1025,30 +1028,34 @@ EnvironmentCache.prototype = {
*
* @return An object containing the preferences values.
*/
_getPrefData() {
let prefData = {};
for (let [pref, policy] of this._watchedPrefs.entries()) {
let prefType = Services.prefs.getPrefType(pref);
- if (policy.what == TelemetryEnvironment.RECORD_DEFAULTPREF_VALUE) {
+ let what = policy.what;
+ if (what == TelemetryEnvironment.RECORD_DEFAULTPREF_VALUE ||
+ what == TelemetryEnvironment.RECORD_DEFAULTPREF_STATE) {
// For default prefs, make sure they exist
if (prefType == Ci.nsIPrefBranch.PREF_INVALID) {
continue;
}
} else if (!Services.prefs.prefHasUserValue(pref)) {
// For user prefs, make sure they are set
continue;
}
// Check the policy for the preference and decide if we need to store its value
// or whether it changed from the default value.
let prefValue;
- if (policy.what == TelemetryEnvironment.RECORD_PREF_STATE) {
+ if (what == TelemetryEnvironment.RECORD_DEFAULTPREF_STATE) {
+ prefValue = "<set>";
+ } else if (what == TelemetryEnvironment.RECORD_PREF_STATE) {
prefValue = "<user-set>";
} else if (prefType == Ci.nsIPrefBranch.PREF_STRING) {
prefValue = Services.prefs.getStringPref(pref);
} else if (prefType == Ci.nsIPrefBranch.PREF_BOOL) {
prefValue = Services.prefs.getBoolPref(pref);
} else if (prefType == Ci.nsIPrefBranch.PREF_INT) {
prefValue = Services.prefs.getIntPref(pref);
} else if (prefType == Ci.nsIPrefBranch.PREF_INVALID) {
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
@@ -1027,16 +1027,34 @@ add_task(async function test_prefDefault
// Set the Environment preferences to watch.
// We're not watching, but this function does the setup we need.
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
Assert.strictEqual(TelemetryEnvironment.currentEnvironment.settings.userPrefs[PREF_TEST], expectedValue);
});
+add_task(async function test_prefDefaultState() {
+ const PREF_TEST = "toolkit.telemetry.test.defaultpref2";
+ const expectedValue = "some-test-value";
+
+ const PREFS_TO_WATCH = new Map([
+ [PREF_TEST, {what: TelemetryEnvironment.RECORD_DEFAULTPREF_STATE}],
+ ]);
+
+ TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
+
+ Assert.equal(PREF_TEST in TelemetryEnvironment.currentEnvironment.settings.userPrefs, false);
+
+ // Set the preference to a default value.
+ Services.prefs.getDefaultBranch(null).setCharPref(PREF_TEST, expectedValue);
+
+ Assert.strictEqual(TelemetryEnvironment.currentEnvironment.settings.userPrefs[PREF_TEST], "<set>");
+});
+
add_task(async function test_addonsWatch_InterestingChange() {
const ADDON_INSTALL_URL = gDataRoot + "restartless.xpi";
const ADDON_ID = "tel-restartless-webext@tests.mozilla.org";
// We only expect a single notification for each install, uninstall, enable, disable.
const EXPECTED_NOTIFICATIONS = 4;
let receivedNotifications = 0;