Bug 1344295 - Consolidate Telemetry preferences in TelemetryUtils.Preferences. r=dexter
authordjmdev <djmdeveloper060796@gmail.com>
Sat, 08 Apr 2017 11:31:18 +0530
changeset 367457 1d9dbeee6130f6acbcd83a10beff2b7cf58d1aa5
parent 367456 8eb0c588a43e2dd84638c60b8cdf66a845c5f6b9
child 367458 4cb18ada2641ceafb624b28e584904a04bc60e00
push id32135
push userkwierso@gmail.com
push dateThu, 06 Jul 2017 00:12:17 +0000
treeherdermozilla-central@af0466865a21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdexter
bugs1344295
milestone56.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 1344295 - Consolidate Telemetry preferences in TelemetryUtils.Preferences. r=dexter Moved all Preferences declarations to Preferences object in TelemetryUtils.jsm and used them in the test files.
toolkit/components/telemetry/TelemetryUtils.jsm
toolkit/components/telemetry/tests/unit/head.js
toolkit/components/telemetry/tests/unit/test_ChildEvents.js
toolkit/components/telemetry/tests/unit/test_ChildHistograms.js
toolkit/components/telemetry/tests/unit/test_ChildScalars.js
toolkit/components/telemetry/tests/unit/test_PingAPI.js
toolkit/components/telemetry/tests/unit/test_PingSender.js
toolkit/components/telemetry/tests/unit/test_SubsessionChaining.js
toolkit/components/telemetry/tests/unit/test_TelemetryCaptureStack.js
toolkit/components/telemetry/tests/unit/test_TelemetryController.js
toolkit/components/telemetry/tests/unit/test_TelemetryControllerBuildID.js
toolkit/components/telemetry/tests/unit/test_TelemetryControllerShutdown.js
toolkit/components/telemetry/tests/unit/test_TelemetryController_idle.js
toolkit/components/telemetry/tests/unit/test_TelemetryLog.js
toolkit/components/telemetry/tests/unit/test_TelemetryModules.js
toolkit/components/telemetry/tests/unit/test_TelemetryReportingPolicy.js
toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js
toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js
--- a/toolkit/components/telemetry/TelemetryUtils.jsm
+++ b/toolkit/components/telemetry/TelemetryUtils.jsm
@@ -19,16 +19,37 @@ const PREF_TELEMETRY_ENABLED = "toolkit.
 const IS_CONTENT_PROCESS = (function() {
   // We cannot use Services.appinfo here because in telemetry xpcshell tests,
   // appinfo is initially unavailable, and becomes available only later on.
   let runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
   return runtime.processType == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT;
 })();
 
 this.TelemetryUtils = {
+  Preferences: Object.freeze({
+    // General Preferences
+    ArchiveEnabled: "toolkit.telemetry.archive.enabled",
+    CachedClientId: "toolkit.telemetry.cachedClientID",
+    FirstRun: "toolkit.telemetry.reportingpolicy.firstRun",
+    OverrideOfficialCheck: "toolkit.telemetry.send.overrideOfficialCheck",
+    Server: "toolkit.telemetry.server",
+    ShutdownPingSender: "toolkit.telemetry.shutdownPingSender.enabled",
+    TelemetryEnabled: "toolkit.telemetry.enabled",
+    Unified: "toolkit.telemetry.unified",
+
+    // Data reporting Preferences
+    AcceptedPolicyDate: "datareporting.policy.dataSubmissionPolicyNotifiedTime",
+    AcceptedPolicyVersion: "datareporting.policy.dataSubmissionPolicyAcceptedVersion",
+    BypassNotification: "datareporting.policy.dataSubmissionPolicyBypassNotification",
+    CurrentPolicyVersion: "datareporting.policy.currentPolicyVersion",
+    DataSubmissionEnabled: "datareporting.policy.dataSubmissionEnabled",
+    FhrUploadEnabled: "datareporting.healthreport.uploadEnabled",
+    MinimumPolicyVersion: "datareporting.policy.minimumPolicyVersion",
+  }),
+
   /**
    * True if this is a content process.
    */
   get isContentProcess() {
     return IS_CONTENT_PROCESS;
   },
 
   /**
--- a/toolkit/components/telemetry/tests/unit/head.js
+++ b/toolkit/components/telemetry/tests/unit/head.js
@@ -1,14 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 var { classes: Cc, utils: Cu, interfaces: Ci, results: Cr } = Components;
 
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/PromiseUtils.jsm", this);
 Cu.import("resource://gre/modules/FileUtils.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 Cu.import("resource://testing-common/httpd.js", this);
 Cu.import("resource://gre/modules/AppConstants.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AddonTestUtils",
@@ -24,18 +25,16 @@ const gIsAndroid = AppConstants.platform
 const gIsLinux = AppConstants.platform == "linux";
 
 const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
 
 const MILLISECONDS_PER_MINUTE = 60 * 1000;
 const MILLISECONDS_PER_HOUR = 60 * MILLISECONDS_PER_MINUTE;
 const MILLISECONDS_PER_DAY = 24 * MILLISECONDS_PER_HOUR;
 
-const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";
-
 const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
 
 var gGlobalScope = this;
 
 const PingServer = {
   _httpServer: null,
   _started: false,
   _defers: [ PromiseUtils.defer() ],
@@ -297,25 +296,25 @@ function setEmptyPrefWatchlist() {
 
   });
 }
 
 if (runningInParent) {
   // Set logging preferences for all the tests.
   Services.prefs.setCharPref("toolkit.telemetry.log.level", "Trace");
   // Telemetry archiving should be on.
-  Services.prefs.setBoolPref("toolkit.telemetry.archive.enabled", true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.ArchiveEnabled, true);
   // Telemetry xpcshell tests cannot show the infobar.
-  Services.prefs.setBoolPref("datareporting.policy.dataSubmissionPolicyBypassNotification", true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.BypassNotification, true);
   // FHR uploads should be enabled.
-  Services.prefs.setBoolPref("datareporting.healthreport.uploadEnabled", true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true);
   // Many tests expect the shutdown and the new-profile to not be sent on shutdown
   // and will fail if receive an unexpected ping. Let's globally disable these features:
   // the relevant tests will enable these prefs when needed.
-  Services.prefs.setBoolPref("toolkit.telemetry.shutdownPingSender.enabled", false);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.ShutdownPingSender, false);
   Services.prefs.setBoolPref("toolkit.telemetry.newProfilePing.enabled", false);
   // Ensure browser experiments are also disabled, to avoid network activity
   // when toggling PREF_ENABLED.
   Services.prefs.setBoolPref("experiments.enabled", false);
 
 
   fakePingSendTimer((callback, timeout) => {
     Services.tm.dispatchToMainThread(() => callback());
--- a/toolkit/components/telemetry/tests/unit/test_ChildEvents.js
+++ b/toolkit/components/telemetry/tests/unit/test_ChildEvents.js
@@ -61,17 +61,17 @@ add_task(async function() {
     run_child_test();
     do_send_remote_message(MESSAGE_CHILD_TEST_DONE);
     return;
   }
 
   // Setup.
   do_get_profile(true);
   loadAddonManager(APP_ID, APP_NAME, APP_VERSION, PLATFORM_VERSION);
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
   await TelemetryController.testSetup();
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
   // Enable recording for the test event category.
   Telemetry.setEventRecordingEnabled("telemetry.test", true);
 
   // Run test in child, don't wait for it to finish: just wait for the
   // MESSAGE_CHILD_TEST_DONE.
--- a/toolkit/components/telemetry/tests/unit/test_ChildHistograms.js
+++ b/toolkit/components/telemetry/tests/unit/test_ChildHistograms.js
@@ -86,17 +86,17 @@ add_task(async function() {
     dump("... done with child test\n");
     do_send_remote_message(MESSAGE_CHILD_TEST_DONE);
     return;
   }
 
   // Setup.
   do_get_profile(true);
   loadAddonManager(APP_ID, APP_NAME, APP_VERSION, PLATFORM_VERSION);
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
   await TelemetryController.testSetup();
   if (runningInParent) {
     // Make sure we don't generate unexpected pings due to pref changes.
     await setEmptyPrefWatchlist();
   }
 
   // Run test in child, don't wait for it to finish.
   run_test_in_child("test_ChildHistograms.js");
--- a/toolkit/components/telemetry/tests/unit/test_ChildScalars.js
+++ b/toolkit/components/telemetry/tests/unit/test_ChildScalars.js
@@ -135,17 +135,17 @@ add_task(async function() {
     run_child_test();
     do_send_remote_message(MESSAGE_CHILD_TEST_DONE);
     return;
   }
 
   // Setup.
   do_get_profile(true);
   loadAddonManager(APP_ID, APP_NAME, APP_VERSION, PLATFORM_VERSION);
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
   await TelemetryController.testSetup();
   if (runningInParent) {
     setParentScalars();
     // Make sure we don't generate unexpected pings due to pref changes.
     await setEmptyPrefWatchlist();
   }
 
   // Run test in child, don't wait for it to finish: just wait for the
--- a/toolkit/components/telemetry/tests/unit/test_PingAPI.js
+++ b/toolkit/components/telemetry/tests/unit/test_PingAPI.js
@@ -63,17 +63,17 @@ var getArchivedPingsInfo = async functio
   archivedPings.sort((a, b) => b.timestamp - a.timestamp);
   return archivedPings;
 };
 
 add_task(async function test_setup() {
   do_get_profile(true);
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
 });
 
 add_task(async function test_archivedPings() {
   // TelemetryController should not be fully initialized at this point.
   // Submitting pings should still work fine.
 
   const PINGS = [
     {
--- a/toolkit/components/telemetry/tests/unit/test_PingSender.js
+++ b/toolkit/components/telemetry/tests/unit/test_PingSender.js
@@ -10,19 +10,16 @@ Cu.import("resource://gre/modules/osfile
 Cu.import("resource://gre/modules/Preferences.jsm", this);
 Cu.import("resource://gre/modules/PromiseUtils.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySend.jsm", this);
 Cu.import("resource://gre/modules/TelemetryStorage.jsm", this);
 Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 Cu.import("resource://gre/modules/Timer.jsm", this);
 
-const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
-const PREF_TELEMETRY_SERVER = "toolkit.telemetry.server";
-
 /**
  * Wait for a ping file to be deleted from the pending pings directory.
  */
 function waitForPingDeletion(pingId) {
   const path = OS.Path.join(TelemetryStorage.pingDirectoryPath, pingId);
 
   let checkFn = (resolve, reject) => setTimeout(() => {
     OS.File.exists(path).then(exists => {
@@ -37,18 +34,18 @@ function waitForPingDeletion(pingId) {
 
   return new Promise((resolve, reject) => checkFn(resolve, reject));
 }
 
 add_task(async function setup() {
   // Init the profile.
   do_get_profile(true);
 
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
-  Services.prefs.setBoolPref(PREF_FHR_UPLOAD_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true);
 
   // Start the ping server and let Telemetry know about it.
   PingServer.start();
 });
 
 add_task(async function test_pingSender() {
   // Generate a new ping and save it among the pending pings.
   const data = {
--- a/toolkit/components/telemetry/tests/unit/test_SubsessionChaining.js
+++ b/toolkit/components/telemetry/tests/unit/test_SubsessionChaining.js
@@ -8,17 +8,16 @@ Cu.import("resource://gre/modules/Teleme
 Cu.import("resource://gre/modules/TelemetryEnvironment.jsm", this);
 Cu.import("resource://gre/modules/osfile.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 
 const MS_IN_ONE_HOUR  = 60 * 60 * 1000;
 const MS_IN_ONE_DAY   = 24 * MS_IN_ONE_HOUR;
 
 const PREF_BRANCH = "toolkit.telemetry.";
-const PREF_ARCHIVE_ENABLED = PREF_BRANCH + "archive.enabled";
 
 const REASON_ABORTED_SESSION = "aborted-session";
 const REASON_DAILY = "daily";
 const REASON_ENVIRONMENT_CHANGE = "environment-change";
 const REASON_SHUTDOWN = "shutdown";
 
 XPCOMUtils.defineLazyGetter(this, "DATAREPORTING_PATH", function() {
   return OS.Path.join(OS.Constants.Path.profileDir, "datareporting");
@@ -86,17 +85,17 @@ add_task(async function test_setup() {
   do_test_pending();
 
   // Addon manager needs a profile directory
   do_get_profile();
   loadAddonManager("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
 
-  Preferences.set(PREF_TELEMETRY_ENABLED, true);
+  Preferences.set(TelemetryUtils.Preferences.TelemetryEnabled, true);
 });
 
 add_task(async function test_subsessionsChaining() {
   if (gIsAndroid) {
     // We don't support subsessions yet on Android, so skip the next checks.
     return;
   }
 
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryCaptureStack.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryCaptureStack.js
@@ -178,11 +178,11 @@ add_task({
     let stacks = captureStacks(badKey);
     let captureData = stacks.captures.find(capture => capture[0] === badKey)
     Assert.ok(!captureData, `"${badKey}" should not be allowed as a key`);
   }
 });
 
 function run_test() {
   do_get_profile(true);
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
   run_next_test();
 }
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryController.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryController.js
@@ -22,22 +22,16 @@ Cu.import("resource://gre/modules/Prefer
 const PING_FORMAT_VERSION = 4;
 const DELETION_PING_TYPE = "deletion";
 const TEST_PING_TYPE = "test-ping-type";
 
 const PLATFORM_VERSION = "1.9.2";
 const APP_VERSION = "1";
 const APP_NAME = "XPCShell";
 
-const PREF_BRANCH = "toolkit.telemetry.";
-const PREF_ENABLED = PREF_BRANCH + "enabled";
-const PREF_ARCHIVE_ENABLED = PREF_BRANCH + "archive.enabled";
-const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
-const PREF_UNIFIED = PREF_BRANCH + "unified";
-
 var gClientID = null;
 
 XPCOMUtils.defineLazyGetter(this, "DATAREPORTING_PATH", function() {
   return OS.Path.join(OS.Constants.Path.profileDir, "datareporting");
 });
 
 function sendPing(aSendClientId, aSendEnvironment) {
   if (PingServer.started) {
@@ -96,18 +90,18 @@ function checkPingFormat(aPing, aType, a
 
 add_task(async function test_setup() {
   // Addon manager needs a profile directory
   do_get_profile();
   loadAddonManager("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
 
-  Services.prefs.setBoolPref(PREF_ENABLED, true);
-  Services.prefs.setBoolPref(PREF_FHR_UPLOAD_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true);
 
   await new Promise(resolve =>
     Telemetry.asyncFetchTelemetryData(wrapWithExceptionHandler(resolve)));
 });
 
 add_task(async function asyncSetup() {
   await TelemetryController.testSetup();
 });
@@ -121,59 +115,59 @@ add_task(async function test_overwritePi
 });
 
 // Checks that a sent ping is correctly received by a dummy http server.
 add_task(async function test_simplePing() {
   PingServer.start();
   // Update the Telemetry Server preference with the address of the local server.
   // Otherwise we might end up sending stuff to a non-existing server after
   // |TelemetryController.testReset| is called.
-  Preferences.set(TelemetryController.Constants.PREF_SERVER, "http://localhost:" + PingServer.port);
+  Preferences.set(TelemetryUtils.Preferences.Server, "http://localhost:" + PingServer.port);
 
   await sendPing(false, false);
   let request = await PingServer.promiseNextRequest();
 
   // Check that we have a version query parameter in the URL.
   Assert.notEqual(request.queryString, "");
 
   // Make sure the version in the query string matches the new ping format version.
   let params = request.queryString.split("&");
   Assert.ok(params.find(p => p == ("v=" + PING_FORMAT_VERSION)));
 
   let ping = decodeRequestPayload(request);
   checkPingFormat(ping, TEST_PING_TYPE, false, false);
 });
 
 add_task(async function test_disableDataUpload() {
-  const isUnified = Preferences.get(PREF_UNIFIED, false);
+  const isUnified = Preferences.get(TelemetryUtils.Preferences.Unified, false);
   if (!isUnified) {
     // Skipping the test if unified telemetry is off, as no deletion ping will
     // be generated.
     return;
   }
 
   // Disable FHR upload: this should trigger a deletion ping.
-  Preferences.set(PREF_FHR_UPLOAD_ENABLED, false);
+  Preferences.set(TelemetryUtils.Preferences.FhrUploadEnabled, false);
 
   let ping = await PingServer.promiseNextPing();
   checkPingFormat(ping, DELETION_PING_TYPE, true, false);
   // Wait on ping activity to settle.
   await TelemetrySend.testWaitOnOutgoingPings();
 
   // Restore FHR Upload.
-  Preferences.set(PREF_FHR_UPLOAD_ENABLED, true);
+  Preferences.set(TelemetryUtils.Preferences.FhrUploadEnabled, true);
 
   // Simulate a failure in sending the deletion ping by disabling the HTTP server.
   await PingServer.stop();
 
   // Try to send a ping. It will be saved as pending  and get deleted when disabling upload.
   TelemetryController.submitExternalPing(TEST_PING_TYPE, {});
 
   // Disable FHR upload to send a deletion ping again.
-  Preferences.set(PREF_FHR_UPLOAD_ENABLED, false);
+  Preferences.set(TelemetryUtils.Preferences.FhrUploadEnabled, false);
 
   // Wait on sending activity to settle, as |TelemetryController.testReset()| doesn't do that.
   await TelemetrySend.testWaitOnOutgoingPings();
   // Wait for the pending pings to be deleted. Resetting TelemetryController doesn't
   // trigger the shutdown, so we need to call it ourselves.
   await TelemetryStorage.shutdown();
   // Simulate a restart, and spin the send task.
   await TelemetryController.testReset();
@@ -182,41 +176,39 @@ add_task(async function test_disableData
   let pendingPings = await TelemetryStorage.loadPendingPingList();
   Assert.equal(pendingPings.length, 1,
                "All the pending pings but the deletion ping should have been deleted");
 
   // Enable the ping server again.
   PingServer.start();
   // We set the new server using the pref, otherwise it would get reset with
   // |TelemetryController.testReset|.
-  Preferences.set(TelemetryController.Constants.PREF_SERVER, "http://localhost:" + PingServer.port);
+  Preferences.set(TelemetryUtils.Preferences.Server, "http://localhost:" + PingServer.port);
 
   // Stop the sending task and then start it again.
   await TelemetrySend.shutdown();
   // Reset the controller to spin the ping sending task.
   await TelemetryController.testReset();
   ping = await PingServer.promiseNextPing();
   checkPingFormat(ping, DELETION_PING_TYPE, true, false);
 
   // Wait on ping activity to settle before moving on to the next test. If we were
   // to shut down telemetry, even though the PingServer caught the expected pings,
   // TelemetrySend could still be processing them (clearing pings would happen in
   // a couple of ticks). Shutting down would cancel the request and save them as
   // pending pings.
   await TelemetrySend.testWaitOnOutgoingPings();
   // Restore FHR Upload.
-  Preferences.set(PREF_FHR_UPLOAD_ENABLED, true);
+  Preferences.set(TelemetryUtils.Preferences.FhrUploadEnabled, true);
 });
 
 add_task(async function test_pingHasClientId() {
-  const PREF_CACHED_CLIENTID = "toolkit.telemetry.cachedClientID";
-
   // Make sure we have no cached client ID for this test: we'll try to send
   // a ping with it while Telemetry is being initialized.
-  Preferences.reset(PREF_CACHED_CLIENTID);
+  Preferences.reset(TelemetryUtils.Preferences.CachedClientId);
   await TelemetryController.testShutdown();
   await ClientID._reset();
   await TelemetryStorage.testClearPendingPings();
   // And also clear the counter histogram since we're here.
   let h = Telemetry.getHistogramById("TELEMETRY_PING_SUBMISSION_WAITING_CLIENTID");
   h.clear();
 
   // Init telemetry and try to send a ping with a client ID.
@@ -252,17 +244,17 @@ add_task(async function test_pingHasClie
   Assert.equal(h.snapshot().sum, 0, "We must have used the cached clientId.");
   ping = await PingServer.promiseNextPing();
   checkPingFormat(ping, TEST_PING_TYPE, true, false);
   Assert.equal(ping.clientId, gClientID,
                "Telemetry should report the correct cached clientId.");
 
   // Check that sending a ping without relying on the cache, after the
   // initialization, still works.
-  Preferences.reset(PREF_CACHED_CLIENTID);
+  Preferences.reset(TelemetryUtils.Preferences.CachedClientId);
   await TelemetryController.testShutdown();
   await TelemetryStorage.testClearPendingPings();
   await TelemetryController.testReset();
   await sendPing(true, false);
   ping = await PingServer.promiseNextPing();
   checkPingFormat(ping, TEST_PING_TYPE, true, false);
   Assert.equal(ping.clientId, gClientID, "The correct clientId must be reported.");
   Assert.equal(h.snapshot().sum, 0, "No ping should have been waiting for a clientId.");
@@ -292,18 +284,18 @@ add_task(async function test_pingHasEnvi
 
 add_task(async function test_archivePings() {
   let now = new Date(2009, 10, 18, 12, 0, 0);
   fakeNow(now);
 
   // Disable ping upload so that pings don't get sent.
   // With unified telemetry the FHR upload pref controls this,
   // with non-unified telemetry the Telemetry enabled pref.
-  const isUnified = Preferences.get(PREF_UNIFIED, false);
-  const uploadPref = isUnified ? PREF_FHR_UPLOAD_ENABLED : PREF_ENABLED;
+  const isUnified = Preferences.get(TelemetryUtils.Preferences.Unified, false);
+  const uploadPref = isUnified ? TelemetryUtils.Preferences.FhrUploadEnabled : TelemetryUtils.Preferences.TelemetryEnabled;
   Preferences.set(uploadPref, false);
 
   // If we're using unified telemetry, disabling ping upload will generate a "deletion"
   // ping. Catch it.
   if (isUnified) {
     let ping = await PingServer.promiseNextPing();
     checkPingFormat(ping, DELETION_PING_TYPE, true, false);
   }
@@ -314,25 +306,25 @@ add_task(async function test_archivePing
 
   // Check that the ping was archived, even with upload disabled.
   let ping = await TelemetryArchive.promiseArchivedPingById(pingId);
   Assert.equal(ping.id, pingId, "TelemetryController should still archive pings.");
 
   // Check that pings don't get archived if not allowed to.
   now = new Date(2010, 10, 18, 12, 0, 0);
   fakeNow(now);
-  Preferences.set(PREF_ARCHIVE_ENABLED, false);
+  Preferences.set(TelemetryUtils.Preferences.ArchiveEnabled, false);
   pingId = await sendPing(true, true);
   let promise = TelemetryArchive.promiseArchivedPingById(pingId);
   Assert.ok((await promiseRejects(promise)),
     "TelemetryController should not archive pings if the archive pref is disabled.");
 
   // Enable archiving and the upload so that pings get sent and archived again.
   Preferences.set(uploadPref, true);
-  Preferences.set(PREF_ARCHIVE_ENABLED, true);
+  Preferences.set(TelemetryUtils.Preferences.ArchiveEnabled, true);
 
   now = new Date(2014, 6, 18, 22, 0, 0);
   fakeNow(now);
   // Restore the non asserting ping handler.
   PingServer.resetPingHandler();
   pingId = await sendPing(true, true);
 
   // Check that we archive pings when successfully sending them.
@@ -428,42 +420,42 @@ add_task(async function test_changePingA
   Assert.equal(archivedCopy.payload.canary, "test",
                "The payload must not be changed after being submitted.");
 });
 
 add_task(async function test_telemetryEnabledUnexpectedValue() {
   // Remove the default value for toolkit.telemetry.enabled from the default prefs.
   // Otherwise, we wouldn't be able to set the pref to a string.
   let defaultPrefBranch = Services.prefs.getDefaultBranch(null);
-  defaultPrefBranch.deleteBranch(PREF_ENABLED);
+  defaultPrefBranch.deleteBranch(TelemetryUtils.Preferences.TelemetryEnabled);
 
   // Set the preferences controlling the Telemetry status to a string.
-  Preferences.set(PREF_ENABLED, "false");
+  Preferences.set(TelemetryUtils.Preferences.TelemetryEnabled, "false");
   // Check that Telemetry is not enabled.
   await TelemetryController.testReset();
   Assert.equal(Telemetry.canRecordExtended, false,
                "Invalid values must not enable Telemetry recording.");
 
   // Delete the pref again.
-  defaultPrefBranch.deleteBranch(PREF_ENABLED);
+  defaultPrefBranch.deleteBranch(TelemetryUtils.Preferences.TelemetryEnabled);
 
   // Make sure that flipping it to true works.
-  Preferences.set(PREF_ENABLED, true);
+  Preferences.set(TelemetryUtils.Preferences.TelemetryEnabled, true);
   await TelemetryController.testReset();
   Assert.equal(Telemetry.canRecordExtended, true,
                "True must enable Telemetry recording.");
 
   // Also check that the false works as well.
-  Preferences.set(PREF_ENABLED, false);
+  Preferences.set(TelemetryUtils.Preferences.TelemetryEnabled, false);
   await TelemetryController.testReset();
   Assert.equal(Telemetry.canRecordExtended, false,
                "False must disable Telemetry recording.");
 
   // Restore the state of the pref.
-  Preferences.set(PREF_ENABLED, true);
+  Preferences.set(TelemetryUtils.Preferences.TelemetryEnabled, true);
 });
 
 add_task(async function test_telemetryCleanFHRDatabase() {
   const FHR_DBNAME_PREF = "datareporting.healthreport.dbName";
   const CUSTOM_DB_NAME = "unlikely.to.be.used.sqlite";
   const DEFAULT_DB_NAME = "healthreport.sqlite";
 
   // Check that we're able to remove a FHR DB with a custom name.
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryControllerBuildID.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryControllerBuildID.js
@@ -16,17 +16,17 @@
 "use strict";
 
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 // Force the Telemetry enabled preference so that TelemetrySession.testReset() doesn't exit early.
-Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
 
 // Set up our dummy AppInfo object so we can control the appBuildID.
 Cu.import("resource://testing-common/AppInfo.jsm", this);
 updateAppInfo();
 
 // Check that when run with no previous build ID stored, we update the pref but do not
 // put anything into the metadata.
 add_task(async function test_firstRun() {
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryControllerShutdown.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryControllerShutdown.js
@@ -9,36 +9,33 @@
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySend.jsm", this);
 Cu.import("resource://gre/modules/Timer.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 Cu.import("resource://gre/modules/AsyncShutdown.jsm", this);
 Cu.import("resource://testing-common/httpd.js", this);
 
-const PREF_BRANCH = "toolkit.telemetry.";
-const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
-
 function contentHandler(metadata, response) {
   dump("contentHandler called for path: " + metadata._path + "\n");
   // We intentionally don't finish writing the response here to let the
   // client time out.
   response.processAsync();
   response.setHeader("Content-Type", "text/plain");
 }
 
 add_task(async function test_setup() {
   // Addon manager needs a profile directory
   do_get_profile();
   loadAddonManager("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
 
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
-  Services.prefs.setBoolPref(PREF_FHR_UPLOAD_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true);
 });
 
 /**
  * Ensures that TelemetryController does not hang processing shutdown
  * phases. Assumes that Telemetry shutdown routines do not take longer than
  * CRASH_TIMEOUT_MS to complete.
  */
 add_task(async function test_sendTelemetryShutsDownWithinReasonableTimeout() {
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryController_idle.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryController_idle.js
@@ -6,28 +6,26 @@
 Cu.import("resource://testing-common/httpd.js", this);
 Cu.import("resource://gre/modules/PromiseUtils.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/TelemetryStorage.jsm", this);
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySend.jsm", this);
 
-const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
-
 var gHttpServer = null;
 
 add_task(async function test_setup() {
   do_get_profile();
 
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
 
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
-  Services.prefs.setBoolPref(PREF_FHR_UPLOAD_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true);
 
   // Start the webserver to check if the pending ping correctly arrives.
   gHttpServer = new HttpServer();
   gHttpServer.start(-1);
 });
 
 add_task(async function testSendPendingOnIdleDaily() {
   // Create a valid pending ping.
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryLog.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryLog.js
@@ -22,18 +22,17 @@ function check_event(event, id, data) {
       do_check_eq(typeof(event[i + 2]), "string");
       do_check_eq(event[i + 2], data[i]);
     }
   }
 }
 
 add_task(async function() {
   do_get_profile();
-  // TODO: After Bug 1254550 lands we should not need to set the pref here.
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
   await TelemetryController.testSetup();
 
   TelemetryLog.log(TEST_PREFIX + "1", ["val", 123, undefined]);
   TelemetryLog.log(TEST_PREFIX + "2", []);
   TelemetryLog.log(TEST_PREFIX + "3");
 
   var log = TelemetrySession.getPayload().log.filter(function(e) {
     // Only want events that were generated by the test.
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryModules.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryModules.js
@@ -112,17 +112,17 @@ add_task(async function setup() {
 
   // Force the timer to fire (using a small interval).
   Cc["@mozilla.org/updates/timer-manager;1"].getService(Ci.nsIObserver).observe(null, "utm-test-init", "");
   Preferences.set("toolkit.telemetry.modulesPing.interval", 0);
   Preferences.set("app.update.url", "http:/localhost");
 
   // Start the local ping server and setup Telemetry to use it during the tests.
   PingServer.start();
-  Preferences.set("toolkit.telemetry.server", "http://localhost:" + PingServer.port);
+  Preferences.set(TelemetryUtils.Preferences.Server, "http://localhost:" + PingServer.port);
 });
 
 do_register_cleanup(function() {
   if (libModulesHandle) {
     libModulesHandle.close();
   }
   if (libUnicodeHandle) {
     libUnicodeHandle.close();
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryReportingPolicy.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryReportingPolicy.js
@@ -11,77 +11,68 @@ Cu.import("resource://gre/modules/Servic
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySend.jsm", this);
 Cu.import("resource://gre/modules/TelemetryReportingPolicy.jsm", this);
 Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 Cu.import("resource://gre/modules/Timer.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 Cu.import("resource://gre/modules/UpdateUtils.jsm", this);
 
-const PREF_BRANCH = "toolkit.telemetry.";
-const PREF_SERVER = PREF_BRANCH + "server";
-
 const TEST_CHANNEL = "TestChannelABC";
 
-const PREF_POLICY_BRANCH = "datareporting.policy.";
-const PREF_BYPASS_NOTIFICATION = PREF_POLICY_BRANCH + "dataSubmissionPolicyBypassNotification";
-const PREF_DATA_SUBMISSION_ENABLED = PREF_POLICY_BRANCH + "dataSubmissionEnabled";
-const PREF_CURRENT_POLICY_VERSION = PREF_POLICY_BRANCH + "currentPolicyVersion";
-const PREF_MINIMUM_POLICY_VERSION = PREF_POLICY_BRANCH + "minimumPolicyVersion";
-const PREF_MINIMUM_CHANNEL_POLICY_VERSION = PREF_MINIMUM_POLICY_VERSION + ".channel-" + TEST_CHANNEL;
-const PREF_ACCEPTED_POLICY_VERSION = PREF_POLICY_BRANCH + "dataSubmissionPolicyAcceptedVersion";
-const PREF_ACCEPTED_POLICY_DATE = PREF_POLICY_BRANCH + "dataSubmissionPolicyNotifiedTime";
+const PREF_MINIMUM_CHANNEL_POLICY_VERSION =
+  TelemetryUtils.Preferences.MinimumPolicyVersion + ".channel-" + TEST_CHANNEL;
 
 function fakeShowPolicyTimeout(set, clear) {
   let reportingPolicy = Cu.import("resource://gre/modules/TelemetryReportingPolicy.jsm", {});
   reportingPolicy.Policy.setShowInfobarTimeout = set;
   reportingPolicy.Policy.clearShowInfobarTimeout = clear;
 }
 
 function fakeResetAcceptedPolicy() {
-  Preferences.reset(PREF_ACCEPTED_POLICY_DATE);
-  Preferences.reset(PREF_ACCEPTED_POLICY_VERSION);
+  Preferences.reset(TelemetryUtils.Preferences.AcceptedPolicyDate);
+  Preferences.reset(TelemetryUtils.Preferences.AcceptedPolicyVersion);
 }
 
 function setMinimumPolicyVersion(aNewPolicyVersion) {
   const CHANNEL_NAME = UpdateUtils.getUpdateChannel(false);
   // We might have channel-dependent minimum policy versions.
-  const CHANNEL_DEPENDENT_PREF = PREF_MINIMUM_POLICY_VERSION + ".channel-" + CHANNEL_NAME;
+  const CHANNEL_DEPENDENT_PREF =
+    TelemetryUtils.Preferences.MinimumPolicyVersion + ".channel-" + CHANNEL_NAME;
 
   // Does the channel-dependent pref exist? If so, set its value.
   if (Preferences.get(CHANNEL_DEPENDENT_PREF, undefined)) {
     Preferences.set(CHANNEL_DEPENDENT_PREF, aNewPolicyVersion);
     return;
   }
 
   // We don't have a channel specific minimu, so set the common one.
-  Preferences.set(PREF_MINIMUM_POLICY_VERSION, aNewPolicyVersion);
+  Preferences.set(TelemetryUtils.Preferences.MinimumPolicyVersion, aNewPolicyVersion);
 }
 
 add_task(async function test_setup() {
   // Addon manager needs a profile directory
   do_get_profile(true);
   loadAddonManager("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
 
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
   // Don't bypass the notifications in this test, we'll fake it.
-  Services.prefs.setBoolPref(PREF_BYPASS_NOTIFICATION, false);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.BypassNotification, false);
 
   TelemetryReportingPolicy.setup();
 });
 
 add_task(async function test_firstRun() {
-  const PREF_FIRST_RUN = "toolkit.telemetry.reportingpolicy.firstRun";
   const FIRST_RUN_TIMEOUT_MSEC = 60 * 1000; // 60s
   const OTHER_RUNS_TIMEOUT_MSEC = 10 * 1000; // 10s
 
-  Preferences.reset(PREF_FIRST_RUN);
+  Preferences.reset(TelemetryUtils.Preferences.FirstRun);
 
   let startupTimeout = 0;
   fakeShowPolicyTimeout((callback, timeout) => startupTimeout = timeout, () => {});
   TelemetryReportingPolicy.reset();
 
   Services.obs.notifyObservers(null, "sessionstore-windows-restored");
   Assert.equal(startupTimeout, FIRST_RUN_TIMEOUT_MSEC,
                "The infobar display timeout should be 60s on the first run.");
@@ -96,47 +87,47 @@ add_task(async function test_firstRun() 
 add_task(async function test_prefs() {
   TelemetryReportingPolicy.reset();
 
   let now = fakeNow(2009, 11, 18);
 
   // If the date is not valid (earlier than 2012), we don't regard the policy as accepted.
   TelemetryReportingPolicy.testInfobarShown();
   Assert.ok(!TelemetryReportingPolicy.testIsUserNotified());
-  Assert.equal(Preferences.get(PREF_ACCEPTED_POLICY_DATE, null), 0,
-               "Invalid dates should not make the policy accepted.");
+  Assert.equal(Preferences.get(TelemetryUtils.Preferences.AcceptedPolicyDate, null), 0,
+                "Invalid dates should not make the policy accepted.");
 
   // Check that the notification date and version are correctly saved to the prefs.
   now = fakeNow(2012, 11, 18);
   TelemetryReportingPolicy.testInfobarShown();
-  Assert.equal(Preferences.get(PREF_ACCEPTED_POLICY_DATE, null), now.getTime(),
-               "A valid date must correctly be saved.");
+  Assert.equal(Preferences.get(TelemetryUtils.Preferences.AcceptedPolicyDate, null), now.getTime(),
+                "A valid date must correctly be saved.");
 
   // Now that user is notified, check if we are allowed to upload.
   Assert.ok(TelemetryReportingPolicy.canUpload(),
             "We must be able to upload after the policy is accepted.");
 
   // Disable submission and check that we're no longer allowed to upload.
-  Preferences.set(PREF_DATA_SUBMISSION_ENABLED, false);
+  Preferences.set(TelemetryUtils.Preferences.DataSubmissionEnabled, false);
   Assert.ok(!TelemetryReportingPolicy.canUpload(),
             "We must not be able to upload if data submission is disabled.");
 
   // Turn the submission back on.
-  Preferences.set(PREF_DATA_SUBMISSION_ENABLED, true);
+  Preferences.set(TelemetryUtils.Preferences.DataSubmissionEnabled, true);
   Assert.ok(TelemetryReportingPolicy.canUpload(),
             "We must be able to upload if data submission is enabled and the policy was accepted.");
 
   // Set a new minimum policy version and check that user is no longer notified.
-  let newMinimum = Preferences.get(PREF_CURRENT_POLICY_VERSION, 1) + 1;
+  let newMinimum = Preferences.get(TelemetryUtils.Preferences.CurrentPolicyVersion, 1) + 1;
   setMinimumPolicyVersion(newMinimum);
   Assert.ok(!TelemetryReportingPolicy.testIsUserNotified(),
             "A greater minimum policy version must invalidate the policy and disable upload.");
 
   // Eventually accept the policy and make sure user is notified.
-  Preferences.set(PREF_CURRENT_POLICY_VERSION, newMinimum);
+  Preferences.set(TelemetryUtils.Preferences.CurrentPolicyVersion, newMinimum);
   TelemetryReportingPolicy.testInfobarShown();
   Assert.ok(TelemetryReportingPolicy.testIsUserNotified(),
             "Accepting the policy again should show the user as notified.");
   Assert.ok(TelemetryReportingPolicy.canUpload(),
             "Accepting the policy again should let us upload data.");
 
   // Set a new, per channel, minimum policy version. Start by setting a test current channel.
   let defaultPrefs = new Preferences({ defaultBranch: true });
@@ -144,17 +135,17 @@ add_task(async function test_prefs() {
 
   // Increase and set the new minimum version, then check that we're not notified anymore.
   newMinimum++;
   Preferences.set(PREF_MINIMUM_CHANNEL_POLICY_VERSION, newMinimum);
   Assert.ok(!TelemetryReportingPolicy.testIsUserNotified(),
             "Increasing the minimum policy version should invalidate the policy.");
 
   // Eventually accept the policy and make sure user is notified.
-  Preferences.set(PREF_CURRENT_POLICY_VERSION, newMinimum);
+  Preferences.set(TelemetryUtils.Preferences.CurrentPolicyVersion, newMinimum);
   TelemetryReportingPolicy.testInfobarShown();
   Assert.ok(TelemetryReportingPolicy.testIsUserNotified(),
             "Accepting the policy again should show the user as notified.");
   Assert.ok(TelemetryReportingPolicy.canUpload(),
             "Accepting the policy again should let us upload data.");
 });
 
 add_task(async function test_migratePrefs() {
@@ -181,47 +172,47 @@ add_task(async function test_userNotifie
   fakeResetAcceptedPolicy();
   TelemetryReportingPolicy.reset();
 
   // User should be reported as not notified by default.
   Assert.ok(!TelemetryReportingPolicy.testIsUserNotified(),
             "The initial state should be unnotified.");
 
   // Forcing a policy version should not automatically make the user notified.
-  Preferences.set(PREF_ACCEPTED_POLICY_VERSION,
+  Preferences.set(TelemetryUtils.Preferences.AcceptedPolicyVersion,
                   TelemetryReportingPolicy.DEFAULT_DATAREPORTING_POLICY_VERSION);
   Assert.ok(!TelemetryReportingPolicy.testIsUserNotified(),
                  "The default state of the date should have a time of 0 and it should therefore fail");
 
   // Showing the notification bar should make the user notified.
   fakeNow(2012, 11, 11);
   TelemetryReportingPolicy.testInfobarShown();
   Assert.ok(TelemetryReportingPolicy.testIsUserNotified(),
             "Using the proper API causes user notification to report as true.");
 
   // It is assumed that later versions of the policy will incorporate previous
   // ones, therefore this should also return true.
   let newVersion =
-    Preferences.get(PREF_CURRENT_POLICY_VERSION, 1) + 1;
-  Preferences.set(PREF_ACCEPTED_POLICY_VERSION, newVersion);
+    Preferences.get(TelemetryUtils.Preferences.CurrentPolicyVersion, 1) + 1;
+  Preferences.set(TelemetryUtils.Preferences.AcceptedPolicyVersion, newVersion);
   Assert.ok(TelemetryReportingPolicy.testIsUserNotified(),
             "A future version of the policy should pass.");
 
   newVersion =
-    Preferences.get(PREF_CURRENT_POLICY_VERSION, 1) - 1;
-  Preferences.set(PREF_ACCEPTED_POLICY_VERSION, newVersion);
+    Preferences.get(TelemetryUtils.Preferences.CurrentPolicyVersion, 1) - 1;
+  Preferences.set(TelemetryUtils.Preferences.AcceptedPolicyVersion, newVersion);
   Assert.ok(!TelemetryReportingPolicy.testIsUserNotified(),
             "A previous version of the policy should fail.");
 });
 
 add_task(async function test_canSend() {
   const TEST_PING_TYPE = "test-ping";
 
   PingServer.start();
-  Preferences.set(PREF_SERVER, "http://localhost:" + PingServer.port);
+  Preferences.set(TelemetryUtils.Preferences.Server, "http://localhost:" + PingServer.port);
 
   await TelemetryController.testReset();
   TelemetryReportingPolicy.reset();
 
   // User should be reported as not notified by default.
   Assert.ok(!TelemetryReportingPolicy.testIsUserNotified(),
             "The initial state should be unnotified.");
 
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
@@ -11,18 +11,16 @@ Cu.import("resource://testing-common/Con
 Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySend.jsm", this);
 Cu.import("resource://gre/modules/TelemetryStorage.jsm", this);
 Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/Preferences.jsm", this);
 Cu.import("resource://gre/modules/osfile.jsm", this);
 
-const PREF_TELEMETRY_SERVER = "toolkit.telemetry.server";
-
 const MS_IN_A_MINUTE = 60 * 1000;
 
 function countPingTypes(pings) {
   let countByType = new Map();
   for (let p of pings) {
     countByType.set(p.type, 1 + (countByType.get(p.type) || 0));
   }
   return countByType;
@@ -75,17 +73,17 @@ function histogramValueCount(h) {
   return h.counts.reduce((a, b) => a + b);
 }
 
 add_task(async function test_setup() {
   // Trigger a proper telemetry init.
   do_get_profile(true);
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
 });
 
 // Test the ping sending logic.
 add_task(async function test_sendPendingPings() {
   const TYPE_PREFIX = "test-sendPendingPings-";
   const TEST_TYPE_A = TYPE_PREFIX + "A";
   const TEST_TYPE_B = TYPE_PREFIX + "B";
 
@@ -133,17 +131,17 @@ add_task(async function test_sendPending
   Assert.equal(histSendTimeSuccess.snapshot().sum, 0,
                "Should not have recorded any sending in histograms yet.");
   Assert.equal(histSendTimeFail.snapshot().sum, 0,
                "Should not have recorded any sending in histograms yet.");
 
   // Now enable sending to the ping server.
   now = fakeNow(futureDate(now, MS_IN_A_MINUTE));
   PingServer.start();
-  Preferences.set(PREF_TELEMETRY_SERVER, "http://localhost:" + PingServer.port);
+  Preferences.set(TelemetryUtils.Preferences.Server, "http://localhost:" + PingServer.port);
 
   let timerPromise = waitForTimer();
   await TelemetryController.testReset();
   let [pingSendTimerCallback, pingSendTimeout] = await timerPromise;
   Assert.ok(!!pingSendTimerCallback, "Should have a timer callback");
 
   // We should have received 10 pings from the first send batch:
   // 5 of type B and 5 of type A, as sending is newest-first.
@@ -421,53 +419,52 @@ add_task(async function test_persistCurr
 
   // After a restart the pings should have been found when scanning.
   await TelemetrySend.reset();
   Assert.equal(TelemetrySend.pendingPingCount, PING_COUNT, "Should have the correct pending ping count");
 });
 
 add_task(async function test_sendCheckOverride() {
   const TEST_PING_TYPE = "test-sendCheckOverride";
-  const PREF_OVERRIDE_OFFICIAL_CHECK = "toolkit.telemetry.send.overrideOfficialCheck";
 
   // Clear any pending pings.
   await TelemetryController.testShutdown();
   await TelemetryStorage.testClearPendingPings();
 
   // Enable the ping server.
   PingServer.start();
-  Preferences.set(PREF_TELEMETRY_SERVER, "http://localhost:" + PingServer.port);
+  Preferences.set(TelemetryUtils.Preferences.Server, "http://localhost:" + PingServer.port);
 
   // Start Telemetry and disable the test-mode so pings don't get
   // sent unless we enable the override.
   await TelemetryController.testReset();
 
   // Submit a test ping and make sure it doesn't get sent. We only do
   // that if we're on unofficial builds: pings will always get sent otherwise.
   if (!Services.telemetry.isOfficialTelemetry) {
     TelemetrySend.setTestModeEnabled(false);
     PingServer.registerPingHandler(() => Assert.ok(false, "Should not have received any pings now"));
 
     await TelemetryController.submitExternalPing(TEST_PING_TYPE, { test: "test" });
     Assert.equal(TelemetrySend.pendingPingCount, 0, "Should have no pending pings");
   }
 
   // Enable the override and try to send again.
-  Preferences.set(PREF_OVERRIDE_OFFICIAL_CHECK, true);
+  Preferences.set(TelemetryUtils.Preferences.OverrideOfficialCheck, true);
   PingServer.resetPingHandler();
   await TelemetrySend.reset();
   await TelemetryController.submitExternalPing(TEST_PING_TYPE, { test: "test" });
 
   // Make sure we received the ping.
   const ping = await PingServer.promiseNextPing();
   Assert.equal(ping.type, TEST_PING_TYPE, "Must receive a ping of the expected type");
 
   // Restore the test mode and disable the override.
   TelemetrySend.setTestModeEnabled(true);
-  Preferences.reset(PREF_OVERRIDE_OFFICIAL_CHECK);
+  Preferences.reset(TelemetryUtils.Preferences.OverrideOfficialCheck);
 });
 
 add_task(async function test_measurePingsSize() {
   const TEST_TYPE = "test-measure-ping-size";
 
   let histSuccessPingSize = Telemetry.getHistogramById("TELEMETRY_SUCCESSFUL_SEND_PINGS_SIZE_KB");
   let histFailedPingSize = Telemetry.getHistogramById("TELEMETRY_FAILED_SEND_PINGS_SIZE_KB");
 
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js
@@ -25,18 +25,16 @@ const OVERDUE_PING_FILE_AGE = TelemetryS
 const PING_SAVE_FOLDER = "saved-telemetry-pings";
 const PING_TIMEOUT_LENGTH = 5000;
 const OVERDUE_PINGS = 6;
 const OLD_FORMAT_PINGS = 4;
 const RECENT_PINGS = 4;
 
 const TOTAL_EXPECTED_PINGS = OVERDUE_PINGS + RECENT_PINGS + OLD_FORMAT_PINGS;
 
-const PREF_FHR_UPLOAD = "datareporting.healthreport.uploadEnabled";
-
 var gCreatedPings = 0;
 var gSeenPings = 0;
 
 /**
  * Creates some Telemetry pings for the and saves them to disk. Each ping gets a
  * unique ID based on an incrementor.
  *
  * @param {Array} aPingInfos An array of ping type objects. Each entry must be an
@@ -144,28 +142,28 @@ function pingHandler(aRequest) {
 add_task(async function test_setup() {
   PingServer.start();
   PingServer.registerPingHandler(pingHandler);
   do_get_profile();
   loadAddonManager("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
 
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
-  Services.prefs.setCharPref(TelemetryController.Constants.PREF_SERVER,
-                             "http://localhost:" + PingServer.port);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
+  Services.prefs.setCharPref(TelemetryUtils.Preferences.Server,
+                              "http://localhost:" + PingServer.port);
 });
 
 /**
  * Setup the tests by making sure the ping storage directory is available, otherwise
  * |TelemetryController.testSaveDirectoryToFile| could fail.
  */
 add_task(async function setupEnvironment() {
   // The following tests assume this pref to be true by default.
-  Services.prefs.setBoolPref(PREF_FHR_UPLOAD, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true);
 
   await TelemetryController.testSetup();
 
   let directory = TelemetryStorage.pingDirectoryPath;
   await File.makeDir(directory, { ignoreExisting: true, unixMode: OS.Constants.S_IRWXU });
 
   await TelemetryStorage.testClearPendingPings();
 });
@@ -380,17 +378,17 @@ add_task(async function test_overdue_old
   await TelemetryStorage.testClearPendingPings();
   PingServer.resetPingHandler();
 });
 
 add_task(async function test_pendingPingsQuota() {
   const PING_TYPE = "foo";
 
   // Disable upload so pings don't get sent and removed from the pending pings directory.
-  Services.prefs.setBoolPref(PREF_FHR_UPLOAD, false);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, false);
 
   // Remove all the pending pings then startup and wait for the cleanup task to complete.
   // There should be nothing to remove.
   await TelemetryStorage.testClearPendingPings();
   await TelemetryController.testReset();
   await TelemetrySend.testWaitOnOutgoingPings();
   await TelemetryStorage.testPendingQuotaTaskPromise();
 
@@ -531,14 +529,14 @@ add_task(async function test_pendingPing
   await checkPendingPings();
 
   // Make sure we're correctly updating the related histograms.
   h = Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_PENDING").snapshot();
   Assert.equal(h.sum, 2, "Telemetry must report 1 oversized ping in the pending pings directory.");
   h = Telemetry.getHistogramById("TELEMETRY_DISCARDED_PENDING_PINGS_SIZE_MB").snapshot();
   Assert.equal(h.counts[2], 2, "Telemetry must report two 2MB, oversized, pings.");
 
-  Services.prefs.setBoolPref(PREF_FHR_UPLOAD, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true);
 });
 
 add_task(async function teardown() {
   await PingServer.stop();
 });
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
@@ -52,23 +52,16 @@ const PR_TRUNCATE = 0x20;
 const RW_OWNER = parseInt("0600", 8);
 
 const NUMBER_OF_THREADS_TO_LAUNCH = 30;
 var gNumberOfThreadsLaunched = 0;
 
 const MS_IN_ONE_HOUR  = 60 * 60 * 1000;
 const MS_IN_ONE_DAY   = 24 * MS_IN_ONE_HOUR;
 
-const PREF_BRANCH = "toolkit.telemetry.";
-const PREF_SERVER = PREF_BRANCH + "server";
-const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
-const PREF_BYPASS_NOTIFICATION = "datareporting.policy.dataSubmissionPolicyBypassNotification";
-const PREF_SHUTDOWN_PINGSENDER = "toolkit.telemetry.shutdownPingSender.enabled";
-const PREF_POLICY_FIRSTRUN = "toolkit.telemetry.reportingpolicy.firstRun";
-
 const DATAREPORTING_DIR = "datareporting";
 const ABORTED_PING_FILE_NAME = "aborted-session-ping";
 const ABORTED_SESSION_UPDATE_INTERVAL_MS = 5 * 60 * 1000;
 
 XPCOMUtils.defineLazyGetter(this, "DATAREPORTING_PATH", function() {
   return OS.Path.join(OS.Constants.Path.profileDir, DATAREPORTING_DIR);
 });
 
@@ -478,18 +471,18 @@ function write_fake_failedprofilelocks_f
 
 add_task(async function test_setup() {
   // Addon manager needs a profile directory
   do_get_profile();
   loadAddonManager(APP_ID, APP_NAME, APP_VERSION, PLATFORM_VERSION);
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
 
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
-  Services.prefs.setBoolPref(PREF_FHR_UPLOAD_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true);
 
   // Make it look like we've previously failed to lock a profile a couple times.
   write_fake_failedprofilelocks_file();
 
   // Make it look like we've shutdown before.
   write_fake_shutdown_file();
 
   let currentMaxNumberOfThreads = Telemetry.maximalNumberOfConcurrentThreads;
@@ -545,17 +538,17 @@ add_task(async function test_noServerPin
   // problems to the consequent tests.
   await TelemetryController.testShutdown();
 });
 
 // Checks that a sent ping is correctly received by a dummy http server.
 add_task(async function test_simplePing() {
   await TelemetryStorage.testClearPendingPings();
   PingServer.start();
-  Preferences.set(PREF_SERVER, "http://localhost:" + PingServer.port);
+  Preferences.set(TelemetryUtils.Preferences.Server, "http://localhost:" + PingServer.port);
 
   let now = new Date(2020, 1, 1, 12, 5, 6);
   let expectedDate = new Date(2020, 1, 1, 12, 0, 0);
   fakeNow(now);
   gMonotonicNow = fakeMonotonicNow(gMonotonicNow + 5000);
 
   const expectedSessionUUID = "bd314d15-95bf-4356-b682-b6c4a8942202";
   const expectedSubsessionUUID = "3e2e5f6c-74ba-4e4d-a93f-a48af238a8c7";
@@ -1381,18 +1374,18 @@ add_task(async function test_sendShutdow
     Assert.ok(pings.find(p => p.type == "saved-session"),
               "The 'saved-session' ping must be saved to disk.");
     Assert.equal("shutdown", shutdownPing.payload.info.reason,
                  "The 'shutdown' ping must be saved to disk.");
     Assert.ok(shutdownPing.payload.processes.parent.scalars[OSSHUTDOWN_SCALAR],
               "The OS shutdown scalar must be set to true.");
   };
 
-  Preferences.set(PREF_SHUTDOWN_PINGSENDER, true);
-  Preferences.set(PREF_POLICY_FIRSTRUN, false);
+  Preferences.set(TelemetryUtils.Preferences.ShutdownPingSender, true);
+  Preferences.set(TelemetryUtils.Preferences.FirstRun, false);
   // Make sure the reporting policy picks up the updated pref.
   TelemetryReportingPolicy.testUpdateFirstRun();
   PingServer.clearRequests();
   Telemetry.clearScalars();
 
   // Shutdown telemetry and wait for an incoming ping.
   let nextPing = PingServer.promiseNextPing();
   await TelemetryController.testShutdown();
@@ -1402,26 +1395,26 @@ add_task(async function test_sendShutdow
   checkPingFormat(ping, ping.type, true, true);
   Assert.equal(ping.payload.info.reason, REASON_SHUTDOWN);
   Assert.equal(ping.clientId, gClientID);
   Assert.ok(!(OSSHUTDOWN_SCALAR in ping.payload.processes.parent.scalars),
             "The OS shutdown scalar must not be set.");
   // Try again, this time disable ping upload. The PingSender
   // should not be sending any ping!
   PingServer.registerPingHandler(() => Assert.ok(false, "Telemetry must not send pings if not allowed to."));
-  Preferences.set(PREF_FHR_UPLOAD_ENABLED, false);
+  Preferences.set(TelemetryUtils.Preferences.FhrUploadEnabled, false);
   await TelemetryController.testReset();
   await TelemetryController.testShutdown();
 
   // Make sure we have no pending pings between the runs.
   await TelemetryStorage.testClearPendingPings();
 
   // Enable ping upload and signal an OS shutdown. The pingsender
   // will not be spawned and no ping will be sent.
-  Preferences.set(PREF_FHR_UPLOAD_ENABLED, true);
+  Preferences.set(TelemetryUtils.Preferences.FhrUploadEnabled, true);
   await TelemetryController.testReset();
   Services.obs.notifyObservers(null, "quit-application-forced");
   await TelemetryController.testShutdown();
 
   // Check that the "shutdown" ping was correctly saved to disk.
   await checkPendingShutdownPing();
 
   // Make sure we have no pending pings between the runs.
@@ -1432,40 +1425,40 @@ add_task(async function test_sendShutdow
   Services.obs.notifyObservers(null, "quit-application-granted", "syncShutdown");
   await TelemetryController.testShutdown();
   await checkPendingShutdownPing();
 
   // Make sure we have no pending pings between the runs.
   await TelemetryStorage.testClearPendingPings();
 
   // Disable the "submission policy". The shutdown ping must not be sent.
-  Preferences.set(PREF_BYPASS_NOTIFICATION, false);
+  Preferences.set(TelemetryUtils.Preferences.BypassNotification, false);
   await TelemetryController.testReset();
   await TelemetryController.testShutdown();
 
   // Make sure we have no pending pings between the runs.
   await TelemetryStorage.testClearPendingPings();
 
-  // We cannot reset PREF_BYPASS_NOTIFICATION, as we need it to be
+  // We cannot reset the BypassNotification pref, as we need it to be
   // |true| in tests.
-  Preferences.set(PREF_BYPASS_NOTIFICATION, true);
+  Preferences.set(TelemetryUtils.Preferences.BypassNotification, true);
 
   // With both upload enabled and the policy shown, make sure we don't
   // send the shutdown ping using the pingsender on the first
   // subsession.
-  Preferences.set(PREF_POLICY_FIRSTRUN, true);
+  Preferences.set(TelemetryUtils.Preferences.FirstRun, true);
   // Make sure the reporting policy picks up the updated pref.
   TelemetryReportingPolicy.testUpdateFirstRun();
 
   await TelemetryController.testReset();
   await TelemetryController.testShutdown();
 
   // Reset the pref and restart Telemetry.
-  Preferences.set(PREF_SHUTDOWN_PINGSENDER, false);
-  Preferences.reset(PREF_POLICY_FIRSTRUN);
+  Preferences.set(TelemetryUtils.Preferences.ShutdownPingSender, false);
+  Preferences.reset(TelemetryUtils.Preferences.FirstRun);
   PingServer.resetPingHandler();
   await TelemetryController.testReset();
 });
 
 add_task(async function test_savedSessionData() {
   // Create the directory which will contain the data file, if it doesn't already
   // exist.
   await OS.File.makeDir(DATAREPORTING_PATH);
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js
@@ -8,17 +8,17 @@ Cu.import("resource://gre/modules/Teleme
 
 add_task(async function test_setup() {
   // Addon manager needs a profile directory
   do_get_profile();
   loadAddonManager("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
 
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
 });
 
 add_task(async function test_record_activeTicks() {
   await TelemetryController.testSetup();
 
   let checkActiveTicks = (expected) => {
     let payload = TelemetrySession.getPayload();
     Assert.equal(payload.simpleMeasurements.activeTicks, expected,