Bug 1411867 - Linux repacks detected as unofficial builds. r=k88hudson draft
authorAndrei Oprea <andrei.br92@gmail.com>
Thu, 30 Nov 2017 18:24:12 +0100
changeset 705796 e1cfaaeea4beb21e32decc7d448bb70e546f0256
parent 704525 bff979e2ef09d34ff2dd042dca9d2fca559eb4fd
child 742460 9606e51647bc40179bf869c58f91d71d203f4278
push id91584
push userbmo:andrei.br92@gmail.com
push dateThu, 30 Nov 2017 17:24:52 +0000
reviewersk88hudson
bugs1411867
milestone58.0
Bug 1411867 - Linux repacks detected as unofficial builds. r=k88hudson MozReview-Commit-ID: 7itcGkDxKZx
browser/extensions/activity-stream/lib/ActivityStreamPrefs.jsm
browser/extensions/activity-stream/test/unit/lib/ActivityStreamPrefs.test.js
browser/extensions/activity-stream/test/unit/unit-entry.js
--- a/browser/extensions/activity-stream/lib/ActivityStreamPrefs.jsm
+++ b/browser/extensions/activity-stream/lib/ActivityStreamPrefs.jsm
@@ -1,14 +1,15 @@
 /* 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/. */
 "use strict";
 
 const {utils: Cu} = Components;
+Cu.import("resource://gre/modules/AppConstants.jsm");
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 const ACTIVITY_STREAM_PREF_BRANCH = "browser.newtabpage.activity-stream.";
 
 this.Prefs = class Prefs extends Preferences {
   /**
    * Prefs - A wrapper around Preferences that always sets the branch to
@@ -70,19 +71,18 @@ this.DefaultPrefs = class DefaultPrefs {
         break;
     }
   }
 
   /**
    * init - Set default prefs for all prefs in the config
    */
   init() {
-    // If Firefox is a locally built version or a testing build on try, etc.
-    // the value of the app.update.channel pref should be "default"
-    const IS_UNOFFICIAL_BUILD = Services.prefs.getStringPref("app.update.channel") === "default";
+    // Local developer builds (with the default mozconfig) aren't OFFICIAL
+    const IS_UNOFFICIAL_BUILD = !AppConstants.MOZILLA_OFFICIAL;
 
     for (const pref of this._config.keys()) {
       const prefConfig = this._config.get(pref);
       let value;
       if (IS_UNOFFICIAL_BUILD && "value_local_dev" in prefConfig) {
         value = prefConfig.value_local_dev;
       } else {
         value = prefConfig.value;
--- a/browser/extensions/activity-stream/test/unit/lib/ActivityStreamPrefs.test.js
+++ b/browser/extensions/activity-stream/test/unit/lib/ActivityStreamPrefs.test.js
@@ -96,18 +96,22 @@ describe("ActivityStreamPrefs", () => {
       it("should initialize a string pref", () => {
         defaultPrefs.init();
         assert.calledWith(defaultPrefs.branch.setStringPref, "bar", "BAR");
       });
       it("should initialize a integer pref", () => {
         defaultPrefs.init();
         assert.calledWith(defaultPrefs.branch.setIntPref, "baz", 1);
       });
+      it("should initialize a pref with value if Firefox is not a local build", () => {
+        defaultPrefs.init();
+        assert.calledWith(defaultPrefs.branch.setStringPref, "qux", "foo");
+      });
       it("should initialize a pref with value_local_dev if Firefox is a local build", () => {
-        sandbox.stub(global.Services.prefs, "getStringPref").returns("default");
+        sandbox.stub(global.AppConstants, "MOZILLA_OFFICIAL").value(false);
         defaultPrefs.init();
         assert.calledWith(defaultPrefs.branch.setStringPref, "qux", "foofoo");
       });
     });
     describe("#reset", () => {
       it("should clear user preferences for each pref in the config", () => {
         const defaultPrefs = new DefaultPrefs(TEST_PREF_CONFIG);
         sinon.spy(defaultPrefs.branch, "clearUserPref");
--- a/browser/extensions/activity-stream/test/unit/unit-entry.js
+++ b/browser/extensions/activity-stream/test/unit/unit-entry.js
@@ -7,16 +7,17 @@ const files = req.keys();
 // This exposes sinon assertions to chai.assert
 sinon.assert.expose(assert, {prefix: ""});
 
 chai.use(chaiAssertions);
 
 let overrider = new GlobalOverrider();
 
 overrider.set({
+  AppConstants: {MOZILLA_OFFICIAL: true},
   Components: {
     classes: {},
     interfaces: {},
     utils: {
       import() {},
       importGlobalProperties() {},
       reportError() {},
       now: () => window.performance.now()