Bug 1541416 - Ensure more engines are available in applicable regions. r=daleharvey
☠☠ backed out by c98b1ae65a07 ☠ ☠
authorMark Banner <standard8@mozilla.com>
Tue, 07 May 2019 16:40:39 +0000
changeset 531740 90e7019e0fa8e062f4b887d2802e203e4bd39300
parent 531739 d59bc9316e781b0620f534692a5e104578f87157
child 531741 4d5a0aca43c2f8303078cdc003848ce4930c6b10
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaleharvey
bugs1541416
milestone68.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 1541416 - Ensure more engines are available in applicable regions. r=daleharvey Depends on D29808 Differential Revision: https://phabricator.services.mozilla.com/D29862
toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js
toolkit/components/search/tests/xpcshell/searchconfigs/test_amazon.js
toolkit/components/search/tests/xpcshell/searchconfigs/test_duckduckgo.js
toolkit/components/search/tests/xpcshell/searchconfigs/test_ebay.js
toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.ini
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js
@@ -196,56 +196,75 @@ class SearchConfigTest {
       if (inRegions && inLocales) {
         return true;
       }
     }
     return false;
   }
 
   /**
+   * Helper function to determine if an engine matches within a list.
+   * Due to Amazon's current complex setup with three different identifiers,
+   * if the identifier is 'amazon', then we do a startsWith match. Otherwise
+   * we expect the names to equal.
+   *
+   * @param {Array} engines
+   *   The list of engines to check.
+   * @param {string} identifier
+   *   The identifier to look for in the list.
+   * @returns {boolean}
+   *   Returns true if the engine is found within the list.
+   */
+  _enginesMatch(engines, identifier) {
+    if (identifier == "amazon") {
+      return !!engines.find(engine => engine.startsWith(identifier));
+    }
+    return engines.includes(identifier);
+  }
+
+  /**
    * Asserts whether the engines rules defined in the configuration are met.
    *
    * @param {Array} engines
    *   The list of engines to check.
    * @param {string} region
    *   The two-letter region code.
    * @param {string} locale
    *   The two-letter locale code.
    * @param {string} section
    *   The section of the configuration to check.
    */
   _assertEngineRules(engines, region, locale, section) {
     const infoString = `region: "${region}" locale: "${locale}"`;
     const config = this._config[section];
     const hasIncluded = "included" in config;
     const hasExcluded = "excluded" in config;
+    const identifierIncluded = this._enginesMatch(engines, this._config.identifier);
 
     // If there's not included/excluded, then this shouldn't be the default anywhere.
     if (section == "default" && !hasIncluded && !hasExcluded) {
-      Assert.ok(!engines.includes(this._config.identifier),
+      Assert.ok(!identifierIncluded,
         `Should not be ${section} for any locale/region,
          currently set for ${infoString}`);
       return;
     }
 
     // If there's no included section, we assume the engine is default everywhere
     // and we should apply the exclusions instead.
     let included = (hasIncluded &&
       this._localeRegionInSection(config.included, region, locale));
 
     let notExcluded = (hasExcluded &&
      !this._localeRegionInSection(config.excluded, region, locale));
 
     if (included || notExcluded) {
-      Assert.ok(engines.includes(this._config.identifier),
-        `Should be ${section} for ${infoString}`);
+      Assert.ok(identifierIncluded, `Should be ${section} for ${infoString}`);
       return;
     }
-    Assert.ok(!engines.includes(this._config.identifier),
-      `Should not be ${section} for ${infoString}`);
+    Assert.ok(!identifierIncluded, `Should not be ${section} for ${infoString}`);
   }
 
   /**
    * Asserts whether the engine is correctly set as default or not.
    *
    * @param {string} region
    *   The two-letter region code.
    * @param {string} locale
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_amazon.js
@@ -0,0 +1,41 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const test = new SearchConfigTest({
+  identifier: "amazon",
+  default: {
+    // Not included anywhere.
+  },
+  available: {
+    included: [{
+      // We don't currently enforce by region, but do locale instead.
+      // regions: [
+      //   "at", "au", "be", "ca", "ch", "de", "fr", "gb", "ie", "it", "jp", "nl",
+      //   "us",
+      // ],
+      locales: {
+        matches: [
+          "ach", "af", "ar", "as", "az", "bg", "bn", "bn-IN", "br", "cak", "cy",
+          "da", "de", "dsb", "el", "eo", "es-AR", "eu", "fa", "ff", "fr",
+          "ga-IE", "gd", "gl", "gn", "gu-IN", "hr", "hsb", "hy-AM", "ia", "is",
+          "it", "ja-JP-mac", "ja", "ka", "km", "kn", "lij", "lt", "mai", "mk",
+          "ml", "mr", "ms", "my", "nb-NO", "nn-NO", "or", "pa-IN", "pt-PT", "ro",
+          "si", "son", "sq", "sr", "ta", "te", "th", "tl", "trs", "ur", "uz",
+          "wo", "zh-CN",
+        ],
+        startsWith: ["en"],
+      },
+    }],
+  },
+});
+
+add_task(async function setup() {
+  // We only need to do setup on one of the tests.
+  await test.setup();
+});
+
+add_task(async function test_searchConfig_amazon() {
+  await test.run();
+});
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_duckduckgo.js
@@ -0,0 +1,24 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const test = new SearchConfigTest({
+  identifier: "ddg",
+  default: {
+    // Not included anywhere.
+  },
+  available: {
+    excluded: [
+      // Should be available everywhere.
+    ],
+  },
+});
+
+add_task(async function setup() {
+  await test.setup();
+});
+
+add_task(async function test_searchConfig_duckduckgo() {
+  await test.run();
+});
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_ebay.js
@@ -0,0 +1,70 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const test = new SearchConfigTest({
+  identifier: "ebay",
+  default: {
+    // Not included anywhere.
+  },
+  available: {
+    included: [{
+      // We don't currently enforce by region, but do locale instead.
+      // regions: [
+      //   "us", "gb", "ca", "ie", "fr", "it", "de", "at", "es", "nl", "ch", "au"
+      // ],
+      locales: {
+        matches: ["an", "en-US", "ast", "br", "ca", "cy", "de", "dsb", "en-CA", "en-GB", "es-ES", "eu", "fr", "fy-NL", "ga-IE", "gd", "gl", "hsb", "it", "lij", "nl", "rm", "wo"],
+      },
+    }],
+  },
+  // domains: {
+  //   // Note: These should be based on region, but we don't currently enforce that.
+  //   "ebay.com": {
+  //     locales: { matches: ["en-US"] },
+  //   },
+  //   "ebay.co.uk": {
+  //     locales: { matches: ["en-GB"] },
+  //   },
+  //   "ebay.ca": {
+  //     locales: { matches: ["en-CA"] },
+  //   },
+  //   "ebay.ie": {
+  //     locales: { matches: ["ie"] },
+  //   },
+  //   "ebay.fr": {
+  //     locales: { matches: ["fr"] },
+  //   },
+  //   "ebay.it": {
+  //     locales: { matches: ["it"] },
+  //   },
+  //   "ebay.de": {
+  //     locales: { matches: ["de"] },
+  //   },
+  //   "ebay.at": {
+  //     locales: { matches: ["ast"] },
+  //   },
+  //   "ebay.es": {
+  //     locales: { matches: ["an", "es-ES"] },
+  //   },
+  //   "ebay.nl": {
+  //     locales: { matches: ["nl"] },
+  //   },
+  //   "ebay.ch": {
+  //     locales: { matches: ["rm"] },
+  //   },
+  //   "ebay.au": {
+  //     regions: ["au"],
+  //   },
+  // },
+  // noSuggestionsURL: true,
+});
+
+add_task(async function setup() {
+  await test.setup();
+});
+
+add_task(async function test_searchConfig_ebay() {
+  await test.run();
+});
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.ini
@@ -1,26 +1,32 @@
 [DEFAULT]
 firefox-appdir = browser
 head = head_searchconfig.js
 skip-if = toolkit == 'android'
 support-files =
   ../../../../../../browser/locales/all-locales
 tags=searchconfig
 
+[test_amazon.js]
+requesttimeoutfactor = 2
 [test_baidu.js]
 # This is an extensive test and currently takes a long time. Therefore skip on
 # debug/asan and extend the timeout length otherwise.
 skip-if = debug || asan
 requesttimeoutfactor = 2
 [test_bing.js]
 # This is an extensive test and currently takes a long time. Therefore skip on
 # debug/asan and extend the timeout length otherwise.
 skip-if = debug || asan
 requesttimeoutfactor = 2
+[test_duckduckgo.js]
+requesttimeoutfactor = 2
+[test_ebay.js]
+requesttimeoutfactor = 2
 [test_google.js]
 # This is an extensive test and currently takes a long time. Therefore skip on
 # debug/asan and extend the timeout length otherwise.
 skip-if = debug || asan
 requesttimeoutfactor = 2
 [test_yandex.js]
 # This is an extensive test and currently takes a long time. Therefore skip on
 # debug/asan and extend the timeout length otherwise.