From d0a29268bee0a5b0ea63b71bd9c22f6d2a36f39a Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Thu, 21 Nov 2019 21:54:06 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- .../schemas/chrome_settings_overrides.json | 3 +- .../search/extensions/google/manifest.json | 2 +- .../xpcshell/searchconfigs/test_google.js | 54 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/browser/components/extensions/schemas/chrome_settings_overrides.json b/browser/components/extensions/schemas/chrome_settings_overrides.json index 5d8c486fb814..8aa9b3e5dd80 100644 --- a/browser/components/extensions/schemas/chrome_settings_overrides.json +++ b/browser/components/extensions/schemas/chrome_settings_overrides.json @@ -149,7 +149,8 @@ "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", diff --git a/browser/components/search/extensions/google/manifest.json b/browser/components/search/extensions/google/manifest.json index 72ffd5698321..d51213b52d22 100644 --- a/browser/components/search/extensions/google/manifest.json +++ b/browser/components/search/extensions/google/manifest.json @@ -26,7 +26,7 @@ { "name": "channel", "condition": "pref", - "pref": "__MSG_channel_pref__" + "pref": "__MSG_channelPref__" } ], "search_url_get_params": "__MSG_searchUrlGetParams__" diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js index f893abc07747..5dabefeb0d39 100644 --- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js +++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_google.js @@ -71,3 +71,57 @@ 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" + ); + } + } +});