Bug 1541417 - Add tests to ensure search engines send the correct codes with the search url and form urls. r=daleharvey

Differential Revision: https://phabricator.services.mozilla.com/D32226

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2019-05-23 14:24:57 +00:00
parent 77d4bd0ad9
commit beec9b6250
3 changed files with 34 additions and 0 deletions

View File

@ -341,6 +341,9 @@ class SearchConfigTest {
if (rule.codes) {
this._assertCorrectCodes(location, engine, rule);
}
if (rule.searchUrlCode || rule.searchFormUrlCode) {
this._assertCorrectUrlCode(location, engine, rule);
}
}
}
@ -401,6 +404,29 @@ class SearchConfigTest {
}
}
/**
* Asserts whether the engine is using the correct URL codes or not.
*
* @param {string} location
* Debug string with locale + region information.
* @param {object} engine
* The engine being tested.
* @param {object} rules
* Rules to test.
*/
_assertCorrectUrlCode(location, engine, rule) {
if (rule.searchUrlCode) {
const submission = engine.getSubmission("test", URLTYPE_SEARCH_HTML);
this.assertOk(submission.uri.query.split("&").includes(rule.searchUrlCode),
`Expected "${rule.searchUrlCode}" in "${submission.uri.spec}"`);
}
if (rule.searchFormUrlCode) {
const uri = engine.searchForm;
this.assertOk(uri.includes(rule.searchFormUrlCode),
`Expected "${rule.searchFormUrlCode}" in "${uri}"`);
}
}
/**
* Helper functions which avoid outputting test results when there are no
* failures. These help the tests to run faster, and avoid clogging up the

View File

@ -94,6 +94,7 @@ const test = new SearchConfigTest({
},
}],
excluded: [{regions: ["ca"]}],
searchUrlCode: "tag=firefox-fr-21",
noSuggestionsURL: true,
}, {
domain: "amazon.co.uk",
@ -115,6 +116,7 @@ const test = new SearchConfigTest({
},
}],
excluded: [{regions: ["au"]}],
searchUrlCode: "tag=firefox-uk-21",
noSuggestionsURL: true,
}, {
domain: "amazon.com",
@ -128,6 +130,7 @@ const test = new SearchConfigTest({
},
}],
excluded: [{regions: ["au", "ca", "fr", "gb"]}],
searchUrlCode: "tag=mozilla-20",
}, {
domain: "amazon.cn",
included: [{
@ -135,6 +138,7 @@ const test = new SearchConfigTest({
matches: ["zh-CN"],
},
}],
searchUrlCode: "ix=sunray",
noSuggestionsURL: true,
}, {
domain: "amazon.co.jp",
@ -143,6 +147,7 @@ const test = new SearchConfigTest({
startsWith: ["ja"],
},
}],
searchUrlCode: "tag=mozillajapan-fx-22",
noSuggestionsURL: true,
}, {
domain: "amazon.de",
@ -170,6 +175,7 @@ const test = new SearchConfigTest({
matches: ["it", "lij"],
},
}],
searchUrlCode: "tag=firefoxit-21",
noSuggestionsURL: true,
}],
});

View File

@ -42,6 +42,8 @@ const test = new SearchConfigTest({
"homepage": "form=MOZSPG",
"newtab": "form=MOZTSB",
},
searchUrlCode: "pc=MOZI",
searchFormUrlCode: "pc=MOZI",
}],
});