Bug 1400870 - Keep the attribution code on environment changes. r=chutten, a=sledru
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Thu, 21 Sep 2017 09:34:58 +0200
changeset 434209 7e35ed4a8c47909b300a79079ea05fba53cf80fe
parent 434208 bc83af76203e62c7b61040630538a6d7d07458e3
child 434210 ced074245173c8b2eb9890aa7208eeece6757986
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten, sledru
bugs1400870
milestone57.0
Bug 1400870 - Keep the attribution code on environment changes. r=chutten, a=sledru This patch makes sure |_updateSettings| carries over the attribution code, if present. Without this patch the whole "environment.settings" section is replaced and the attribution code disppears after the first environment change/subsession split. MozReview-Commit-ID: 8bxjVOl2mUp
toolkit/components/telemetry/TelemetryEnvironment.jsm
toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
--- a/toolkit/components/telemetry/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm
@@ -1358,17 +1358,23 @@ EnvironmentCache.prototype = {
    * Update the cached settings data.
    */
   _updateSettings() {
     let updateChannel = null;
     try {
       updateChannel = UpdateUtils.getUpdateChannel(false);
     } catch (e) {}
 
+    // Make sure to retain the attribution code across environment changes.
+    const attributionCode =
+      (this._currentEnvironment.settings &&
+       this._currentEnvironment.settings.attribution) || {};
+
     this._currentEnvironment.settings = {
+      attribution: attributionCode,
       blocklistEnabled: Services.prefs.getBoolPref(PREF_BLOCKLIST_ENABLED, true),
       e10sEnabled: Services.appinfo.browserTabsRemoteAutostart,
       e10sMultiProcesses: Services.appinfo.maxWebProcessCount,
       e10sCohort: Services.prefs.getStringPref(PREF_E10S_COHORT, "unknown"),
       telemetryEnabled: Utils.isTelemetryEnabled,
       locale: getBrowserLocale(),
       update: {
         channel: updateChannel,
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
@@ -445,17 +445,17 @@ function checkSettingsSection(data) {
   Assert.equal(typeof update.autoDownload, "boolean");
 
   // Check "defaultSearchEngine" separately, as it can either be undefined or string.
   if ("defaultSearchEngine" in data.settings) {
     checkString(data.settings.defaultSearchEngine);
     Assert.equal(typeof data.settings.defaultSearchEngineData, "object");
   }
 
-  if ("attribution" in data.settings) {
+  if (gIsWindows) {
     Assert.equal(typeof data.settings.attribution, "object");
     Assert.equal(data.settings.attribution.source, "google.com");
   }
 }
 
 function checkProfileSection(data) {
   Assert.ok("profile" in data, "There must be a profile section in Environment.");
   Assert.equal(data.profile.creationDate, truncateToDays(PROFILE_CREATION_DATE_MS));