Bug 1597727 - Preference based MozParams should be able to have a localised preference name. r=mixedpuppy,mikedeboer
authorMark Banner <standard8@mozilla.com>
Thu, 21 Nov 2019 21:54:06 +0000
changeset 503342 7711a2e44c1b13c510956aeebf0da00c4d1e1616
parent 503341 521cf01eb61383c3d4b2a7f66fce4433588b48b5
child 503343 f433ef4311a87f50fbfb36bfb1ddf06af33d9f99
push id36833
push userbtara@mozilla.com
push dateFri, 22 Nov 2019 21:40:53 +0000
treeherdermozilla-central@2c912e46295e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, mikedeboer
bugs1597727
milestone72.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 1597727 - Preference based MozParams should be able to have a localised preference name. r=mixedpuppy,mikedeboer Differential Revision: https://phabricator.services.mozilla.com/D54112
browser/components/extensions/schemas/chrome_settings_overrides.json
browser/components/search/extensions/google/manifest.json
toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js
--- a/browser/components/extensions/schemas/chrome_settings_overrides.json
+++ b/browser/components/extensions/schemas/chrome_settings_overrides.json
@@ -144,17 +144,18 @@
                           "type": "string",
                           "optional": true,
                           "enum": ["purpose", "pref"],
                           "description": "The type of param can be either \"purpose\" or \"pref\"."
                         },
                         "pref": {
                           "type": "string",
                           "optional": true,
-                          "description": "The preference to retreive the value from."
+                          "description": "The preference to retrieve the value from.",
+                          "preprocess": "localize"
                         },
                         "purpose": {
                           "type": "string",
                           "optional": true,
                           "enum": ["contextmenu", "searchbar", "homepage", "keyword", "newtab"],
                           "description": "The context that initiates a search, required if condition is \"purpose\"."
                         },
                         "value": {
--- a/browser/components/search/extensions/google/manifest.json
+++ b/browser/components/search/extensions/google/manifest.json
@@ -21,15 +21,15 @@
       "name": "__MSG_extensionName__",
       "search_url": "__MSG_searchUrl__",
       "search_form": "__MSG_searchForm__",
       "suggest_url": "__MSG_suggestUrl__",
       "params": [
         {
           "name": "channel",
           "condition": "pref",
-          "pref": "__MSG_channel_pref__"
+          "pref": "__MSG_channelPref__"
         }
       ],
       "search_url_get_params": "__MSG_searchUrlGetParams__"
     }
   }
 }
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js
@@ -66,8 +66,62 @@ const test = new SearchConfigTest({
 add_task(async function setup() {
   await test.setup();
 });
 
 add_task(async function test_searchConfig_google() {
   await test.run(false);
   await test.run(true);
 });
+
+add_task(async function test_searchConfig_google_with_mozparam() {
+  // Test a couple of configurations with a MozParam set up.
+  const TEST_DATA = [
+    {
+      locale: "en-US",
+      region: "US",
+      pref: "google_channel_us",
+      expected: "us_param",
+    },
+    {
+      locale: "en-US",
+      region: "GB",
+      pref: "google_channel_row",
+      expected: "row_param",
+    },
+  ];
+
+  const defaultBranch = Services.prefs.getDefaultBranch(
+    SearchUtils.BROWSER_SEARCH_PREF
+  );
+  for (const testData of TEST_DATA) {
+    defaultBranch.setCharPref("param." + testData.pref, testData.expected);
+  }
+
+  // TODO: Bug 1598270 will add the true option here, to test for the selector,
+  // aka modern configuration.
+  for (const useSelector of [false]) {
+    info("Using " + (useSelector ? "Selector" : "Legacy Configuration"));
+    for (const testData of TEST_DATA) {
+      info(`Checking region ${testData.region}, locale ${testData.locale}`);
+      await test._reinit(testData.region, testData.locale);
+      const engines = await test._getEngines(
+        useSelector,
+        testData.region,
+        testData.locale
+      );
+
+      Assert.ok(
+        engines[0].identifier.startsWith("google"),
+        "Should have the correct engine"
+      );
+      console.log(engines[0]);
+
+      const submission = engines[0].getSubmission("test", URLTYPE_SEARCH_HTML);
+      Assert.ok(
+        submission.uri.query
+          .split("&")
+          .includes("channel=" + testData.expected),
+        "Should be including the correct MozParam parameter for the engine"
+      );
+    }
+  }
+});