Bug 1705374 - Add new Amazon search engines and reorganise existing ones. r=daleharvey, a=test-only
authorMark Banner <standard8@mozilla.com>
Mon, 14 Jun 2021 13:05:02 +0000
changeset 649709 4544ca2be2ca93193884a7a8daee0c22fd649f50
parent 649708 9a7059c55eeb1fb0d34b389d36461454b62f6523
child 649710 2d1d0a88a86c16dfaa3f4edf65e28a004c538919
push id15542
push userjcristau@mozilla.com
push dateMon, 14 Jun 2021 16:15:48 +0000
treeherdermozilla-beta@2d1d0a88a86c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaleharvey, test-only
bugs1705374
milestone90.0
Bug 1705374 - Add new Amazon search engines and reorganise existing ones. r=daleharvey, a=test-only Differential Revision: https://phabricator.services.mozilla.com/D113398
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_distributions.js
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js
@@ -107,24 +107,27 @@ class SearchConfigTest {
    *   The initial configuration for this test, see above.
    */
   constructor(config = {}) {
     this._config = config;
   }
 
   /**
    * Sets up the test.
+   *
+   * @param {string} [version]
+   *   The version to simulate for running the tests.
    */
-  async setup() {
+  async setup(version = "42.0") {
     AddonTestUtils.init(GLOBAL_SCOPE);
     AddonTestUtils.createAppInfo(
       "xpcshell@tests.mozilla.org",
       "XPCShell",
-      "42",
-      "42"
+      version,
+      version
     );
 
     await maybeSetupConfig();
 
     // Disable region checks.
     Services.prefs.setBoolPref("browser.search.geoSpecificDefaults", false);
 
     // Enable separatePrivateDefault testing. We test with this on, as we have
@@ -338,21 +341,23 @@ class SearchConfigTest {
     }
 
     // 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 =
+    let excluded =
       hasExcluded &&
-      !this._localeRegionInSection(config.excluded, region, locale);
-
-    if (included || notExcluded) {
+      this._localeRegionInSection(config.excluded, region, locale);
+    if (
+      (included && (!hasExcluded || !excluded)) ||
+      (!hasIncluded && hasExcluded && !excluded)
+    ) {
       this.assertOk(
         identifierIncluded,
         `Should be ${section} for ${infoString}`
       );
       return true;
     }
     this.assertOk(
       !identifierIncluded,
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_amazon.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_amazon.js
@@ -1,97 +1,112 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+const mainShippedRegions = [
+  "at",
+  "au",
+  "be",
+  "ca",
+  "ch",
+  "cn",
+  "de",
+  "es",
+  "fr",
+  "mc",
+  "gb",
+  "ie",
+  "it",
+  "jp",
+  "nl",
+  "pt",
+  "se",
+  "sm",
+  "us",
+  "va",
+];
+
+const amazondotcomLocales = [
+  "ach",
+  "af",
+  "ar",
+  "az",
+  "bg",
+  "cak",
+  "cy",
+  "da",
+  "el",
+  "en-US",
+  "en-GB",
+  "eo",
+  "es-AR",
+  "eu",
+  "fa",
+  "ga-IE",
+  "gd",
+  "gl",
+  "gn",
+  "hr",
+  "hy-AM",
+  "ia",
+  "is",
+  "ka",
+  "km",
+  "lt",
+  "mk",
+  "ms",
+  "my",
+  "nb-NO",
+  "nn-NO",
+  "pt-PT",
+  "ro",
+  "si",
+  "sq",
+  "sr",
+  "th",
+  "tl",
+  "trs",
+  "uz",
+];
+
 const test = new SearchConfigTest({
   identifier: "amazon",
   default: {
-    // Not included anywhere.
+    // Not default anywhere.
   },
   available: {
     included: [
-      // 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.
+      {
+        // The main regions we ship Amazon to. Below this are special cases.
+        regions: mainShippedRegions,
+      },
       {
-        regions: ["au", "ca"],
+        // Amazon.com ships to all of these locales, excluding the ones where
+        // we ship other items, but it does not matter that they are duplicated
+        // in the available list.
+        locales: {
+          matches: amazondotcomLocales,
+        },
       },
       {
-        // 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",
-        // ],
+        // Amazon.in
+        regions: ["in"],
         locales: {
-          matches: [
-            "ach",
-            "af",
-            "ar",
-            "az",
-            "bg",
-            "bn",
-            "bn-IN",
-            "br",
-            "cak",
-            "cy",
-            "da",
-            "de",
-            "dsb",
-            "el",
-            "en-US",
-            "en-GB",
-            "eo",
-            "es-AR",
-            "eu",
-            "fa",
-            "ff",
-            "fr",
-            "ga-IE",
-            "gd",
-            "gl",
-            "gn",
-            "gu-IN",
-            "hr",
-            "hsb",
-            "hy-AM",
-            "ia",
-            "is",
-            "it",
-            "ja-JP-macos",
-            "ja",
-            "ka",
-            "km",
-            "kn",
-            "lij",
-            "lt",
-            "mk",
-            "mr",
-            "ms",
-            "my",
-            "nb-NO",
-            "nn-NO",
-            "pa-IN",
-            "pt-PT",
-            "ro",
-            "si",
-            "son",
-            "sq",
-            "sr",
-            "ta",
-            "te",
-            "th",
-            "tl",
-            "trs",
-            "ur",
-            "uz",
-            "wo",
-            "zh-CN",
-          ],
+          matches: ["bn", "gu-IN", "kn", "mr", "pa-IN", "ta", "te", "ur"],
+        },
+      },
+    ],
+    excluded: [
+      {
+        // Extra special case for cn as that only ships to the one locale.
+        regions: ["in"],
+        locales: {
+          matches: amazondotcomLocales,
         },
       },
     ],
   },
   details: [
     {
       domain: "amazon.com.au",
       telemetryId: "amazon-au",
@@ -113,255 +128,234 @@ const test = new SearchConfigTest({
           regions: ["ca"],
         },
       ],
       searchUrlCode: "tag=mozillacanada-20",
       suggestionUrlBase: "https://completion.amazon.ca/search/complete",
       suggestUrlCode: "mkt=7",
     },
     {
-      domain: "amazon.fr",
-      telemetryId: "amazon-france",
-      aliases: ["@amazon"],
-      included: [
-        {
-          locales: {
-            matches: ["br", "fr", "ff", "son", "wo"],
-          },
-        },
-        {
-          regions: ["fr"],
-          locales: {
-            matches: [
-              "ach",
-              "af",
-              "ar",
-              "az",
-              "bg",
-              "bn-IN",
-              "cak",
-              "unknown",
-              "eo",
-              "en-US",
-              "es-AR",
-              "fa",
-              "gn",
-              "hy-AM",
-              "ia",
-              "is",
-              "ka",
-              "km",
-              "lt",
-              "mk",
-              "ms",
-              "my",
-              "ro",
-              "si",
-              "th",
-              "tl",
-              "trs",
-              "uz",
-            ],
-          },
-        },
-      ],
-      excluded: [{ regions: ["au", "ca"] }],
-      searchUrlCode: "tag=firefox-fr-21",
-      suggestionUrlBase: "https://completion.amazon.fr/search/complete",
-      suggestUrlCode: "mkt=5",
-    },
-    {
-      domain: "amazon.co.uk",
-      telemetryId: "amazon-en-GB",
-      aliases: ["@amazon"],
-      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",
-              "az",
-              "bg",
-              "bn-IN",
-              "cak",
-              "unknown",
-              "eo",
-              "en-US",
-              "es-AR",
-              "fa",
-              "gn",
-              "hy-AM",
-              "ia",
-              "is",
-              "ka",
-              "km",
-              "lt",
-              "mk",
-              "ms",
-              "my",
-              "ro",
-              "si",
-              "th",
-              "tl",
-              "trs",
-              "uz",
-            ],
-          },
-        },
-      ],
-      excluded: [{ regions: ["au", "ca"] }],
-      searchUrlCode: "tag=firefox-uk-21",
-      suggestionUrlBase: "https://completion.amazon.co.uk/search/complete",
-      suggestUrlCode: "mkt=3",
-    },
-    {
-      domain: "amazon.com",
-      telemetryId: "amazondotcom",
-      aliases: ["@amazon"],
-      included: [
-        {
-          locales: {
-            matches: [
-              "ach",
-              "af",
-              "ar",
-              "az",
-              "bg",
-              "bn-IN",
-              "cak",
-              "unknown",
-              "eo",
-              "en-US",
-              "es-AR",
-              "fa",
-              "gn",
-              "hy-AM",
-              "ia",
-              "is",
-              "ka",
-              "km",
-              "lt",
-              "mk",
-              "ms",
-              "my",
-              "ro",
-              "si",
-              "th",
-              "tl",
-              "trs",
-              "uz",
-            ],
-          },
-        },
-      ],
-      excluded: [{ regions: ["au", "ca", "fr", "gb"] }],
-      searchUrlCode: "tag=mozilla-20",
-    },
-    {
       domain: "amazon.cn",
       telemetryId: "amazondotcn",
       included: [
         {
-          locales: {
-            matches: ["zh-CN"],
-          },
+          regions: ["cn"],
         },
       ],
-      excluded: [{ regions: ["au", "ca"] }],
       searchUrlCode: "ix=sunray",
       noSuggestionsURL: true,
     },
     {
       domain: "amazon.co.jp",
       telemetryId: "amazon-jp",
       aliases: ["@amazon"],
       included: [
         {
+          regions: ["jp"],
+        },
+      ],
+      searchUrlCode: "tag=mozillajapan-fx-22",
+      suggestionUrlBase: "https://completion.amazon.co.jp/search/complete",
+      suggestUrlCode: "mkt=6",
+    },
+    {
+      domain: "amazon.co.uk",
+      telemetryId: "amazon-en-GB",
+      aliases: ["@amazon"],
+      included: [
+        {
+          regions: ["gb", "ie"],
+        },
+      ],
+      searchUrlCode: "tag=firefox-uk-21",
+      suggestionUrlBase: "https://completion.amazon.co.uk/search/complete",
+      suggestUrlCode: "mkt=3",
+    },
+    {
+      domain: "amazon.com",
+      telemetryId: "amazondotcom-us",
+      aliases: ["@amazon"],
+      included: [
+        {
+          regions: ["us"],
+        },
+      ],
+      searchUrlCode: "tag=moz-us-20",
+    },
+    {
+      domain: "amazon.com",
+      telemetryId: "amazondotcom",
+      aliases: ["@amazon"],
+      included: [
+        {
           locales: {
-            startsWith: ["ja"],
+            matches: amazondotcomLocales,
           },
         },
       ],
-      excluded: [{ regions: ["au", "ca"] }],
-      searchUrlCode: "tag=mozillajapan-fx-22",
-      suggestionUrlBase: "https://completion.amazon.co.jp/search/complete",
-      suggestUrlCode: "mkt=6",
+      excluded: [{ regions: mainShippedRegions }],
+      searchUrlCode: "tag=mozilla-20",
     },
     {
       domain: "amazon.de",
       telemetryId: "amazon-de",
       aliases: ["@amazon"],
       included: [
         {
+          regions: ["at", "ch", "de"],
+        },
+      ],
+      searchUrlCode: "tag=firefox-de-21",
+      suggestionUrlBase: "https://completion.amazon.de/search/complete",
+      suggestUrlCode: "mkt=4",
+    },
+    {
+      domain: "amazon.es",
+      telemetryId: "amazon-es",
+      aliases: ["@amazon"],
+      included: [
+        {
+          regions: ["es", "pt"],
+        },
+      ],
+      searchUrlCode: "tag=mozillaspain-21",
+      suggestionUrlBase: "https://completion.amazon.es/search/complete",
+      suggestUrlCode: "mkt=44551",
+    },
+    {
+      domain: "amazon.fr",
+      telemetryId: "amazon-france",
+      aliases: ["@amazon"],
+      included: [
+        {
+          regions: ["fr", "mc"],
+        },
+        {
+          regions: ["be"],
           locales: {
-            matches: ["de", "dsb", "hsb"],
+            matches: ["fr"],
           },
         },
       ],
-      excluded: [{ regions: ["au", "ca"] }],
-      searchUrlCode: "tag=firefox-de-21",
-      suggestionUrlBase: "https://completion.amazon.de/search/complete",
-      suggestUrlCode: "mkt=4",
+      searchUrlCode: "tag=firefox-fr-21",
+      suggestionUrlBase: "https://completion.amazon.fr/search/complete",
+      suggestUrlCode: "mkt=5",
     },
     {
       domain: "amazon.in",
       telemetryId: "amazon-in",
       aliases: ["@amazon"],
       included: [
         {
           locales: {
             matches: ["bn", "gu-IN", "kn", "mr", "pa-IN", "ta", "te", "ur"],
           },
+          regions: ["in"],
         },
       ],
-      excluded: [{ regions: ["au", "ca"] }],
       suggestionUrlBase: "https://completion.amazon.in/search/complete",
       suggestUrlCode: "mkt=44571",
     },
     {
       domain: "amazon.it",
       telemetryId: "amazon-it",
       aliases: ["@amazon"],
       included: [
         {
+          regions: ["it", "sm", "va"],
+        },
+      ],
+      searchUrlCode: "tag=firefoxit-21",
+      suggestionUrlBase: "https://completion.amazon.it/search/complete",
+      suggestUrlCode: "mkt=35691",
+    },
+    {
+      domain: "amazon.nl",
+      telemetryId: "amazon-nl",
+      aliases: ["@amazon"],
+      included: [
+        {
+          regions: ["nl"],
+        },
+      ],
+      searchUrlCode: "tag=mozillanether-21",
+      suggestionUrlBase: "https://completion.amazon.nl/search/complete",
+      suggestUrlCode: "mkt=328451",
+    },
+    {
+      domain: "amazon.nl",
+      telemetryId: "amazon-nl",
+      aliases: ["@amazon"],
+      included: [
+        {
+          regions: ["be"],
+        },
+      ],
+      excluded: [
+        {
           locales: {
-            matches: ["it", "lij"],
+            matches: ["fr"],
           },
         },
       ],
-      excluded: [{ regions: ["au", "ca"] }],
-      searchUrlCode: "tag=firefoxit-21",
-      suggestionUrlBase: "https://completion.amazon.it/search/complete",
-      suggestUrlCode: "mkt=35691",
+      searchUrlCode: "tag=mozillanether-21",
+      suggestionUrlBase: "https://completion.amazon.nl/search/complete",
+      suggestUrlCode: "mkt=328451",
+    },
+    {
+      domain: "amazon.se",
+      telemetryId: "amazon-se",
+      aliases: ["@amazon"],
+      included: [
+        {
+          regions: ["se"],
+        },
+      ],
+      searchUrlCode: "tag=mozillasweede-21",
+      suggestionUrlBase: "https://completion.amazon.se/search/complete",
+      suggestUrlCode: "mkt=704403121",
     },
   ],
 });
 
 add_task(async function setup() {
   // We only need to do setup on one of the tests.
-  await test.setup();
+  await test.setup("89.0");
 });
 
 add_task(async function test_searchConfig_amazon() {
   await test.run();
 });
+
+add_task(async function test_searchConfig_amazon_pre89() {
+  AddonTestUtils.createAppInfo(
+    "xpcshell@tests.mozilla.org",
+    "XPCShell",
+    "88.0",
+    "88.0"
+  );
+  // For pre-89, Amazon has a slightly different config.
+  let details = test._config.details.find(
+    d => d.telemetryId == "amazondotcom-us"
+  );
+  details.telemetryId = "amazondotcom";
+  details.searchUrlCode = "tag=mozilla-20";
+
+  // nl not present due to urls that don't work.
+  let availableIn = test._config.available.included;
+  availableIn[0].regions = availableIn[0].regions.filter(
+    r => r != "be" && r != "nl"
+  );
+  availableIn.push({
+    regions: ["be"],
+    locales: {
+      matches: ["fr"],
+    },
+  });
+  // Due to the way the exclusions work, no Amazon present in nl/be in the
+  // dot com locales for pre-89.
+  test._config.available.excluded[0].regions.push("be", "nl");
+  test._config.details = test._config.details.filter(
+    d => d.telemetryId != "amazon-nl"
+  );
+
+  await test.run();
+});
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_distributions.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_distributions.js
@@ -212,30 +212,32 @@ tests.push({
     hasParams(engines, "Поиск Mail.Ru", "searchbar", "gp=900208") &&
     hasParams(engines, "Поиск Mail.Ru", "searchbar", "frc=900208") &&
     hasDefault(engines, "Поиск Mail.Ru") &&
     hasEnginesFirst(engines, ["Поиск Mail.Ru"]),
 });
 
 tests.push({
   locale: "zh-CN",
+  region: "CN",
   distribution: "MozillaOnline",
   test: engines =>
     hasParams(engines, "百度", "searchbar", "tn=monline_4_dg") &&
     hasParams(engines, "百度", "suggestions", "tn=monline_4_dg") &&
     hasParams(engines, "百度", "homepage", "tn=monline_3_dg") &&
     hasParams(engines, "百度", "newtab", "tn=monline_3_dg") &&
     hasParams(engines, "百度", "contextmenu", "tn=monline_4_dg") &&
     hasParams(engines, "百度", "keyword", "tn=monline_4_dg") &&
     hasDefault(engines, "百度") &&
     hasEnginesFirst(engines, ["百度", "Bing", "Google", "亚马逊", "维基百科"]),
 });
 
 tests.push({
   locale: "zh-CN",
+  region: "CN",
   distribution: "MozillaOnline",
   test: engines =>
     hasParams(engines, "亚马逊", "searchbar", "engine=amazon_shopping") &&
     hasParams(engines, "亚马逊", "suggestions", "tag=mozilla") &&
     hasParams(engines, "亚马逊", "homepage", "create=2028") &&
     hasParams(engines, "亚马逊", "homepage", "adid=1NZNRHJZ2Q87NTS7YW6N") &&
     hasParams(engines, "亚马逊", "homepage", "campaign=408") &&
     hasParams(engines, "亚马逊", "homepage", "create=2028") &&