From 9352dd94f89103fba52d018f24d657e7884fda5d Mon Sep 17 00:00:00 2001 From: vabr Date: Fri, 19 Feb 2016 08:09:49 -0800 Subject: Remove Profile dependency from some ProfileSyncService unittests More precisely, this removes the //chrome dependencies from TestProfileSyncService, AbstractProfileSyncServiceTest, ProfileSyncServiceTypedUrlTest and ProfileSyncServiceAutofillTest. BUG=581640 Review URL: https://codereview.chromium.org/1646553002 Cr-Commit-Position: refs/heads/master@{#376446} --- .../sync/abstract_profile_sync_service_test.cc | 162 +++++++++++- .../sync/abstract_profile_sync_service_test.h | 33 ++- .../sync/profile_sync_service_autofill_unittest.cc | 292 ++++++++------------- .../profile_sync_service_typed_url_unittest.cc | 224 +++++++--------- chrome/browser/sync/test_profile_sync_service.cc | 200 +------------- chrome/browser/sync/test_profile_sync_service.h | 83 +----- .../one_click_signin_sync_observer_unittest.cc | 22 +- components/browser_sync/browser/BUILD.gn | 3 + .../browser_sync/browser/profile_sync_test_util.cc | 225 ++++++++++++++-- .../browser_sync/browser/profile_sync_test_util.h | 71 ++++- components/history/core/browser/history_service.h | 2 +- 11 files changed, 689 insertions(+), 628 deletions(-) diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.cc b/chrome/browser/sync/abstract_profile_sync_service_test.cc index 3089b52..28d6396 100644 --- a/chrome/browser/sync/abstract_profile_sync_service_test.cc +++ b/chrome/browser/sync/abstract_profile_sync_service_test.cc @@ -4,19 +4,138 @@ #include "chrome/browser/sync/abstract_profile_sync_service_test.h" +#include + #include "base/bind.h" #include "base/bind_helpers.h" +#include "base/files/file_path.h" #include "base/location.h" #include "base/run_loop.h" +#include "chrome/browser/sync/test/test_http_bridge_factory.h" #include "chrome/browser/sync/test_profile_sync_service.h" +#include "components/sync_driver/glue/sync_backend_host_core.h" +#include "components/sync_driver/sync_api_component_factory_mock.h" #include "content/public/test/test_utils.h" +#include "google_apis/gaia/gaia_constants.h" +#include "sync/internal_api/public/test/sync_manager_factory_for_profile_sync_test.h" +#include "sync/internal_api/public/test/test_internal_components_factory.h" #include "sync/internal_api/public/test/test_user_share.h" -#include "sync/internal_api/public/write_transaction.h" #include "sync/protocol/sync.pb.h" -#include "sync/util/cryptographer.h" +using content::BrowserThread; using syncer::ModelType; -using syncer::UserShare; +using testing::_; +using testing::Return; + +namespace { + +class SyncBackendHostForProfileSyncTest + : public browser_sync::SyncBackendHostImpl { + public: + SyncBackendHostForProfileSyncTest( + const base::FilePath& temp_dir, + sync_driver::SyncClient* sync_client, + const scoped_refptr& ui_thread, + invalidation::InvalidationService* invalidator, + const base::WeakPtr& sync_prefs, + const base::Closure& callback); + ~SyncBackendHostForProfileSyncTest() override; + + void RequestConfigureSyncer( + syncer::ConfigureReason reason, + syncer::ModelTypeSet to_download, + syncer::ModelTypeSet to_purge, + syncer::ModelTypeSet to_journal, + syncer::ModelTypeSet to_unapply, + syncer::ModelTypeSet to_ignore, + const syncer::ModelSafeRoutingInfo& routing_info, + const base::Callback& + ready_task, + const base::Closure& retry_callback) override; + + protected: + void InitCore(scoped_ptr options) override; + + private: + // Invoked at the start of HandleSyncManagerInitializationOnFrontendLoop. + // Allows extra initialization work to be performed before the backend comes + // up. + base::Closure callback_; + + DISALLOW_COPY_AND_ASSIGN(SyncBackendHostForProfileSyncTest); +}; + +SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( + const base::FilePath& temp_dir, + sync_driver::SyncClient* sync_client, + const scoped_refptr& ui_thread, + invalidation::InvalidationService* invalidator, + const base::WeakPtr& sync_prefs, + const base::Closure& callback) + : browser_sync::SyncBackendHostImpl( + "dummy_debug_name", + sync_client, + ui_thread, + invalidator, + sync_prefs, + temp_dir.Append(base::FilePath(FILE_PATH_LITERAL("test")))), + callback_(callback) {} + +SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} + +void SyncBackendHostForProfileSyncTest::InitCore( + scoped_ptr options) { + options->http_bridge_factory = scoped_ptr( + new browser_sync::TestHttpBridgeFactory()); + options->sync_manager_factory.reset( + new syncer::SyncManagerFactoryForProfileSyncTest(callback_)); + options->credentials.email = "testuser@gmail.com"; + options->credentials.sync_token = "token"; + options->credentials.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); + options->restored_key_for_bootstrapping.clear(); + + // It'd be nice if we avoided creating the InternalComponentsFactory in the + // first place, but SyncBackendHost will have created one by now so we must + // free it. Grab the switches to pass on first. + syncer::InternalComponentsFactory::Switches factory_switches = + options->internal_components_factory->GetSwitches(); + options->internal_components_factory.reset( + new syncer::TestInternalComponentsFactory( + factory_switches, + syncer::InternalComponentsFactory::STORAGE_IN_MEMORY, nullptr)); + + browser_sync::SyncBackendHostImpl::InitCore(std::move(options)); +} + +void SyncBackendHostForProfileSyncTest::RequestConfigureSyncer( + syncer::ConfigureReason reason, + syncer::ModelTypeSet to_download, + syncer::ModelTypeSet to_purge, + syncer::ModelTypeSet to_journal, + syncer::ModelTypeSet to_unapply, + syncer::ModelTypeSet to_ignore, + const syncer::ModelSafeRoutingInfo& routing_info, + const base::Callback& + ready_task, + const base::Closure& retry_callback) { + syncer::ModelTypeSet failed_configuration_types; + + // The first parameter there should be the set of enabled types. That's not + // something we have access to from this strange test harness. We'll just + // send back the list of newly configured types instead and hope it doesn't + // break anything. + // Posted to avoid re-entrancy issues. + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, + base::Bind(&SyncBackendHostForProfileSyncTest:: + FinishConfigureDataTypesOnFrontendLoop, + base::Unretained(this), + syncer::Difference(to_download, failed_configuration_types), + syncer::Difference(to_download, failed_configuration_types), + failed_configuration_types, ready_task)); +} + +} // namespace /* static */ syncer::ImmutableChangeRecordList @@ -47,14 +166,14 @@ AbstractProfileSyncServiceTest::AbstractProfileSyncServiceTest() // Purposefully do not use a real FILE thread, see crbug/550013. : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | content::TestBrowserThreadBundle::REAL_IO_THREAD), - sync_service_(NULL) {} - -AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() {} - -void AbstractProfileSyncServiceTest::SetUp() { + profile_sync_service_bundle_( + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), + BrowserThread::GetBlockingPool()) { + CHECK(temp_dir_.CreateUniqueTempDir()); } -void AbstractProfileSyncServiceTest::TearDown() { +AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() { // Pump messages posted by the sync core thread (which may end up // posting on the IO thread). base::RunLoop().RunUntilIdle(); @@ -67,6 +186,31 @@ bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) { sync_service_->GetUserShare()); } +scoped_ptr +AbstractProfileSyncServiceTest::CreateSyncService( + scoped_ptr sync_client, + const base::Closure& initialization_success_callback) { + DCHECK(sync_client); + ProfileSyncService::InitParams init_params = + profile_sync_service_bundle_.CreateBasicInitParams( + browser_sync::AUTO_START, std::move(sync_client)); + auto sync_service = + make_scoped_ptr(new TestProfileSyncService(std::move(init_params))); + + SyncApiComponentFactoryMock* components = + profile_sync_service_bundle_.component_factory(); + EXPECT_CALL(*components, CreateSyncBackendHost(_, _, _, _)) + .WillOnce(Return(new SyncBackendHostForProfileSyncTest( + temp_dir_.path(), sync_service->GetSyncClient(), + base::ThreadTaskRunnerHandle::Get(), + profile_sync_service_bundle_.fake_invalidation_service(), + sync_service->sync_prefs()->AsWeakPtr(), + initialization_success_callback))); + + sync_service->SetFirstSetupComplete(); + return sync_service; +} + CreateRootHelper::CreateRootHelper(AbstractProfileSyncServiceTest* test, ModelType model_type) : callback_(base::Bind(&CreateRootHelper::CreateRootCallback, diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.h b/chrome/browser/sync/abstract_profile_sync_service_test.h index d6131b7..b539e98 100644 --- a/chrome/browser/sync/abstract_profile_sync_service_test.h +++ b/chrome/browser/sync/abstract_profile_sync_service_test.h @@ -10,16 +10,15 @@ #include #include "base/callback.h" -#include "base/compiler_specific.h" +#include "base/files/scoped_temp_dir.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" -#include "base/message_loop/message_loop.h" -#include "components/sync_driver/sync_api_component_factory_mock.h" +#include "components/browser_sync/browser/profile_sync_test_util.h" #include "content/public/test/test_browser_thread_bundle.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/change_record.h" #include "testing/gtest/include/gtest/gtest.h" -class ProfileSyncService; class TestProfileSyncService; namespace syncer { @@ -37,6 +36,9 @@ class ProfileSyncServiceTestHelper { MakeSingletonDeletionChangeRecordList( int64_t node_id, const sync_pb::EntitySpecifics& specifics); + + private: + DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceTestHelper); }; class AbstractProfileSyncServiceTest : public testing::Test { @@ -44,15 +46,26 @@ class AbstractProfileSyncServiceTest : public testing::Test { AbstractProfileSyncServiceTest(); ~AbstractProfileSyncServiceTest() override; - void SetUp() override; - - void TearDown() override; - bool CreateRoot(syncer::ModelType model_type); protected: + // Creates a TestProfileSyncService instance based on + // |profile_sync_service_bundle_|, with start behavior + // browser_sync::AUTO_START. Passes |callback| down to + // SyncManagerForProfileSyncTest to be used by NotifyInitializationSuccess. + // |sync_client| is passed to the service. + scoped_ptr CreateSyncService( + scoped_ptr sync_client, + const base::Closure& initialization_success_callback); + content::TestBrowserThreadBundle thread_bundle_; - TestProfileSyncService* sync_service_; + browser_sync::ProfileSyncServiceBundle profile_sync_service_bundle_; + scoped_ptr sync_service_; + + private: + base::ScopedTempDir temp_dir_; // To pass to the backend host. + + DISALLOW_COPY_AND_ASSIGN(AbstractProfileSyncServiceTest); }; class CreateRootHelper { @@ -71,6 +84,8 @@ class CreateRootHelper { AbstractProfileSyncServiceTest* test_; syncer::ModelType model_type_; bool success_; + + DISALLOW_COPY_AND_ASSIGN(CreateRootHelper); }; #endif // CHROME_BROWSER_SYNC_ABSTRACT_PROFILE_SYNC_SERVICE_TEST_H_ diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index ccd554d..889a745 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -15,7 +15,6 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/callback.h" -#include "base/compiler_specific.h" #include "base/location.h" #include "base/macros.h" #include "base/memory/ref_counted.h" @@ -24,20 +23,10 @@ #include "base/strings/string16.h" #include "base/strings/utf_string_conversions.h" #include "base/synchronization/waitable_event.h" +#include "base/thread_task_runner_handle.h" #include "base/time/time.h" -#include "chrome/browser/autofill/personal_data_manager_factory.h" -#include "chrome/browser/signin/account_tracker_service_factory.h" -#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" -#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" -#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/sync/abstract_profile_sync_service_test.h" -#include "chrome/browser/sync/profile_sync_service_factory.h" -#include "chrome/browser/sync/profile_sync_test_util.h" #include "chrome/browser/sync/test_profile_sync_service.h" -#include "chrome/browser/web_data_service_factory.h" -#include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_profile.h" -#include "chrome/test/base/testing_profile_manager.h" #include "components/autofill/core/browser/autofill_test_utils.h" #include "components/autofill/core/browser/country_names.h" #include "components/autofill/core/browser/personal_data_manager.h" @@ -49,18 +38,15 @@ #include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_table.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" +#include "components/autofill/core/common/autofill_pref_names.h" #include "components/browser_sync/browser/profile_sync_service.h" -#include "components/signin/core/browser/account_tracker_service.h" -#include "components/signin/core/browser/fake_profile_oauth2_token_service.h" -#include "components/signin/core/browser/signin_manager.h" #include "components/sync_driver/data_type_controller.h" -#include "components/sync_driver/fake_sync_client.h" +#include "components/sync_driver/data_type_manager_impl.h" #include "components/sync_driver/sync_api_component_factory_mock.h" #include "components/syncable_prefs/pref_service_syncable.h" #include "components/webdata/common/web_database.h" #include "components/webdata_services/web_data_service_test_util.h" #include "content/public/test/test_browser_thread.h" -#include "google_apis/gaia/gaia_constants.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/data_type_debug_info_listener.h" #include "sync/internal_api/public/read_node.h" @@ -70,14 +56,12 @@ #include "sync/protocol/autofill_specifics.pb.h" #include "sync/syncable/mutable_entry.h" #include "sync/syncable/syncable_write_transaction.h" -#include "sync/test/engine/test_id_factory.h" #include "testing/gmock/include/gmock/gmock.h" using autofill::AutocompleteSyncableService; using autofill::AutofillChange; using autofill::AutofillChangeList; using autofill::AutofillEntry; -using autofill::ServerFieldType; using autofill::AutofillKey; using autofill::AutofillProfile; using autofill::AutofillProfileChange; @@ -94,16 +78,12 @@ using content::BrowserThread; using syncer::AUTOFILL; using syncer::AUTOFILL_PROFILE; using syncer::BaseNode; -using syncer::syncable::BASE_VERSION; using syncer::syncable::CREATE; using syncer::syncable::GET_TYPE_ROOT; using syncer::syncable::MutableEntry; -using syncer::syncable::SERVER_SPECIFICS; -using syncer::syncable::SPECIFICS; using syncer::syncable::UNITTEST; using syncer::syncable::WriterTag; using syncer::syncable::WriteTransaction; -using sync_driver::DataTypeController; using testing::_; using testing::DoAll; using testing::ElementsAre; @@ -113,7 +93,11 @@ using testing::Return; namespace { -const char kTestProfileName[] = "test-profile"; +void RegisterAutofillPrefs(user_prefs::PrefRegistrySyncable* registry) { + registry->RegisterBooleanPref(autofill::prefs::kAutofillEnabled, true); + registry->RegisterBooleanPref(autofill::prefs::kAutofillWalletImportEnabled, + true); +} void RunAndSignal(const base::Closure& cb, WaitableEvent* event) { cb.Run(); @@ -133,8 +117,8 @@ class AutofillTableMock : public AutofillTable { MOCK_METHOD4(GetAutofillTimestamps, bool(const base::string16& name, // NOLINT const base::string16& value, - base::Time* date_created, - base::Time* date_last_used)); + Time* date_created, + Time* date_last_used)); MOCK_METHOD1(UpdateAutofillEntries, bool(const std::vector&)); // NOLINT MOCK_METHOD1(GetAutofillProfiles, @@ -151,45 +135,6 @@ MATCHER_P(MatchProfiles, profile, "") { return (profile.Compare(arg) == 0); } -class TestSyncClient : public sync_driver::FakeSyncClient { - public: - TestSyncClient(PersonalDataManager* pdm, - const scoped_refptr& web_data_service) - : pdm_(pdm), - sync_service_(nullptr), - web_data_service_(web_data_service) {} - ~TestSyncClient() override {} - - // FakeSyncClient overrides. - autofill::PersonalDataManager* GetPersonalDataManager() override { - return pdm_; - } - sync_driver::SyncService* GetSyncService() override { - DCHECK(sync_service_); - return sync_service_; - } - base::WeakPtr GetSyncableServiceForType( - syncer::ModelType type) override { - DCHECK(type == AUTOFILL || type == AUTOFILL_PROFILE); - if (type == AUTOFILL) { - return AutocompleteSyncableService::FromWebDataService( - web_data_service_.get())->AsWeakPtr(); - } else { - return AutofillProfileSyncableService::FromWebDataService( - web_data_service_.get())->AsWeakPtr(); - } - } - - void SetSyncService(sync_driver::SyncService* sync_service) { - sync_service_ = sync_service; - } - - private: - PersonalDataManager* pdm_; - sync_driver::SyncService* sync_service_; - scoped_refptr web_data_service_; -}; - class WebDatabaseFake : public WebDatabase { public: explicit WebDatabaseFake(AutofillTable* autofill_table) { @@ -232,12 +177,12 @@ syncer::ModelType GetModelType() { template<> syncer::ModelType GetModelType() { - return syncer::AUTOFILL; + return AUTOFILL; } template<> syncer::ModelType GetModelType() { - return syncer::AUTOFILL_PROFILE; + return AUTOFILL_PROFILE; } class TokenWebDataServiceFake : public TokenWebData { @@ -378,12 +323,6 @@ class WebDataServiceFake : public AutofillWebDataService { DISALLOW_COPY_AND_ASSIGN(WebDataServiceFake); }; -scoped_ptr BuildMockWebDataServiceWrapper( - content::BrowserContext* profile) { - return make_scoped_ptr(new MockWebDataServiceWrapper( - new WebDataServiceFake(), new TokenWebDataServiceFake())); -} - ACTION_P(MakeAutocompleteSyncComponents, wds) { EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); if (!BrowserThread::CurrentlyOn(BrowserThread::DB)) @@ -407,10 +346,6 @@ class MockPersonalDataManager : public PersonalDataManager { MOCK_METHOD0(LoadProfiles, void()); MOCK_METHOD0(LoadCreditCards, void()); MOCK_METHOD0(Refresh, void()); - - static scoped_ptr Build(content::BrowserContext* profile) { - return make_scoped_ptr(new MockPersonalDataManager()); - } }; template class AddAutofillHelper; @@ -427,57 +362,42 @@ class ProfileSyncServiceAutofillTest } protected: - ProfileSyncServiceAutofillTest() - : profile_manager_(TestingBrowserProcess::GetGlobal()), - debug_ptr_factory_(this) { + ProfileSyncServiceAutofillTest() : debug_ptr_factory_(this) { autofill::CountryNames::SetLocaleString("en-US"); - } + RegisterAutofillPrefs( + profile_sync_service_bundle_.pref_service()->registry()); - ~ProfileSyncServiceAutofillTest() override {} - - void SetUp() override { - AbstractProfileSyncServiceTest::SetUp(); - ASSERT_TRUE(profile_manager_.SetUp()); - TestingProfile::TestingFactories testing_factories; - testing_factories.push_back(std::make_pair( - ProfileOAuth2TokenServiceFactory::GetInstance(), - BuildAutoIssuingFakeProfileOAuth2TokenService)); - profile_ = profile_manager_.CreateTestingProfile( - kTestProfileName, - scoped_ptr(), - base::UTF8ToUTF16(kTestProfileName), - 0, - std::string(), - testing_factories); web_database_.reset(new WebDatabaseFake(&autofill_table_)); - MockWebDataServiceWrapper* wrapper = - static_cast( - WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse( - profile_, BuildMockWebDataServiceWrapper)); - web_data_service_ = - static_cast(wrapper->GetAutofillWebData().get()); + web_data_wrapper_ = make_scoped_ptr(new MockWebDataServiceWrapper( + new WebDataServiceFake(), new TokenWebDataServiceFake())); + web_data_service_ = static_cast( + web_data_wrapper_->GetAutofillWebData().get()); web_data_service_->SetDatabase(web_database_.get()); - personal_data_manager_ = static_cast( - autofill::PersonalDataManagerFactory::GetInstance() - ->SetTestingFactoryAndUse(profile_, - MockPersonalDataManager::Build)); + personal_data_manager_ = make_scoped_ptr(new MockPersonalDataManager()); - EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1); - EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1); + EXPECT_CALL(*personal_data_manager_, LoadProfiles()); + EXPECT_CALL(*personal_data_manager_, LoadCreditCards()); personal_data_manager_->Init( - WebDataServiceFactory::GetAutofillWebDataForProfile( - profile_, ServiceAccessType::EXPLICIT_ACCESS), - profile_->GetPrefs(), - AccountTrackerServiceFactory::GetForProfile(profile_), - SigninManagerFactory::GetForProfile(profile_), - profile_->IsOffTheRecord()); + web_data_service_, profile_sync_service_bundle_.pref_service(), + profile_sync_service_bundle_.account_tracker(), + profile_sync_service_bundle_.signin_manager(), false); web_data_service_->StartSyncableService(); - sync_client_.reset(new TestSyncClient(personal_data_manager_, - web_data_service_)); + browser_sync::ProfileSyncServiceBundle::SyncClientBuilder builder( + &profile_sync_service_bundle_); + builder.SetPersonalDataManager(personal_data_manager_.get()); + builder.SetSyncServiceCallback( + base::Bind(&ProfileSyncServiceAutofillTest::GetSyncService, + base::Unretained(this))); + builder.SetSyncableServiceCallback( + base::Bind(&ProfileSyncServiceAutofillTest::GetSyncableServiceForType, + base::Unretained(this))); + builder.set_activate_model_creation(); + sync_client_owned_ = builder.Build(); + sync_client_ = sync_client_owned_.get(); // When UpdateAutofillEntries() is called with an empty list, the return // value should be |true|, rather than the default of |false|. @@ -486,23 +406,17 @@ class ProfileSyncServiceAutofillTest .WillRepeatedly(Return(true)); } - void TearDown() override { + ~ProfileSyncServiceAutofillTest() override { // Note: The tear down order is important. - ProfileSyncServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL); + sync_service_->Shutdown(); web_data_service_->ShutdownOnUIThread(); web_data_service_->ShutdownSyncableService(); - web_data_service_ = NULL; - // To prevent a leak, fully release TestURLRequestContext to ensure its - // destruction on the IO message loop. - profile_ = NULL; - profile_manager_.DeleteTestingProfile(kTestProfileName); - AbstractProfileSyncServiceTest::TearDown(); } int GetSyncCount(syncer::ModelType type) { syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); syncer::ReadNode node(&trans); - if (node.InitTypeRoot(type) != syncer::BaseNode::INIT_OK) + if (node.InitTypeRoot(type) != BaseNode::INIT_OK) return 0; return node.GetTotalNodeCount() - 1; } @@ -510,26 +424,21 @@ class ProfileSyncServiceAutofillTest void StartSyncService(const base::Closure& callback, bool will_fail_association, syncer::ModelType type) { - SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); + SigninManagerBase* signin = profile_sync_service_bundle_.signin_manager(); signin->SetAuthenticatedAccountInfo("12345", "test_user@gmail.com"); - sync_service_ = TestProfileSyncService::BuildAutoStartAsyncInit(profile_, - callback); - sync_client_->SetSyncService(sync_service_); - - SyncApiComponentFactoryMock* components = - sync_service_->GetSyncApiComponentFactoryMock(); + sync_service_ = CreateSyncService(std::move(sync_client_owned_), callback); - EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _)). - WillOnce(ReturnNewDataTypeManagerWithDebugListener( - syncer::MakeWeakHandle(debug_ptr_factory_.GetWeakPtr()))); + EXPECT_CALL(*profile_sync_service_bundle_.component_factory(), + CreateDataTypeManager(_, _, _, _, _)) + .WillOnce(ReturnNewDataTypeManagerWithDebugListener( + syncer::MakeWeakHandle(debug_ptr_factory_.GetWeakPtr()))); EXPECT_CALL(*personal_data_manager_, IsDataLoaded()). WillRepeatedly(Return(true)); // We need tokens to get the tests going - ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) - ->UpdateCredentials(signin->GetAuthenticatedAccountId(), - "oauth2_login_token"); + profile_sync_service_bundle_.auth_service()->UpdateCredentials( + signin->GetAuthenticatedAccountId(), "oauth2_login_token"); sync_service_->RegisterDataTypeController(CreateDataTypeController(type)); sync_service_->Initialize(); @@ -554,7 +463,7 @@ class ProfileSyncServiceAutofillTest base::UTF16ToUTF8(entry.key().name()), base::UTF16ToUTF8(entry.key().value())); syncer::WriteNode::InitUniqueByCreationResult result = - node.InitUniqueByCreation(syncer::AUTOFILL, tag); + node.InitUniqueByCreation(AUTOFILL, tag); if (result != syncer::WriteNode::INIT_SUCCESS) return false; @@ -569,7 +478,7 @@ class ProfileSyncServiceAutofillTest syncer::WriteNode node(&trans); std::string tag = profile.guid(); syncer::WriteNode::InitUniqueByCreationResult result = - node.InitUniqueByCreation(syncer::AUTOFILL_PROFILE, tag); + node.InitUniqueByCreation(AUTOFILL_PROFILE, tag); if (result != syncer::WriteNode::INIT_SUCCESS) return false; @@ -583,7 +492,7 @@ class ProfileSyncServiceAutofillTest std::vector* profiles) { syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); syncer::ReadNode autofill_root(&trans); - if (autofill_root.InitTypeRoot(syncer::AUTOFILL) != BaseNode::INIT_OK) { + if (autofill_root.InitTypeRoot(AUTOFILL) != BaseNode::INIT_OK) { return false; } @@ -598,7 +507,7 @@ class ProfileSyncServiceAutofillTest if (autofill.has_value()) { AutofillKey key(base::UTF8ToUTF16(autofill.name()), base::UTF8ToUTF16(autofill.value())); - std::vector timestamps; + std::vector