зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1572030 - Reland Add support for experiments in modernConfig r=Standard8
This reverts commit 6e8f8684501061d1d759d1dab40b867e90f2b85d. Differential Revision: https://phabricator.services.mozilla.com/D44376 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
b5c83385d6
Коммит
eaf9d22b52
|
@ -14,6 +14,7 @@ XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||||
|
|
||||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||||
SearchUtils: "resource://gre/modules/SearchUtils.jsm",
|
SearchUtils: "resource://gre/modules/SearchUtils.jsm",
|
||||||
|
Services: "resource://gre/modules/Services.jsm",
|
||||||
});
|
});
|
||||||
|
|
||||||
const EXT_SEARCH_PREFIX = "resource://search-extensions/";
|
const EXT_SEARCH_PREFIX = "resource://search-extensions/";
|
||||||
|
@ -57,6 +58,7 @@ class SearchEngineSelector {
|
||||||
throw new Error("region and locale parameters required");
|
throw new Error("region and locale parameters required");
|
||||||
}
|
}
|
||||||
log(`fetchEngineConfiguration ${region}:${locale}`);
|
log(`fetchEngineConfiguration ${region}:${locale}`);
|
||||||
|
let cohort = Services.prefs.getCharPref("browser.search.cohort", null);
|
||||||
let engines = [];
|
let engines = [];
|
||||||
for (let config of this.configuration) {
|
for (let config of this.configuration) {
|
||||||
const appliesTo = config.appliesTo || [];
|
const appliesTo = config.appliesTo || [];
|
||||||
|
@ -67,6 +69,9 @@ class SearchEngineSelector {
|
||||||
let excluded =
|
let excluded =
|
||||||
"excluded" in section &&
|
"excluded" in section &&
|
||||||
this._isInSection(region, locale, section.excluded);
|
this._isInSection(region, locale, section.excluded);
|
||||||
|
if ("cohort" in section && cohort != section.cohort) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return included && !excluded;
|
return included && !excluded;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,36 @@ configuration object with the users locale. For example:
|
||||||
Will report either ``us`` or ``gb`` as the ``webExtensionLocale``
|
Will report either ``us`` or ``gb`` as the ``webExtensionLocale``
|
||||||
depending on the user.
|
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
|
Engine Defaults
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,10 @@ const CONFIG_URL =
|
||||||
included: { everywhere: true },
|
included: { everywhere: true },
|
||||||
excluded: { regions: ["us"] },
|
excluded: { regions: ["us"] },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
included: { everywhere: true },
|
||||||
|
cohort: "acohortid",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -96,4 +100,15 @@ add_task(async function() {
|
||||||
["excite", "aol"],
|
["excite", "aol"],
|
||||||
"The engines should be in the correct order"
|
"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"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче