| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/glue/sync_backend_registrar.h" | 5 #include "components/sync/driver/glue/sync_backend_registrar.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "components/sync/driver/change_processor_mock.h" | 11 #include "components/sync/driver/change_processor_mock.h" |
| 12 #include "components/sync/driver/fake_sync_client.h" | 12 #include "components/sync/driver/fake_sync_client.h" |
| 13 #include "components/sync/driver/glue/browser_thread_model_worker.h" | 13 #include "components/sync/driver/glue/browser_thread_model_worker.h" |
| 14 #include "components/sync/driver/sync_api_component_factory_mock.h" | 14 #include "components/sync/driver/sync_api_component_factory_mock.h" |
| 15 #include "components/sync/engine/passive_model_worker.h" | 15 #include "components/sync/engine/passive_model_worker.h" |
| 16 #include "components/sync/syncable/test_user_share.h" | 16 #include "components/sync/syncable/test_user_share.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace syncer { | 20 namespace syncer { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 using ::testing::_; | 24 using ::testing::_; |
| 25 using ::testing::InSequence; | 25 using ::testing::InSequence; |
| 26 using ::testing::Return; | 26 using ::testing::Return; |
| 27 using ::testing::StrictMock; | 27 using ::testing::StrictMock; |
| 28 | 28 |
| 29 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { | 29 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { |
| 30 registrar->OnChangesApplied(type, 0, NULL, ImmutableChangeRecordList()); | 30 registrar->OnChangesApplied(type, 0, nullptr, ImmutableChangeRecordList()); |
| 31 registrar->OnChangesComplete(type); | 31 registrar->OnChangesComplete(type); |
| 32 } | 32 } |
| 33 | 33 |
| 34 class RegistrarSyncClient : public FakeSyncClient { | 34 class RegistrarSyncClient : public FakeSyncClient { |
| 35 public: | 35 public: |
| 36 RegistrarSyncClient( | 36 RegistrarSyncClient( |
| 37 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 37 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| 38 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner, | 38 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner, |
| 39 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | 39 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 40 : ui_task_runner_(ui_task_runner), | 40 : ui_task_runner_(ui_task_runner), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 ExpectRoutingInfo(registrar_.get(), {{AUTOFILL, GROUP_DB}}); | 74 ExpectRoutingInfo(registrar_.get(), {{AUTOFILL, GROUP_DB}}); |
| 75 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet(AUTOFILL)); | 75 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet(AUTOFILL)); |
| 76 TriggerChanges(registrar_.get(), AUTOFILL); | 76 TriggerChanges(registrar_.get(), AUTOFILL); |
| 77 done->Signal(); | 77 done->Signal(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 protected: | 80 protected: |
| 81 SyncBackendRegistrarTest() | 81 SyncBackendRegistrarTest() |
| 82 : db_thread_("DBThreadForTest"), | 82 : db_thread_("DBThreadForTest"), |
| 83 file_thread_("FileThreadForTest"), | 83 file_thread_("FileThreadForTest"), |
| 84 sync_thread_(NULL) {} | 84 sync_thread_(nullptr) {} |
| 85 | 85 |
| 86 ~SyncBackendRegistrarTest() override {} | 86 ~SyncBackendRegistrarTest() override {} |
| 87 | 87 |
| 88 void SetUp() override { | 88 void SetUp() override { |
| 89 db_thread_.StartAndWaitForTesting(); | 89 db_thread_.StartAndWaitForTesting(); |
| 90 file_thread_.StartAndWaitForTesting(); | 90 file_thread_.StartAndWaitForTesting(); |
| 91 test_user_share_.SetUp(); | 91 test_user_share_.SetUp(); |
| 92 sync_client_ = base::MakeUnique<RegistrarSyncClient>( | 92 sync_client_ = base::MakeUnique<RegistrarSyncClient>( |
| 93 ui_task_runner(), db_task_runner(), file_task_runner()); | 93 ui_task_runner(), db_task_runner(), file_task_runner()); |
| 94 registrar_ = base::MakeUnique<SyncBackendRegistrar>( | 94 registrar_ = base::MakeUnique<SyncBackendRegistrar>( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { | 217 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { |
| 218 InSequence in_sequence; | 218 InSequence in_sequence; |
| 219 registrar_->SetInitialTypes(ModelTypeSet()); | 219 registrar_->SetInitialTypes(ModelTypeSet()); |
| 220 | 220 |
| 221 // Should do nothing. | 221 // Should do nothing. |
| 222 TriggerChanges(registrar_.get(), BOOKMARKS); | 222 TriggerChanges(registrar_.get(), BOOKMARKS); |
| 223 | 223 |
| 224 StrictMock<ChangeProcessorMock> change_processor_mock; | 224 StrictMock<ChangeProcessorMock> change_processor_mock; |
| 225 EXPECT_CALL(change_processor_mock, StartImpl()); | 225 EXPECT_CALL(change_processor_mock, StartImpl()); |
| 226 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); | 226 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
| 227 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); | 227 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(nullptr, _, _)); |
| 228 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); | 228 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
| 229 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); | 229 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); |
| 230 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); | 230 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); |
| 231 | 231 |
| 232 const ModelTypeSet types(BOOKMARKS); | 232 const ModelTypeSet types(BOOKMARKS); |
| 233 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); | 233 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); |
| 234 registrar_->ActivateDataType(BOOKMARKS, GROUP_UI, &change_processor_mock, | 234 registrar_->ActivateDataType(BOOKMARKS, GROUP_UI, &change_processor_mock, |
| 235 test_user_share_.user_share()); | 235 test_user_share_.user_share()); |
| 236 ExpectRoutingInfo(registrar_.get(), {{BOOKMARKS, GROUP_UI}}); | 236 ExpectRoutingInfo(registrar_.get(), {{BOOKMARKS, GROUP_UI}}); |
| 237 ExpectHasProcessorsForTypes(*registrar_, types); | 237 ExpectHasProcessorsForTypes(*registrar_, types); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 249 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { | 249 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { |
| 250 InSequence in_sequence; | 250 InSequence in_sequence; |
| 251 registrar_->SetInitialTypes(ModelTypeSet()); | 251 registrar_->SetInitialTypes(ModelTypeSet()); |
| 252 | 252 |
| 253 // Should do nothing. | 253 // Should do nothing. |
| 254 TriggerChanges(registrar_.get(), AUTOFILL); | 254 TriggerChanges(registrar_.get(), AUTOFILL); |
| 255 | 255 |
| 256 StrictMock<ChangeProcessorMock> change_processor_mock; | 256 StrictMock<ChangeProcessorMock> change_processor_mock; |
| 257 EXPECT_CALL(change_processor_mock, StartImpl()); | 257 EXPECT_CALL(change_processor_mock, StartImpl()); |
| 258 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); | 258 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
| 259 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); | 259 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(nullptr, _, _)); |
| 260 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); | 260 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
| 261 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); | 261 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); |
| 262 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); | 262 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); |
| 263 | 263 |
| 264 const ModelTypeSet types(AUTOFILL); | 264 const ModelTypeSet types(AUTOFILL); |
| 265 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); | 265 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); |
| 266 | 266 |
| 267 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 267 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 268 base::WaitableEvent::InitialState::NOT_SIGNALED); | 268 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 269 db_task_runner()->PostTask( | 269 db_task_runner()->PostTask( |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 db_thread_lock_.Release(); | 424 db_thread_lock_.Release(); |
| 425 | 425 |
| 426 // Run the main thread loop until all workers have been removed and the | 426 // Run the main thread loop until all workers have been removed and the |
| 427 // registrar destroyed. | 427 // registrar destroyed. |
| 428 run_loop_.Run(); | 428 run_loop_.Run(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 } // namespace | 431 } // namespace |
| 432 | 432 |
| 433 } // namespace syncer | 433 } // namespace syncer |
| OLD | NEW |