| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "components/sync_driver/data_type_error_handler_mock.h" | 16 #include "components/sync_driver/data_type_error_handler_mock.h" |
| 17 #include "components/sync_driver/fake_sync_client.h" |
| 17 #include "components/sync_driver/generic_change_processor.h" | 18 #include "components/sync_driver/generic_change_processor.h" |
| 18 #include "components/sync_driver/generic_change_processor_factory.h" | 19 #include "components/sync_driver/generic_change_processor_factory.h" |
| 20 #include "components/sync_driver/local_device_info_provider.h" |
| 19 #include "components/sync_driver/sync_api_component_factory.h" | 21 #include "components/sync_driver/sync_api_component_factory.h" |
| 20 #include "sync/api/attachments/attachment_id.h" | 22 #include "sync/api/attachments/attachment_id.h" |
| 21 #include "sync/api/attachments/attachment_store.h" | 23 #include "sync/api/attachments/attachment_store.h" |
| 22 #include "sync/api/fake_syncable_service.h" | 24 #include "sync/api/fake_syncable_service.h" |
| 23 #include "sync/internal_api/public/attachments/attachment_service_impl.h" | 25 #include "sync/internal_api/public/attachments/attachment_service_impl.h" |
| 24 #include "sync/internal_api/public/base/model_type.h" | 26 #include "sync/internal_api/public/base/model_type.h" |
| 25 #include "sync/internal_api/public/test/test_user_share.h" | 27 #include "sync/internal_api/public/test/test_user_share.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 30 |
| 29 namespace sync_driver { | 31 namespace sync_driver { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 using ::testing::NiceMock; | 35 using ::testing::NiceMock; |
| 34 using ::testing::StrictMock; | 36 using ::testing::StrictMock; |
| 35 | 37 |
| 38 class TestSyncApiComponentFactory : public SyncApiComponentFactory { |
| 39 public: |
| 40 TestSyncApiComponentFactory() {} |
| 41 ~TestSyncApiComponentFactory() override {} |
| 42 |
| 43 // SyncApiComponentFactory implementation. |
| 44 void Initialize(sync_driver::SyncService* pss) override {} |
| 45 void RegisterDataTypes(sync_driver::SyncService* pss) override {} |
| 46 sync_driver::DataTypeManager* CreateDataTypeManager( |
| 47 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 48 debug_info_listener, |
| 49 const sync_driver::DataTypeController::TypeMap* controllers, |
| 50 const sync_driver::DataTypeEncryptionHandler* encryption_handler, |
| 51 browser_sync::SyncBackendHost* backend, |
| 52 sync_driver::DataTypeManagerObserver* observer) override { |
| 53 return nullptr; |
| 54 } |
| 55 browser_sync::SyncBackendHost* CreateSyncBackendHost( |
| 56 const std::string& name, |
| 57 invalidation::InvalidationService* invalidator, |
| 58 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, |
| 59 const base::FilePath& sync_folder) override { |
| 60 return nullptr; |
| 61 } |
| 62 scoped_ptr<sync_driver::LocalDeviceInfoProvider> |
| 63 CreateLocalDeviceInfoProvider() override { |
| 64 return nullptr; |
| 65 } |
| 66 SyncApiComponentFactory::SyncComponents CreateBookmarkSyncComponents( |
| 67 sync_driver::SyncService* sync_service, |
| 68 sync_driver::DataTypeErrorHandler* error_handler) override { |
| 69 return SyncApiComponentFactory::SyncComponents(nullptr, nullptr); |
| 70 } |
| 71 SyncApiComponentFactory::SyncComponents CreateTypedUrlSyncComponents( |
| 72 sync_driver::SyncService* sync_service, |
| 73 history::HistoryBackend* history_backend, |
| 74 sync_driver::DataTypeErrorHandler* error_handler) override { |
| 75 return SyncApiComponentFactory::SyncComponents(nullptr, nullptr); |
| 76 } |
| 77 scoped_ptr<syncer::AttachmentService> CreateAttachmentService( |
| 78 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store, |
| 79 const syncer::UserShare& user_share, |
| 80 const std::string& store_birthday, |
| 81 syncer::ModelType model_type, |
| 82 syncer::AttachmentService::Delegate* delegate) override { |
| 83 return syncer::AttachmentServiceImpl::CreateForTest(); |
| 84 } |
| 85 }; |
| 86 |
| 36 class SyncSharedChangeProcessorTest : | 87 class SyncSharedChangeProcessorTest : |
| 37 public testing::Test, | 88 public testing::Test, |
| 38 public SyncApiComponentFactory { | 89 public FakeSyncClient { |
| 39 public: | 90 public: |
| 40 SyncSharedChangeProcessorTest() | 91 SyncSharedChangeProcessorTest() |
| 41 : backend_thread_("dbthread"), | 92 : FakeSyncClient(&factory_), |
| 93 backend_thread_("dbthread"), |
| 42 did_connect_(false), | 94 did_connect_(false), |
| 43 has_attachment_service_(false) {} | 95 has_attachment_service_(false) {} |
| 44 | 96 |
| 45 ~SyncSharedChangeProcessorTest() override { | 97 ~SyncSharedChangeProcessorTest() override { |
| 46 EXPECT_FALSE(db_syncable_service_.get()); | 98 EXPECT_FALSE(db_syncable_service_.get()); |
| 47 } | 99 } |
| 48 | 100 |
| 101 // FakeSyncClient override. |
| 49 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( | 102 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( |
| 50 syncer::ModelType type) override { | 103 syncer::ModelType type) override { |
| 51 return db_syncable_service_->AsWeakPtr(); | 104 return db_syncable_service_->AsWeakPtr(); |
| 52 } | 105 } |
| 53 | 106 |
| 54 scoped_ptr<syncer::AttachmentService> CreateAttachmentService( | |
| 55 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store, | |
| 56 const syncer::UserShare& user_share, | |
| 57 const std::string& store_birthday, | |
| 58 syncer::ModelType model_type, | |
| 59 syncer::AttachmentService::Delegate* delegate) override { | |
| 60 return syncer::AttachmentServiceImpl::CreateForTest(); | |
| 61 } | |
| 62 | |
| 63 protected: | 107 protected: |
| 64 void SetUp() override { | 108 void SetUp() override { |
| 65 test_user_share_.SetUp(); | 109 test_user_share_.SetUp(); |
| 66 shared_change_processor_ = new SharedChangeProcessor(); | 110 shared_change_processor_ = new SharedChangeProcessor(); |
| 67 ASSERT_TRUE(backend_thread_.Start()); | 111 ASSERT_TRUE(backend_thread_.Start()); |
| 68 ASSERT_TRUE(backend_thread_.task_runner()->PostTask( | 112 ASSERT_TRUE(backend_thread_.task_runner()->PostTask( |
| 69 FROM_HERE, | 113 FROM_HERE, |
| 70 base::Bind(&SyncSharedChangeProcessorTest::SetUpDBSyncableService, | 114 base::Bind(&SyncSharedChangeProcessorTest::SetUpDBSyncableService, |
| 71 base::Unretained(this)))); | 115 base::Unretained(this)))); |
| 72 } | 116 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 void CheckAttachmentServiceOnDBThread(base::WaitableEvent* event) { | 201 void CheckAttachmentServiceOnDBThread(base::WaitableEvent* event) { |
| 158 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); | 202 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); |
| 159 DCHECK(db_syncable_service_.get()); | 203 DCHECK(db_syncable_service_.get()); |
| 160 has_attachment_service_ = !!db_syncable_service_->attachment_service(); | 204 has_attachment_service_ = !!db_syncable_service_->attachment_service(); |
| 161 event->Signal(); | 205 event->Signal(); |
| 162 } | 206 } |
| 163 | 207 |
| 164 base::MessageLoop frontend_loop_; | 208 base::MessageLoop frontend_loop_; |
| 165 base::Thread backend_thread_; | 209 base::Thread backend_thread_; |
| 166 syncer::TestUserShare test_user_share_; | 210 syncer::TestUserShare test_user_share_; |
| 211 TestSyncApiComponentFactory factory_; |
| 167 | 212 |
| 168 scoped_refptr<SharedChangeProcessor> shared_change_processor_; | 213 scoped_refptr<SharedChangeProcessor> shared_change_processor_; |
| 169 StrictMock<DataTypeErrorHandlerMock> error_handler_; | 214 StrictMock<DataTypeErrorHandlerMock> error_handler_; |
| 170 | 215 |
| 171 GenericChangeProcessorFactory processor_factory_; | 216 GenericChangeProcessorFactory processor_factory_; |
| 172 bool did_connect_; | 217 bool did_connect_; |
| 173 bool has_attachment_service_; | 218 bool has_attachment_service_; |
| 174 | 219 |
| 175 // Used only on DB thread. | 220 // Used only on DB thread. |
| 176 scoped_ptr<syncer::FakeSyncableService> db_syncable_service_; | 221 scoped_ptr<syncer::FakeSyncableService> db_syncable_service_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 187 // creates AttachmentService and passes it back to the syncable service. | 232 // creates AttachmentService and passes it back to the syncable service. |
| 188 TEST_F(SyncSharedChangeProcessorTest, ConnectWithAttachmentStore) { | 233 TEST_F(SyncSharedChangeProcessorTest, ConnectWithAttachmentStore) { |
| 189 SetAttachmentStore(); | 234 SetAttachmentStore(); |
| 190 Connect(); | 235 Connect(); |
| 191 EXPECT_TRUE(HasAttachmentService()); | 236 EXPECT_TRUE(HasAttachmentService()); |
| 192 } | 237 } |
| 193 | 238 |
| 194 } // namespace | 239 } // namespace |
| 195 | 240 |
| 196 } // namespace sync_driver | 241 } // namespace sync_driver |
| OLD | NEW |