Move Brave keyed services factories initialization to a common place.
This would also initialize Brave keyed services factories in upstream unit tests. This is a solution proposed by bridiver. Addresses various issues that this change introduced.
This commit is contained in:
@@ -26,7 +26,6 @@
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
class DayZeroBrowserUIExptTest : public testing::Test,
|
||||
public ProfileManagerObserver,
|
||||
public testing::WithParamInterface<bool> {
|
||||
public:
|
||||
DayZeroBrowserUIExptTest()
|
||||
@@ -34,7 +33,6 @@ class DayZeroBrowserUIExptTest : public testing::Test,
|
||||
|
||||
void SetUp() override {
|
||||
ASSERT_TRUE(testing_profile_manager_.SetUp());
|
||||
observation_.Observe(g_browser_process->profile_manager());
|
||||
p3a::P3AService::RegisterPrefs(testing_local_state_.registry(), true);
|
||||
|
||||
if (IsDayZeroEnabled()) {
|
||||
@@ -73,28 +71,11 @@ class DayZeroBrowserUIExptTest : public testing::Test,
|
||||
|
||||
bool IsDayZeroEnabled() { return GetParam(); }
|
||||
|
||||
// ProfileManagerObserver overrides:
|
||||
void OnProfileAdded(Profile* profile) override {
|
||||
// Need to explicitely register as it's done via its factory.
|
||||
ntp_background_images::ViewCounterService::RegisterProfilePrefs(
|
||||
static_cast<TestingProfile*>(profile)
|
||||
->GetTestingPrefService()
|
||||
->registry());
|
||||
}
|
||||
|
||||
void OnProfileManagerDestroying() override {
|
||||
if (observation_.IsObserving()) {
|
||||
observation_.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
content::BrowserTaskEnvironment task_environment_;
|
||||
TestingPrefServiceSimple testing_local_state_;
|
||||
TestingProfileManager testing_profile_manager_;
|
||||
base::test::ScopedFeatureList feature_list_;
|
||||
std::unique_ptr<DayZeroBrowserUIExptManager> manager_;
|
||||
base::ScopedObservation<ProfileManager, ProfileManagerObserver> observation_{
|
||||
this};
|
||||
};
|
||||
|
||||
TEST_P(DayZeroBrowserUIExptTest, PrefsTest) {
|
||||
|
||||
@@ -67,8 +67,6 @@ class EphemeralStorageServiceTest : public testing::Test {
|
||||
~EphemeralStorageServiceTest() override = default;
|
||||
|
||||
void SetUp() override {
|
||||
profile_.GetTestingPrefService()->registry()->RegisterListPref(
|
||||
kFirstPartyStorageOriginsToCleanup);
|
||||
service_ = CreateEphemeralStorageService(&profile_, mock_delegate_,
|
||||
&mock_observer_);
|
||||
}
|
||||
|
||||
@@ -134,8 +134,6 @@ class PermissionLifetimeManagerTest : public testing::Test {
|
||||
void SetUp() override {
|
||||
host_content_settings_map_ =
|
||||
HostContentSettingsMapFactory::GetForProfile(&profile_);
|
||||
PermissionLifetimeManager::RegisterProfilePrefs(
|
||||
profile_.GetTestingPrefService()->registry());
|
||||
}
|
||||
|
||||
void TearDown() override { manager_.reset(); }
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/check_is_test.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "brave/browser/brave_wallet/brave_wallet_context_utils.h"
|
||||
#include "brave/browser/ethereum_remote_client/ethereum_remote_client_constants.h"
|
||||
@@ -81,12 +82,16 @@ BraveRendererUpdater::BraveRendererUpdater(
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_WIDEVINE)
|
||||
widevine_enabled_.Init(kWidevineEnabled, local_state);
|
||||
local_state_change_registrar_.Init(local_state);
|
||||
local_state_change_registrar_.Add(
|
||||
kWidevineEnabled,
|
||||
base::BindRepeating(&BraveRendererUpdater::UpdateAllRenderers,
|
||||
base::Unretained(this)));
|
||||
if (local_state_) {
|
||||
widevine_enabled_.Init(kWidevineEnabled, local_state_);
|
||||
local_state_change_registrar_.Init(local_state_);
|
||||
local_state_change_registrar_.Add(
|
||||
kWidevineEnabled,
|
||||
base::BindRepeating(&BraveRendererUpdater::UpdateAllRenderers,
|
||||
base::Unretained(this)));
|
||||
} else {
|
||||
CHECK_IS_TEST();
|
||||
}
|
||||
#endif
|
||||
|
||||
pref_change_registrar_.Add(
|
||||
@@ -219,7 +224,11 @@ void BraveRendererUpdater::UpdateRenderer(
|
||||
#endif
|
||||
bool widevine_enabled = false;
|
||||
#if BUILDFLAG(ENABLE_WIDEVINE)
|
||||
widevine_enabled = local_state_->GetBoolean(kWidevineEnabled);
|
||||
if (local_state_) {
|
||||
widevine_enabled = local_state_->GetBoolean(kWidevineEnabled);
|
||||
} else {
|
||||
CHECK_IS_TEST();
|
||||
}
|
||||
#endif
|
||||
|
||||
const bool playlist_enabled =
|
||||
|
||||
@@ -126,7 +126,15 @@ class BraveRenderViewContextMenuTest : public testing::Test {
|
||||
ProtocolHandlerRegistryFactory::GetInstance()->SetTestingFactory(
|
||||
profile_.get(), base::BindRepeating(&BuildProtocolHandlerRegistry));
|
||||
}
|
||||
void TearDown() override { registry_.reset(); }
|
||||
|
||||
void TearDown() override {
|
||||
registry_.reset();
|
||||
web_contents_.reset();
|
||||
client_.reset();
|
||||
browser_.reset();
|
||||
profile_.reset();
|
||||
}
|
||||
|
||||
PrefService* GetPrefs() { return profile_->GetPrefs(); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -6,12 +6,10 @@
|
||||
#include "brave/browser/ui/commands/accelerator_service.h"
|
||||
|
||||
#include "base/test/scoped_feature_list.h"
|
||||
#include "brave/components/commands/browser/accelerator_pref_manager.h"
|
||||
#include "brave/components/commands/common/accelerator_parsing.h"
|
||||
#include "brave/components/commands/common/features.h"
|
||||
#include "chrome/app/chrome_command_ids.h"
|
||||
#include "chrome/test/base/testing_profile.h"
|
||||
#include "components/sync_preferences/testing_pref_service_syncable.h"
|
||||
#include "content/public/test/browser_task_environment.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
@@ -23,11 +21,6 @@ class AcceleratorServiceUnitTest : public testing::Test {
|
||||
|
||||
~AcceleratorServiceUnitTest() override = default;
|
||||
|
||||
void SetUp() override {
|
||||
commands::AcceleratorPrefManager::RegisterProfilePrefs(
|
||||
profile().GetTestingPrefService()->registry());
|
||||
}
|
||||
|
||||
TestingProfile& profile() { return profile_; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -85,6 +85,7 @@ class BraveBookmarkSubMenuModelUnitTest : public testing::Test {
|
||||
}
|
||||
void TearDown() override {
|
||||
browser_.reset();
|
||||
profile_.reset();
|
||||
TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +37,6 @@ class WebDiscoveryCTATest : public testing::Test {
|
||||
TestingBrowserProcess::GetGlobal()->SetLocalState(&test_local_state_);
|
||||
test_clock_.SetNow(base::Time::Now());
|
||||
test_util_ = std::make_unique<TemplateURLServiceTestUtil>();
|
||||
test_util_->profile()
|
||||
->GetTestingPrefService()
|
||||
->registry()
|
||||
->RegisterBooleanPref(prefs::kDefaultSearchProviderByExtension, false);
|
||||
web_contents_ =
|
||||
content::WebContentsTester::CreateTestWebContents(profile(), nullptr);
|
||||
ASSERT_TRUE(web_contents_.get());
|
||||
@@ -102,9 +98,9 @@ class WebDiscoveryCTATest : public testing::Test {
|
||||
base::SimpleTestClock test_clock_;
|
||||
content::BrowserTaskEnvironment task_environment_;
|
||||
content::RenderViewHostTestEnabler render_view_host_test_enabler_;
|
||||
TestingPrefServiceSimple test_local_state_;
|
||||
std::unique_ptr<TemplateURLServiceTestUtil> test_util_;
|
||||
std::unique_ptr<content::WebContents> web_contents_;
|
||||
TestingPrefServiceSimple test_local_state_;
|
||||
};
|
||||
|
||||
TEST_F(WebDiscoveryCTATest, InitialDataTest) {
|
||||
|
||||
@@ -1,39 +1,14 @@
|
||||
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#define AddProfilesExtraParts AddProfilesExtraParts_ChromiumImpl
|
||||
#include "src/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc"
|
||||
#undef AddProfilesExtraParts
|
||||
* You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "brave/browser/browser_context_keyed_service_factories.h"
|
||||
#include "chrome/browser/webdata_services/web_data_service_factory.h"
|
||||
|
||||
namespace {
|
||||
#define WebDataServiceFactory \
|
||||
brave::EnsureBrowserContextKeyedServiceFactoriesBuilt(); \
|
||||
WebDataServiceFactory
|
||||
|
||||
class BraveBrowserMainExtraPartsProfiles
|
||||
: public ChromeBrowserMainExtraPartsProfiles {
|
||||
public:
|
||||
BraveBrowserMainExtraPartsProfiles()
|
||||
: ChromeBrowserMainExtraPartsProfiles() {}
|
||||
|
||||
BraveBrowserMainExtraPartsProfiles(
|
||||
const BraveBrowserMainExtraPartsProfiles&) = delete;
|
||||
BraveBrowserMainExtraPartsProfiles& operator=(
|
||||
const BraveBrowserMainExtraPartsProfiles&) = delete;
|
||||
|
||||
void PreProfileInit() override {
|
||||
brave::EnsureBrowserContextKeyedServiceFactoriesBuilt();
|
||||
ChromeBrowserMainExtraPartsProfiles::PreProfileInit();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace chrome {
|
||||
|
||||
void AddProfilesExtraParts(ChromeBrowserMainParts* main_parts) {
|
||||
main_parts->AddParts(std::make_unique<BraveBrowserMainExtraPartsProfiles>());
|
||||
}
|
||||
|
||||
} // namespace chrome
|
||||
#include "src/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc"
|
||||
#undef WebDataServiceFactory
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "brave/browser/browser_context_keyed_service_factories.h"
|
||||
#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class BraveBrowserMainExtraPartsProfiles
|
||||
: public ChromeBrowserMainExtraPartsProfiles {
|
||||
public:
|
||||
BraveBrowserMainExtraPartsProfiles() = default;
|
||||
BraveBrowserMainExtraPartsProfiles(
|
||||
const BraveBrowserMainExtraPartsProfiles&) = delete;
|
||||
BraveBrowserMainExtraPartsProfiles& operator=(
|
||||
const BraveBrowserMainExtraPartsProfiles&) = delete;
|
||||
~BraveBrowserMainExtraPartsProfiles() override = default;
|
||||
|
||||
static void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
|
||||
ChromeBrowserMainExtraPartsProfiles::
|
||||
EnsureBrowserContextKeyedServiceFactoriesBuilt();
|
||||
brave::EnsureBrowserContextKeyedServiceFactoriesBuilt();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#define ChromeBrowserMainExtraPartsProfiles BraveBrowserMainExtraPartsProfiles
|
||||
#include "src/chrome/browser/startup_data.cc"
|
||||
#undef ChromeBrowserMainExtraPartsProfiles
|
||||
@@ -45,8 +45,6 @@ class BraveSearchProviderTest : public testing::Test {
|
||||
base::BindRepeating(&TemplateURLServiceFactory::BuildInstanceFor));
|
||||
|
||||
profile_ = profile_builder.Build();
|
||||
profile_->GetTestingPrefService()->registry()->RegisterBooleanPref(
|
||||
prefs::kDefaultSearchProviderByExtension, false);
|
||||
}
|
||||
|
||||
BraveSearchProviderTest(const BraveSearchProviderTest&) = delete;
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/functional/callback_helpers.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
#include "base/task/thread_pool.h"
|
||||
#include "brave/components/brave_shields/content/browser/ad_block_service.h"
|
||||
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
|
||||
#include "brave/components/tor/buildflags/buildflags.h"
|
||||
@@ -53,7 +58,17 @@ TestingBraveBrowserProcess::~TestingBraveBrowserProcess() = default;
|
||||
void TestingBraveBrowserProcess::StartBraveServices() {}
|
||||
|
||||
brave_shields::AdBlockService* TestingBraveBrowserProcess::ad_block_service() {
|
||||
DCHECK(ad_block_service_);
|
||||
if (!ad_block_service_) {
|
||||
scoped_refptr<base::SequencedTaskRunner> task_runner(
|
||||
base::ThreadPool::CreateSequencedTaskRunner(
|
||||
{base::MayBlock(), base::TaskPriority::USER_BLOCKING,
|
||||
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}));
|
||||
ad_block_service_ = std::make_unique<brave_shields::AdBlockService>(
|
||||
/*local_state*/ nullptr, /*locale*/ "en", /*component_updater*/ nullptr,
|
||||
task_runner,
|
||||
/*subscription_download_manager_getter*/ base::DoNothing(),
|
||||
/*profile_dir*/ base::FilePath(FILE_PATH_LITERAL("")));
|
||||
}
|
||||
return ad_block_service_.get();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user