Bug 1344295 - Consolidate Telemetry preferences in TelemetryUtils.Preferences. r=dexter
☠☠ backed out by d7af59656111 ☠ ☠
authordjmdev <djmdeveloper060796@gmail.com>
Sat, 08 Apr 2017 11:31:18 +0530
changeset 352178 16e85d7e7400febe85909d6f1baa5b0ff03fb2ab
parent 352177 56af34f86b180aac4b01775fad19ce49ee3ed71f
child 352179 5a07a004ca309f405dd7b20ba57ab224aae494b5
push id31633
push userkwierso@gmail.com
push dateMon, 10 Apr 2017 23:32:51 +0000
treeherdermozilla-central@b5b5dbed1c40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdexter
bugs1344295
milestone55.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_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
--- 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
@@ -24,18 +24,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() ],
--- a/toolkit/components/telemetry/tests/unit/test_ChildEvents.js
+++ b/toolkit/components/telemetry/tests/unit/test_ChildEvents.js
@@ -2,16 +2,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/
 */
 
 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/PromiseUtils.jsm", this);
 Cu.import("resource://testing-common/ContentTaskUtils.jsm", this);
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 
 const MESSAGE_CHILD_TEST_DONE = "ChildTest:Done";
 
 const PLATFORM_VERSION = "1.9.2";
 const APP_VERSION = "1";
 const APP_ID = "xpcshell@tests.mozilla.org";
 const APP_NAME = "XPCShell";
 
@@ -61,17 +62,17 @@ add_task(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);
   yield TelemetryController.testSetup();
   // Make sure we don't generate unexpected pings due to pref changes.
   yield 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
@@ -1,13 +1,14 @@
 
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
 Cu.import("resource://gre/modules/PromiseUtils.jsm", this);
 Cu.import("resource://testing-common/ContentTaskUtils.jsm", this);
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 
 const MESSAGE_TELEMETRY_PAYLOAD = "Telemetry:Payload";
 const MESSAGE_TELEMETRY_GET_CHILD_PAYLOAD = "Telemetry:GetChildPayload";
 const MESSAGE_CHILD_TEST_DONE = "ChildTest:Done";
 
 const PLATFORM_VERSION = "1.9.2";
 const APP_VERSION = "1";
 const APP_ID = "xpcshell@tests.mozilla.org";
@@ -72,17 +73,17 @@ add_task(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);
   yield TelemetryController.testSetup();
   if (runningInParent) {
     // Make sure we don't generate unexpected pings due to pref changes.
     yield 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
@@ -2,16 +2,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/
 */
 
 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/PromiseUtils.jsm", this);
 Cu.import("resource://testing-common/ContentTaskUtils.jsm", this);
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 
 const MESSAGE_CHILD_TEST_DONE = "ChildTest:Done";
 
 const PLATFORM_VERSION = "1.9.2";
 const APP_VERSION = "1";
 const APP_ID = "xpcshell@tests.mozilla.org";
 const APP_NAME = "XPCShell";
 
@@ -135,17 +136,17 @@ add_task(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);
   yield TelemetryController.testSetup();
   if (runningInParent) {
     setParentScalars();
     // Make sure we don't generate unexpected pings due to pref changes.
     yield 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
@@ -7,16 +7,17 @@
 "use strict";
 
 Cu.import("resource://gre/modules/ClientID.jsm", this);
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 Cu.import("resource://gre/modules/TelemetryArchive.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 Cu.import("resource://gre/modules/osfile.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 
 XPCOMUtils.defineLazyGetter(this, "gPingsArchivePath", function() {
   return OS.Path.join(OS.Constants.Path.profileDir, "datareporting", "archived");
 });
 
 /**
  * Fakes the archive storage quota.
  * @param {Integer} aArchiveQuota The new quota, in bytes.
@@ -63,17 +64,17 @@ var getArchivedPingsInfo = async functio
   archivedPings.sort((a, b) => b.timestamp - a.timestamp);
   return archivedPings;
 };
 
 add_task(function* test_setup() {
   do_get_profile(true);
   // Make sure we don't generate unexpected pings due to pref changes.
   yield setEmptyPrefWatchlist();
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
 });
 
 add_task(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
@@ -9,19 +9,16 @@
 Cu.import("resource://gre/modules/osfile.jsm", this);
 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/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 => {
@@ -36,18 +33,18 @@ function waitForPingDeletion(pingId) {
 
   return new Promise((resolve, reject) => checkFn(resolve, reject));
 }
 
 add_task(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(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
@@ -4,22 +4,22 @@
 
 Cu.import("resource://gre/modules/Preferences.jsm", this);
 Cu.import("resource://gre/modules/Promise.jsm", this);
 Cu.import("resource://gre/modules/TelemetryArchive.jsm", this);
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 Cu.import("resource://gre/modules/TelemetryEnvironment.jsm", this);
 Cu.import("resource://gre/modules/osfile.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
+Cu.import("resource://gre/modules/TelemetryUtils.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");
@@ -87,17 +87,17 @@ add_task(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.
   yield setEmptyPrefWatchlist();
 
-  Preferences.set(PREF_TELEMETRY_ENABLED, true);
+  Preferences.set(TelemetryUtils.Preferences.TelemetryEnabled, true);
 });
 
 add_task(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
@@ -1,13 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 Cu.import("resource://gre/modules/AppConstants.jsm", this);
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 
 // We need both in order to capture stacks.
 const ENABLE_TESTS = AppConstants.MOZ_GECKO_PROFILER;
 
 /**
  * Ensures that the sctucture of the javascript object used for capturing stacks
  * is as intended. The structure is expected to be as in this example:
  *
@@ -178,11 +179,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
@@ -23,22 +23,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;
 
 function sendPing(aSendClientId, aSendEnvironment) {
   if (PingServer.started) {
     TelemetrySend.setServer("http://localhost:" + PingServer.port);
   } else {
     TelemetrySend.setServer("http://doesnotexist");
   }
@@ -93,18 +87,18 @@ function checkPingFormat(aPing, aType, a
 
 add_task(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.
   yield 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);
 
   yield new Promise(resolve =>
     Telemetry.asyncFetchTelemetryData(wrapWithExceptionHandler(resolve)));
 });
 
 add_task(function* asyncSetup() {
   yield TelemetryController.testSetup();
 });
@@ -118,59 +112,59 @@ add_task(function* test_overwritePing() 
 });
 
 // Checks that a sent ping is correctly received by a dummy http server.
 add_task(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);
 
   yield sendPing(false, false);
   let request = yield 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(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 = yield PingServer.promiseNextPing();
   checkPingFormat(ping, DELETION_PING_TYPE, true, false);
   // Wait on ping activity to settle.
   yield 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.
   yield 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.
   yield TelemetrySend.testWaitOnOutgoingPings();
   // Wait for the pending pings to be deleted. Resetting TelemetryController doesn't
   // trigger the shutdown, so we need to call it ourselves.
   yield TelemetryStorage.shutdown();
   // Simulate a restart, and spin the send task.
   yield TelemetryController.testReset();
@@ -179,41 +173,40 @@ add_task(function* test_disableDataUploa
   let pendingPings = yield 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.
   yield TelemetrySend.shutdown();
   // Reset the controller to spin the ping sending task.
   yield TelemetryController.testReset();
   ping = yield 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.
   yield TelemetrySend.testWaitOnOutgoingPings();
   // Restore FHR Upload.
-  Preferences.set(PREF_FHR_UPLOAD_ENABLED, true);
+  Preferences.set(TelemetryUtils.Preferences.FhrUploadEnabled, true);
 });
 
 add_task(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);
   yield TelemetryController.testShutdown();
   yield ClientID._reset();
   yield 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.
@@ -249,17 +242,17 @@ add_task(function* test_pingHasClientId(
   Assert.equal(h.snapshot().sum, 0, "We must have used the cached clientId.");
   ping = yield 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);
   yield TelemetryController.testShutdown();
   yield TelemetryStorage.testClearPendingPings();
   yield TelemetryController.testReset();
   yield sendPing(true, false);
   ping = yield 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.");
@@ -289,18 +282,18 @@ add_task(function* test_pingHasEnvironme
 
 add_task(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 = yield PingServer.promiseNextPing();
     checkPingFormat(ping, DELETION_PING_TYPE, true, false);
   }
@@ -311,25 +304,25 @@ add_task(function* test_archivePings() {
 
   // Check that the ping was archived, even with upload disabled.
   let ping = yield 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 = yield sendPing(true, true);
   let promise = TelemetryArchive.promiseArchivedPingById(pingId);
   Assert.ok((yield 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 = yield sendPing(true, true);
 
   // Check that we archive pings when successfully sending them.
@@ -425,42 +418,42 @@ add_task(function* test_changePingAfterS
   Assert.equal(archivedCopy.payload.canary, "test",
                "The payload must not be changed after being submitted.");
 });
 
 add_task(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.
   yield 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);
   yield 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);
   yield 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(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
@@ -14,19 +14,20 @@
  */
 
 "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");
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 
 // 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(function* test_firstRun() {
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryControllerShutdown.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryControllerShutdown.js
@@ -7,38 +7,36 @@
 "use strict";
 
 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://gre/modules/TelemetryUtils.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(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.
   yield 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(function* test_sendTelemetryShutsDownWithinReasonableTimeout() {
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryController_idle.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryController_idle.js
@@ -4,31 +4,30 @@
 // Check that TelemetrySession notifies correctly on idle-daily.
 
 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/Task.jsm", this);
 Cu.import("resource://gre/modules/TelemetryStorage.jsm", this);
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
+Cu.import("resource://gre/modules/TelemetryUtils.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(function* test_setup() {
   do_get_profile();
 
   // Make sure we don't generate unexpected pings due to pref changes.
   yield 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(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
@@ -1,13 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 Cu.import("resource://gre/modules/TelemetryLog.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 
 const TEST_PREFIX = "TEST-";
 const TEST_REGEX = new RegExp("^" + TEST_PREFIX);
 
 function check_event(event, id, data) {
   do_print("Checking message " + id);
   do_check_eq(event[0], id);
   do_check_true(event[1] > 0);
@@ -21,17 +22,17 @@ function check_event(event, id, data) {
       do_check_eq(event[i + 2], data[i]);
     }
   }
 }
 
 add_task(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);
   yield 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_TelemetryReportingPolicy.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryReportingPolicy.js
@@ -11,77 +11,66 @@ 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(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.
   yield 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(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", null);
   Assert.equal(startupTimeout, FIRST_RUN_TIMEOUT_MSEC,
                "The infobar display timeout should be 60s on the first run.");
@@ -96,47 +85,47 @@ add_task(function* test_firstRun() {
 add_task(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 +133,17 @@ add_task(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(function* test_migratePrefs() {
@@ -181,47 +170,47 @@ add_task(function* test_userNotifiedOfCu
   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(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);
 
   yield 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
@@ -10,18 +10,16 @@ Cu.import("resource://gre/modules/Teleme
 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;
@@ -74,17 +72,17 @@ function histogramValueCount(h) {
   return h.counts.reduce((a, b) => a + b);
 }
 
 add_task(function* test_setup() {
   // Trigger a proper telemetry init.
   do_get_profile(true);
   // Make sure we don't generate unexpected pings due to pref changes.
   yield setEmptyPrefWatchlist();
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
 });
 
 // Test the ping sending logic.
 add_task(function* test_sendPendingPings() {
   const TYPE_PREFIX = "test-sendPendingPings-";
   const TEST_TYPE_A = TYPE_PREFIX + "A";
   const TEST_TYPE_B = TYPE_PREFIX + "B";
 
@@ -132,17 +130,17 @@ add_task(function* test_sendPendingPings
   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();
   yield TelemetryController.testReset();
   let [pingSendTimerCallback, pingSendTimeout] = yield 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.
@@ -424,50 +422,49 @@ add_task(function* test_persistCurrentPi
 
   // After a restart the pings should have been found when scanning.
   yield TelemetrySend.reset();
   Assert.equal(TelemetrySend.pendingPingCount, PING_COUNT, "Should have the correct pending ping count");
 });
 
 add_task(function* test_sendCheckOverride() {
   const TEST_PING_TYPE = "test-sendCheckOverride";
-  const PREF_OVERRIDE_OFFICIAL_CHECK = "toolkit.telemetry.send.overrideOfficialCheck";
 
   // Clear any pending pings.
   yield TelemetryController.testShutdown();
   yield 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.
   yield 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"));
 
     yield 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();
   yield TelemetrySend.reset();
   yield TelemetryController.submitExternalPing(TEST_PING_TYPE, { test: "test" });
 
   // Make sure we received the ping.
   const ping = yield 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(function* cleanup() {
   yield PingServer.stop();
 });
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js
@@ -8,16 +8,17 @@
  */
 
 "use strict"
 
 Cu.import("resource://gre/modules/osfile.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/Promise.jsm", this);
 Cu.import("resource://gre/modules/TelemetryStorage.jsm", this);
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySend.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 var {OS: {File, Path, Constants}} = Cu.import("resource://gre/modules/osfile.jsm", {});
 
 // We increment TelemetryStorage's MAX_PING_FILE_AGE and
 // OVERDUE_PING_FILE_AGE by 1 minute so that our test pings exceed
 // those points in time, even taking into account file system imprecision.
@@ -27,18 +28,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
@@ -146,28 +145,28 @@ function pingHandler(aRequest) {
 add_task(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.
   yield setEmptyPrefWatchlist();
 
-  Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
-  Services.prefs.setCharPref(TelemetryController.Constants.PREF_SERVER,
-                             "http://localhost:" + PingServer.port);
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, 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(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);
 
   yield TelemetryController.testSetup();
 
   let directory = TelemetryStorage.pingDirectoryPath;
   yield File.makeDir(directory, { ignoreExisting: true, unixMode: OS.Constants.S_IRWXU });
 
   yield TelemetryStorage.testClearPendingPings();
 });
@@ -382,17 +381,17 @@ add_task(function* test_overdue_old_form
   yield TelemetryStorage.testClearPendingPings();
   PingServer.resetPingHandler();
 });
 
 add_task(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.
   yield TelemetryStorage.testClearPendingPings();
   yield TelemetryController.testReset();
   yield TelemetrySend.testWaitOnOutgoingPings();
   yield TelemetryStorage.testPendingQuotaTaskPromise();
 
@@ -533,14 +532,14 @@ add_task(function* test_pendingPingsQuot
   yield 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(function* teardown() {
   yield PingServer.stop();
 });
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
@@ -55,22 +55,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 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);
 });
 
@@ -490,18 +484,18 @@ function write_fake_failedprofilelocks_f
 
 add_task(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.
   yield 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;
@@ -557,17 +551,17 @@ add_task(function* test_noServerPing() {
   // problems to the consequent tests.
   yield TelemetryController.testShutdown();
 });
 
 // Checks that a sent ping is correctly received by a dummy http server.
 add_task(function* test_simplePing() {
   yield 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";
@@ -1371,52 +1365,52 @@ add_task(function* test_sendShutdownPing
       (AppConstants.platform == "linux" && OS.Constants.Sys.bits == 32)) {
     // We don't support the pingsender on Android, yet, see bug 1335917.
     // We also don't suppor the pingsender testing on Treeherder for
     // Linux 32 bit (due to missing libraries). So skip it there too.
     // See bug 1310703 comment 78.
     return;
   }
 
-  Preferences.set(PREF_SHUTDOWN_PINGSENDER, true);
+  Preferences.set(TelemetryUtils.Preferences.ShutdownPingSender, true);
   PingServer.clearRequests();
 
   // Shutdown telemetry and wait for an incoming ping.
   let nextPing = PingServer.promiseNextPing();
   yield TelemetryController.testShutdown();
   const ping = yield nextPing;
 
   // Check that we received a shutdown ping.
   checkPingFormat(ping, ping.type, true, true);
   Assert.equal(ping.payload.info.reason, REASON_SHUTDOWN);
   Assert.equal(ping.clientId, gClientID);
 
   // 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);
   yield TelemetryController.testReset();
   yield TelemetryController.testShutdown();
 
   // Make sure we have no pending pings between the runs.
   yield TelemetryStorage.testClearPendingPings();
 
   // Enable ping upload and disable the "submission policy".
   // The shutdown ping must not be sent.
-  Preferences.set(PREF_FHR_UPLOAD_ENABLED, true);
-  Preferences.set(PREF_BYPASS_NOTIFICATION, false);
+  Preferences.set(TelemetryUtils.Preferences.FhrUploadEnabled, true);
+  Preferences.set(TelemetryUtils.Preferences.BypassNotification, false);
   yield TelemetryController.testReset();
   yield TelemetryController.testShutdown();
 
 
   // Reset the pref and restart Telemetry.
-  Preferences.reset(PREF_SHUTDOWN_PINGSENDER);
+  Preferences.reset(TelemetryUtils.Preferences.ShutdownPingSender);
   // We cannot reset PREF_BYPASS_NOTIFICATION, as we need it to be
   // |true| in tests.
-  Preferences.set(PREF_BYPASS_NOTIFICATION, true);
+  Preferences.set(TelemetryUtils.Preferences.BypassNotification, true);
   PingServer.resetPingHandler();
   yield TelemetryController.testReset();
 });
 
 add_task(function* test_savedSessionData() {
   // Create the directory which will contain the data file, if it doesn't already
   // exist.
   yield OS.File.makeDir(DATAREPORTING_PATH);