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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2019-05-13 12:22:21 +00:00
Родитель 4c547aee3e
Коммит 59eb6f8361
8 изменённых файлов: 363 добавлений и 16 удалений

Просмотреть файл

@ -13,6 +13,9 @@ XPCOMUtils.defineLazyModuleGetters(this, {
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
@ -101,7 +104,11 @@ class SearchConfigTest {
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);
}
}
}
@ -201,7 +208,7 @@ class SearchConfigTest {
}
/**
* 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.
@ -210,14 +217,14 @@ class SearchConfigTest {
* 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);
}
/**
@ -231,20 +238,22 @@ class SearchConfigTest {
* 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
@ -257,9 +266,10 @@ class SearchConfigTest {
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;
}
/**
@ -271,8 +281,8 @@ class SearchConfigTest {
* 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");
}
/**
@ -282,10 +292,57 @@ class SearchConfigTest {
* 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}".`);
}
}
}
}

Просмотреть файл

@ -29,6 +29,147 @@ const test = new SearchConfigTest({
},
}],
},
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() {

Просмотреть файл

@ -22,6 +22,11 @@ const test = new SearchConfigTest({
},
}],
},
domains: {
"baidu.com": {
included: [{}],
},
},
});
add_task(async function setup() {

Просмотреть файл

@ -32,6 +32,11 @@ const test = new SearchConfigTest({
},
}],
},
domains: {
"bing.com": {
included: [{}],
},
},
});
add_task(async function setup() {

Просмотреть файл

@ -13,6 +13,11 @@ const test = new SearchConfigTest({
// Should be available everywhere.
],
},
domains: {
"duckduckgo.com": {
included: [{}],
},
},
});
add_task(async function setup() {

Просмотреть файл

@ -19,6 +19,103 @@ const test = new SearchConfigTest({
},
}],
},
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() {

Просмотреть файл

@ -29,6 +29,11 @@ const test = new SearchConfigTest({
// Should be available everywhere.
],
},
domains: {
"google.com": {
included: [{}],
},
},
});
add_task(async function setup() {

Просмотреть файл

@ -24,6 +24,38 @@ const test = new SearchConfigTest({
},
}],
},
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() {