Bug 1171730 - Funnelcake builds should use geo-specific defaults. r=florian
authorMike Connor <mconnor@mozilla.com>
Fri, 05 Jun 2015 08:30:00 -0400
changeset 247435 c557991689fb299a4158319165affe4ac93ba9fb
parent 247434 970330c5d6f3b4caa9c0be0a2d3b470b33329bb0
child 247436 cba90cce9749b60bcbce1c89aecde873bcbc9909
push id28865
push userkwierso@gmail.com
push dateFri, 05 Jun 2015 22:26:42 +0000
treeherdermozilla-central@49f13b251968 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1171730
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1171730 - Funnelcake builds should use geo-specific defaults. r=florian
toolkit/components/search/nsSearchService.js
toolkit/components/search/tests/xpcshell/head_search.js
toolkit/components/search/tests/xpcshell/test_location_funnelcake.js
toolkit/components/search/tests/xpcshell/test_location_partner.js
toolkit/components/search/tests/xpcshell/xpcshell.ini
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -404,27 +404,34 @@ loadListener.prototype = {
   onRedirect: function (aChannel, aNewChannel) {},
   // nsIProgressEventSink
   onProgress: function (aRequest, aContext, aProgress, aProgressMax) {},
   onStatus: function (aRequest, aContext, aStatus, aStatusArg) {}
 }
 
 // Method to determine if we should be using geo-specific defaults
 function geoSpecificDefaultsEnabled() {
+  // check to see if this is a partner build.  Partner builds should not use geo-specific defaults.
+  let distroID;
+  try {
+    distroID = Services.prefs.getCharPref("distribution.id");
+
+    // Mozilla-provided builds (i.e. funnelcake) are not partner builds
+    if (distroID && !distroID.startsWith("mozilla")) {
+      return false;
+    }
+  } catch (e) {}
+
+  // if we make it here, the pref should dictate behaviour
   let geoSpecificDefaults = false;
   try {
     geoSpecificDefaults = Services.prefs.getBoolPref("browser.search.geoSpecificDefaults");
   } catch(e) {}
 
-  let distroID;
-  try {
-    distroID = Services.prefs.getCharPref("distribution.id");
-  } catch (e) {}
-
-  return (geoSpecificDefaults && !distroID);
+  return geoSpecificDefaults;
 }
 
 // Some notes on countryCode and region prefs:
 // * A "countryCode" pref is set via a geoip lookup.  It always reflects the
 //   result of that geoip request.
 // * A "region" pref, once set, is the region actually used for search.  In
 //   most cases it will be identical to the countryCode pref.
 // * The value of "region" and "countryCode" will only not agree in one edge
--- a/toolkit/components/search/tests/xpcshell/head_search.js
+++ b/toolkit/components/search/tests/xpcshell/head_search.js
@@ -331,16 +331,63 @@ function installTestEngine() {
   do_get_file("data/engine.xml").copyTo(engineDir, "engine.xml");
 
   do_register_cleanup(function() {
     removeMetadata();
     removeCacheFile();
   });
 }
 
+/**
+ * Wrapper for nsIPrefBranch::setComplexValue.
+ * @param aPrefName
+ *        The name of the pref to set.
+ */
+function setLocalizedPref(aPrefName, aValue) {
+  const nsIPLS = Ci.nsIPrefLocalizedString;
+  try {
+    var pls = Components.classes["@mozilla.org/pref-localizedstring;1"]
+                        .createInstance(Ci.nsIPrefLocalizedString);
+    pls.data = aValue;
+    Services.prefs.setComplexValue(aPrefName, nsIPLS, pls);
+  } catch (ex) {}
+}
+
+
+/**
+ * Installs two test engines, sets them as default for US vs. general.
+ */
+function setUpGeoDefaults() {
+  removeMetadata();
+  removeCacheFile();
+
+  do_check_false(Services.search.isInitialized);
+
+  let engineDummyFile = gProfD.clone();
+  engineDummyFile.append("searchplugins");
+  engineDummyFile.append("test-search-engine.xml");
+  let engineDir = engineDummyFile.parent;
+  engineDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
+
+  do_get_file("data/engine.xml").copyTo(engineDir, "engine.xml");
+
+  engineDummyFile = gProfD.clone();
+  engineDummyFile.append("searchplugins");
+  engineDummyFile.append("test-search-engine2.xml");
+
+  do_get_file("data/engine2.xml").copyTo(engineDir, "engine2.xml");
+
+  setLocalizedPref("browser.search.defaultenginename",    "Test search engine");
+  setLocalizedPref("browser.search.defaultenginename.US", "A second test engine");
+
+  do_register_cleanup(function() {
+    removeMetadata();
+    removeCacheFile();
+  });
+}
 
 /**
  * Returns a promise that is resolved when an observer notification from the
  * search service fires with the specified data.
  *
  * @param aExpectedData
  *        The value the observer notification sends that causes us to resolve
  *        the promise.
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_location_funnelcake.js
@@ -0,0 +1,17 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function run_test() {
+  Services.prefs.setCharPref("browser.search.geoip.url", 'data:application/json,{"country_code": "US"}');
+  // funnelcake builds start with "mozilla"
+  Services.prefs.setCharPref("distribution.id", 'mozilla38');
+  setUpGeoDefaults();
+
+  Services.search.init(() => {
+    equal(Services.search.defaultEngine.name, "A second test engine");
+
+    do_test_finished();
+    run_next_test();
+  });
+  do_test_pending();
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_location_partner.js
@@ -0,0 +1,16 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function run_test() {
+  Services.prefs.setCharPref("browser.search.geoip.url", 'data:application/json,{"country_code": "US"}');
+  Services.prefs.setCharPref("distribution.id", 'partner-1');
+  setUpGeoDefaults();
+
+  Services.search.init(() => {
+    equal(Services.search.defaultEngine.name, "Test search engine");
+
+    do_test_finished();
+    run_next_test();
+  });
+  do_test_pending();
+}
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -33,16 +33,18 @@ support-files =
 [test_init_async_multiple_then_sync.js]
 [test_json_cache.js]
 [test_location.js]
 [test_location_error.js]
 [test_location_malformed_json.js]
 [test_location_migrate_countrycode_isUS.js]
 [test_location_migrate_no_countrycode_isUS.js]
 [test_location_migrate_no_countrycode_notUS.js]
+[test_location_partner.js]
+[test_location_funnelcake.js]
 [test_location_sync.js]
 [test_location_timeout.js]
 [test_location_timeout_xhr.js]
 [test_nodb.js]
 [test_nodb_pluschanges.js]
 [test_save_sorted_engines.js]
 [test_purpose.js]
 [test_defaultEngine.js]