| 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/generic_change_processor.h" | 5 #include "components/sync_driver/generic_change_processor.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "components/sync_driver/data_type_error_handler_mock.h" | 12 #include "components/sync_driver/data_type_error_handler_mock.h" |
| 13 #include "components/sync_driver/fake_sync_client.h" |
| 14 #include "components/sync_driver/local_device_info_provider.h" |
| 13 #include "components/sync_driver/sync_api_component_factory.h" | 15 #include "components/sync_driver/sync_api_component_factory.h" |
| 14 #include "sync/api/attachments/attachment_id.h" | 16 #include "sync/api/attachments/attachment_id.h" |
| 15 #include "sync/api/attachments/attachment_store.h" | 17 #include "sync/api/attachments/attachment_store.h" |
| 16 #include "sync/api/fake_syncable_service.h" | 18 #include "sync/api/fake_syncable_service.h" |
| 17 #include "sync/api/sync_change.h" | 19 #include "sync/api/sync_change.h" |
| 18 #include "sync/api/sync_merge_result.h" | 20 #include "sync/api/sync_merge_result.h" |
| 19 #include "sync/internal_api/public/attachments/attachment_service_impl.h" | 21 #include "sync/internal_api/public/attachments/attachment_service_impl.h" |
| 20 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" | 22 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" |
| 21 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" | 23 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" |
| 22 #include "sync/internal_api/public/base/model_type.h" | 24 #include "sync/internal_api/public/base/model_type.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 MockAttachmentService::attachment_id_lists() { | 75 MockAttachmentService::attachment_id_lists() { |
| 74 return &attachment_id_lists_; | 76 return &attachment_id_lists_; |
| 75 } | 77 } |
| 76 | 78 |
| 77 // MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and | 79 // MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and |
| 78 // pass MockAttachmentService to it. | 80 // pass MockAttachmentService to it. |
| 79 class MockSyncApiComponentFactory : public SyncApiComponentFactory { | 81 class MockSyncApiComponentFactory : public SyncApiComponentFactory { |
| 80 public: | 82 public: |
| 81 MockSyncApiComponentFactory() {} | 83 MockSyncApiComponentFactory() {} |
| 82 | 84 |
| 83 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( | 85 // SyncApiComponentFactory implementation. |
| 84 syncer::ModelType type) override { | 86 void Initialize(SyncService* sync_service) override {} |
| 85 // Shouldn't be called for this test. | 87 void RegisterDataTypes(SyncService* sync_service) override {} |
| 86 NOTREACHED(); | 88 sync_driver::DataTypeManager* CreateDataTypeManager( |
| 87 return base::WeakPtr<syncer::SyncableService>(); | 89 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 90 debug_info_listener, |
| 91 const sync_driver::DataTypeController::TypeMap* controllers, |
| 92 const sync_driver::DataTypeEncryptionHandler* encryption_handler, |
| 93 browser_sync::SyncBackendHost* backend, |
| 94 sync_driver::DataTypeManagerObserver* observer) override{ |
| 95 return nullptr; |
| 96 }; |
| 97 browser_sync::SyncBackendHost* CreateSyncBackendHost( |
| 98 const std::string& name, |
| 99 invalidation::InvalidationService* invalidator, |
| 100 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, |
| 101 const base::FilePath& sync_folder) override { |
| 102 return nullptr; |
| 103 } |
| 104 scoped_ptr<sync_driver::LocalDeviceInfoProvider> |
| 105 CreateLocalDeviceInfoProvider() override { return nullptr; } |
| 106 SyncComponents CreateBookmarkSyncComponents( |
| 107 sync_driver::SyncService* sync_service, |
| 108 sync_driver::DataTypeErrorHandler* error_handler) override { |
| 109 return SyncComponents(nullptr, nullptr); |
| 110 } |
| 111 SyncComponents CreateTypedUrlSyncComponents( |
| 112 sync_driver::SyncService* sync_service, |
| 113 history::HistoryBackend* history_backend, |
| 114 sync_driver::DataTypeErrorHandler* error_handler) override { |
| 115 return SyncComponents(nullptr, nullptr); |
| 88 } | 116 } |
| 89 | 117 |
| 90 scoped_ptr<syncer::AttachmentService> CreateAttachmentService( | 118 scoped_ptr<syncer::AttachmentService> CreateAttachmentService( |
| 91 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store, | 119 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store, |
| 92 const syncer::UserShare& user_share, | 120 const syncer::UserShare& user_share, |
| 93 const std::string& store_birthday, | 121 const std::string& store_birthday, |
| 94 syncer::ModelType model_type, | 122 syncer::ModelType model_type, |
| 95 syncer::AttachmentService::Delegate* delegate) override { | 123 syncer::AttachmentService::Delegate* delegate) override { |
| 96 scoped_ptr<MockAttachmentService> attachment_service( | 124 scoped_ptr<MockAttachmentService> attachment_service( |
| 97 new MockAttachmentService(attachment_store.Pass())); | 125 new MockAttachmentService(attachment_store.Pass())); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 112 }; | 140 }; |
| 113 | 141 |
| 114 class SyncGenericChangeProcessorTest : public testing::Test { | 142 class SyncGenericChangeProcessorTest : public testing::Test { |
| 115 public: | 143 public: |
| 116 // Most test cases will use this type. For those that need a | 144 // Most test cases will use this type. For those that need a |
| 117 // GenericChangeProcessor for a different type, use |InitializeForType|. | 145 // GenericChangeProcessor for a different type, use |InitializeForType|. |
| 118 static const syncer::ModelType kType = syncer::PREFERENCES; | 146 static const syncer::ModelType kType = syncer::PREFERENCES; |
| 119 | 147 |
| 120 SyncGenericChangeProcessorTest() | 148 SyncGenericChangeProcessorTest() |
| 121 : syncable_service_ptr_factory_(&fake_syncable_service_), | 149 : syncable_service_ptr_factory_(&fake_syncable_service_), |
| 122 mock_attachment_service_(NULL) {} | 150 mock_attachment_service_(NULL), |
| 151 sync_client_(&sync_factory_) {} |
| 123 | 152 |
| 124 void SetUp() override { | 153 void SetUp() override { |
| 125 // Use kType by default, but allow test cases to re-initialize with whatever | 154 // Use kType by default, but allow test cases to re-initialize with whatever |
| 126 // type they choose. Therefore, it's important that all type dependent | 155 // type they choose. Therefore, it's important that all type dependent |
| 127 // initialization occurs in InitializeForType. | 156 // initialization occurs in InitializeForType. |
| 128 InitializeForType(kType); | 157 InitializeForType(kType); |
| 129 } | 158 } |
| 130 | 159 |
| 131 void TearDown() override { | 160 void TearDown() override { |
| 132 mock_attachment_service_ = NULL; | 161 mock_attachment_service_ = NULL; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 150 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good(); | 179 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good(); |
| 151 iter.Inc()) { | 180 iter.Inc()) { |
| 152 syncer::TestUserShare::CreateRoot(iter.Get(), | 181 syncer::TestUserShare::CreateRoot(iter.Get(), |
| 153 test_user_share_->user_share()); | 182 test_user_share_->user_share()); |
| 154 } | 183 } |
| 155 test_user_share_->encryption_handler()->Init(); | 184 test_user_share_->encryption_handler()->Init(); |
| 156 ConstructGenericChangeProcessor(type); | 185 ConstructGenericChangeProcessor(type); |
| 157 } | 186 } |
| 158 | 187 |
| 159 void ConstructGenericChangeProcessor(syncer::ModelType type) { | 188 void ConstructGenericChangeProcessor(syncer::ModelType type) { |
| 160 MockSyncApiComponentFactory sync_factory; | |
| 161 scoped_ptr<syncer::AttachmentStore> attachment_store = | 189 scoped_ptr<syncer::AttachmentStore> attachment_store = |
| 162 syncer::AttachmentStore::CreateInMemoryStore(); | 190 syncer::AttachmentStore::CreateInMemoryStore(); |
| 163 change_processor_.reset(new GenericChangeProcessor( | 191 change_processor_.reset(new GenericChangeProcessor( |
| 164 type, &data_type_error_handler_, | 192 type, &data_type_error_handler_, |
| 165 syncable_service_ptr_factory_.GetWeakPtr(), | 193 syncable_service_ptr_factory_.GetWeakPtr(), |
| 166 merge_result_ptr_factory_->GetWeakPtr(), test_user_share_->user_share(), | 194 merge_result_ptr_factory_->GetWeakPtr(), test_user_share_->user_share(), |
| 167 &sync_factory, attachment_store->CreateAttachmentStoreForSync())); | 195 &sync_client_, attachment_store->CreateAttachmentStoreForSync())); |
| 168 mock_attachment_service_ = sync_factory.GetMockAttachmentService(); | 196 mock_attachment_service_ = sync_factory_.GetMockAttachmentService(); |
| 169 } | 197 } |
| 170 | 198 |
| 171 void BuildChildNodes(syncer::ModelType type, int n) { | 199 void BuildChildNodes(syncer::ModelType type, int n) { |
| 172 syncer::WriteTransaction trans(FROM_HERE, user_share()); | 200 syncer::WriteTransaction trans(FROM_HERE, user_share()); |
| 173 for (int i = 0; i < n; ++i) { | 201 for (int i = 0; i < n; ++i) { |
| 174 syncer::WriteNode node(&trans); | 202 syncer::WriteNode node(&trans); |
| 175 node.InitUniqueByCreation(type, base::StringPrintf("node%05d", i)); | 203 node.InitUniqueByCreation(type, base::StringPrintf("node%05d", i)); |
| 176 } | 204 } |
| 177 } | 205 } |
| 178 | 206 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 200 scoped_ptr<base::WeakPtrFactory<syncer::SyncMergeResult> > | 228 scoped_ptr<base::WeakPtrFactory<syncer::SyncMergeResult> > |
| 201 merge_result_ptr_factory_; | 229 merge_result_ptr_factory_; |
| 202 | 230 |
| 203 syncer::FakeSyncableService fake_syncable_service_; | 231 syncer::FakeSyncableService fake_syncable_service_; |
| 204 base::WeakPtrFactory<syncer::FakeSyncableService> | 232 base::WeakPtrFactory<syncer::FakeSyncableService> |
| 205 syncable_service_ptr_factory_; | 233 syncable_service_ptr_factory_; |
| 206 | 234 |
| 207 DataTypeErrorHandlerMock data_type_error_handler_; | 235 DataTypeErrorHandlerMock data_type_error_handler_; |
| 208 scoped_ptr<syncer::TestUserShare> test_user_share_; | 236 scoped_ptr<syncer::TestUserShare> test_user_share_; |
| 209 MockAttachmentService* mock_attachment_service_; | 237 MockAttachmentService* mock_attachment_service_; |
| 238 FakeSyncClient sync_client_; |
| 239 MockSyncApiComponentFactory sync_factory_; |
| 210 | 240 |
| 211 scoped_ptr<GenericChangeProcessor> change_processor_; | 241 scoped_ptr<GenericChangeProcessor> change_processor_; |
| 212 }; | 242 }; |
| 213 | 243 |
| 214 // Similar to above, but focused on the method that implements sync/api | 244 // Similar to above, but focused on the method that implements sync/api |
| 215 // interfaces and is hence exposed to datatypes directly. | 245 // interfaces and is hence exposed to datatypes directly. |
| 216 TEST_F(SyncGenericChangeProcessorTest, StressGetAllSyncData) { | 246 TEST_F(SyncGenericChangeProcessorTest, StressGetAllSyncData) { |
| 217 const int kNumChildNodes = 1000; | 247 const int kNumChildNodes = 1000; |
| 218 const int kRepeatCount = 1; | 248 const int kRepeatCount = 1; |
| 219 | 249 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 syncer::SyncDataList sync_data = | 538 syncer::SyncDataList sync_data = |
| 509 change_processor()->GetAllSyncData(syncer::SESSIONS); | 539 change_processor()->GetAllSyncData(syncer::SESSIONS); |
| 510 ASSERT_EQ(sync_data.size(), 1U); | 540 ASSERT_EQ(sync_data.size(), 1U); |
| 511 ASSERT_EQ("session tag 2", | 541 ASSERT_EQ("session tag 2", |
| 512 sync_data[0].GetSpecifics().session().session_tag()); | 542 sync_data[0].GetSpecifics().session().session_tag()); |
| 513 } | 543 } |
| 514 | 544 |
| 515 } // namespace | 545 } // namespace |
| 516 | 546 |
| 517 } // namespace sync_driver | 547 } // namespace sync_driver |
| OLD | NEW |