| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/sync/driver/shared_change_processor.h" | 5 #include "components/sync/driver/shared_change_processor.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "components/sync/core/attachments/attachment_service_impl.h" | 23 #include "components/sync/core/attachments/attachment_service_impl.h" |
| 24 #include "components/sync/core/test/test_user_share.h" | 24 #include "components/sync/core/test/test_user_share.h" |
| 25 #include "components/sync/device_info/local_device_info_provider.h" | 25 #include "components/sync/device_info/local_device_info_provider.h" |
| 26 #include "components/sync/driver/fake_sync_client.h" | 26 #include "components/sync/driver/fake_sync_client.h" |
| 27 #include "components/sync/driver/generic_change_processor.h" | 27 #include "components/sync/driver/generic_change_processor.h" |
| 28 #include "components/sync/driver/generic_change_processor_factory.h" | 28 #include "components/sync/driver/generic_change_processor_factory.h" |
| 29 #include "components/sync/driver/sync_api_component_factory.h" | 29 #include "components/sync/driver/sync_api_component_factory.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 32 |
| 33 namespace sync_driver { | 33 namespace syncer { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 using ::testing::NiceMock; | 37 using ::testing::NiceMock; |
| 38 using ::testing::StrictMock; | 38 using ::testing::StrictMock; |
| 39 | 39 |
| 40 class TestSyncApiComponentFactory : public SyncApiComponentFactory { | 40 class TestSyncApiComponentFactory : public SyncApiComponentFactory { |
| 41 public: | 41 public: |
| 42 TestSyncApiComponentFactory() {} | 42 TestSyncApiComponentFactory() {} |
| 43 ~TestSyncApiComponentFactory() override {} | 43 ~TestSyncApiComponentFactory() override {} |
| 44 | 44 |
| 45 // SyncApiComponentFactory implementation. | 45 // SyncApiComponentFactory implementation. |
| 46 void RegisterDataTypes( | 46 void RegisterDataTypes( |
| 47 sync_driver::SyncService* sync_service, | 47 SyncService* sync_service, |
| 48 const RegisterDataTypesMethod& register_platform_types_method) override {} | 48 const RegisterDataTypesMethod& register_platform_types_method) override {} |
| 49 sync_driver::DataTypeManager* CreateDataTypeManager( | 49 DataTypeManager* CreateDataTypeManager( |
| 50 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 50 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, |
| 51 debug_info_listener, | 51 const DataTypeController::TypeMap* controllers, |
| 52 const sync_driver::DataTypeController::TypeMap* controllers, | 52 const DataTypeEncryptionHandler* encryption_handler, |
| 53 const sync_driver::DataTypeEncryptionHandler* encryption_handler, | 53 SyncBackendHost* backend, |
| 54 browser_sync::SyncBackendHost* backend, | 54 DataTypeManagerObserver* observer) override { |
| 55 sync_driver::DataTypeManagerObserver* observer) override { | |
| 56 return nullptr; | 55 return nullptr; |
| 57 } | 56 } |
| 58 browser_sync::SyncBackendHost* CreateSyncBackendHost( | 57 SyncBackendHost* CreateSyncBackendHost( |
| 59 const std::string& name, | 58 const std::string& name, |
| 60 invalidation::InvalidationService* invalidator, | 59 invalidation::InvalidationService* invalidator, |
| 61 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, | 60 const base::WeakPtr<SyncPrefs>& sync_prefs, |
| 62 const base::FilePath& sync_folder) override { | 61 const base::FilePath& sync_folder) override { |
| 63 return nullptr; | 62 return nullptr; |
| 64 } | 63 } |
| 65 std::unique_ptr<sync_driver::LocalDeviceInfoProvider> | 64 std::unique_ptr<LocalDeviceInfoProvider> CreateLocalDeviceInfoProvider() |
| 66 CreateLocalDeviceInfoProvider() override { | 65 override { |
| 67 return nullptr; | 66 return nullptr; |
| 68 } | 67 } |
| 69 SyncApiComponentFactory::SyncComponents CreateBookmarkSyncComponents( | 68 SyncApiComponentFactory::SyncComponents CreateBookmarkSyncComponents( |
| 70 sync_driver::SyncService* sync_service, | 69 SyncService* sync_service, |
| 71 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler) override { | 70 std::unique_ptr<DataTypeErrorHandler> error_handler) override { |
| 72 return SyncApiComponentFactory::SyncComponents(nullptr, nullptr); | 71 return SyncApiComponentFactory::SyncComponents(nullptr, nullptr); |
| 73 } | 72 } |
| 74 std::unique_ptr<syncer::AttachmentService> CreateAttachmentService( | 73 std::unique_ptr<AttachmentService> CreateAttachmentService( |
| 75 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store, | 74 std::unique_ptr<AttachmentStoreForSync> attachment_store, |
| 76 const syncer::UserShare& user_share, | 75 const UserShare& user_share, |
| 77 const std::string& store_birthday, | 76 const std::string& store_birthday, |
| 78 syncer::ModelType model_type, | 77 ModelType model_type, |
| 79 syncer::AttachmentService::Delegate* delegate) override { | 78 AttachmentService::Delegate* delegate) override { |
| 80 return syncer::AttachmentServiceImpl::CreateForTest(); | 79 return AttachmentServiceImpl::CreateForTest(); |
| 81 } | 80 } |
| 82 }; | 81 }; |
| 83 | 82 |
| 84 class SyncSharedChangeProcessorTest : public testing::Test, | 83 class SyncSharedChangeProcessorTest : public testing::Test, |
| 85 public FakeSyncClient { | 84 public FakeSyncClient { |
| 86 public: | 85 public: |
| 87 SyncSharedChangeProcessorTest() | 86 SyncSharedChangeProcessorTest() |
| 88 : FakeSyncClient(&factory_), | 87 : FakeSyncClient(&factory_), |
| 89 backend_thread_("dbthread"), | 88 backend_thread_("dbthread"), |
| 90 did_connect_(false), | 89 did_connect_(false), |
| 91 has_attachment_service_(false) {} | 90 has_attachment_service_(false) {} |
| 92 | 91 |
| 93 ~SyncSharedChangeProcessorTest() override { | 92 ~SyncSharedChangeProcessorTest() override { |
| 94 EXPECT_FALSE(db_syncable_service_.get()); | 93 EXPECT_FALSE(db_syncable_service_.get()); |
| 95 } | 94 } |
| 96 | 95 |
| 97 // FakeSyncClient override. | 96 // FakeSyncClient override. |
| 98 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( | 97 base::WeakPtr<SyncableService> GetSyncableServiceForType( |
| 99 syncer::ModelType type) override { | 98 ModelType type) override { |
| 100 return db_syncable_service_->AsWeakPtr(); | 99 return db_syncable_service_->AsWeakPtr(); |
| 101 } | 100 } |
| 102 | 101 |
| 103 protected: | 102 protected: |
| 104 void SetUp() override { | 103 void SetUp() override { |
| 105 test_user_share_.SetUp(); | 104 test_user_share_.SetUp(); |
| 106 shared_change_processor_ = new SharedChangeProcessor(syncer::AUTOFILL); | 105 shared_change_processor_ = new SharedChangeProcessor(AUTOFILL); |
| 107 ASSERT_TRUE(backend_thread_.Start()); | 106 ASSERT_TRUE(backend_thread_.Start()); |
| 108 ASSERT_TRUE(backend_thread_.task_runner()->PostTask( | 107 ASSERT_TRUE(backend_thread_.task_runner()->PostTask( |
| 109 FROM_HERE, | 108 FROM_HERE, |
| 110 base::Bind(&SyncSharedChangeProcessorTest::SetUpDBSyncableService, | 109 base::Bind(&SyncSharedChangeProcessorTest::SetUpDBSyncableService, |
| 111 base::Unretained(this)))); | 110 base::Unretained(this)))); |
| 112 } | 111 } |
| 113 | 112 |
| 114 void TearDown() override { | 113 void TearDown() override { |
| 115 EXPECT_TRUE(backend_thread_.task_runner()->PostTask( | 114 EXPECT_TRUE(backend_thread_.task_runner()->PostTask( |
| 116 FROM_HERE, | 115 FROM_HERE, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 base::Unretained(this), base::Unretained(&event)))); | 157 base::Unretained(this), base::Unretained(&event)))); |
| 159 event.Wait(); | 158 event.Wait(); |
| 160 return has_attachment_service_; | 159 return has_attachment_service_; |
| 161 } | 160 } |
| 162 | 161 |
| 163 private: | 162 private: |
| 164 // Used by SetUp(). | 163 // Used by SetUp(). |
| 165 void SetUpDBSyncableService() { | 164 void SetUpDBSyncableService() { |
| 166 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); | 165 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); |
| 167 DCHECK(!db_syncable_service_.get()); | 166 DCHECK(!db_syncable_service_.get()); |
| 168 db_syncable_service_.reset(new syncer::FakeSyncableService()); | 167 db_syncable_service_.reset(new FakeSyncableService()); |
| 169 } | 168 } |
| 170 | 169 |
| 171 // Used by TearDown(). | 170 // Used by TearDown(). |
| 172 void TearDownDBSyncableService() { | 171 void TearDownDBSyncableService() { |
| 173 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); | 172 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); |
| 174 DCHECK(db_syncable_service_.get()); | 173 DCHECK(db_syncable_service_.get()); |
| 175 db_syncable_service_.reset(); | 174 db_syncable_service_.reset(); |
| 176 } | 175 } |
| 177 | 176 |
| 178 void SetAttachmentStoreOnDBThread() { | 177 void SetAttachmentStoreOnDBThread() { |
| 179 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); | 178 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); |
| 180 DCHECK(db_syncable_service_.get()); | 179 DCHECK(db_syncable_service_.get()); |
| 181 db_syncable_service_->set_attachment_store( | 180 db_syncable_service_->set_attachment_store( |
| 182 syncer::AttachmentStore::CreateInMemoryStore()); | 181 AttachmentStore::CreateInMemoryStore()); |
| 183 } | 182 } |
| 184 | 183 |
| 185 // Used by Connect(). The SharedChangeProcessor is passed in | 184 // Used by Connect(). The SharedChangeProcessor is passed in |
| 186 // because we modify |shared_change_processor_| on the main thread | 185 // because we modify |shared_change_processor_| on the main thread |
| 187 // (in TearDown()). | 186 // (in TearDown()). |
| 188 void ConnectOnDBThread( | 187 void ConnectOnDBThread( |
| 189 const scoped_refptr<SharedChangeProcessor>& shared_change_processor) { | 188 const scoped_refptr<SharedChangeProcessor>& shared_change_processor) { |
| 190 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); | 189 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); |
| 191 EXPECT_TRUE(shared_change_processor->Connect( | 190 EXPECT_TRUE(shared_change_processor->Connect( |
| 192 this, &processor_factory_, test_user_share_.user_share(), | 191 this, &processor_factory_, test_user_share_.user_share(), |
| 193 base::MakeUnique<syncer::DataTypeErrorHandlerMock>(), | 192 base::MakeUnique<DataTypeErrorHandlerMock>(), |
| 194 base::WeakPtr<syncer::SyncMergeResult>())); | 193 base::WeakPtr<SyncMergeResult>())); |
| 195 did_connect_ = true; | 194 did_connect_ = true; |
| 196 } | 195 } |
| 197 | 196 |
| 198 void CheckAttachmentServiceOnDBThread(base::WaitableEvent* event) { | 197 void CheckAttachmentServiceOnDBThread(base::WaitableEvent* event) { |
| 199 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); | 198 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); |
| 200 DCHECK(db_syncable_service_.get()); | 199 DCHECK(db_syncable_service_.get()); |
| 201 has_attachment_service_ = !!db_syncable_service_->attachment_service(); | 200 has_attachment_service_ = !!db_syncable_service_->attachment_service(); |
| 202 event->Signal(); | 201 event->Signal(); |
| 203 } | 202 } |
| 204 | 203 |
| 205 base::MessageLoop frontend_loop_; | 204 base::MessageLoop frontend_loop_; |
| 206 base::Thread backend_thread_; | 205 base::Thread backend_thread_; |
| 207 syncer::TestUserShare test_user_share_; | 206 TestUserShare test_user_share_; |
| 208 TestSyncApiComponentFactory factory_; | 207 TestSyncApiComponentFactory factory_; |
| 209 | 208 |
| 210 scoped_refptr<SharedChangeProcessor> shared_change_processor_; | 209 scoped_refptr<SharedChangeProcessor> shared_change_processor_; |
| 211 | 210 |
| 212 GenericChangeProcessorFactory processor_factory_; | 211 GenericChangeProcessorFactory processor_factory_; |
| 213 bool did_connect_; | 212 bool did_connect_; |
| 214 bool has_attachment_service_; | 213 bool has_attachment_service_; |
| 215 | 214 |
| 216 // Used only on DB thread. | 215 // Used only on DB thread. |
| 217 std::unique_ptr<syncer::FakeSyncableService> db_syncable_service_; | 216 std::unique_ptr<FakeSyncableService> db_syncable_service_; |
| 218 }; | 217 }; |
| 219 | 218 |
| 220 // Simply connect the shared change processor. It should succeed, and | 219 // Simply connect the shared change processor. It should succeed, and |
| 221 // nothing further should happen. | 220 // nothing further should happen. |
| 222 TEST_F(SyncSharedChangeProcessorTest, Basic) { | 221 TEST_F(SyncSharedChangeProcessorTest, Basic) { |
| 223 Connect(); | 222 Connect(); |
| 224 } | 223 } |
| 225 | 224 |
| 226 // Connect the shared change processor to a syncable service with | 225 // Connect the shared change processor to a syncable service with |
| 227 // AttachmentStore. Verify that shared change processor implementation | 226 // AttachmentStore. Verify that shared change processor implementation |
| 228 // creates AttachmentService and passes it back to the syncable service. | 227 // creates AttachmentService and passes it back to the syncable service. |
| 229 TEST_F(SyncSharedChangeProcessorTest, ConnectWithAttachmentStore) { | 228 TEST_F(SyncSharedChangeProcessorTest, ConnectWithAttachmentStore) { |
| 230 SetAttachmentStore(); | 229 SetAttachmentStore(); |
| 231 Connect(); | 230 Connect(); |
| 232 EXPECT_TRUE(HasAttachmentService()); | 231 EXPECT_TRUE(HasAttachmentService()); |
| 233 } | 232 } |
| 234 | 233 |
| 235 } // namespace | 234 } // namespace |
| 236 | 235 |
| 237 } // namespace sync_driver | 236 } // namespace syncer |
| OLD | NEW |