Skip to content

Commit 73815c6

Browse files
mkaplyagoloman
authored andcommitted
Bug 2048048 - Fix policy issues with new tab preferences. r=jmendez
Differential Revision: https://phabricator.services.mozilla.com/D307332
1 parent d890576 commit 73815c6

3 files changed

Lines changed: 91 additions & 11 deletions

File tree

‎browser/components/enterprisepolicies/Policies.sys.mjs‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,13 @@ export var Policies = {
17451745
param.Weather,
17461746
param.Locked
17471747
);
1748+
// The Nova layout (enabled by default) binds the weather toggle to a
1749+
// different pref, so set it too.
1750+
PoliciesUtils.setDefaultPref(
1751+
"browser.newtabpage.activity-stream.widgets.weather.enabled",
1752+
param.Weather,
1753+
param.Locked
1754+
);
17481755
}
17491756
if ("TopSites" in param) {
17501757
PoliciesUtils.setDefaultPref(
@@ -1768,23 +1775,13 @@ export var Policies = {
17681775
);
17691776
}
17701777
if ("Pocket" in param) {
1771-
PoliciesUtils.setDefaultPref(
1772-
"browser.newtabpage.activity-stream.feeds.system.topstories",
1773-
param.Pocket,
1774-
param.Locked
1775-
);
17761778
PoliciesUtils.setDefaultPref(
17771779
"browser.newtabpage.activity-stream.feeds.section.topstories",
17781780
param.Pocket,
17791781
param.Locked
17801782
);
17811783
}
17821784
if ("Stories" in param) {
1783-
PoliciesUtils.setDefaultPref(
1784-
"browser.newtabpage.activity-stream.feeds.system.topstories",
1785-
param.Stories,
1786-
param.Locked
1787-
);
17881785
PoliciesUtils.setDefaultPref(
17891786
"browser.newtabpage.activity-stream.feeds.section.topstories",
17901787
param.Stories,
@@ -1805,6 +1802,20 @@ export var Policies = {
18051802
param.Locked
18061803
);
18071804
}
1805+
// The "Support Firefox" toggle in the settings UI is a parent control for
1806+
// the two sponsored child settings. When both are locked by policy, lock
1807+
// it to their combined value so it can't be toggled to no effect.
1808+
if (
1809+
param.Locked &&
1810+
"SponsoredTopSites" in param &&
1811+
"SponsoredStories" in param
1812+
) {
1813+
PoliciesUtils.setDefaultPref(
1814+
"browser.newtabpage.activity-stream.showSponsoredCheckboxes",
1815+
param.SponsoredTopSites || param.SponsoredStories,
1816+
param.Locked
1817+
);
1818+
}
18081819
},
18091820
},
18101821

‎browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxhome.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,44 @@ add_task(async function test_firefoxhome_preferences_set() {
193193
});
194194
await SpecialPowers.popPrefEnv();
195195
});
196+
197+
add_task(async function test_firefoxhome_support_firefox_sponsored_locked() {
198+
// The supportFirefox setting only exists in the Settings Redesign UI.
199+
await SpecialPowers.pushPrefEnv({
200+
set: [["browser.settings-redesign.enabled", true]],
201+
});
202+
203+
await setupPolicyEngineWithJson({
204+
policies: {
205+
FirefoxHome: {
206+
SponsoredTopSites: false,
207+
SponsoredStories: false,
208+
Locked: true,
209+
},
210+
},
211+
});
212+
213+
await BrowserTestUtils.withNewTab("about:preferences#home", async browser => {
214+
let doc = browser.contentDocument;
215+
let control = await TestUtils.waitForCondition(() =>
216+
doc.getElementById("setting-control-supportFirefox")
217+
);
218+
await control.updateComplete;
219+
let toggle = control.querySelector("moz-toggle");
220+
ok(
221+
toggle.disabled,
222+
"Support Firefox toggle is disabled when both sponsored prefs are locked"
223+
);
224+
ok(
225+
!toggle.pressed,
226+
"Support Firefox toggle is off when both sponsored prefs are locked off"
227+
);
228+
});
229+
230+
await setupPolicyEngineWithJson({
231+
policies: {
232+
FirefoxHome: {},
233+
},
234+
});
235+
await SpecialPowers.popPrefEnv();
236+
});

‎browser/components/enterprisepolicies/tests/xpcshell/test_simple_pref_policies.js‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,40 @@ const POLICIES_TESTS = [
631631
},
632632
},
633633
lockedPrefs: {
634-
"browser.newtabpage.activity-stream.feeds.system.topstories": false,
635634
"browser.newtabpage.activity-stream.feeds.section.topstories": false,
636635
"browser.newtabpage.activity-stream.showSponsored": false,
637636
},
638637
},
639638

639+
// POLICY: FirefoxHome (Weather sets both the legacy and Nova prefs)
640+
{
641+
policies: {
642+
FirefoxHome: {
643+
Weather: false,
644+
Locked: true,
645+
},
646+
},
647+
lockedPrefs: {
648+
"browser.newtabpage.activity-stream.showWeather": false,
649+
"browser.newtabpage.activity-stream.widgets.weather.enabled": false,
650+
},
651+
},
652+
653+
// POLICY: FirefoxHome (locking both sponsored settings locks the parent
654+
// "Support Firefox" toggle to their combined value)
655+
{
656+
policies: {
657+
FirefoxHome: {
658+
SponsoredTopSites: false,
659+
SponsoredStories: false,
660+
Locked: true,
661+
},
662+
},
663+
lockedPrefs: {
664+
"browser.newtabpage.activity-stream.showSponsoredCheckboxes": false,
665+
},
666+
},
667+
640668
// POLICY: OfferToSaveLoginsDefault
641669
{
642670
policies: {

0 commit comments

Comments
 (0)