tor-browser

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

commit e518714623cf11af3fdcecdf08ae4247412f86f5
parent 6f28d4acfc772766682375cb6cdb4f8a530e239a
Author: scottdowne <sdowne@mozilla.com>
Date:   Fri, 14 Nov 2025 15:17:52 +0000

Bug 1996347 - Newtab move feature gate for tests and automation into activitystream r=whimboo,home-newtab-reviewers,nbarrett

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

Diffstat:
Mbrowser/extensions/newtab/content-src/components/Weather/Weather.jsx | 3++-
Mbrowser/extensions/newtab/data/content/activity-stream.bundle.js | 2+-
Mbrowser/extensions/newtab/lib/ActivityStream.sys.mjs | 30+++++++++++++++++++++++++++++-
Mbrowser/extensions/newtab/test/unit/content-src/components/Weather.test.jsx | 1+
Mbrowser/extensions/newtab/test/unit/utils.js | 4++--
Mbrowser/modules/AboutNewTab.sys.mjs | 11-----------
Mbrowser/modules/test/browser/browser.toml | 2--
Dbrowser/modules/test/browser/browser_aboutnewtab_init_gate.js | 28----------------------------
Mremote/shared/RecommendedPreferences.sys.mjs | 13++-----------
Mtesting/marionette/client/marionette_driver/geckoinstance.py | 12++----------
Mtesting/marionette/harness/marionette_harness/tests/unit/test_navigation.py | 7+++----
11 files changed, 42 insertions(+), 71 deletions(-)

diff --git a/browser/extensions/newtab/content-src/components/Weather/Weather.jsx b/browser/extensions/newtab/content-src/components/Weather/Weather.jsx @@ -245,7 +245,8 @@ export class _Weather extends React.PureComponent { isEnabled() { const { values } = this.props.Prefs; - const systemValue = values[PREF_SYSTEM_SHOW_WEATHER]; + const systemValue = + values[PREF_SYSTEM_SHOW_WEATHER] && values["feeds.weatherfeed"]; const experimentValue = values.trainhopConfig?.weather?.enabled; return systemValue || experimentValue; } diff --git a/browser/extensions/newtab/data/content/activity-stream.bundle.js b/browser/extensions/newtab/data/content/activity-stream.bundle.js @@ -11396,7 +11396,7 @@ class _Weather extends (external_React_default()).PureComponent { const { values } = this.props.Prefs; - const systemValue = values[PREF_SYSTEM_SHOW_WEATHER]; + const systemValue = values[PREF_SYSTEM_SHOW_WEATHER] && values["feeds.weatherfeed"]; const experimentValue = values.trainhopConfig?.weather?.enabled; return systemValue || experimentValue; } diff --git a/browser/extensions/newtab/lib/ActivityStream.sys.mjs b/browser/extensions/newtab/lib/ActivityStream.sys.mjs @@ -95,6 +95,8 @@ const LOCALE_SECTIONS_CONFIG = "browser.newtabpage.activity-stream.discoverystream.sections.locale-content-config"; const BROWSER_URLBAR_PLACEHOLDERNAME = "browser.urlbar.placeholderName"; +const PREF_SHOULD_AS_INITIALIZE_FEEDS = + "browser.newtabpage.activity-stream.testing.shouldInitializeFeeds"; export const WEATHER_OPTIN_REGIONS = [ "AT", // Austria @@ -145,6 +147,17 @@ export function csvPrefHasValue(stringPrefName, value) { return prefValues.includes(value); } +export function shouldInitializeFeeds(defaultValue = true) { + // For tests/automation: when false, newtab won't initialize + // select feeds in this session. + // Flipping after initialization has no effect on the current session. + const shouldInitialize = Services.prefs.getBoolPref( + PREF_SHOULD_AS_INITIALIZE_FEEDS, + defaultValue + ); + return shouldInitialize; +} + function useInferredPersonalization({ geo, locale }) { return ( csvPrefHasValue(REGION_INFERRED_PERSONALIZATION_CONFIG, geo) && @@ -1566,6 +1579,7 @@ const FEEDS_DATA = [ ]; const FEEDS_CONFIG = new Map(); + for (const config of FEEDS_DATA) { const pref = `feeds.${config.name}`; FEEDS_CONFIG.set(pref, config.factory); @@ -1579,10 +1593,24 @@ export class ActivityStream { constructor() { this.initialized = false; this.store = new lazy.Store(); - this.feeds = FEEDS_CONFIG; this._defaultPrefs = new lazy.DefaultPrefs(PREFS_CONFIG); } + get feeds() { + if (shouldInitializeFeeds()) { + return FEEDS_CONFIG; + } + + // We currently make excpetions for topsites, and prefs feeds + // because they currently impacts tests timing for places initialization. + // See bug 1999166. + const feeds = new Map([ + ["feeds.system.topsites", FEEDS_CONFIG.get("feeds.system.topsites")], + ["feeds.prefs", FEEDS_CONFIG.get("feeds.prefs")], + ]); + return feeds; + } + init() { this._updateDynamicPrefs(); this._defaultPrefs.init(); diff --git a/browser/extensions/newtab/test/unit/content-src/components/Weather.test.jsx b/browser/extensions/newtab/test/unit/content-src/components/Weather.test.jsx @@ -40,6 +40,7 @@ const mockState = { ...INITIAL_STATE.Prefs.values, [PREF_SYS_SHOW_WEATHER]: true, [PREF_SYS_SHOW_WEATHER_OPT_IN]: false, + "feeds.weatherfeed": true, }, }, Weather: { ...weatherInit }, diff --git a/browser/extensions/newtab/test/unit/utils.js b/browser/extensions/newtab/test/unit/utils.js @@ -118,8 +118,8 @@ export class FakensIPrefBranch { setBoolPref(prefName, value) { this.set(prefName, value); } - getBoolPref(prefName) { - return this.get(prefName); + getBoolPref(prefName, defaultValue) { + return this.get(prefName, defaultValue); } setIntPref(prefName, value) { this.set(prefName, value); diff --git a/browser/modules/AboutNewTab.sys.mjs b/browser/modules/AboutNewTab.sys.mjs @@ -21,7 +21,6 @@ const PREF_ACTIVITY_STREAM_DEBUG = "browser.newtabpage.activity-stream.debug"; // AboutHomeStartupCache needs us in "quit-application", so stay alive longer. // TODO: We could better have a shared async shutdown blocker? const TOPIC_APP_QUIT = "profile-before-change"; -const PREF_SHOULD_INITIALIZE = "browser.newtabpage.shouldInitialize"; export const AboutNewTab = { QueryInterface: ChromeUtils.generateQI([ @@ -51,16 +50,6 @@ export const AboutNewTab = { return; } - // For tests/automation: when false, newtab won't initialize in this session. - // Flipping after initialization has no effect on the current session. - const shouldInitialize = Services.prefs.getBoolPref( - PREF_SHOULD_INITIALIZE, - true - ); - if (!shouldInitialize) { - return; - } - Services.obs.addObserver(this, TOPIC_APP_QUIT); if (!AppConstants.RELEASE_OR_BETA) { XPCOMUtils.defineLazyPreferenceGetter( diff --git a/browser/modules/test/browser/browser.toml b/browser/modules/test/browser/browser.toml @@ -77,8 +77,6 @@ https_first_disabled = true ["browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js"] https_first_disabled = true -["browser_aboutnewtab_init_gate.js"] - ["browser_preloading_tab_moving.js"] ["browser_taskbar_preview.js"] diff --git a/browser/modules/test/browser/browser_aboutnewtab_init_gate.js b/browser/modules/test/browser/browser_aboutnewtab_init_gate.js @@ -1,28 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const PREF = "browser.newtabpage.shouldInitialize"; - -add_task(async function test_aboutnewtab_init_gate() { - ok(AboutNewTab.initialized, "AboutNewTab should initialize by default"); - - await SpecialPowers.pushPrefEnv({ set: [[PREF, false]] }); - - // Reset for a clean start. - AboutNewTab.uninit(); - - // Call init(); with pref=false, we should bail out early. - AboutNewTab.init(); - - ok( - !AboutNewTab.initialized, - "AboutNewTab should not be initialized when pref is false" - ); - - // Cleanup and reset. - await SpecialPowers.popPrefEnv(); - AboutNewTab.init(); - await AboutNewTab.onBrowserReady(); -}); diff --git a/remote/shared/RecommendedPreferences.sys.mjs b/remote/shared/RecommendedPreferences.sys.mjs @@ -128,21 +128,12 @@ const COMMON_PREFERENCES = new Map([ // Disable CFR features for automated tests. ["browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features", false], - // Make sure newtab weather doesn't hit the network to retrieve weather data. - [ - "browser.newtabpage.activity-stream.discoverystream.region-weather-config", - "", - ], - - // Make sure newtab wallpapers don't hit the network to retrieve wallpaper data. - ["browser.newtabpage.activity-stream.newtabWallpapers.enabled", false], + // Do not initialize any activitystream features + ["browser.newtabpage.activity-stream.testing.shouldInitializeFeeds", false], // Make sure Topsites doesn't hit the network to retrieve sponsored tiles. ["browser.newtabpage.activity-stream.showSponsoredTopSites", false], - // Always display a blank page - ["browser.newtabpage.enabled", false], - // Background thumbnails in particular cause grief, and disabling // thumbnails in general cannot hurt ["browser.pagethumbnails.capturing_disabled", true], diff --git a/testing/marionette/client/marionette_driver/geckoinstance.py b/testing/marionette/client/marionette_driver/geckoinstance.py @@ -50,12 +50,6 @@ class GeckoInstance: "browser.http.blank_page_with_error_response.enabled": True, # Disable CFR features for automated tests. "browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features": False, - # Don't pull weather data from the network - "browser.newtabpage.activity-stream.discoverystream.region-weather-config": "", - # Don't pull wallpaper content from the network - "browser.newtabpage.activity-stream.newtabWallpapers.enabled": False, - # Remove once Firefox 140 is no longer supported (see bug 1902921) - "browser.newtabpage.activity-stream.newtabWallpapers.v2.enabled": False, # Don't pull sponsored Top Sites content from the network "browser.newtabpage.activity-stream.showSponsoredTopSites": False, # Disable geolocation ping (#1) @@ -646,10 +640,8 @@ class DesktopInstance(GeckoInstance): "browser.EULA.override": True, # Disable all machine learning features by default "browser.ml.enable": False, - # Disable Activity Stream telemetry pings - "browser.newtabpage.activity-stream.telemetry": False, - # Always display a blank page - "browser.newtabpage.enabled": False, + # Do not initialize any activitystream features + "browser.newtabpage.activity-stream.testing.shouldInitializeFeeds": False, # Background thumbnails in particular cause grief, and disabling thumbnails # in general can"t hurt - we re-enable them when tests need them "browser.pagethumbnails.capturing_disabled": True, diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py b/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py @@ -306,11 +306,10 @@ class TestNavigate(BaseNavigationTestCase): self.marionette.navigate("about:blank") def test_about_newtab(self): - with self.marionette.using_prefs({"browser.newtabpage.enabled": True}): - self.marionette.navigate("about:newtab") + self.marionette.navigate("about:newtab") - self.marionette.navigate(self.test_page_remote) - self.marionette.find_element(By.ID, "testDiv") + self.marionette.navigate(self.test_page_remote) + self.marionette.find_element(By.ID, "testDiv") @run_if_manage_instance("Only runnable if Marionette manages the instance") def test_focus_after_navigation(self):