Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: components/sync/driver/shared_change_processor_unittest.cc

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 syncer { 33 namespace sync_driver {
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 SyncService* sync_service, 47 sync_driver::SyncService* sync_service,
48 const RegisterDataTypesMethod& register_platform_types_method) override {} 48 const RegisterDataTypesMethod& register_platform_types_method) override {}
49 DataTypeManager* CreateDataTypeManager( 49 sync_driver::DataTypeManager* CreateDataTypeManager(
50 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, 50 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
51 const DataTypeController::TypeMap* controllers, 51 debug_info_listener,
52 const DataTypeEncryptionHandler* encryption_handler, 52 const sync_driver::DataTypeController::TypeMap* controllers,
53 SyncBackendHost* backend, 53 const sync_driver::DataTypeEncryptionHandler* encryption_handler,
54 DataTypeManagerObserver* observer) override { 54 browser_sync::SyncBackendHost* backend,
55 sync_driver::DataTypeManagerObserver* observer) override {
55 return nullptr; 56 return nullptr;
56 } 57 }
57 SyncBackendHost* CreateSyncBackendHost( 58 browser_sync::SyncBackendHost* CreateSyncBackendHost(
58 const std::string& name, 59 const std::string& name,
59 invalidation::InvalidationService* invalidator, 60 invalidation::InvalidationService* invalidator,
60 const base::WeakPtr<SyncPrefs>& sync_prefs, 61 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs,
61 const base::FilePath& sync_folder) override { 62 const base::FilePath& sync_folder) override {
62 return nullptr; 63 return nullptr;
63 } 64 }
64 std::unique_ptr<LocalDeviceInfoProvider> CreateLocalDeviceInfoProvider() 65 std::unique_ptr<sync_driver::LocalDeviceInfoProvider>
65 override { 66 CreateLocalDeviceInfoProvider() override {
66 return nullptr; 67 return nullptr;
67 } 68 }
68 SyncApiComponentFactory::SyncComponents CreateBookmarkSyncComponents( 69 SyncApiComponentFactory::SyncComponents CreateBookmarkSyncComponents(
69 SyncService* sync_service, 70 sync_driver::SyncService* sync_service,
70 std::unique_ptr<DataTypeErrorHandler> error_handler) override { 71 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler) override {
71 return SyncApiComponentFactory::SyncComponents(nullptr, nullptr); 72 return SyncApiComponentFactory::SyncComponents(nullptr, nullptr);
72 } 73 }
73 std::unique_ptr<AttachmentService> CreateAttachmentService( 74 std::unique_ptr<syncer::AttachmentService> CreateAttachmentService(
74 std::unique_ptr<AttachmentStoreForSync> attachment_store, 75 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store,
75 const UserShare& user_share, 76 const syncer::UserShare& user_share,
76 const std::string& store_birthday, 77 const std::string& store_birthday,
77 ModelType model_type, 78 syncer::ModelType model_type,
78 AttachmentService::Delegate* delegate) override { 79 syncer::AttachmentService::Delegate* delegate) override {
79 return AttachmentServiceImpl::CreateForTest(); 80 return syncer::AttachmentServiceImpl::CreateForTest();
80 } 81 }
81 }; 82 };
82 83
83 class SyncSharedChangeProcessorTest : public testing::Test, 84 class SyncSharedChangeProcessorTest : public testing::Test,
84 public FakeSyncClient { 85 public FakeSyncClient {
85 public: 86 public:
86 SyncSharedChangeProcessorTest() 87 SyncSharedChangeProcessorTest()
87 : FakeSyncClient(&factory_), 88 : FakeSyncClient(&factory_),
88 backend_thread_("dbthread"), 89 backend_thread_("dbthread"),
89 did_connect_(false), 90 did_connect_(false),
90 has_attachment_service_(false) {} 91 has_attachment_service_(false) {}
91 92
92 ~SyncSharedChangeProcessorTest() override { 93 ~SyncSharedChangeProcessorTest() override {
93 EXPECT_FALSE(db_syncable_service_.get()); 94 EXPECT_FALSE(db_syncable_service_.get());
94 } 95 }
95 96
96 // FakeSyncClient override. 97 // FakeSyncClient override.
97 base::WeakPtr<SyncableService> GetSyncableServiceForType( 98 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType(
98 ModelType type) override { 99 syncer::ModelType type) override {
99 return db_syncable_service_->AsWeakPtr(); 100 return db_syncable_service_->AsWeakPtr();
100 } 101 }
101 102
102 protected: 103 protected:
103 void SetUp() override { 104 void SetUp() override {
104 test_user_share_.SetUp(); 105 test_user_share_.SetUp();
105 shared_change_processor_ = new SharedChangeProcessor(AUTOFILL); 106 shared_change_processor_ = new SharedChangeProcessor(syncer::AUTOFILL);
106 ASSERT_TRUE(backend_thread_.Start()); 107 ASSERT_TRUE(backend_thread_.Start());
107 ASSERT_TRUE(backend_thread_.task_runner()->PostTask( 108 ASSERT_TRUE(backend_thread_.task_runner()->PostTask(
108 FROM_HERE, 109 FROM_HERE,
109 base::Bind(&SyncSharedChangeProcessorTest::SetUpDBSyncableService, 110 base::Bind(&SyncSharedChangeProcessorTest::SetUpDBSyncableService,
110 base::Unretained(this)))); 111 base::Unretained(this))));
111 } 112 }
112 113
113 void TearDown() override { 114 void TearDown() override {
114 EXPECT_TRUE(backend_thread_.task_runner()->PostTask( 115 EXPECT_TRUE(backend_thread_.task_runner()->PostTask(
115 FROM_HERE, 116 FROM_HERE,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 base::Unretained(this), base::Unretained(&event)))); 158 base::Unretained(this), base::Unretained(&event))));
158 event.Wait(); 159 event.Wait();
159 return has_attachment_service_; 160 return has_attachment_service_;
160 } 161 }
161 162
162 private: 163 private:
163 // Used by SetUp(). 164 // Used by SetUp().
164 void SetUpDBSyncableService() { 165 void SetUpDBSyncableService() {
165 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); 166 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread());
166 DCHECK(!db_syncable_service_.get()); 167 DCHECK(!db_syncable_service_.get());
167 db_syncable_service_.reset(new FakeSyncableService()); 168 db_syncable_service_.reset(new syncer::FakeSyncableService());
168 } 169 }
169 170
170 // Used by TearDown(). 171 // Used by TearDown().
171 void TearDownDBSyncableService() { 172 void TearDownDBSyncableService() {
172 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); 173 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread());
173 DCHECK(db_syncable_service_.get()); 174 DCHECK(db_syncable_service_.get());
174 db_syncable_service_.reset(); 175 db_syncable_service_.reset();
175 } 176 }
176 177
177 void SetAttachmentStoreOnDBThread() { 178 void SetAttachmentStoreOnDBThread() {
178 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); 179 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread());
179 DCHECK(db_syncable_service_.get()); 180 DCHECK(db_syncable_service_.get());
180 db_syncable_service_->set_attachment_store( 181 db_syncable_service_->set_attachment_store(
181 AttachmentStore::CreateInMemoryStore()); 182 syncer::AttachmentStore::CreateInMemoryStore());
182 } 183 }
183 184
184 // Used by Connect(). The SharedChangeProcessor is passed in 185 // Used by Connect(). The SharedChangeProcessor is passed in
185 // because we modify |shared_change_processor_| on the main thread 186 // because we modify |shared_change_processor_| on the main thread
186 // (in TearDown()). 187 // (in TearDown()).
187 void ConnectOnDBThread( 188 void ConnectOnDBThread(
188 const scoped_refptr<SharedChangeProcessor>& shared_change_processor) { 189 const scoped_refptr<SharedChangeProcessor>& shared_change_processor) {
189 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread()); 190 DCHECK(backend_thread_.task_runner()->BelongsToCurrentThread());
190 EXPECT_TRUE(shared_change_processor->Connect( 191 EXPECT_TRUE(shared_change_processor->Connect(
191 this, &processor_factory_, test_user_share_.user_share(), 192 this, &processor_factory_, test_user_share_.user_share(),
192 base::MakeUnique<DataTypeErrorHandlerMock>(), 193 base::MakeUnique<syncer::DataTypeErrorHandlerMock>(),
193 base::WeakPtr<SyncMergeResult>())); 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 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 211
211 GenericChangeProcessorFactory processor_factory_; 212 GenericChangeProcessorFactory processor_factory_;
212 bool did_connect_; 213 bool did_connect_;
213 bool has_attachment_service_; 214 bool has_attachment_service_;
214 215
215 // Used only on DB thread. 216 // Used only on DB thread.
216 std::unique_ptr<FakeSyncableService> db_syncable_service_; 217 std::unique_ptr<syncer::FakeSyncableService> db_syncable_service_;
217 }; 218 };
218 219
219 // Simply connect the shared change processor. It should succeed, and 220 // Simply connect the shared change processor. It should succeed, and
220 // nothing further should happen. 221 // nothing further should happen.
221 TEST_F(SyncSharedChangeProcessorTest, Basic) { 222 TEST_F(SyncSharedChangeProcessorTest, Basic) {
222 Connect(); 223 Connect();
223 } 224 }
224 225
225 // Connect the shared change processor to a syncable service with 226 // Connect the shared change processor to a syncable service with
226 // AttachmentStore. Verify that shared change processor implementation 227 // AttachmentStore. Verify that shared change processor implementation
227 // creates AttachmentService and passes it back to the syncable service. 228 // creates AttachmentService and passes it back to the syncable service.
228 TEST_F(SyncSharedChangeProcessorTest, ConnectWithAttachmentStore) { 229 TEST_F(SyncSharedChangeProcessorTest, ConnectWithAttachmentStore) {
229 SetAttachmentStore(); 230 SetAttachmentStore();
230 Connect(); 231 Connect();
231 EXPECT_TRUE(HasAttachmentService()); 232 EXPECT_TRUE(HasAttachmentService());
232 } 233 }
233 234
234 } // namespace 235 } // namespace
235 236
236 } // namespace syncer 237 } // namespace sync_driver
OLDNEW
« no previous file with comments | « components/sync/driver/shared_change_processor_ref.cc ('k') | components/sync/driver/startup_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698