Bug 1239480 - Make test_TelemetryReportingPolicy.js set the minimum policy version pref for the right channel. r=gfritzsche, a=test-only
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Sat, 16 Jan 2016 08:39:38 +0100
changeset 310844 7990e9d7ec79a722c676d2715fefd02c132e12ea
parent 310843 07672cba658e2d403b91e039f049890bf9bbc002
child 310845 9247229e7aa2fcddd2b92bc286f1691fc511baa7
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche, test-only
bugs1239480
milestone45.0a2
Bug 1239480 - Make test_TelemetryReportingPolicy.js set the minimum policy version pref for the right channel. r=gfritzsche, a=test-only
toolkit/components/telemetry/tests/unit/test_TelemetryReportingPolicy.js
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryReportingPolicy.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryReportingPolicy.js
@@ -9,16 +9,17 @@
 Cu.import("resource://gre/modules/Preferences.jsm", this);
 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/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 PREF_DRS_ENABLED = "datareporting.healthreport.service.enabled";
 
 const TEST_CHANNEL = "TestChannelABC";
 
 const PREF_POLICY_BRANCH = "datareporting.policy.";
@@ -36,16 +37,31 @@ function fakeShowPolicyTimeout(set, clea
   reportingPolicy.Policy.clearShowInfobarTimeout = clear;
 }
 
 function fakeResetAcceptedPolicy() {
   Preferences.reset(PREF_ACCEPTED_POLICY_DATE);
   Preferences.reset(PREF_ACCEPTED_POLICY_VERSION);
 }
 
+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;
+
+  // 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);
+}
+
 function run_test() {
   // Addon manager needs a profile directory
   do_get_profile(true);
   loadAddonManager("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
   Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
   // We need to disable FHR in order to use the policy from telemetry.
   Services.prefs.setBoolPref(PREF_DRS_ENABLED, false);
@@ -107,17 +123,17 @@ add_task(function* test_prefs() {
 
   // Turn the submission back on.
   Preferences.set(PREF_DATA_SUBMISSION_ENABLED, 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;
-  Preferences.set(PREF_MINIMUM_POLICY_VERSION, newMinimum);
+  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);
   TelemetryReportingPolicy.testInfobarShown();
   Assert.ok(TelemetryReportingPolicy.testIsUserNotified(),
             "Accepting the policy again should show the user as notified.");