| 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/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "components/sync/base/model_type.h" | 10 #include "components/sync/base/model_type.h" |
| 11 #include "components/sync/core/test/test_user_share.h" | 11 #include "components/sync/core/test/test_user_share.h" |
| 12 #include "components/sync/driver/change_processor_mock.h" |
| 13 #include "components/sync/driver/fake_sync_client.h" |
| 14 #include "components/sync/driver/glue/browser_thread_model_worker.h" |
| 15 #include "components/sync/driver/sync_api_component_factory_mock.h" |
| 12 #include "components/sync/engine/passive_model_worker.h" | 16 #include "components/sync/engine/passive_model_worker.h" |
| 13 #include "components/sync_driver/change_processor_mock.h" | |
| 14 #include "components/sync_driver/fake_sync_client.h" | |
| 15 #include "components/sync_driver/glue/browser_thread_model_worker.h" | |
| 16 #include "components/sync_driver/sync_api_component_factory_mock.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 browser_sync { | 20 namespace browser_sync { |
| 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; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 74 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 75 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; | 75 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; |
| 76 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 76 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // Flaky: https://crbug.com/498238 | 79 // Flaky: https://crbug.com/498238 |
| 80 class SyncBackendRegistrarTest : public testing::Test { | 80 class SyncBackendRegistrarTest : public testing::Test { |
| 81 public: | 81 public: |
| 82 void TestNonUIDataTypeActivationAsync(sync_driver::ChangeProcessor* processor, | 82 void TestNonUIDataTypeActivationAsync(sync_driver::ChangeProcessor* processor, |
| 83 base::WaitableEvent* done) { | 83 base::WaitableEvent* done) { |
| 84 registrar_->ActivateDataType(AUTOFILL, | 84 registrar_->ActivateDataType(AUTOFILL, syncer::GROUP_DB, processor, |
| 85 syncer::GROUP_DB, | |
| 86 processor, | |
| 87 test_user_share_.user_share()); | 85 test_user_share_.user_share()); |
| 88 syncer::ModelSafeRoutingInfo expected_routing_info; | 86 syncer::ModelSafeRoutingInfo expected_routing_info; |
| 89 expected_routing_info[AUTOFILL] = syncer::GROUP_DB; | 87 expected_routing_info[AUTOFILL] = syncer::GROUP_DB; |
| 90 ExpectRoutingInfo(registrar_.get(), expected_routing_info); | 88 ExpectRoutingInfo(registrar_.get(), expected_routing_info); |
| 91 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet(AUTOFILL)); | 89 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet(AUTOFILL)); |
| 92 TriggerChanges(registrar_.get(), AUTOFILL); | 90 TriggerChanges(registrar_.get(), AUTOFILL); |
| 93 done->Signal(); | 91 done->Signal(); |
| 94 } | 92 } |
| 95 | 93 |
| 96 protected: | 94 protected: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 std::unique_ptr<RegistrarSyncClient> sync_client_; | 158 std::unique_ptr<RegistrarSyncClient> sync_client_; |
| 161 std::unique_ptr<SyncBackendRegistrar> registrar_; | 159 std::unique_ptr<SyncBackendRegistrar> registrar_; |
| 162 | 160 |
| 163 base::Thread* sync_thread_; | 161 base::Thread* sync_thread_; |
| 164 }; | 162 }; |
| 165 | 163 |
| 166 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { | 164 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { |
| 167 registrar_->SetInitialTypes(ModelTypeSet()); | 165 registrar_->SetInitialTypes(ModelTypeSet()); |
| 168 EXPECT_FALSE(registrar_->IsNigoriEnabled()); | 166 EXPECT_FALSE(registrar_->IsNigoriEnabled()); |
| 169 { | 167 { |
| 170 std::vector<scoped_refptr<syncer::ModelSafeWorker> > workers; | 168 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers; |
| 171 registrar_->GetWorkers(&workers); | 169 registrar_->GetWorkers(&workers); |
| 172 EXPECT_EQ(4u, workers.size()); | 170 EXPECT_EQ(4u, workers.size()); |
| 173 } | 171 } |
| 174 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo()); | 172 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo()); |
| 175 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); | 173 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); |
| 176 } | 174 } |
| 177 | 175 |
| 178 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) { | 176 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) { |
| 179 const ModelTypeSet initial_types(BOOKMARKS, NIGORI, PASSWORDS); | 177 const ModelTypeSet initial_types(BOOKMARKS, NIGORI, PASSWORDS); |
| 180 registrar_->RegisterNonBlockingType(BOOKMARKS); | 178 registrar_->RegisterNonBlockingType(BOOKMARKS); |
| 181 registrar_->SetInitialTypes(initial_types); | 179 registrar_->SetInitialTypes(initial_types); |
| 182 EXPECT_TRUE(registrar_->IsNigoriEnabled()); | 180 EXPECT_TRUE(registrar_->IsNigoriEnabled()); |
| 183 { | 181 { |
| 184 std::vector<scoped_refptr<syncer::ModelSafeWorker> > workers; | 182 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers; |
| 185 registrar_->GetWorkers(&workers); | 183 registrar_->GetWorkers(&workers); |
| 186 EXPECT_EQ(4u, workers.size()); | 184 EXPECT_EQ(4u, workers.size()); |
| 187 } | 185 } |
| 188 { | 186 { |
| 189 syncer::ModelSafeRoutingInfo expected_routing_info; | 187 syncer::ModelSafeRoutingInfo expected_routing_info; |
| 190 expected_routing_info[BOOKMARKS] = syncer::GROUP_NON_BLOCKING; | 188 expected_routing_info[BOOKMARKS] = syncer::GROUP_NON_BLOCKING; |
| 191 expected_routing_info[NIGORI] = syncer::GROUP_PASSIVE; | 189 expected_routing_info[NIGORI] = syncer::GROUP_PASSIVE; |
| 192 // Passwords dropped because of no password store. | 190 // Passwords dropped because of no password store. |
| 193 ExpectRoutingInfo(registrar_.get(), expected_routing_info); | 191 ExpectRoutingInfo(registrar_.get(), expected_routing_info); |
| 194 } | 192 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 231 |
| 234 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { | 232 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { |
| 235 InSequence in_sequence; | 233 InSequence in_sequence; |
| 236 registrar_->SetInitialTypes(ModelTypeSet()); | 234 registrar_->SetInitialTypes(ModelTypeSet()); |
| 237 | 235 |
| 238 // Should do nothing. | 236 // Should do nothing. |
| 239 TriggerChanges(registrar_.get(), BOOKMARKS); | 237 TriggerChanges(registrar_.get(), BOOKMARKS); |
| 240 | 238 |
| 241 StrictMock<sync_driver::ChangeProcessorMock> change_processor_mock; | 239 StrictMock<sync_driver::ChangeProcessorMock> change_processor_mock; |
| 242 EXPECT_CALL(change_processor_mock, StartImpl()); | 240 EXPECT_CALL(change_processor_mock, StartImpl()); |
| 243 EXPECT_CALL(change_processor_mock, IsRunning()) | 241 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
| 244 .WillRepeatedly(Return(true)); | |
| 245 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); | 242 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); |
| 246 EXPECT_CALL(change_processor_mock, IsRunning()) | 243 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
| 247 .WillRepeatedly(Return(true)); | |
| 248 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); | 244 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); |
| 249 EXPECT_CALL(change_processor_mock, IsRunning()) | 245 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); |
| 250 .WillRepeatedly(Return(false)); | |
| 251 | 246 |
| 252 const ModelTypeSet types(BOOKMARKS); | 247 const ModelTypeSet types(BOOKMARKS); |
| 253 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); | 248 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); |
| 254 registrar_->ActivateDataType(BOOKMARKS, syncer::GROUP_UI, | 249 registrar_->ActivateDataType(BOOKMARKS, syncer::GROUP_UI, |
| 255 &change_processor_mock, | 250 &change_processor_mock, |
| 256 test_user_share_.user_share()); | 251 test_user_share_.user_share()); |
| 257 { | 252 { |
| 258 syncer::ModelSafeRoutingInfo expected_routing_info; | 253 syncer::ModelSafeRoutingInfo expected_routing_info; |
| 259 expected_routing_info[BOOKMARKS] = syncer::GROUP_UI; | 254 expected_routing_info[BOOKMARKS] = syncer::GROUP_UI; |
| 260 ExpectRoutingInfo(registrar_.get(), expected_routing_info); | 255 ExpectRoutingInfo(registrar_.get(), expected_routing_info); |
| 261 } | 256 } |
| 262 ExpectHasProcessorsForTypes(*registrar_, types); | 257 ExpectHasProcessorsForTypes(*registrar_, types); |
| 263 | 258 |
| 264 TriggerChanges(registrar_.get(), BOOKMARKS); | 259 TriggerChanges(registrar_.get(), BOOKMARKS); |
| 265 | 260 |
| 266 registrar_->DeactivateDataType(BOOKMARKS); | 261 registrar_->DeactivateDataType(BOOKMARKS); |
| 267 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo()); | 262 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo()); |
| 268 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); | 263 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); |
| 269 | 264 |
| 270 // Should do nothing. | 265 // Should do nothing. |
| 271 TriggerChanges(registrar_.get(), BOOKMARKS); | 266 TriggerChanges(registrar_.get(), BOOKMARKS); |
| 272 } | 267 } |
| 273 | 268 |
| 274 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { | 269 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { |
| 275 InSequence in_sequence; | 270 InSequence in_sequence; |
| 276 registrar_->SetInitialTypes(ModelTypeSet()); | 271 registrar_->SetInitialTypes(ModelTypeSet()); |
| 277 | 272 |
| 278 // Should do nothing. | 273 // Should do nothing. |
| 279 TriggerChanges(registrar_.get(), AUTOFILL); | 274 TriggerChanges(registrar_.get(), AUTOFILL); |
| 280 | 275 |
| 281 StrictMock<sync_driver::ChangeProcessorMock> change_processor_mock; | 276 StrictMock<sync_driver::ChangeProcessorMock> change_processor_mock; |
| 282 EXPECT_CALL(change_processor_mock, StartImpl()); | 277 EXPECT_CALL(change_processor_mock, StartImpl()); |
| 283 EXPECT_CALL(change_processor_mock, IsRunning()) | 278 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
| 284 .WillRepeatedly(Return(true)); | |
| 285 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); | 279 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); |
| 286 EXPECT_CALL(change_processor_mock, IsRunning()) | 280 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
| 287 .WillRepeatedly(Return(true)); | |
| 288 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); | 281 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); |
| 289 EXPECT_CALL(change_processor_mock, IsRunning()) | 282 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); |
| 290 .WillRepeatedly(Return(false)); | |
| 291 | 283 |
| 292 const ModelTypeSet types(AUTOFILL); | 284 const ModelTypeSet types(AUTOFILL); |
| 293 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); | 285 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); |
| 294 | 286 |
| 295 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 287 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 296 base::WaitableEvent::InitialState::NOT_SIGNALED); | 288 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 297 db_task_runner()->PostTask( | 289 db_task_runner()->PostTask( |
| 298 FROM_HERE, | 290 FROM_HERE, |
| 299 base::Bind(&SyncBackendRegistrarTest::TestNonUIDataTypeActivationAsync, | 291 base::Bind(&SyncBackendRegistrarTest::TestNonUIDataTypeActivationAsync, |
| 300 base::Unretained(this), &change_processor_mock, &done)); | 292 base::Unretained(this), &change_processor_mock, &done)); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 db_thread_lock_.Release(); | 452 db_thread_lock_.Release(); |
| 461 | 453 |
| 462 // Run the main thread loop until all workers have been removed and the | 454 // Run the main thread loop until all workers have been removed and the |
| 463 // registrar destroyed. | 455 // registrar destroyed. |
| 464 run_loop_.Run(); | 456 run_loop_.Run(); |
| 465 } | 457 } |
| 466 | 458 |
| 467 } // namespace | 459 } // namespace |
| 468 | 460 |
| 469 } // namespace browser_sync | 461 } // namespace browser_sync |
| OLD | NEW |