Bug 1226616 - The presence of the general.config.filename preference should be reported on telemetry. r=chutten, data-review=francois
authorFlorian Quèze <florian@queze.net>
Sat, 25 Nov 2017 00:01:17 +0100
changeset 393668 76c8206c543712966580ad91bbc04af636e9cfc9
parent 393667 3d72084b1e1b7f8a89d1f5081aec7ab8e7fccdcb
child 393669 c841dbfc685301fe4d6163e841ec06f8139d8b94
push id32969
push usernerli@mozilla.com
push dateSat, 25 Nov 2017 10:05:56 +0000
treeherdermozilla-central@b2200418de0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1226616
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1226616 - The presence of the general.config.filename preference should be reported on telemetry. r=chutten, data-review=francois
toolkit/components/telemetry/TelemetryEnvironment.jsm
toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
--- 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}],
@@ -223,16 +225,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}],
   ["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}],
   ["layers.async-video.enabled", {what: RECORD_PREF_VALUE}],
@@ -1028,30 +1031,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
@@ -1026,16 +1026,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;