Bug 1660030 - Add pref to enable locale only based decision for newtab stories. r=Mardak

Differential Revision: https://phabricator.services.mozilla.com/D87626
This commit is contained in:
Scott 2020-08-19 18:44:16 +00:00
Родитель 05ab468b46
Коммит 7ae2069352
3 изменённых файлов: 28 добавлений и 65 удалений

Просмотреть файл

@ -1358,6 +1358,8 @@ pref("browser.newtabpage.activity-stream.asrouter.useRemoteL10n", true);
pref("browser.newtabpage.activity-stream.discoverystream.enabled", true);
pref("browser.newtabpage.activity-stream.discoverystream.hardcoded-basic-layout", false);
pref("browser.newtabpage.activity-stream.discoverystream.spocs-endpoint", "");
// List of locales that get stories by default, regardless of region.
pref("browser.newtabpage.activity-stream.discoverystream.locale-list-config", "");
// List of regions that get stories by default.
pref("browser.newtabpage.activity-stream.discoverystream.region-stories-config", "US,DE,CA,GB,IE");
// List of regions that get spocs by default.

Просмотреть файл

@ -115,6 +115,8 @@ const REGION_SPOCS_CONFIG =
"browser.newtabpage.activity-stream.discoverystream.region-spocs-config";
const REGION_LAYOUT_CONFIG =
"browser.newtabpage.activity-stream.discoverystream.region-layout-config";
const LOCALE_LIST_CONFIG =
"browser.newtabpage.activity-stream.discoverystream.locale-list-config";
// Determine if spocs should be shown for a geo/locale
function showSpocs({ geo }) {
@ -581,7 +583,12 @@ const FEEDS_DATA = [
getValue: ({ geo, locale }) => {
const preffedRegionsString =
Services.prefs.getStringPref(REGION_STORIES_CONFIG) || "";
const preffedLocaleListString =
Services.prefs.getStringPref(LOCALE_LIST_CONFIG) || "";
const preffedRegions = preffedRegionsString.split(",").map(s => s.trim());
const preffedLocales = preffedLocaleListString
.split(",")
.map(s => s.trim());
const locales = {
US: ["en-CA", "en-GB", "en-US"],
CA: ["en-CA", "en-GB", "en-US"],
@ -602,7 +609,8 @@ const FEEDS_DATA = [
JP: ["ja", "ja-JP-mac"],
}[geo];
return (
preffedRegions.includes(geo) && !!locales && locales.includes(locale)
(locale && preffedLocales.includes(locale)) ||
(preffedRegions.includes(geo) && !!locales && locales.includes(locale))
);
},
},

Просмотреть файл

@ -202,66 +202,6 @@ describe("ActivityStream", () => {
assert.calledWith(global.Services.prefs.clearUserPref, "oldPrefName");
});
});
describe("_updateDynamicPrefs Discovery Stream", () => {
it("should be true with expected en-US geo and locale", () => {
sandbox.stub(global.Region, "home").returns("US");
sandbox
.stub(global.Services.locale, "appLocaleAsBCP47")
.get(() => "en-US");
as._updateDynamicPrefs();
assert.isTrue(
JSON.parse(PREFS_CONFIG.get("discoverystream.config").value).enabled
);
});
it("should be true with expected en-CA geo and locale", () => {
sandbox.stub(global.Region, "home").returns("CA");
sandbox
.stub(global.Services.locale, "appLocaleAsBCP47")
.get(() => "en-CA");
as._updateDynamicPrefs();
assert.isTrue(
JSON.parse(PREFS_CONFIG.get("discoverystream.config").value).enabled
);
});
it("should be true with expected de geo and locale", () => {
sandbox.stub(global.Region, "home").returns("DE");
sandbox
.stub(global.Services.locale, "appLocaleAsBCP47")
.get(() => "de-DE");
as._updateDynamicPrefs();
assert.isTrue(
JSON.parse(PREFS_CONFIG.get("discoverystream.config").value).enabled
);
});
it("should enable spocs based on region based pref", () => {
const getStringPrefStub = sandbox.stub(
global.Services.prefs,
"getStringPref"
);
sandbox.stub(global.Region, "home").returns("CA");
getStringPrefStub
.withArgs(
"browser.newtabpage.activity-stream.discoverystream.region-spocs-config"
)
.returns("US,CA");
sandbox
.stub(global.Services.locale, "appLocaleAsBCP47")
.get(() => "en-CA");
as._updateDynamicPrefs();
assert.isTrue(
JSON.parse(PREFS_CONFIG.get("discoverystream.config").value).show_spocs
);
});
});
describe("discoverystream.region-basic-layout config", () => {
let getStringPrefStub;
beforeEach(() => {
@ -316,7 +256,7 @@ describe("ActivityStream", () => {
appLocaleAsBCP47Stub.get(() => "en-US");
sandbox.stub(global.Region, "home").returns("US");
sandbox.stub(global.Region, "home").get(() => "US");
getStringPrefStub
.withArgs(
@ -326,7 +266,7 @@ describe("ActivityStream", () => {
});
it("should be false with no geo/locale", () => {
appLocaleAsBCP47Stub.get(() => "");
sandbox.stub(global.Region, "home").returns("");
sandbox.stub(global.Region, "home").get(() => "");
as._updateDynamicPrefs();
@ -365,12 +305,25 @@ describe("ActivityStream", () => {
});
it("should be true with updated pref change", () => {
appLocaleAsBCP47Stub.get(() => "en-GB");
sandbox.stub(global.Region, "home").returns("GB");
sandbox.stub(global.Region, "home").get(() => "GB");
getStringPrefStub
.withArgs(
"browser.newtabpage.activity-stream.discoverystream.region-stories-config"
)
.returns("US,CA,GB");
.returns("GB");
as._updateDynamicPrefs();
assert.isTrue(PREFS_CONFIG.get("feeds.system.topstories").value);
});
it("should be true with allowed locale in non US region", () => {
appLocaleAsBCP47Stub.get(() => "en-CA");
sandbox.stub(global.Region, "home").get(() => "DE");
getStringPrefStub
.withArgs(
"browser.newtabpage.activity-stream.discoverystream.locale-list-config"
)
.returns("en-US,en-CA,en-GB");
as._updateDynamicPrefs();