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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "components/sync/api/attachments/attachment_id.h" | 18 #include "components/sync/api/attachments/attachment_id.h" |
19 #include "components/sync/api/attachments/attachment_store.h" | 19 #include "components/sync/api/attachments/attachment_store.h" |
| 20 #include "components/sync/api/data_type_error_handler_mock.h" |
20 #include "components/sync/api/fake_syncable_service.h" | 21 #include "components/sync/api/fake_syncable_service.h" |
21 #include "components/sync/base/model_type.h" | 22 #include "components/sync/base/model_type.h" |
22 #include "components/sync/core/attachments/attachment_service_impl.h" | 23 #include "components/sync/core/attachments/attachment_service_impl.h" |
23 #include "components/sync/core/test/data_type_error_handler_mock.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 sync_driver { |
(...skipping 27 matching lines...) Expand all Loading... |
61 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, | 61 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, |
62 const base::FilePath& sync_folder) override { | 62 const base::FilePath& sync_folder) override { |
63 return nullptr; | 63 return nullptr; |
64 } | 64 } |
65 std::unique_ptr<sync_driver::LocalDeviceInfoProvider> | 65 std::unique_ptr<sync_driver::LocalDeviceInfoProvider> |
66 CreateLocalDeviceInfoProvider() override { | 66 CreateLocalDeviceInfoProvider() override { |
67 return nullptr; | 67 return nullptr; |
68 } | 68 } |
69 SyncApiComponentFactory::SyncComponents CreateBookmarkSyncComponents( | 69 SyncApiComponentFactory::SyncComponents CreateBookmarkSyncComponents( |
70 sync_driver::SyncService* sync_service, | 70 sync_driver::SyncService* sync_service, |
71 syncer::DataTypeErrorHandler* error_handler) override { | 71 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler) override { |
72 return SyncApiComponentFactory::SyncComponents(nullptr, nullptr); | 72 return SyncApiComponentFactory::SyncComponents(nullptr, nullptr); |
73 } | 73 } |
74 std::unique_ptr<syncer::AttachmentService> CreateAttachmentService( | 74 std::unique_ptr<syncer::AttachmentService> CreateAttachmentService( |
75 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store, | 75 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store, |
76 const syncer::UserShare& user_share, | 76 const syncer::UserShare& user_share, |
77 const std::string& store_birthday, | 77 const std::string& store_birthday, |
78 syncer::ModelType model_type, | 78 syncer::ModelType model_type, |
79 syncer::AttachmentService::Delegate* delegate) override { | 79 syncer::AttachmentService::Delegate* delegate) override { |
80 return syncer::AttachmentServiceImpl::CreateForTest(); | 80 return syncer::AttachmentServiceImpl::CreateForTest(); |
81 } | 81 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 183 } |
184 | 184 |
185 // Used by Connect(). The SharedChangeProcessor is passed in | 185 // Used by Connect(). The SharedChangeProcessor is passed in |
186 // because we modify |shared_change_processor_| on the main thread | 186 // because we modify |shared_change_processor_| on the main thread |
187 // (in TearDown()). | 187 // (in TearDown()). |
188 void ConnectOnDBThread( | 188 void ConnectOnDBThread( |
189 const scoped_refptr<SharedChangeProcessor>& shared_change_processor) { | 189 const scoped_refptr<SharedChangeProcessor>& shared_change_processor) { |
190 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); | 190 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); |
191 EXPECT_TRUE(shared_change_processor->Connect( | 191 EXPECT_TRUE(shared_change_processor->Connect( |
192 this, &processor_factory_, test_user_share_.user_share(), | 192 this, &processor_factory_, test_user_share_.user_share(), |
193 &error_handler_, base::WeakPtr<syncer::SyncMergeResult>())); | 193 base::MakeUnique<syncer::DataTypeErrorHandlerMock>(), |
| 194 base::WeakPtr<syncer::SyncMergeResult>())); |
194 did_connect_ = true; | 195 did_connect_ = true; |
195 } | 196 } |
196 | 197 |
197 void CheckAttachmentServiceOnDBThread(base::WaitableEvent* event) { | 198 void CheckAttachmentServiceOnDBThread(base::WaitableEvent* event) { |
198 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); | 199 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); |
199 DCHECK(db_syncable_service_.get()); | 200 DCHECK(db_syncable_service_.get()); |
200 has_attachment_service_ = !!db_syncable_service_->attachment_service(); | 201 has_attachment_service_ = !!db_syncable_service_->attachment_service(); |
201 event->Signal(); | 202 event->Signal(); |
202 } | 203 } |
203 | 204 |
204 base::MessageLoop frontend_loop_; | 205 base::MessageLoop frontend_loop_; |
205 base::Thread backend_thread_; | 206 base::Thread backend_thread_; |
206 syncer::TestUserShare test_user_share_; | 207 syncer::TestUserShare test_user_share_; |
207 TestSyncApiComponentFactory factory_; | 208 TestSyncApiComponentFactory factory_; |
208 | 209 |
209 scoped_refptr<SharedChangeProcessor> shared_change_processor_; | 210 scoped_refptr<SharedChangeProcessor> shared_change_processor_; |
210 StrictMock<syncer::DataTypeErrorHandlerMock> error_handler_; | |
211 | 211 |
212 GenericChangeProcessorFactory processor_factory_; | 212 GenericChangeProcessorFactory processor_factory_; |
213 bool did_connect_; | 213 bool did_connect_; |
214 bool has_attachment_service_; | 214 bool has_attachment_service_; |
215 | 215 |
216 // Used only on DB thread. | 216 // Used only on DB thread. |
217 std::unique_ptr<syncer::FakeSyncableService> db_syncable_service_; | 217 std::unique_ptr<syncer::FakeSyncableService> db_syncable_service_; |
218 }; | 218 }; |
219 | 219 |
220 // Simply connect the shared change processor. It should succeed, and | 220 // Simply connect the shared change processor. It should succeed, and |
221 // nothing further should happen. | 221 // nothing further should happen. |
222 TEST_F(SyncSharedChangeProcessorTest, Basic) { | 222 TEST_F(SyncSharedChangeProcessorTest, Basic) { |
223 Connect(); | 223 Connect(); |
224 } | 224 } |
225 | 225 |
226 // Connect the shared change processor to a syncable service with | 226 // Connect the shared change processor to a syncable service with |
227 // AttachmentStore. Verify that shared change processor implementation | 227 // AttachmentStore. Verify that shared change processor implementation |
228 // creates AttachmentService and passes it back to the syncable service. | 228 // creates AttachmentService and passes it back to the syncable service. |
229 TEST_F(SyncSharedChangeProcessorTest, ConnectWithAttachmentStore) { | 229 TEST_F(SyncSharedChangeProcessorTest, ConnectWithAttachmentStore) { |
230 SetAttachmentStore(); | 230 SetAttachmentStore(); |
231 Connect(); | 231 Connect(); |
232 EXPECT_TRUE(HasAttachmentService()); | 232 EXPECT_TRUE(HasAttachmentService()); |
233 } | 233 } |
234 | 234 |
235 } // namespace | 235 } // namespace |
236 | 236 |
237 } // namespace sync_driver | 237 } // namespace sync_driver |
OLD | NEW |