Skip to content

Commit a339736

Browse files
mkaplypchevrel@mozilla.com
authored andcommitted
Bug 2048048 - Fix policy issues with new tab preferences. a=pascalc
Original Revision: https://phabricator.services.mozilla.com/D307332 Differential Revision: https://phabricator.services.mozilla.com/D309878
1 parent 566a562 commit a339736

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
@@ -1742,6 +1742,13 @@ export var Policies = {
17421742
param.Weather,
17431743
param.Locked
17441744
);
1745+
// The Nova layout (enabled by default) binds the weather toggle to a
1746+
// different pref, so set it too.
1747+
PoliciesUtils.setDefaultPref(
1748+
"browser.newtabpage.activity-stream.widgets.weather.enabled",
1749+
param.Weather,
1750+
param.Locked
1751+
);
17451752
}
17461753
if ("TopSites" in param) {
17471754
PoliciesUtils.setDefaultPref(
@@ -1765,23 +1772,13 @@ export var Policies = {
17651772
);
17661773
}
17671774
if ("Pocket" in param) {
1768-
PoliciesUtils.setDefaultPref(
1769-
"browser.newtabpage.activity-stream.feeds.system.topstories",
1770-
param.Pocket,
1771-
param.Locked
1772-
);
17731775
PoliciesUtils.setDefaultPref(
17741776
"browser.newtabpage.activity-stream.feeds.section.topstories",
17751777
param.Pocket,
17761778
param.Locked
17771779
);
17781780
}
17791781
if ("Stories" in param) {
1780-
PoliciesUtils.setDefaultPref(
1781-
"browser.newtabpage.activity-stream.feeds.system.topstories",
1782-
param.Stories,
1783-
param.Locked
1784-
);
17851782
PoliciesUtils.setDefaultPref(
17861783
"browser.newtabpage.activity-stream.feeds.section.topstories",
17871784
param.Stories,
@@ -1802,6 +1799,20 @@ export var Policies = {
18021799
param.Locked
18031800
);
18041801
}
1802+
// The "Support Firefox" toggle in the settings UI is a parent control for
1803+
// the two sponsored child settings. When both are locked by policy, lock
1804+
// it to their combined value so it can't be toggled to no effect.
1805+
if (
1806+
param.Locked &&
1807+
"SponsoredTopSites" in param &&
1808+
"SponsoredStories" in param
1809+
) {
1810+
PoliciesUtils.setDefaultPref(
1811+
"browser.newtabpage.activity-stream.showSponsoredCheckboxes",
1812+
param.SponsoredTopSites || param.SponsoredStories,
1813+
param.Locked
1814+
);
1815+
}
18051816
},
18061817
},
18071818

‎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)