diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/sync/chrome_sync_client.cc | 11 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_typed_url_unittest.cc | 101 |
2 files changed, 50 insertions, 62 deletions
diff --git a/chrome/browser/sync/chrome_sync_client.cc b/chrome/browser/sync/chrome_sync_client.cc index b826216..9cf8938 100644 --- a/chrome/browser/sync/chrome_sync_client.cc +++ b/chrome/browser/sync/chrome_sync_client.cc @@ -214,9 +214,7 @@ void ChromeSyncClient::Initialize(sync_driver::SyncService* sync_service) { } sync_driver::SyncService* ChromeSyncClient::GetSyncService() { - // TODO(zea): bring back this DCHECK after Typed URLs are converted to - // SyncableService. - // DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK_CURRENTLY_ON(BrowserThread::UI); return sync_service_; } @@ -354,6 +352,13 @@ ChromeSyncClient::GetSyncableServiceForType(syncer::ModelType type) { return history ? history->AsWeakPtr() : base::WeakPtr<history::HistoryService>(); } + case syncer::TYPED_URLS: { + history::HistoryService* history = HistoryServiceFactory::GetForProfile( + profile_, ServiceAccessType::EXPLICIT_ACCESS); + if (!history) + return base::WeakPtr<history::TypedUrlSyncableService>(); + return history->GetTypedUrlSyncableService()->AsWeakPtr(); + } #if defined(ENABLE_SPELLCHECK) case syncer::DICTIONARY: return SpellcheckServiceFactory::GetForContext(profile_)-> diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc index 540595a..c21a42a 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -42,9 +42,7 @@ #include "components/history/core/browser/history_db_task.h" #include "components/history/core/browser/history_service.h" #include "components/history/core/browser/history_types.h" -#include "components/history/core/browser/typed_url_change_processor.h" #include "components/history/core/browser/typed_url_data_type_controller.h" -#include "components/history/core/browser/typed_url_model_associator.h" #include "components/invalidation/impl/profile_invalidation_provider.h" #include "components/invalidation/public/invalidation_service.h" #include "components/keyed_service/core/refcounted_keyed_service.h" @@ -66,11 +64,10 @@ using base::Thread; using base::Time; -using browser_sync::TypedUrlChangeProcessor; using browser_sync::TypedUrlDataTypeController; -using browser_sync::TypedUrlModelAssociator; using history::HistoryBackend; using history::HistoryBackendNotifier; +using history::TypedUrlSyncableService; using history::URLID; using history::URLRow; using syncer::syncable::WriteTransaction; @@ -136,6 +133,8 @@ class HistoryServiceMock : public history::HistoryService { MOCK_METHOD0(Shutdown, void()); + MOCK_CONST_METHOD0(GetTypedUrlSyncableService, TypedUrlSyncableService*()); + void ShutdownBaseService() { history::HistoryService::Shutdown(); } void set_task_runner( @@ -170,13 +169,21 @@ scoped_ptr<KeyedService> BuildHistoryService(content::BrowserContext* profile) { return scoped_ptr<KeyedService>(new HistoryServiceMock); } -class TestTypedUrlModelAssociator : public TypedUrlModelAssociator { +class TestTypedUrlSyncableService : public TypedUrlSyncableService { + // TODO(gangwu): remove TestProfileSyncService or even remove whole test + // suite, and make sure typed_url_syncable_service_unittest.cc and the various + // typed url integration tests. public: - TestTypedUrlModelAssociator( - ProfileSyncService* sync_service, - history::HistoryBackend* history_backend, - sync_driver::DataTypeErrorHandler* error_handler) : - TypedUrlModelAssociator(sync_service, history_backend, error_handler) {} + TestTypedUrlSyncableService(history::HistoryBackend* history_backend) + : TypedUrlSyncableService(history_backend) {} + + static void WriteToSyncNode(const history::URLRow& url, + const history::VisitVector& visits, + syncer::WriteNode* node) { + sync_pb::TypedUrlSpecifics typed_url; + WriteToTypedUrlSpecifics(url, visits, &typed_url); + node->SetTypedUrlSpecifics(typed_url); + } protected: // Don't clear error stats - that way we can verify their values in our @@ -189,24 +196,9 @@ ACTION_P2(ShutdownHistoryService, thread, service) { delete thread; } -ACTION_P6(MakeTypedUrlSyncComponents, - profile, - service, - hb, - dtc, - error_handler, - model_associator) { - *model_associator = - new TestTypedUrlModelAssociator(service, hb, error_handler); - - const scoped_refptr<base::SingleThreadTaskRunner> ui_thread = - content::BrowserThread::GetMessageLoopProxyForThread( - content::BrowserThread::UI); - TypedUrlChangeProcessor* change_processor = - new TypedUrlChangeProcessor(*model_associator, hb, dtc, ui_thread); - - return sync_driver::SyncApiComponentFactory::SyncComponents(*model_associator, - change_processor); +ACTION_P2(ReturnTypedUrlSyncableService, hb, syncable_service) { + syncable_service->reset(new TestTypedUrlSyncableService(hb)); + return syncable_service->get(); } class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { @@ -220,7 +212,7 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { syncer::WriteNode::InitUniqueByCreationResult result = node.InitUniqueByCreation(syncer::TYPED_URLS, tag); ASSERT_EQ(syncer::WriteNode::INIT_SUCCESS, result); - TypedUrlModelAssociator::WriteToSyncNode(url, visits, &node); + TestTypedUrlSyncableService::WriteToSyncNode(url, visits, &node); } protected: @@ -263,8 +255,7 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { AbstractProfileSyncServiceTest::TearDown(); } - TypedUrlModelAssociator* StartSyncService(const base::Closure& callback) { - TypedUrlModelAssociator* model_associator = NULL; + TypedUrlSyncableService* StartSyncService(const base::Closure& callback) { if (!sync_service_) { std::string account_id = AccountTrackerServiceFactory::GetForProfile(profile_) @@ -273,23 +264,19 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { signin->SetAuthenticatedAccountInfo("gaia_id", "test"); sync_service_ = TestProfileSyncService::BuildAutoStartAsyncInit(profile_, callback); - TypedUrlDataTypeController* data_type_controller = - new TypedUrlDataTypeController(base::ThreadTaskRunnerHandle::Get(), - base::Bind(&base::DoNothing), - sync_service_->GetSyncClient(), - prefs::kSavingBrowserHistoryDisabled); + data_type_controller = new TypedUrlDataTypeController( + base::ThreadTaskRunnerHandle::Get(), base::Bind(&base::DoNothing), + sync_service_->GetSyncClient(), prefs::kSavingBrowserHistoryDisabled); SyncApiComponentFactoryMock* components = sync_service_->GetSyncApiComponentFactoryMock(); - EXPECT_CALL(*components, CreateTypedUrlSyncComponents(_, _, _)). - WillOnce(MakeTypedUrlSyncComponents(profile_, - sync_service_, - history_backend_.get(), - data_type_controller, - &error_handler_, - &model_associator)); + EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _)). WillOnce(ReturnNewDataTypeManager()); + EXPECT_CALL(*history_service_, GetTypedUrlSyncableService()) + .WillOnce(ReturnTypedUrlSyncableService(history_backend_.get(), + &syncable_service_)); + ProfileOAuth2TokenService* oauth2_token_service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); oauth2_token_service->UpdateCredentials(account_id, "oauth2_login_token"); @@ -299,7 +286,7 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { sync_service_->Initialize(); base::MessageLoop::current()->Run(); } - return model_associator; + return syncable_service_.get(); } void GetTypedUrlsFromSyncDB(history::URLRows* urls) { @@ -416,6 +403,8 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { scoped_refptr<HistoryBackendMock> history_backend_; HistoryServiceMock* history_service_; sync_driver::DataTypeErrorHandlerMock error_handler_; + TypedUrlDataTypeController* data_type_controller; + scoped_ptr<TestTypedUrlSyncableService> syncable_service_; }; void AddTypedUrlEntries(ProfileSyncServiceTypedUrlTest* test, @@ -437,12 +426,12 @@ TEST_F(ProfileSyncServiceTypedUrlTest, EmptyNativeEmptySync) { WillOnce(Return(true)); SetIdleChangeProcessorExpectations(); CreateRootHelper create_root(this, syncer::TYPED_URLS); - TypedUrlModelAssociator* associator = + TypedUrlSyncableService* syncable_service = StartSyncService(create_root.callback()); history::URLRows sync_entries; GetTypedUrlsFromSyncDB(&sync_entries); EXPECT_EQ(0U, sync_entries.size()); - ASSERT_EQ(0, associator->GetErrorPercentage()); + ASSERT_EQ(0, syncable_service->GetErrorPercentage()); } TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeEmptySync) { @@ -457,13 +446,13 @@ TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeEmptySync) { WillRepeatedly(DoAll(SetArgumentPointee<2>(visits), Return(true))); SetIdleChangeProcessorExpectations(); CreateRootHelper create_root(this, syncer::TYPED_URLS); - TypedUrlModelAssociator* associator = + TypedUrlSyncableService* syncable_service = StartSyncService(create_root.callback()); history::URLRows sync_entries; GetTypedUrlsFromSyncDB(&sync_entries); ASSERT_EQ(1U, sync_entries.size()); EXPECT_TRUE(URLsEqual(entries[0], sync_entries[0])); - ASSERT_EQ(0, associator->GetErrorPercentage()); + ASSERT_EQ(0, syncable_service->GetErrorPercentage()); } TEST_F(ProfileSyncServiceTypedUrlTest, HasNativeErrorReadingVisits) { @@ -954,8 +943,8 @@ TEST_F(ProfileSyncServiceTypedUrlTest, FailWriteToHistoryBackend) { native_entries.push_back(native_entry); EXPECT_CALL((*history_backend_.get()), GetAllTypedURLs(_)). WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); - EXPECT_CALL((*history_backend_.get()), GetURL(_, _)). - WillOnce(DoAll(SetArgumentPointee<1>(native_entry), Return(true))); + EXPECT_CALL((*history_backend_.get()), GetURL(_, _)) + .WillOnce(DoAll(SetArgumentPointee<1>(native_entry), Return(false))); EXPECT_CALL((*history_backend_.get()), GetMostRecentVisitsForURL(_, _, _)). WillRepeatedly(DoAll(SetArgumentPointee<2>(native_visits), Return(true))); EXPECT_CALL((*history_backend_.get()), @@ -966,7 +955,7 @@ TEST_F(ProfileSyncServiceTypedUrlTest, FailWriteToHistoryBackend) { EXPECT_CALL((*history_backend_.get()), UpdateURL(_, _)). WillRepeatedly(Return(false)); - TypedUrlModelAssociator* associator = + TypedUrlSyncableService* syncable_service = StartSyncService(base::Bind(&AddTypedUrlEntries, this, sync_entries)); // Errors writing to the DB should be recorded, but should not cause an // unrecoverable error. @@ -975,8 +964,8 @@ TEST_F(ProfileSyncServiceTypedUrlTest, FailWriteToHistoryBackend) { syncer::TYPED_URLS)); // Some calls should have succeeded, so the error percentage should be // somewhere > 0 and < 100. - ASSERT_NE(0, associator->GetErrorPercentage()); - ASSERT_NE(100, associator->GetErrorPercentage()); + ASSERT_NE(0, syncable_service->GetErrorPercentage()); + ASSERT_NE(100, syncable_service->GetErrorPercentage()); } TEST_F(ProfileSyncServiceTypedUrlTest, FailToGetTypedURLs) { @@ -995,12 +984,6 @@ TEST_F(ProfileSyncServiceTypedUrlTest, FailToGetTypedURLs) { history::URLRows sync_entries; sync_entries.push_back(sync_entry); - EXPECT_CALL(error_handler_, CreateAndUploadError(_, _, _)). - WillOnce(Return(syncer::SyncError( - FROM_HERE, - syncer::SyncError::DATATYPE_ERROR, - "Unit test", - syncer::TYPED_URLS))); StartSyncService(base::Bind(&AddTypedUrlEntries, this, sync_entries)); // Errors getting typed URLs will cause an unrecoverable error (since we can // do *nothing* in that case). |