Bug 1541417 - Add tests to ensure search engines send the correct codes with the search url and form urls. r=daleharvey
authorMark Banner <standard8@mozilla.com>
Thu, 23 May 2019 14:24:57 +0000
changeset 475192 963955816d383e7a277930c8ce58a08fefa7b26a
parent 475191 b0d23e155d8772321220306d07a3f192ded929cf
child 475193 f310229807a47d75373d48994be96355ccbe6e61
push id86195
push usermbanner@mozilla.com
push dateThu, 23 May 2019 14:41:40 +0000
treeherderautoland@f310229807a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaleharvey
bugs1541417
milestone69.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 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
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_bing.js
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js
@@ -336,16 +336,19 @@ class SearchConfigTest {
 
     const location = `in region:${region}, locale:${locale}`;
 
     for (const rule of details) {
       this._assertCorrectDomains(location, engine, rule);
       if (rule.codes) {
         this._assertCorrectCodes(location, engine, rule);
       }
+      if (rule.searchUrlCode || rule.searchFormUrlCode) {
+        this._assertCorrectUrlCode(location, engine, rule);
+      }
     }
   }
 
   /**
    * Asserts whether the engine is using the correct domains or not.
    *
    * @param {string} location
    *   Debug string with locale + region information.
@@ -397,16 +400,39 @@ class SearchConfigTest {
        rules.codes[purpose];
       const submission = engine.getSubmission("test", "text/html", purpose);
       this.assertOk(submission.uri.query.split("&").includes(code),
         `Expected "${code}" in url "${submission.uri.spec}" from purpose "${purpose}" ${location}`);
     }
   }
 
   /**
+   * 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
    * python test runner process.
    */
   assertOk(value, message) {
     if (!value || this._testDebug) {
       Assert.ok(value, message);
     }
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_amazon.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_amazon.js
@@ -89,16 +89,17 @@ const test = new SearchConfigTest({
         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",
         ],
       },
     }],
     excluded: [{regions: ["ca"]}],
+    searchUrlCode: "tag=firefox-fr-21",
     noSuggestionsURL: true,
   }, {
     domain: "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",
@@ -110,44 +111,48 @@ const test = new SearchConfigTest({
         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",
         ],
       },
     }],
     excluded: [{regions: ["au"]}],
+    searchUrlCode: "tag=firefox-uk-21",
     noSuggestionsURL: true,
   }, {
     domain: "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",
         ],
       },
     }],
     excluded: [{regions: ["au", "ca", "fr", "gb"]}],
+    searchUrlCode: "tag=mozilla-20",
   }, {
     domain: "amazon.cn",
     included: [{
       locales: {
         matches: ["zh-CN"],
       },
     }],
+    searchUrlCode: "ix=sunray",
     noSuggestionsURL: true,
   }, {
     domain: "amazon.co.jp",
     included: [{
       locales: {
         startsWith: ["ja"],
       },
     }],
+    searchUrlCode: "tag=mozillajapan-fx-22",
     noSuggestionsURL: true,
   }, {
     domain: "amazon.de",
     included: [{
       locales: {
         matches: ["de", "dsb", "hsb"],
       },
     }],
@@ -165,16 +170,17 @@ const test = new SearchConfigTest({
     noSuggestionsURL: true,
   }, {
     domain: "amazon.it",
     included: [{
       locales: {
         matches: ["it", "lij"],
       },
     }],
+    searchUrlCode: "tag=firefoxit-21",
     noSuggestionsURL: true,
   }],
 });
 
 add_task(async function setup() {
   // We only need to do setup on one of the tests.
   await test.setup();
 });
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_bing.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_bing.js
@@ -37,16 +37,18 @@ const test = new SearchConfigTest({
     domain: "bing.com",
     codes: {
       "searchbar": "form=MOZSBR",
       "keyword": "form=MOZLBR",
       "contextmenu": "form=MOZCON",
       "homepage": "form=MOZSPG",
       "newtab": "form=MOZTSB",
     },
+    searchUrlCode: "pc=MOZI",
+    searchFormUrlCode: "pc=MOZI",
   }],
 });
 
 add_task(async function setup() {
   await test.setup();
 });
 
 add_task(async function test_searchConfig_bing() {