Bug 1582942 - Port Search tests relating to the configuration to the modern configuration. r=mikedeboer
authorMark Banner <standard8@mozilla.com>
Thu, 03 Oct 2019 13:30:54 +0000
changeset 496173 9c35d67bf7b211993f4a2a1b19700707866fec40
parent 496172 7b3c76142ad70ce1fa8df3d55f32206b42cf3e4b
child 496174 8dc6192a2bc5e51e4f89a8dd3c85f27575b85310
push id36646
push usernerli@mozilla.com
push dateThu, 03 Oct 2019 21:48:01 +0000
treeherdermozilla-central@2e1bfb7458de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1582942
milestone71.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 1582942 - Port Search tests relating to the configuration to the modern configuration. r=mikedeboer Differential Revision: https://phabricator.services.mozilla.com/D47436
toolkit/components/search/SearchEngineSelector.jsm
toolkit/components/search/tests/xpcshell/data/engines.json
toolkit/components/search/tests/xpcshell/data1/engines.json
toolkit/components/search/tests/xpcshell/test_list_json_locale.js
toolkit/components/search/tests/xpcshell/test_list_json_searchorder.js
toolkit/components/search/tests/xpcshell/xpcshell-common.ini
toolkit/components/search/tests/xpcshell/xpcshell-legacyconfig.ini
--- a/toolkit/components/search/SearchEngineSelector.jsm
+++ b/toolkit/components/search/SearchEngineSelector.jsm
@@ -52,25 +52,27 @@ class SearchEngineSelector {
    * @returns {object} result - An object with "engines" field, a sorted
    *   list of engines and optionally "privateDefault" indicating the
    *   name of the engine which should be the default in private.
    */
   fetchEngineConfiguration(locale, region = "default") {
     log(`fetchEngineConfiguration ${region}:${locale}`);
     let cohort = Services.prefs.getCharPref("browser.search.cohort", null);
     let engines = [];
+    const lcLocale = locale.toLowerCase();
+    const lcRegion = region.toLowerCase();
     for (let config of this.configuration) {
       const appliesTo = config.appliesTo || [];
       const applies = appliesTo.filter(section => {
         let included =
           "included" in section &&
-          this._isInSection(region, locale, section.included);
+          this._isInSection(lcRegion, lcLocale, section.included);
         let excluded =
           "excluded" in section &&
-          this._isInSection(region, locale, section.excluded);
+          this._isInSection(lcRegion, lcLocale, section.excluded);
         if ("cohort" in section && cohort != section.cohort) {
           return false;
         }
         return included && !excluded;
       });
 
       let baseConfig = this._copyObject({}, config);
 
@@ -237,18 +239,22 @@ class SearchEngineSelector {
   _isInSection(region, locale, config) {
     if (!config) {
       return false;
     }
     if (config.everywhere) {
       return true;
     }
     let locales = config.locales || {};
-    let inLocales = locales.matches && locales.matches.includes(locale);
-    let inRegions = config.regions && config.regions.includes(region);
+    let inLocales =
+      "matches" in locales &&
+      !!locales.matches.find(e => e.toLowerCase() == locale);
+    let inRegions =
+      "regions" in config &&
+      !!config.regions.find(e => e.toLowerCase() == region);
     if (
       locales.startsWith &&
       locales.startsWith.some(key => locale.startsWith(key))
     ) {
       inLocales = true;
     }
     if (config.locales && config.regions) {
       return inLocales && inRegions;
--- a/toolkit/components/search/tests/xpcshell/data/engines.json
+++ b/toolkit/components/search/tests/xpcshell/data/engines.json
@@ -1,58 +1,75 @@
 {
   "data": [
     {
       "engineName": "Test search engine",
       "webExtensionId": "engine@search.mozilla.org",
       "webExtensionVersion": "1.0",
+      "orderHint": 10000,
       "appliesTo": [{
         "included": { "everywhere": true },
         "default": "yes"
       }]
     },
     {
       "engineName": "engine-pref",
       "webExtensionId": "engine-pref@search.mozilla.org",
       "webExtensionVersion": "1.0",
+      "orderHint": 7000,
       "appliesTo": [{
         "included": { "everywhere": true },
-        "default": "yes"
+        "excluded": { "locales": { "matches": ["de"] } },
+        "default": "no",
+        "defaultPrivate": "yes"
       }]
     },
     {
       "engineName": "engine-rel-searchform-purpose",
       "webExtensionId": "engine-rel-searchform-purpose@search.mozilla.org",
       "webExtensionVersion": "1.0",
+      "orderHint": 6000,
       "appliesTo": [{
         "included": { "everywhere": true },
-        "default": "yes"
+        "excluded": { "locales": { "matches": ["de", "fr"] } },
+        "default": "no"
       }]
     },
     {
       "engineName": "engine-chromeicon",
       "webExtensionId": "engine-chromeicon@search.mozilla.org",
       "webExtensionVersion": "1.0",
+      "orderHint": 8000,
       "appliesTo": [{
         "included": { "everywhere": true },
-        "default": "yes"
+        "excluded": { "locales": { "matches": ["de", "fr"] } },
+        "default": "no"
+      }, {
+        "included": { "regions": ["ru"] },
+        "default": "no"
       }]
     },
     {
       "engineName": "engine-resourceicon",
       "webExtensionId": "engine-resourceicon@search.mozilla.org",
       "webExtensionVersion": "1.0",
+      "orderHint": 9000,
       "appliesTo": [{
-        "included": { "everywhere": true },
-        "default": "yes"
+        "included": { "locales": { "matches": ["en-US", "fr"] } },
+        "excluded": {
+          "regions": ["ru"]
+        },
+        "default": "no"
       }]
     },
     {
       "engineName": "engine-reordered",
       "webExtensionId": "engine-reordered@search.mozilla.org",
       "webExtensionVersion": "1.0",
+      "orderHint": 5000,
       "appliesTo": [{
         "included": { "everywhere": true },
-        "default": "yes"
+        "excluded": { "locales": { "matches": ["de", "fr"] } },
+        "default": "no"
       }]
     }
   ]
 }
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/data1/engines.json
@@ -0,0 +1,24 @@
+{
+  "data": [
+    {
+      "engineName": "engine1",
+      "webExtensionId": "engine1@search.mozilla.org",
+      "webExtensionVersion": "1.0",
+      "orderHint": 10000,
+      "appliesTo": [{
+        "included": { "everywhere": true },
+        "default": "yes"
+      }]
+    },
+    {
+      "engineName": "engine2",
+      "webExtensionId": "engine2@search.mozilla.org",
+      "webExtensionVersion": "1.0",
+      "orderHint": 7000,
+      "appliesTo": [{
+        "included": { "everywhere": true },
+        "default": "no"
+      }]
+    }
+  ]
+}
--- a/toolkit/components/search/tests/xpcshell/test_list_json_locale.js
+++ b/toolkit/components/search/tests/xpcshell/test_list_json_locale.js
@@ -7,16 +7,17 @@
 
 add_task(function test_setup() {
   useTestEngineConfig();
 
   Services.prefs.setBoolPref(
     SearchUtils.BROWSER_SEARCH_PREF + "separatePrivateDefault",
     true
   );
+  Services.prefs.setCharPref("browser.search.region", "US");
 });
 
 add_task(async function test_listJSONlocale() {
   Services.locale.availableLocales = ["de"];
   Services.locale.requestedLocales = ["de"];
 
   await AddonTestUtils.promiseStartupManager();
   await Services.search.init();
--- a/toolkit/components/search/tests/xpcshell/test_list_json_searchorder.js
+++ b/toolkit/components/search/tests/xpcshell/test_list_json_searchorder.js
@@ -24,27 +24,49 @@ async function checkOrder(expectedOrder)
 }
 
 add_task(async function test_searchOrderJSON_no_separate_private() {
   Services.prefs.setBoolPref(
     SearchUtils.BROWSER_SEARCH_PREF + "separatePrivateDefault",
     false
   );
 
-  await checkOrder([
-    // Default engine
-    "Test search engine",
-    // Two engines listed in searchOrder.
-    "engine-resourceicon",
-    "engine-chromeicon",
-    // Rest of the engines in order.
-    "engine-pref",
-    "engine-rel-searchform-purpose",
-    "Test search engine (Reordered)",
-  ]);
+  // With modern configuration, we have a slightly different order, since the
+  // default private engine will get placed second, regardless of if the
+  // separate private engine is enabled or not.
+  if (
+    Services.prefs.getBoolPref(
+      SearchUtils.BROWSER_SEARCH_PREF + "modernConfig",
+      false
+    )
+  ) {
+    await checkOrder([
+      // Default engines
+      "Test search engine",
+      "engine-pref",
+      // Two engines listed in searchOrder.
+      "engine-resourceicon",
+      "engine-chromeicon",
+      // Rest of the engines in order.
+      "engine-rel-searchform-purpose",
+      "Test search engine (Reordered)",
+    ]);
+  } else {
+    await checkOrder([
+      // Default engine
+      "Test search engine",
+      // Two engines listed in searchOrder.
+      "engine-resourceicon",
+      "engine-chromeicon",
+      // Rest of the engines in order.
+      "engine-pref",
+      "engine-rel-searchform-purpose",
+      "Test search engine (Reordered)",
+    ]);
+  }
 });
 
 add_task(async function test_searchOrderJSON_separate_private() {
   Services.prefs.setBoolPref(
     SearchUtils.BROWSER_SEARCH_PREF + "separatePrivateDefault",
     true
   );
 
--- a/toolkit/components/search/tests/xpcshell/xpcshell-common.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell-common.ini
@@ -21,16 +21,26 @@ skip-if = true # Is confusing
 [test_engineUpdate.js]
 [test_hasEngineWithURL.js]
 [test_identifiers.js]
 [test_ignorelist_update.js]
 [test_ignorelist.js]
 [test_invalid_engine_from_dir.js]
 [test_json_cache_ignorelist.js]
 support-files = data/search_ignorelist.json
+[test_list_json_locale.js]
+[test_list_json_no_private_default.js]
+support-files =
+  data1/engine1/manifest.json
+  data1/engine2/manifest.json
+  data1/list.json
+  data1/engines.json
+[test_list_json_searchdefault_distro.js]
+[test_list_json_searchdefault.js]
+[test_list_json_searchorder.js]
 [test_location_error.js]
 [test_location_malformed_json.js]
 [test_location_timeout_xhr.js]
 [test_location_timeout.js]
 [test_location.js]
 [test_migrateWebExtensionEngine.js]
 [test_multipleIcons.js]
 [test_nocache.js]
--- a/toolkit/components/search/tests/xpcshell/xpcshell-legacyconfig.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell-legacyconfig.ini
@@ -69,24 +69,15 @@ skip-if = appname == "thunderbird"  # Fa
 [test_json_cache.js]
 support-files =
   data1/engine1/manifest.json
   data1/engine2/manifest.json
   data1/list.json
 [test_require_engines_in_cache.js]
 
 # Testing with list.json specifically - Bug 1582942
-[test_list_json_locale.js]
-[test_list_json_no_private_default.js]
-support-files =
-  data1/engine1/manifest.json
-  data1/engine2/manifest.json
-  data1/list.json
-[test_list_json_searchdefault.js]
-[test_list_json_searchdefault_distro.js]
-[test_list_json_searchorder.js]
 
 # Use geoSpecificDefaults - Bug 1542269
 [test_maybereloadengine_update.js]
 [test_reloadEngines.js]
 [test_geodefaults.js]
 [test_hidden.js]
 [test_webextensions_install.js]