diff --git a/toolkit/components/search/SearchEngineSelector.jsm b/toolkit/components/search/SearchEngineSelector.jsm index 0a6e1e8ab177..1a0c75eba929 100644 --- a/toolkit/components/search/SearchEngineSelector.jsm +++ b/toolkit/components/search/SearchEngineSelector.jsm @@ -14,6 +14,7 @@ XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]); XPCOMUtils.defineLazyModuleGetters(this, { SearchUtils: "resource://gre/modules/SearchUtils.jsm", + Services: "resource://gre/modules/Services.jsm", }); const EXT_SEARCH_PREFIX = "resource://search-extensions/"; @@ -57,6 +58,7 @@ class SearchEngineSelector { throw new Error("region and locale parameters required"); } log(`fetchEngineConfiguration ${region}:${locale}`); + let cohort = Services.prefs.getCharPref("browser.search.cohort", null); let engines = []; for (let config of this.configuration) { const appliesTo = config.appliesTo || []; @@ -67,6 +69,9 @@ class SearchEngineSelector { let excluded = "excluded" in section && this._isInSection(region, locale, section.excluded); + if ("cohort" in section && cohort != section.cohort) { + return false; + } return included && !excluded; }); diff --git a/toolkit/components/search/docs/SearchEngineConfiguration.rst b/toolkit/components/search/docs/SearchEngineConfiguration.rst index 99671f225b8a..fa199efa069b 100644 --- a/toolkit/components/search/docs/SearchEngineConfiguration.rst +++ b/toolkit/components/search/docs/SearchEngineConfiguration.rst @@ -132,6 +132,36 @@ configuration object with the users locale. For example: Will report either ``us`` or ``gb`` as the ``webExtensionLocale`` depending on the user. +Experiments +----------- + +We can run experiments by giving sections within ``appliesTo`` a +``cohort`` value, the Search Service can then optionally pass in a +matching ``cohort`` value to match those sections. + +Sections which have a ``cohort`` will not be used unless a matching +``cohort`` has been passed in, for example: + +.. code-block:: js + + "engine1": { + "webExtensionId": "webext", + "webExtensionVersion": "1.0", + "appliesTo": [{ + "included": { + "everywhere": true + }, + "cohort": "nov-16", + "webExtensionId": "webext-experimental", + }, { + "included": { + "everywhere": true + }, + "webExtensionId": "webext-gb", + "webExtensionVersion": "1.2" + }] + } + Engine Defaults --------------- diff --git a/toolkit/components/search/tests/xpcshell/test_engine_selector.js b/toolkit/components/search/tests/xpcshell/test_engine_selector.js index 3916f3fab629..1e2997d337f7 100644 --- a/toolkit/components/search/tests/xpcshell/test_engine_selector.js +++ b/toolkit/components/search/tests/xpcshell/test_engine_selector.js @@ -54,6 +54,10 @@ const CONFIG_URL = included: { everywhere: true }, excluded: { regions: ["us"] }, }, + { + included: { everywhere: true }, + cohort: "acohortid", + }, ], }, { @@ -96,4 +100,15 @@ add_task(async function() { ["excite", "aol"], "The engines should be in the correct order" ); + + Services.prefs.setCharPref("browser.search.cohort", "acohortid"); + ({ engines, privateDefault } = engineSelector.fetchEngineConfiguration( + "us", + "en-US" + )); + Assert.deepEqual( + engines.map(obj => obj.engineName), + ["lycos","altavista","aol","excite"], + "Engines are in the correct order and include the cohort engine" + ); });