From 2b635d9adb2bfe2e131018a5cf7e3357cb7d1cd4 Mon Sep 17 00:00:00 2001 From: Serg Date: Wed, 22 Apr 2026 15:52:23 -0400 Subject: [PATCH] [Android] Fix BraveAdsAdsServiceImplTest on is_official_build x86 (#35792) brave_rewards::features::kBraveRewards is DISABLED_BY_DEFAULT on x86/x86_64 Android official builds, so brave_rewards::IsSupported returned false via IsDisabledByFeature. After https://github.com/brave/brave-core/pull/35698 moved the IsSupported gate into AdsServiceImpl::CanStartBatAdsService, that path now suppresses the service in unit tests too and launch_count stays 0. Force-enable the feature in the fixture so Android tests match the non-Android path they were written against. Resolves: https://github.com/brave/brave-browser/issues/54831 --- components/brave_ads/browser/BUILD.gn | 1 + .../browser/ads_service_impl_unittest.cc | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/components/brave_ads/browser/BUILD.gn b/components/brave_ads/browser/BUILD.gn index b263bd3f6ab..a4680c2edcb 100644 --- a/components/brave_ads/browser/BUILD.gn +++ b/components/brave_ads/browser/BUILD.gn @@ -144,6 +144,7 @@ source_set("unit_tests") { "//brave/components/brave_ads/core/public:headers", "//brave/components/brave_component_updater/browser", "//brave/components/brave_rewards/core", + "//brave/components/brave_rewards/core:features", "//brave/components/brave_rewards/core/buildflags", "//brave/components/ntp_background_images/common", "//components/content_settings/core/browser", diff --git a/components/brave_ads/browser/ads_service_impl_unittest.cc b/components/brave_ads/browser/ads_service_impl_unittest.cc index a7d8db8b21a..d1bee435436 100644 --- a/components/brave_ads/browser/ads_service_impl_unittest.cc +++ b/components/brave_ads/browser/ads_service_impl_unittest.cc @@ -11,6 +11,7 @@ #include "base/files/scoped_temp_dir.h" #include "base/memory/raw_ptr.h" #include "base/test/run_until.h" +#include "base/test/scoped_feature_list.h" #include "base/test/task_environment.h" #include "base/values.h" #include "brave/components/brave_ads/browser/test/fake_ads_service_delegate.h" @@ -21,6 +22,7 @@ #include "brave/components/brave_ads/core/public/prefs/pref_names.h" #include "brave/components/brave_ads/core/public/prefs/pref_registry.h" #include "brave/components/brave_rewards/core/buildflags/buildflags.h" +#include "brave/components/brave_rewards/core/features.h" #include "brave/components/brave_rewards/core/pref_names.h" #include "brave/components/brave_rewards/core/pref_registry.h" #include "brave/components/ntp_background_images/common/pref_names.h" @@ -41,6 +43,16 @@ namespace brave_ads { class BraveAdsAdsServiceImplTest : public testing::Test { public: void SetUp() override { +#if BUILDFLAG(IS_ANDROID) + // `brave_rewards::features::kBraveRewards` is `DISABLED_BY_DEFAULT` on + // `is_official_build=true` x86/x86_64 Android, which routes + // `brave_rewards::IsSupported` through `IsDisabledByFeature` and prevents + // the service from starting. Force-enable so Android matches the + // non-Android path these tests were written against. + scoped_feature_list_.InitAndEnableFeature( + brave_rewards::features::kBraveRewards); +#endif // BUILDFLAG(IS_ANDROID) + ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); RegisterProfilePrefs(prefs_.registry()); @@ -95,6 +107,10 @@ class BraveAdsAdsServiceImplTest : public testing::Test { void Shutdown() { ads_service_->Shutdown(); } +#if BUILDFLAG(IS_ANDROID) + base::test::ScopedFeatureList scoped_feature_list_; +#endif // BUILDFLAG(IS_ANDROID) + base::test::TaskEnvironment task_environment_; base::ScopedTempDir profile_dir_;