Bug 981689 (Show a notice to beta users when we turn telemetry on by default on the beta channel) - For the new channel-override preference, use UpdateChannel.jsm rather than nsIXULRuntime so that it's easier to QA the feature by hacking install.js. As part of that, add a new argument to UpdateChannel.js for excluding partners. r=bsmbedberg.
authorAsaf Romano <mano@mozilla.com>
Mon, 28 Apr 2014 17:04:51 +0300
changeset 181038 cf36a41c16483c38081c47805f932b384496fe13
parent 180931 86dce59c3d16a9c1334bd9cff507f2e77a4d1b49
child 181039 d25120c7a148b85f477595fcde0af21e9321c11c
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbsmbedberg
bugs981689
milestone31.0a1
Bug 981689 (Show a notice to beta users when we turn telemetry on by default on the beta channel) - For the new channel-override preference, use UpdateChannel.jsm rather than nsIXULRuntime so that it's easier to QA the feature by hacking install.js. As part of that, add a new argument to UpdateChannel.js for excluding partners. r=bsmbedberg.
services/datareporting/policy.jsm
toolkit/content/tests/unit/test_updateChannelModule.js
toolkit/content/tests/unit/xpcshell.ini
toolkit/modules/UpdateChannel.jsm
--- a/services/datareporting/policy.jsm
+++ b/services/datareporting/policy.jsm
@@ -25,16 +25,17 @@ this.EXPORTED_SYMBOLS = [
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 #endif
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Promise.jsm");
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://services-common/utils.js");
+Cu.import("resource://gre/modules/UpdateChannel.jsm");
 
 const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
 
 // Used as a sanity lower bound for dates stored in prefs. This module was
 // implemented in 2012, so any earlier dates indicate an incorrect clock.
 const OLDEST_ALLOWED_YEAR = 2012;
 
 const CURRENT_POLICY_VERSION = 2;
@@ -498,17 +499,17 @@ this.DataReportingPolicy.prototype = Obj
   },
 
   /**
    * The minimum policy version which for dataSubmissionPolicyAccepted to
    * to be valid.
    */
   get minimumPolicyVersion() {
     // First check if the current channel has an ove
-    let channel = Services.appinfo.defaultUpdateChannel;
+    let channel = UpdateChannel.get(false);
     let channelPref = this._prefs.get("minimumPolicyVersion.channel-" + channel);
     return channelPref !== undefined ?
            channelPref : this._prefs.get("minimumPolicyVersion", 1);
   },
 
   /**
    * Whether the user has accepted that data submission can occur.
    *
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/unit/test_updateChannelModule.js
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+Components.utils.import("resource://gre/modules/Preferences.jsm");
+Components.utils.import("resource://gre/modules/UpdateChannel.jsm");
+
+const PREF_APP_UPDATE_CHANNEL = "app.update.channel";
+const TEST_CHANNEL            = "TestChannel";
+const PREF_PARTNER_A          = "app.partner.test_partner_a";
+const TEST_PARTNER_A          = "TestPartnerA";
+const PREF_PARTNER_B          = "app.partner.test_partner_b";
+const TEST_PARTNER_B          = "TestPartnerB";
+
+function test_get() {
+  let defaultPrefs = new Preferences({ defaultBranch: true });
+  let currentChannel = defaultPrefs.get(PREF_APP_UPDATE_CHANNEL);
+
+  do_check_eq(UpdateChannel.get(), currentChannel);
+  do_check_eq(UpdateChannel.get(false), currentChannel);
+
+  defaultPrefs.set(PREF_APP_UPDATE_CHANNEL, TEST_CHANNEL);
+  do_check_eq(UpdateChannel.get(), TEST_CHANNEL);
+  do_check_eq(UpdateChannel.get(false), TEST_CHANNEL);
+
+  defaultPrefs.set(PREF_PARTNER_A, TEST_PARTNER_A);
+  defaultPrefs.set(PREF_PARTNER_B, TEST_PARTNER_B);
+  do_check_eq(UpdateChannel.get(),
+              TEST_CHANNEL + "-cck-" + TEST_PARTNER_A + "-" + TEST_PARTNER_B);
+  do_check_eq(UpdateChannel.get(false), TEST_CHANNEL);
+}
+
+function run_test() {
+  test_get();
+}
--- a/toolkit/content/tests/unit/xpcshell.ini
+++ b/toolkit/content/tests/unit/xpcshell.ini
@@ -1,5 +1,6 @@
 [DEFAULT]
 head = 
 tail = 
 
 [test_contentAreaUtils.js]
+[test_updateChannelModule.js]
--- a/toolkit/modules/UpdateChannel.jsm
+++ b/toolkit/modules/UpdateChannel.jsm
@@ -10,33 +10,38 @@ const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/Services.jsm");
 
 this.UpdateChannel = {
   /**
    * Read the update channel from defaults only.  We do this to ensure that
    * the channel is tightly coupled with the application and does not apply
    * to other instances of the application that may use the same profile.
+   *
+   * @param [optional] aIncludePartners
+   *        Whether or not to include the partner bits. Default: true.
    */
-  get: function UpdateChannel_get() {
+  get: function UpdateChannel_get(aIncludePartners = true) {
     let channel = "@MOZ_UPDATE_CHANNEL@";
     let defaults = Services.prefs.getDefaultBranch(null);
     try {
       channel = defaults.getCharPref("app.update.channel");
     } catch (e) {
       // use default value when pref not found
     }
 
-    try {
-      let partners = Services.prefs.getChildList("app.partner.").sort();
-      if (partners.length) {
-        channel += "-cck";
-        partners.forEach(function (prefName) {
-          channel += "-" + Services.prefs.getCharPref(prefName);
-        });
+    if (aIncludePartners) {
+      try {
+        let partners = Services.prefs.getChildList("app.partner.").sort();
+        if (partners.length) {
+          channel += "-cck";
+          partners.forEach(function (prefName) {
+            channel += "-" + Services.prefs.getCharPref(prefName);
+          });
+        }
+      } catch (e) {
+        Cu.reportError(e);
       }
-    } catch (e) {
-      Cu.reportError(e);
     }
 
     return channel;
   }
 };