Bug 1572030 - Add support for experiments in modernConfig r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D44376

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dale Harvey 2019-09-10 19:11:20 +00:00
parent 4991e899e4
commit 82edadf36d
3 changed files with 50 additions and 0 deletions

View File

@ -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;
});

View File

@ -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
---------------

View File

@ -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"
);
});