Bug 1400870 - Keep the attribution code on environment changes. r?chutten draft
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Thu, 21 Sep 2017 09:34:58 +0200
changeset 668173 a210affaaecb39b349419aaf78fc5c0f26898974
parent 667608 a20de99fa3c1ba6287fe47d493a859a4e95120b0
child 732610 c0ccdf85f6c379f0cfbc9395a39c938a14ded39d
push id80949
push useralessio.placitelli@gmail.com
push dateThu, 21 Sep 2017 07:36:11 +0000
reviewerschutten
bugs1400870
milestone57.0a1
Bug 1400870 - Keep the attribution code on environment changes. r?chutten 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
@@ -313,31 +313,27 @@ function spoofPartnerInfo() {
   }
 }
 
 function getAttributionFile() {
   return FileUtils.getFile("LocalAppData", ["mozilla", AppConstants.MOZ_APP_NAME, "postSigningData"]);
 }
 
 function spoofAttributionData() {
-  if (gIsWindows) {
-    AttributionCode._clearCache();
-    let stream = Cc["@mozilla.org/network/file-output-stream;1"].
-                 createInstance(Ci.nsIFileOutputStream);
-    stream.init(getAttributionFile(), -1, -1, 0);
-    stream.write(ATTRIBUTION_CODE, ATTRIBUTION_CODE.length);
-    stream.close();
-  }
+  AttributionCode._clearCache();
+  let stream = Cc["@mozilla.org/network/file-output-stream;1"].
+               createInstance(Ci.nsIFileOutputStream);
+  stream.init(getAttributionFile(), -1, -1, 0);
+  stream.write(ATTRIBUTION_CODE, ATTRIBUTION_CODE.length);
+  stream.close();
 }
 
 function cleanupAttributionData() {
-  if (gIsWindows) {
-    getAttributionFile().remove(false);
-    AttributionCode._clearCache();
-  }
+  getAttributionFile().remove(false);
+  AttributionCode._clearCache();
 }
 
 /**
  * Check that a value is a string and not empty.
  *
  * @param aValue The variable to check.
  * @return True if |aValue| has type "string" and is not empty, False otherwise.
  */
@@ -445,20 +441,20 @@ 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 ("attribution" in data.settings) {
     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));
   Assert.equal(data.profile.resetDate, truncateToDays(PROFILE_RESET_DATE_MS));
 }