Bug 1541417 - Add tests to ensure search engines send the correct codes with the search url and form urls. r?daleharvey,a=test-only
authorMark Banner <standard8@mozilla.com>
Thu, 23 May 2019 15:24:57 +0100
changeset 533475 91a66322104c314f699f83191ed6cfa8667216dc
parent 533474 104b25c67fb01d01383b86a77b5e0cd89e3b1a7f
child 533476 f282d40c4c724f926d1a777eff1e25d8b56ef8c1
push id11332
push usermbanner@mozilla.com
push dateWed, 29 May 2019 15:40:28 +0000
treeherdermozilla-beta@a722f0934123 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaleharvey, test-only
bugs1541417
milestone68.0
Bug 1541417 - Add tests to ensure search engines send the correct codes with the search url and form urls. r?daleharvey,a=test-only 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
@@ -330,16 +330,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.
@@ -391,16 +394,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() {