Bug 1541414 - Ensure engines are available in applicable regions. r=Standard8
☠☠ backed out by 1dde02f1def7 ☠ ☠
authorDale Harvey <dale@arandomurl.com>
Tue, 07 May 2019 13:22:53 +0000
changeset 534785 4db69eae737243de67e3eecf4b4afbba34921471
parent 534784 e6e096360c85a5c694f415667fe6a108f0238bf4
child 534786 1dde02f1def7fe94b166386bb5cabb60a1bcd78a
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1541414
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 1541414 - Ensure engines are available in applicable regions. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D28856
toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.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_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
@@ -92,21 +92,21 @@ class SearchConfigTest {
   async run() {
     const locales = await this._getLocales();
     const regions = this._regions;
 
     // 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) {
-        const infoString = `region: "${region}" locale: "${locale}"`;
-        info(`Checking ${infoString}`);
+        info(`Checking region: "${region}" locale: "${locale}"`);
         await this._reinit(region, locale);
 
-        this._assertDefaultEngines(region, locale, infoString);
+        this._assertDefaultEngines(region, locale);
+        await this._assertAvailableEngines(region, locale);
       }
     }
 
     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.
@@ -184,57 +184,89 @@ class SearchConfigTest {
    *   The two-letter region code.
    * @param {string} locale
    *   The two-letter locale code.
    * @returns {boolean}
    *   True if the locale/region pair matches the section.
    */
   _localeRegionInSection(section, region, locale) {
     for (const {regions, locales} of section) {
-      if (regions.includes(region) &&
-          this._localeIncludes(locales, locale)) {
+      // If we only specify a regions or locales section then
+      // it is always considered included in the other section.
+      const inRegions = !regions || regions.includes(region);
+      const inLocales = !locales || this._localeIncludes(locales, locale);
+      if (inRegions && inLocales) {
         return true;
       }
     }
     return false;
   }
 
   /**
+   * 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;
+
+    // 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),
+        `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}`);
+      return;
+    }
+    Assert.ok(!engines.includes(this._config.identifier),
+      `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
    *   The two-letter locale code.
-   * @param {string} infoString
-   *   An additional message to output with assertions.
    */
-  _assertDefaultEngines(region, locale, infoString) {
-    // We use the originalDefaultEngine here as due to the way we run the tests
-    // the default engine may not have changed.
+  _assertDefaultEngines(region, locale) {
     const identifier = Services.search.originalDefaultEngine.identifier;
+    this._assertEngineRules([identifier], region, locale, "default");
+  }
 
-    // If there's not included/excluded, then this shouldn't be the default anywhere.
-    if (!("included" in this._config.default) &&
-        !("excluded" in this._config.default)) {
-      Assert.notEqual(identifier,
-        this._config.identifier,
-        `Should not be set as the default engine 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.
-    if (("included" in this._config.default &&
-        this._localeRegionInSection(this._config.default.included, region, locale)) ||
-        ("excluded" in this._config.default &&
-         !this._localeRegionInSection(this._config.default.excluded, region, locale))) {
-      Assert.equal(identifier,
-        this._config.identifier,
-        `Should be set as the default engine for ${infoString}`);
-      return;
-    }
-    Assert.notEqual(identifier,
-      this._config.identifier,
-      `Should not be set as the default engine for ${infoString}`);
+  /**
+   * 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.
+   */
+  async _assertAvailableEngines(region, locale) {
+    const engines = await Services.search.getVisibleEngines();
+    const engineNames = engines.map(engine => engine._shortName);
+    this._assertEngineRules(engineNames, region, locale, "available");
   }
 }
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_baidu.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_baidu.js
@@ -10,16 +10,23 @@ const test = new SearchConfigTest({
       regions: [
         "cn",
       ],
       locales: {
         matches: ["zh-CN"],
       },
     }],
   },
+  available: {
+    included: [{
+      locales: {
+        matches: ["zh-CN"],
+      },
+    }]
+  },
 });
 
 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
@@ -3,16 +3,40 @@
 
 "use strict";
 
 const test = new SearchConfigTest({
   identifier: "bing",
   default: {
     // Not included anywhere.
   },
+  available: {
+    included: [{
+      //regions: [
+        // These arent currently enforced.
+        // "au", "at", "be", "br", "ca", "fi", "fr", "de",
+        // "in", "ie", "it", "jp", "my", "mx", "nl", "nz",
+        // "no", "sg", "es", "se", "ch", "gb", "us",
+      //],
+      locales: {
+        matches: [
+          "ach", "af", "an", "ar", "ast", "az", "bn", "bn-BD",
+          "bn-ID", "ca", "cak", "da","de", "dsb", "el", "en-CA",
+          "en-GB", "en-US", "en-ZA", "eo", "es-CL", "es-ES",
+          "es-MX", "eu", "fa", "ff", "fi", "fr", "fy-NL", "gn",
+          "gu-IN", "hi-IN", "hr", "hsb", "ia", "is", "it",
+          "ja-JP-mac", "ja", "ka", "kab", "km", "kn", "lij", "lo",
+          "lt", "mai", "mk", "ml", "ms", "my", "nb-NO", "ne-NP", "nl",
+          "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",
+        ],
+      },
+    }],
+  },
 });
 
 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_google.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js
@@ -18,16 +18,21 @@ const test = new SearchConfigTest({
       },
     }, {
       regions: ["cn"],
       locales: {
         matches: ["zh-CN"],
       },
     }],
   },
+  available: {
+    excluded: [
+      // Should be available everywhere.
+    ],
+  },
 });
 
 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
@@ -11,16 +11,23 @@ const test = new SearchConfigTest({
         "ru", "tr", "by", "kz",
       ],
       locales: {
         matches: ["ru", "tr", "be", "kk"],
         startsWith: ["en"],
       },
     }],
   },
+  available: {
+    included: [{
+      locales: {
+        matches: ["az", "ru", "be", "kk", "tr"]
+      },
+    }],
+  },
 });
 
 add_task(async function setup() {
   await test.setup();
 });
 
 add_task(async function test_searchConfig_yandex() {
   await test.run();