0

Rename SyncServiceFactory::GetAsSyncServiceImpl*() to use ForTesting()

Bug: 1297582
Change-Id: I84a71094f9669836a152f7b3efbbd4117c8eaed7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3790898
Reviewed-by: David Roger <droger@chromium.org>
Commit-Queue: Jood Hajeer <jood@google.com>
Reviewed-by: Maksim Moskvitin <mmoskvitin@google.com>
Reviewed-by: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1032991}
This commit is contained in:
Jood Hajeer
2022-08-09 13:32:37 +00:00
committed by Chromium LUCI CQ
parent e9e6807af1
commit 568e17dec1
17 changed files with 34 additions and 35 deletions

@ -625,7 +625,8 @@ IN_PROC_BROWSER_TEST_F(WebviewLoginTestWithSyncTrustedVaultEnabled,
signin::WaitForRefreshTokensLoaded(identity_manager);
syncer::SyncServiceImpl* sync_service =
SyncServiceFactory::GetAsSyncServiceImplForProfile(browser->profile());
SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(
browser->profile());
syncer::TrustedVaultClient* trusted_vault_client =
sync_service->GetSyncClientForTest()->GetTrustedVaultClient();

@ -20,7 +20,7 @@ std::unique_ptr<SyncServiceImplHarness> InitializeProfileForSync(
base::WeakPtr<fake_server::FakeServer> fake_server) {
DCHECK(profile);
SyncServiceFactory::GetAsSyncServiceImplForProfile(profile)
SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(profile)
->OverrideNetworkForTest(
fake_server::CreateFakeServerHttpPostProviderFactory(
fake_server->AsWeakPtr()));

@ -90,7 +90,7 @@ std::unique_ptr<syncer::LoopbackServerEntity> CreateBookmarkEntity(
syncer::SyncServiceImpl* GetSyncServiceImpl() {
DCHECK(g_browser_process && g_browser_process->profile_manager());
return SyncServiceFactory::GetAsSyncServiceImplForProfile(
return SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(
ProfileManager::GetLastUsedProfile());
}

@ -63,7 +63,7 @@ std::vector<std::vector<uint8_t>> FetchTrustedVaultKeysForProfile(
Profile* profile,
const AccountInfo& account_info) {
syncer::SyncServiceImpl* sync_service =
SyncServiceFactory::GetAsSyncServiceImplForProfile(profile);
SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(profile);
syncer::TrustedVaultClient* trusted_vault_client =
sync_service->GetSyncClientForTest()->GetTrustedVaultClient();

@ -193,8 +193,8 @@ syncer::SyncService* SyncServiceFactory::GetForProfile(Profile* profile) {
}
// static
syncer::SyncServiceImpl* SyncServiceFactory::GetAsSyncServiceImplForProfile(
Profile* profile) {
syncer::SyncServiceImpl*
SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(Profile* profile) {
return static_cast<syncer::SyncServiceImpl*>(GetForProfile(profile));
}

@ -28,7 +28,7 @@ class SyncServiceFactory : public BrowserContextKeyedServiceFactory {
static syncer::SyncService* GetForProfile(Profile* profile);
// Returns the SyncServiceImpl for the given profile. DO NOT USE unless
// absolutely necessary! Prefer GetForProfile instead.
static syncer::SyncServiceImpl* GetAsSyncServiceImplForProfile(
static syncer::SyncServiceImpl* GetAsSyncServiceImplForProfileForTesting(
Profile* profile);
SyncServiceFactory(const SyncServiceFactory&) = delete;

@ -185,7 +185,7 @@ TEST_F(SyncServiceFactoryTest, DisableSyncFlag) {
// and properly initialized.
TEST_F(SyncServiceFactoryTest, CreateSyncServiceImplDefault) {
syncer::SyncServiceImpl* sync_service =
SyncServiceFactory::GetAsSyncServiceImplForProfile(profile());
SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(profile());
syncer::ModelTypeSet types = sync_service->GetRegisteredDataTypesForTest();
const syncer::ModelTypeSet default_types = DefaultDatatypes();
EXPECT_EQ(default_types.Size(), types.Size());

@ -78,7 +78,8 @@ class LocalSyncTest : public InProcessBrowserTest {
(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
IN_PROC_BROWSER_TEST_F(LocalSyncTest, ShouldStart) {
SyncServiceImpl* service =
SyncServiceFactory::GetAsSyncServiceImplForProfile(browser()->profile());
SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(
browser()->profile());
// Wait until the first sync cycle is completed.
ASSERT_TRUE(SyncTransportActiveChecker(service).Wait());

@ -178,7 +178,8 @@ SyncServiceImplHarness::SyncServiceImplHarness(Profile* profile,
const std::string& password,
SigninType signin_type)
: profile_(profile),
service_(SyncServiceFactory::GetAsSyncServiceImplForProfile(profile)),
service_(SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(
profile)),
username_(username),
password_(password),
signin_type_(signin_type),

@ -564,7 +564,8 @@ std::vector<SyncServiceImplHarness*> SyncTest::GetSyncClients() {
}
SyncServiceImpl* SyncTest::GetSyncService(int index) const {
return SyncServiceFactory::GetAsSyncServiceImplForProfile(GetProfile(index));
return SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(
GetProfile(index));
}
syncer::UserSelectableTypeSet SyncTest::GetRegisteredSelectableTypes(
@ -704,7 +705,8 @@ void SyncTest::InitializeProfile(int index, Profile* profile) {
// SyncServiceImplHarness - some tests expect the SyncServiceImpl to
// already exist.
SyncServiceImpl* sync_service_impl =
SyncServiceFactory::GetAsSyncServiceImplForProfile(GetProfile(index));
SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(
GetProfile(index));
if (server_type_ == IN_PROCESS_FAKE_SERVER) {
sync_service_impl->OverrideNetworkForTest(

@ -3344,7 +3344,8 @@ TEST_P(ArcAppModelBuilderTest, DontRemoveRuntimeAppOnPackageChange) {
}
TEST_P(ArcAppModelBuilderTest, PackageSyncableServiceEnabled) {
EXPECT_TRUE(SyncServiceFactory::GetAsSyncServiceImplForProfile(profile_.get())
EXPECT_TRUE(SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(
profile_.get())
->GetRegisteredDataTypesForTest()
.Has(syncer::ARC_PACKAGE));
}
@ -3353,10 +3354,10 @@ TEST_P(ArcAppModelBuilderTest, PackageSyncableServiceDisabled) {
base::test::ScopedCommandLine command_line;
command_line.GetProcessCommandLine()->AppendSwitch(
ash::switches::kArcDisableAppSync);
EXPECT_FALSE(
SyncServiceFactory::GetAsSyncServiceImplForProfile(profile_.get())
->GetRegisteredDataTypesForTest()
.Has(syncer::ARC_PACKAGE));
EXPECT_FALSE(SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(
profile_.get())
->GetRegisteredDataTypesForTest()
.Has(syncer::ARC_PACKAGE));
}
TEST_P(ArcDefaultAppTest, DefaultApps) {

@ -449,7 +449,8 @@ IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest,
// The invocation of the API, even with dummy values, should propagate until
// TrustedVaultClient and its observers.
TrustedVaultKeysChangedStateChecker keys_added_checker(
SyncServiceFactory::GetAsSyncServiceImplForProfile(browser()->profile()));
SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(
browser()->profile()));
EXPECT_TRUE(content::ExecuteScript(
target_contents,
"chrome.setSyncEncryptionKeys(() => {}, \"\", [new ArrayBuffer()], 0);"));

@ -845,7 +845,8 @@ class ProfileMenuClickTest : public SyncTest,
}
syncer::SyncServiceImpl* sync_service() {
return SyncServiceFactory::GetAsSyncServiceImplForProfile(GetProfile());
return SyncServiceFactory::GetAsSyncServiceImplForProfileForTesting(
GetProfile());
}
signin::IdentityManager* identity_manager() {

@ -27,10 +27,7 @@ class SyncServiceFactory : public BrowserStateKeyedServiceFactory {
static syncer::SyncService* GetForBrowserStateIfExists(
ChromeBrowserState* browser_state);
static syncer::SyncServiceImpl* GetAsSyncServiceImplForBrowserState(
ChromeBrowserState* browser_state);
static syncer::SyncServiceImpl* GetAsSyncServiceImplForBrowserStateIfExists(
static syncer::SyncServiceImpl* GetAsSyncServiceImplForBrowserStateForTesting(
ChromeBrowserState* browser_state);
static SyncServiceFactory* GetInstance();

@ -80,20 +80,12 @@ syncer::SyncService* SyncServiceFactory::GetForBrowserStateIfExists(
// static
syncer::SyncServiceImpl*
SyncServiceFactory::GetAsSyncServiceImplForBrowserState(
SyncServiceFactory::GetAsSyncServiceImplForBrowserStateForTesting(
ChromeBrowserState* browser_state) {
return static_cast<syncer::SyncServiceImpl*>(
GetForBrowserState(browser_state));
}
// static
syncer::SyncServiceImpl*
SyncServiceFactory::GetAsSyncServiceImplForBrowserStateIfExists(
ChromeBrowserState* browser_state) {
return static_cast<syncer::SyncServiceImpl*>(
GetForBrowserStateIfExists(browser_state));
}
SyncServiceFactory::SyncServiceFactory()
: BrowserStateKeyedServiceFactory(
"SyncService",

@ -105,7 +105,7 @@ TEST_F(SyncServiceFactoryTest, DisableSyncFlag) {
// and properly initialized.
TEST_F(SyncServiceFactoryTest, CreateSyncServiceImplDefault) {
syncer::SyncServiceImpl* sync_service =
SyncServiceFactory::GetAsSyncServiceImplForBrowserState(
SyncServiceFactory::GetAsSyncServiceImplForBrowserStateForTesting(
chrome_browser_state());
syncer::ModelTypeSet types = sync_service->GetRegisteredDataTypesForTest();
const syncer::ModelTypeSet default_types = DefaultDatatypes();

@ -65,7 +65,8 @@ void OverrideSyncNetwork(const syncer::CreateHttpPostProviderFactory&
chrome_test_util::GetOriginalBrowserState();
DCHECK(browser_state);
syncer::SyncServiceImpl* service =
SyncServiceFactory::GetAsSyncServiceImplForBrowserState(browser_state);
SyncServiceFactory::GetAsSyncServiceImplForBrowserStateForTesting(
browser_state);
service->OverrideNetworkForTest(create_http_post_provider_factory_cb);
}
@ -109,7 +110,8 @@ void StartSync() {
SyncSetupServiceFactory::GetForBrowserState(browser_state);
sync_setup_service->SetSyncEnabled(true);
syncer::SyncServiceImpl* sync_service =
SyncServiceFactory::GetAsSyncServiceImplForBrowserState(browser_state);
SyncServiceFactory::GetAsSyncServiceImplForBrowserStateForTesting(
browser_state);
sync_service->TriggerPoliciesLoadedForTest();
}