Bug 1541419 - Adds test to ensure that search engines are using the correct domain in all regions/locales. r=daleharvey
☠☠ backed out by 44db460adb2b ☠ ☠
authorMark Banner <standard8@mozilla.com>
Thu, 09 May 2019 19:45:49 +0000
changeset 532180 e661822f67309406c695209d4be605ff281a2777
parent 532179 3d13d2cb56d1f1ed2f09dbc630f206f76f2aa368
child 532181 9df2b856b6550578f75d862a1fb4579b5665742e
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
bugs1541419
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 1541419 - Adds test to ensure that search engines are using the correct domain in all regions/locales. r=daleharvey Depends on D30398 Differential Revision: https://phabricator.services.mozilla.com/D30399
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_baidu.js
toolkit/components/search/tests/xpcshell/searchconfigs/test_bing.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/test_google.js
toolkit/components/search/tests/xpcshell/searchconfigs/test_yandex.js
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js
@@ -8,16 +8,19 @@ XPCOMUtils.defineLazyModuleGetters(this,
   AddonTestUtils: "resource://testing-common/AddonTestUtils.jsm",
   OS: "resource://gre/modules/osfile.jsm",
   SearchTestUtils: "resource://testing-common/SearchTestUtils.jsm",
   Services: "resource://gre/modules/Services.jsm",
 });
 
 const GLOBAL_SCOPE = this;
 
+const URLTYPE_SUGGEST_JSON = "application/x-suggestions+json";
+const URLTYPE_SEARCH_HTML  = "text/html";
+
 /**
  * This class implements the test harness for search configuration tests.
  * These tests are designed to ensure that the correct search engines are
  * loaded for the various region/locale configurations.
  *
  * The configuration for each test is represented by an object having the
  * following properties:
  *
@@ -96,17 +99,21 @@ class SearchConfigTest {
     // We loop on region and then locale, so that we always cause a re-init
     // when updating the requested/available locales.
     for (let region of regions) {
       for (let locale of locales) {
         info(`Checking region: "${region}" locale: "${locale}"`);
         await this._reinit(region, locale);
 
         this._assertDefaultEngines(region, locale);
-        await this._assertAvailableEngines(region, locale);
+        const engines = await Services.search.getVisibleEngines();
+        const isPresent = this._assertAvailableEngines(region, locale, engines);
+        if (isPresent) {
+          this._assertCorrectDomains(region, locale, engines);
+        }
       }
     }
 
     Assert.ok(!this._testDebug, "Should not have test debug turned on in production");
   }
 
   /**
    * Causes re-initialization of the SearchService with the new region and locale.
@@ -196,96 +203,146 @@ class SearchConfigTest {
       if (inRegions && inLocales) {
         return true;
       }
     }
     return false;
   }
 
   /**
-   * Helper function to determine if an engine matches within a list.
+   * Helper function to find an engine from 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.
+   * @returns {Engine}
+   *   Returns the engine if found, null otherwise.
    */
-  _enginesMatch(engines, identifier) {
+  _findEngine(engines, identifier) {
     if (identifier == "amazon") {
-      return !!engines.find(engine => engine.startsWith(identifier));
+      return engines.find(engine => engine.identifier.startsWith(identifier));
     }
-    return engines.includes(identifier);
+    return engines.find(engine => engine.identifier == 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.
+   * @returns {boolean}
+   *   Returns true if the engine is expected to be present, false otherwise.
    */
   _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);
+    const identifierIncluded = !!this._findEngine(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(!identifierIncluded,
         `Should not be ${section} for any locale/region,
          currently set for ${infoString}`);
-      return;
+      return false;
     }
 
     // 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(identifierIncluded, `Should be ${section} for ${infoString}`);
-      return;
+      return true;
     }
     Assert.ok(!identifierIncluded, `Should not be ${section} for ${infoString}`);
+    return false;
   }
 
   /**
    * Asserts whether the engine is correctly set as default or not.
    *
    * @param {string} region
    *   The two-letter region code.
    * @param {string} locale
    *   The two-letter locale code.
    */
   _assertDefaultEngines(region, locale) {
-    const identifier = Services.search.originalDefaultEngine.identifier;
-    this._assertEngineRules([identifier], region, locale, "default");
+    this._assertEngineRules([Services.search.originalDefaultEngine], region,
+                            locale, "default");
   }
 
   /**
    * Asserts whether the engine is correctly available or not.
    *
    * @param {string} region
    *   The two-letter region code.
    * @param {string} locale
    *   The two-letter locale code.
+   * @param {array} engines
+   *   The current visible engines.
+   * @returns {boolean}
+   *   Returns true if the engine is expected to be present, false otherwise.
    */
-  async _assertAvailableEngines(region, locale) {
-    const engines = await Services.search.getVisibleEngines();
-    const engineNames = engines.map(engine => engine._shortName);
-    this._assertEngineRules(engineNames, region, locale, "available");
+  _assertAvailableEngines(region, locale, engines) {
+    return this._assertEngineRules(engines, region, locale, "available");
+  }
+
+  /**
+   * Asserts whether the engine is using the correct domains or not.
+   *
+   * @param {string} region
+   *   The two-letter region code.
+   * @param {string} locale
+   *   The two-letter locale code.
+   * @param {array} engines
+   *   The current visible engines.
+   */
+  _assertCorrectDomains(region, locale, engines) {
+    const [expectedDomain, domainConfig] =
+      Object.entries(this._config.domains).find(([key, value]) =>
+        this._localeRegionInSection(value.included, region, locale));
+
+    Assert.ok(expectedDomain,
+      `Should have an expectedDomain for the engine in region: "${region}" locale: "${locale}"`);
+
+    const engine = this._findEngine(engines, this._config.identifier);
+    Assert.ok(engine, "Should have an engine present");
+
+    const searchForm = new URL(engine.searchForm);
+    Assert.ok(searchForm.host.endsWith(expectedDomain),
+      `Should have the correct search form domain for region: "${region}" locale: "${locale}".
+       Got "${searchForm.host}", expected to end with "${expectedDomain}".`);
+
+    for (const urlType of [URLTYPE_SUGGEST_JSON, URLTYPE_SEARCH_HTML]) {
+      info(`Checking urlType ${urlType}`);
+
+      const submission = engine.getSubmission("test", urlType);
+      if (urlType == URLTYPE_SUGGEST_JSON &&
+          (this._config.noSuggestionsURL || domainConfig.noSuggestionsURL)) {
+        Assert.ok(!submission, "Should not have a submission url");
+      } else if (this._config.searchUrlBase) {
+          Assert.equal(submission.uri.prePath + submission.uri.filePath,
+            this._config.searchUrlBase + domainConfig.searchUrlEnd,
+            `Should have the correct domain for region: "${region}" locale: "${locale}".`);
+      } else {
+        Assert.ok(submission.uri.host.endsWith(expectedDomain),
+          `Should have the correct domain for region: "${region}" locale: "${locale}".
+           Got "${submission.uri.host}", expected to end with "${expectedDomain}".`);
+      }
+    }
   }
 }
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_amazon.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_amazon.js
@@ -24,16 +24,157 @@ const test = new SearchConfigTest({
           "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"],
       },
     }],
   },
+  domains: {
+    // Note: These should be based on region, but we don't currently enforce that.
+    // Note: the order here is important. A region/locale match higher up in the
+    // list will override a region/locale match lower down.
+    "amazon.com.au": {
+      included: [{
+        regions: ["au"],
+        locales: {
+          matches: [
+            "ach", "af", "ar", "as", "az", "bg", "bn-IN", "cak", "eo", "en-US",
+            "en-ZA", "es-AR", "fa", "gn", "hy-AM", "ia", "is", "ka", "km", "lt",
+            "mk", "ms", "my", "ro", "si", "th", "tl", "trs", "uz",
+          ],
+        },
+      }, {
+        regions: ["au"],
+        locales: {
+          matches: [
+            "cy", "da", "el", "en-GB", "eu", "ga-IE", "gd", "gl", "hr", "nb-NO",
+            "nn-NO", "pt-PT", "sq", "sr",
+          ],
+        },
+      }],
+      noSuggestionsURL: true,
+    },
+    "amazon.ca": {
+      included: [{
+        locales: {
+          matches: ["ca", "en-CA"],
+        },
+      }, {
+        regions: ["ca"],
+        locales: {
+          matches: [
+            "ach", "af", "ar", "as", "az", "bg", "bn-IN", "cak", "eo", "en-US",
+            "en-ZA", "es-AR", "fa", "gn", "hy-AM", "ia", "is", "ka", "km", "lt",
+            "mk", "ms", "my", "ro", "si", "th", "tl", "trs", "uz",
+          ],
+        },
+      }, {
+        regions: ["ca"],
+        locales: {
+          matches: [
+            "br", "fr", "ff", "son", "wo",
+          ],
+        },
+      }],
+      noSuggestionsURL: true,
+    },
+    "amazon.fr": {
+      included: [{
+        locales: {
+          matches: ["br", "fr", "ff", "son", "wo"],
+        },
+      }, {
+        regions: ["fr"],
+        locales: {
+          matches: [
+            "ach", "af", "ar", "as", "az", "bg", "bn-IN", "cak", "eo", "en-US",
+            "en-ZA", "es-AR", "fa", "gn", "hy-AM", "ia", "is", "ka", "km", "lt",
+            "mk", "ms", "my", "ro", "si", "th", "tl", "trs", "uz",
+          ],
+        },
+      }],
+      noSuggestionsURL: true,
+    },
+    "amazon.co.uk": {
+      included: [{
+        locales: {
+          matches: [
+            "cy", "da", "el", "en-GB", "eu", "ga-IE", "gd", "gl", "hr", "nb-NO",
+            "nn-NO", "pt-PT", "sq", "sr",
+          ],
+        },
+      }, {
+        regions: ["gb"],
+        locales: {
+          matches: [
+            "ach", "af", "ar", "as", "az", "bg", "bn-IN", "cak", "eo", "en-US",
+            "en-ZA", "es-AR", "fa", "gn", "hy-AM", "ia", "is", "ka", "km", "lt",
+            "mk", "ms", "my", "ro", "si", "th", "tl", "trs", "uz",
+          ],
+        },
+      }],
+      noSuggestionsURL: true,
+    },
+    "amazon.com": {
+      included: [{
+        locales: {
+          matches: [
+            "ach", "af", "ar", "as", "az", "bg", "bn-IN", "cak", "eo", "en-US",
+            "en-ZA", "es-AR", "fa", "gn", "hy-AM", "ia", "is", "ka", "km", "lt",
+            "mk", "ms", "my", "ro", "si", "th", "tl", "trs", "uz",
+          ],
+        },
+      }],
+    },
+    "amazon.cn": {
+      included: [{
+        locales: {
+          matches: ["zh-CN"],
+        },
+      }],
+      noSuggestionsURL: true,
+    },
+    "amazon.co.jp": {
+      included: [{
+        locales: {
+          startsWith: ["ja"],
+        },
+      }],
+      noSuggestionsURL: true,
+    },
+    "amazon.de": {
+      included: [{
+        locales: {
+          matches: ["de", "dsb", "hsb"],
+        },
+      }],
+      noSuggestionsURL: true,
+    },
+    "amazon.in": {
+      included: [{
+        locales: {
+          matches: [
+            "bn", "gu-IN", "kn", "mai", "ml", "mr", "or", "pa-IN", "ta",
+            "te", "ur",
+          ],
+        },
+      }],
+      noSuggestionsURL: true,
+    },
+    "amazon.it": {
+      included: [{
+        locales: {
+          matches: ["it", "lij"],
+        },
+      }],
+      noSuggestionsURL: true,
+    },
+  },
 });
 
 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() {
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_baidu.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_baidu.js
@@ -17,16 +17,21 @@ const test = new SearchConfigTest({
   },
   available: {
     included: [{
       locales: {
         matches: ["zh-CN"],
       },
     }],
   },
+  domains: {
+    "baidu.com": {
+      included: [{}],
+    },
+  },
 });
 
 add_task(async function setup() {
   await test.setup();
 });
 
 add_task(async function test_searchConfig_baidu() {
   await test.run();
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_bing.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_bing.js
@@ -27,16 +27,21 @@ const test = new SearchConfigTest({
           "nn-NO", "oc", "or", "pa-IN", "pt-BR", "rm", "ro", "son",
           "sq", "sr", "sv-SE", "th", "tl", "trs", "uk", "ur", "uz",
           "wo", "xh", "zh-CN",
         ],
         startsWith: ["bn", "en"],
       },
     }],
   },
+  domains: {
+    "bing.com": {
+      included: [{}],
+    },
+  },
 });
 
 add_task(async function setup() {
   await test.setup();
 });
 
 add_task(async function test_searchConfig_bing() {
   await test.run();
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_duckduckgo.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_duckduckgo.js
@@ -8,16 +8,21 @@ const test = new SearchConfigTest({
   default: {
     // Not included anywhere.
   },
   available: {
     excluded: [
       // Should be available everywhere.
     ],
   },
+  domains: {
+    "duckduckgo.com": {
+      included: [{}],
+    },
+  },
 });
 
 add_task(async function setup() {
   await test.setup();
 });
 
 add_task(async function test_searchConfig_duckduckgo() {
   await test.run();
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_ebay.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_ebay.js
@@ -14,16 +14,113 @@ const test = new SearchConfigTest({
       // 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"],
       },
     }],
   },
+  searchUrlBase: "https://rover.ebay.com/rover/1/",
+  domains: {
+    // Note: These should be based on region, but we don't currently enforce that.
+    // Note: the order here is important. A region/locale match higher up in the
+    // list will override a region/locale match lower down.
+    "befr.ebay.be": {
+      included: [{
+        regions: ["be"],
+        locales: { matches: ["br", "fr", "fy-NL", "nl", "wo"]},
+      }],
+      searchUrlEnd: "1553-53471-19255-0/1",
+    },
+    "ebay.at": {
+      included: [{
+        regions: ["at"],
+        locales: { matches: ["de", "dsb", "hsb"]},
+      }],
+      searchUrlEnd: "5221-53469-19255-0/1",
+    },
+    "ebay.ca": {
+      included: [{
+        locales: { matches: ["en-CA"] },
+      }, {
+        regions: ["ca"],
+        locales: { matches: ["br", "fr", "wo"]},
+      }],
+      searchUrlEnd: "706-53473-19255-0/1",
+    },
+    "ebay.ch": {
+      included: [{
+        locales: { matches: ["rm"] },
+      }, {
+        regions: ["ch"],
+        locales: { matches: ["br", "de", "dsb", "fr", "hsb", "wo"]},
+      }],
+      searchUrlEnd: "5222-53480-19255-0/1",
+    },
+    "ebay.com": {
+      included: [{
+        locales: { matches: ["en-US"] },
+      }],
+      searchUrlEnd: "711-53200-19255-0/1",
+    },
+    "ebay.com.au": {
+      included: [{
+        regions: ["au"],
+        locales: { matches: ["cy", "en-GB", "gd"]},
+      }],
+      searchUrlEnd: "705-53470-19255-0/1",
+    },
+    "ebay.ie": {
+      included: [{
+        locales: { matches: ["ga-IE", "ie"] },
+      }, {
+        regions: ["ie"],
+        locales: { matches: ["cy", "en-GB", "gd"]},
+      }],
+      searchUrlEnd: "5282-53468-19255-0/1",
+    },
+    "ebay.co.uk": {
+      included: [{
+        locales: { matches: ["cy", "en-GB", "gd"] },
+      }],
+      searchUrlEnd: "710-53481-19255-0/1",
+    },
+    "ebay.de": {
+      included: [{
+        locales: { matches: ["de", "dsb", "hsb"] },
+      }],
+      searchUrlEnd: "707-53477-19255-0/1",
+    },
+    "ebay.es": {
+      included: [{
+        locales: { matches: ["an", "ast", "ca", "es-ES", "eu", "gl"] },
+      }],
+      searchUrlEnd: "1185-53479-19255-0/1",
+    },
+    "ebay.fr": {
+      included: [{
+        locales: { matches: ["br", "fr", "wo"] },
+      }],
+      searchUrlEnd: "709-53476-19255-0/1",
+    },
+    "ebay.it": {
+      included: [{
+        locales: { matches: ["it", "lij"] },
+      }],
+      searchUrlEnd: "724-53478-19255-0/1",
+    },
+    "ebay.nl": {
+      included: [{
+        locales: { matches: ["fy-NL", "nl"] },
+      }],
+      searchUrlEnd: "1346-53482-19255-0/1",
+    },
+  },
+  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/test_google.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js
@@ -24,16 +24,21 @@ const test = new SearchConfigTest({
       },
     }],
   },
   available: {
     excluded: [
       // Should be available everywhere.
     ],
   },
+  domains: {
+    "google.com": {
+      included: [{}],
+    },
+  },
 });
 
 add_task(async function setup() {
   await test.setup();
 });
 
 add_task(async function test_searchConfig_google() {
   await test.run();
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_yandex.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_yandex.js
@@ -19,16 +19,48 @@ const test = new SearchConfigTest({
   },
   available: {
     included: [{
       locales: {
         matches: ["az", "ru", "be", "kk", "tr"],
       },
     }],
   },
+  domains: {
+    "yandex.az": {
+      included: [{
+        locales: { matches: ["az"] },
+      }],
+    },
+    "yandex.com": {
+      included: [{
+        locales: { startsWith: ["en"] },
+      }],
+    },
+    "yandex.ru": {
+      included: [{
+        locales: { matches: ["ru"] },
+      }],
+    },
+    "yandex.by": {
+      included: [{
+        locales: { matches: ["be"] },
+      }],
+    },
+    "yandex.kz": {
+      included: [{
+        locales: { matches: ["kk"] },
+      }],
+    },
+    "yandex.com.tr": {
+      included: [{
+        locales: { matches: ["tr"] },
+      }],
+    },
+  },
 });
 
 add_task(async function setup() {
   await test.setup();
 });
 
 add_task(async function test_searchConfig_yandex() {
   await test.run();