tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 734228b42ecccee410707b5bdf2af85202cb153e
parent 2e87317ac55e46b74e2ec7095c655fa09dc3cae2
Author: Maxx Crawford <mcrawford@mozilla.com>
Date:   Wed, 12 Nov 2025 22:11:49 +0000

Bug 1999005 - Add logic to enable ListsFeed and TimerFeed if enrolled via Nimbus r=home-newtab-reviewers,thecount

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

Diffstat:
Mbrowser/extensions/newtab/lib/Widgets/ListsFeed.sys.mjs | 39+++++++++++++++++++++++++++++----------
Mbrowser/extensions/newtab/lib/Widgets/TimerFeed.sys.mjs | 39+++++++++++++++++++++++++++++----------
Mbrowser/extensions/newtab/test/xpcshell/test_ListsFeed.js | 56+++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mbrowser/extensions/newtab/test/xpcshell/test_TimerFeed.js | 56+++++++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 168 insertions(+), 22 deletions(-)

diff --git a/browser/extensions/newtab/lib/Widgets/ListsFeed.sys.mjs b/browser/extensions/newtab/lib/Widgets/ListsFeed.sys.mjs @@ -29,7 +29,16 @@ export class ListsFeed { get enabled() { const prefs = this.store.getState()?.Prefs.values; - return prefs?.[PREF_LISTS_ENABLED] && prefs?.[PREF_SYSTEM_LISTS_ENABLED]; + const nimbusListsEnabled = prefs.widgetsConfig?.listsEnabled; + const nimbusListsTrainhopEnabled = + prefs.trainhopConfig?.widgets?.listsEnabled; + + return ( + prefs?.[PREF_LISTS_ENABLED] && + (prefs?.[PREF_SYSTEM_LISTS_ENABLED] || + nimbusListsEnabled || + nimbusListsTrainhopEnabled) + ); } async init() { @@ -106,6 +115,24 @@ export class ListsFeed { ); } + /** + * @param {object} action - The action object containing pref change data + * @param {string} action.data.name - The name of the pref that changed + */ + async onPrefChangedAction(action) { + switch (action.data.name) { + case PREF_LISTS_ENABLED: + case PREF_SYSTEM_LISTS_ENABLED: + case "trainhopConfig": + case "widgetsConfig": { + if (this.enabled && !this.initialized) { + await this.init(); + } + break; + } + } + } + async onAction(action) { switch (action.type) { case at.INIT: @@ -114,15 +141,7 @@ export class ListsFeed { } break; case at.PREF_CHANGED: - if ( - (action.data.name === PREF_LISTS_ENABLED || - action.data.name === PREF_SYSTEM_LISTS_ENABLED) && - action.data.value - ) { - if (this.enabled) { - await this.init(); - } - } + await this.onPrefChangedAction(action); break; case at.WIDGETS_LISTS_UPDATE: await this.cache.set("lists", action.data.lists); diff --git a/browser/extensions/newtab/lib/Widgets/TimerFeed.sys.mjs b/browser/extensions/newtab/lib/Widgets/TimerFeed.sys.mjs @@ -65,7 +65,16 @@ export class TimerFeed { get enabled() { const prefs = this.store.getState()?.Prefs.values; - return prefs?.[PREF_TIMER_ENABLED] && prefs?.[PREF_SYSTEM_TIMER_ENABLED]; + const nimbusTimerEnabled = prefs.widgetsConfig?.timerEnabled; + const nimbusTimerTrainhopEnabled = + prefs.trainhopConfig?.widgets?.timerEnabled; + + return ( + prefs?.[PREF_TIMER_ENABLED] && + (prefs?.[PREF_SYSTEM_TIMER_ENABLED] || + nimbusTimerEnabled || + nimbusTimerTrainhopEnabled) + ); } async init() { @@ -91,6 +100,24 @@ export class TimerFeed { ); } + /** + * @param {object} action - The action object containing pref change data + * @param {string} action.data.name - The name of the pref that changed + */ + async onPrefChangedAction(action) { + switch (action.data.name) { + case PREF_TIMER_ENABLED: + case PREF_SYSTEM_TIMER_ENABLED: + case "trainhopConfig": + case "widgetsConfig": { + if (this.enabled && !this.initialized) { + await this.init(); + } + break; + } + } + } + async onAction(action) { switch (action.type) { case at.INIT: @@ -99,15 +126,7 @@ export class TimerFeed { } break; case at.PREF_CHANGED: - if ( - (action.data.name === PREF_TIMER_ENABLED || - action.data.name === PREF_SYSTEM_TIMER_ENABLED) && - action.data.value - ) { - if (this.enabled) { - await this.init(); - } - } + await this.onPrefChangedAction(action); break; case at.WIDGETS_TIMER_END: { diff --git a/browser/extensions/newtab/test/xpcshell/test_ListsFeed.js b/browser/extensions/newtab/test/xpcshell/test_ListsFeed.js @@ -81,7 +81,61 @@ add_task(async function test_isEnabled() { }, }; - info("ListsFeed should be enabled"); + info("ListsFeed should be enabled via system pref"); + Assert.ok(feed.enabled); +}); + +add_task(async function test_isEnabled() { + let feed = new ListsFeed(); + + feed.store = { + getState() { + return this.state; + }, + dispatch: sinon.spy(), + state: { + Prefs: { + values: { + [PREF_LISTS_ENABLED]: true, + trainhopConfig: { + widgets: { + enabled: true, + listsEnabled: true, + timerEnabled: true, + }, + }, + }, + }, + }, + }; + + info("ListsFeed should be enabled via trainhopConfig"); + Assert.ok(feed.enabled); +}); + +add_task(async function test_isEnabled() { + let feed = new ListsFeed(); + + feed.store = { + getState() { + return this.state; + }, + dispatch: sinon.spy(), + state: { + Prefs: { + values: { + [PREF_LISTS_ENABLED]: true, + widgetsConfig: { + enabled: true, + listsEnabled: true, + timerEnabled: true, + }, + }, + }, + }, + }; + + info("ListsFeed should be enabled via widgetsConfig"); Assert.ok(feed.enabled); }); diff --git a/browser/extensions/newtab/test/xpcshell/test_TimerFeed.js b/browser/extensions/newtab/test/xpcshell/test_TimerFeed.js @@ -88,7 +88,61 @@ add_task(async function test_isEnabled() { }, }; - info("TimerFeed should be enabled"); + info("TimerFeed should be enabled via system pref"); + Assert.ok(feed.enabled); +}); + +add_task(async function test_isEnabled() { + let feed = new TimerFeed(); + + feed.store = { + getState() { + return this.state; + }, + dispatch: sinon.spy(), + state: { + Prefs: { + values: { + [PREF_TIMER_ENABLED]: true, + trainhopConfig: { + widgets: { + enabled: true, + listsEnabled: false, + timerEnabled: true, + }, + }, + }, + }, + }, + }; + + info("TimerFeed should be enabled via trainhopConfig"); + Assert.ok(feed.enabled); +}); + +add_task(async function test_isEnabled() { + let feed = new TimerFeed(); + + feed.store = { + getState() { + return this.state; + }, + dispatch: sinon.spy(), + state: { + Prefs: { + values: { + [PREF_TIMER_ENABLED]: true, + widgetsConfig: { + enabled: true, + listsEnabled: false, + timerEnabled: true, + }, + }, + }, + }, + }; + + info("TimerFeed should be enabled via trainhowidgetsConfigpConfig"); Assert.ok(feed.enabled); });