OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/sync/glue/data_type_manager_impl.h" | 5 #include "chrome/browser/sync/glue/data_type_manager_impl.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "chrome/browser/sync/glue/backend_data_type_configurer.h" | 9 #include "chrome/browser/sync/glue/backend_data_type_configurer.h" |
10 #include "chrome/browser/sync/glue/data_type_controller.h" | 10 #include "chrome/browser/sync/glue/data_type_controller.h" |
11 #include "chrome/browser/sync/glue/fake_data_type_controller.h" | 11 #include "chrome/browser/sync/glue/fake_data_type_controller.h" |
12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
13 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
16 #include "content/test/notification_observer_mock.h" | 16 #include "content/test/notification_observer_mock.h" |
17 #include "content/test/test_browser_thread.h" | 17 #include "content/test/test_browser_thread.h" |
18 #include "sync/internal_api/configure_reason.h" | 18 #include "sync/internal_api/configure_reason.h" |
19 #include "sync/syncable/model_type.h" | 19 #include "sync/syncable/model_type.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace browser_sync { | 23 namespace browser_sync { |
24 | 24 |
25 using syncable::ModelType; | 25 using syncable::ModelType; |
26 using syncable::ModelTypeSet; | 26 using syncable::ModelTypeSet; |
27 using syncable::ModelTypeToString; | 27 using syncable::ModelTypeToString; |
28 using syncable::BOOKMARKS; | 28 using syncable::BOOKMARKS; |
| 29 using syncable::APPS; |
29 using syncable::PASSWORDS; | 30 using syncable::PASSWORDS; |
30 using syncable::PREFERENCES; | 31 using syncable::PREFERENCES; |
31 using testing::_; | 32 using testing::_; |
32 using testing::Mock; | 33 using testing::Mock; |
33 using testing::ResultOf; | 34 using testing::ResultOf; |
34 | 35 |
35 // Fake BackendDataTypeConfigurer implementation that simply stores | 36 // Fake BackendDataTypeConfigurer implementation that simply stores |
36 // away the nigori state and callback passed into ConfigureDataTypes. | 37 // away the nigori state and callback passed into ConfigureDataTypes. |
37 class FakeBackendDataTypeConfigurer : public BackendDataTypeConfigurer { | 38 class FakeBackendDataTypeConfigurer : public BackendDataTypeConfigurer { |
38 public: | 39 public: |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 FinishDownload(dtm, ModelTypeSet()); | 196 FinishDownload(dtm, ModelTypeSet()); |
196 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm.state()); | 197 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm.state()); |
197 | 198 |
198 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); | 199 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); |
199 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state()); | 200 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state()); |
200 | 201 |
201 dtm.Stop(); | 202 dtm.Stop(); |
202 EXPECT_EQ(DataTypeManager::STOPPED, dtm.state()); | 203 EXPECT_EQ(DataTypeManager::STOPPED, dtm.state()); |
203 } | 204 } |
204 | 205 |
| 206 // Set up a DTM with 2 controllers. configure it. One of them finishes loading |
| 207 // after the timeout. Make sure eventually all are configured. |
| 208 TEST_P(SyncDataTypeManagerImplTest, ConfigureSlowLoadingType) { |
| 209 AddController(BOOKMARKS); |
| 210 AddController(APPS); |
| 211 |
| 212 GetController(BOOKMARKS)->SetDelayModelLoad(); |
| 213 |
| 214 DataTypeManagerImpl dtm(&configurer_, &controllers_); |
| 215 SetConfigureStartExpectation(); |
| 216 SetConfigureDoneExpectation(DataTypeManager::PARTIAL_SUCCESS); |
| 217 |
| 218 syncable::ModelTypeSet types; |
| 219 types.Put(BOOKMARKS); |
| 220 types.Put(APPS); |
| 221 |
| 222 Configure(&dtm, types); |
| 223 EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm.state()); |
| 224 |
| 225 FinishDownload(dtm, ModelTypeSet()); |
| 226 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm.state()); |
| 227 |
| 228 base::OneShotTimer<ModelAssociationManager>* timer = |
| 229 dtm.GetModelAssociationManagerForTesting()->GetTimerForTesting(); |
| 230 |
| 231 base::Closure task = timer->user_task(); |
| 232 timer->Stop(); |
| 233 task.Run(); |
| 234 |
| 235 SetConfigureDoneExpectation(DataTypeManager::OK); |
| 236 GetController(APPS)->FinishStart(DataTypeController::OK); |
| 237 |
| 238 SetConfigureStartExpectation(); |
| 239 GetController(BOOKMARKS)->SimulateModelLoadFinishing(); |
| 240 |
| 241 FinishDownload(dtm, ModelTypeSet()); |
| 242 GetController(BOOKMARKS)->SimulateModelLoadFinishing(); |
| 243 |
| 244 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); |
| 245 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state()); |
| 246 |
| 247 dtm.Stop(); |
| 248 EXPECT_EQ(DataTypeManager::STOPPED, dtm.state()); |
| 249 } |
| 250 |
| 251 |
205 // Set up a DTM with a single controller, configure it, but stop it | 252 // Set up a DTM with a single controller, configure it, but stop it |
206 // before finishing the download. It should still be safe to run the | 253 // before finishing the download. It should still be safe to run the |
207 // download callback even after the DTM is stopped and destroyed. | 254 // download callback even after the DTM is stopped and destroyed. |
208 TEST_P(SyncDataTypeManagerImplTest, ConfigureOneStopWhileDownloadPending) { | 255 TEST_P(SyncDataTypeManagerImplTest, ConfigureOneStopWhileDownloadPending) { |
209 AddController(BOOKMARKS); | 256 AddController(BOOKMARKS); |
210 | 257 |
211 { | 258 { |
212 DataTypeManagerImpl dtm(&configurer_, &controllers_); | 259 DataTypeManagerImpl dtm(&configurer_, &controllers_); |
213 SetConfigureStartExpectation(); | 260 SetConfigureStartExpectation(); |
214 SetConfigureDoneExpectation(DataTypeManager::ABORTED); | 261 SetConfigureDoneExpectation(DataTypeManager::ABORTED); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 | 718 |
672 INSTANTIATE_TEST_CASE_P( | 719 INSTANTIATE_TEST_CASE_P( |
673 WithoutNigori, SyncDataTypeManagerImplTest, | 720 WithoutNigori, SyncDataTypeManagerImplTest, |
674 ::testing::Values(BackendDataTypeConfigurer::WITHOUT_NIGORI)); | 721 ::testing::Values(BackendDataTypeConfigurer::WITHOUT_NIGORI)); |
675 | 722 |
676 INSTANTIATE_TEST_CASE_P( | 723 INSTANTIATE_TEST_CASE_P( |
677 WithNigori, SyncDataTypeManagerImplTest, | 724 WithNigori, SyncDataTypeManagerImplTest, |
678 ::testing::Values(BackendDataTypeConfigurer::WITH_NIGORI)); | 725 ::testing::Values(BackendDataTypeConfigurer::WITH_NIGORI)); |
679 | 726 |
680 } // namespace browser_sync | 727 } // namespace browser_sync |
OLD | NEW |