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/data_type_manager_impl.h" | 5 #include "components/sync/driver/data_type_manager_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "components/sync/base/model_type.h" | 13 #include "components/sync/base/model_type.h" |
14 #include "components/sync/core/activation_context.h" | 14 #include "components/sync/core/activation_context.h" |
15 #include "components/sync/core/configure_reason.h" | 15 #include "components/sync/core/configure_reason.h" |
16 #include "components/sync/driver/backend_data_type_configurer.h" | 16 #include "components/sync/driver/backend_data_type_configurer.h" |
17 #include "components/sync/driver/data_type_encryption_handler.h" | 17 #include "components/sync/driver/data_type_encryption_handler.h" |
18 #include "components/sync/driver/data_type_manager_observer.h" | 18 #include "components/sync/driver/data_type_manager_observer.h" |
19 #include "components/sync/driver/data_type_status_table.h" | 19 #include "components/sync/driver/data_type_status_table.h" |
20 #include "components/sync/driver/fake_data_type_controller.h" | 20 #include "components/sync/driver/fake_data_type_controller.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace syncer { | 23 namespace sync_driver { |
| 24 |
| 25 using syncer::SyncError; |
| 26 using syncer::ModelType; |
| 27 using syncer::ModelTypeSet; |
| 28 using syncer::ModelTypeToString; |
| 29 using syncer::BOOKMARKS; |
| 30 using syncer::APPS; |
| 31 using syncer::PASSWORDS; |
| 32 using syncer::PREFERENCES; |
| 33 using syncer::NIGORI; |
24 | 34 |
25 namespace { | 35 namespace { |
26 | 36 |
27 // Helper for unioning with control types. | 37 // Helper for unioning with control types. |
28 ModelTypeSet AddControlTypesTo(ModelTypeSet types) { | 38 ModelTypeSet AddControlTypesTo(ModelTypeSet types) { |
29 ModelTypeSet result = ControlTypes(); | 39 ModelTypeSet result = syncer::ControlTypes(); |
30 result.PutAll(types); | 40 result.PutAll(types); |
31 return result; | 41 return result; |
32 } | 42 } |
33 | 43 |
34 DataTypeStatusTable BuildStatusTable(ModelTypeSet crypto_errors, | 44 DataTypeStatusTable BuildStatusTable(ModelTypeSet crypto_errors, |
35 ModelTypeSet association_errors, | 45 ModelTypeSet association_errors, |
36 ModelTypeSet unready_errors, | 46 ModelTypeSet unready_errors, |
37 ModelTypeSet unrecoverable_errors) { | 47 ModelTypeSet unrecoverable_errors) { |
38 DataTypeStatusTable::TypeErrorMap error_map; | 48 DataTypeStatusTable::TypeErrorMap error_map; |
39 for (ModelTypeSet::Iterator iter = crypto_errors.First(); iter.Good(); | 49 for (ModelTypeSet::Iterator iter = crypto_errors.First(); iter.Good(); |
(...skipping 22 matching lines...) Expand all Loading... |
62 return status_table; | 72 return status_table; |
63 } | 73 } |
64 | 74 |
65 // Fake BackendDataTypeConfigurer implementation that simply stores away the | 75 // Fake BackendDataTypeConfigurer implementation that simply stores away the |
66 // callback passed into ConfigureDataTypes. | 76 // callback passed into ConfigureDataTypes. |
67 class FakeBackendDataTypeConfigurer : public BackendDataTypeConfigurer { | 77 class FakeBackendDataTypeConfigurer : public BackendDataTypeConfigurer { |
68 public: | 78 public: |
69 FakeBackendDataTypeConfigurer() : configure_call_count_(0) {} | 79 FakeBackendDataTypeConfigurer() : configure_call_count_(0) {} |
70 ~FakeBackendDataTypeConfigurer() override {} | 80 ~FakeBackendDataTypeConfigurer() override {} |
71 | 81 |
72 ModelTypeSet ConfigureDataTypes( | 82 syncer::ModelTypeSet ConfigureDataTypes( |
73 ConfigureReason reason, | 83 syncer::ConfigureReason reason, |
74 const DataTypeConfigStateMap& config_state_map, | 84 const DataTypeConfigStateMap& config_state_map, |
75 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, | 85 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, |
76 const base::Callback<void()>& retry_callback) override { | 86 const base::Callback<void()>& retry_callback) override { |
77 configure_call_count_++; | 87 configure_call_count_++; |
78 last_ready_task_ = ready_task; | 88 last_ready_task_ = ready_task; |
79 | 89 |
80 for (auto iter = expected_configure_types_.begin(); | 90 for (auto iter = expected_configure_types_.begin(); |
81 iter != expected_configure_types_.end(); ++iter) { | 91 iter != expected_configure_types_.end(); ++iter) { |
82 if (!iter->second.Empty()) { | 92 if (!iter->second.Empty()) { |
83 EXPECT_TRUE(iter->second == | 93 EXPECT_TRUE(iter->second == |
84 GetDataTypesInState(iter->first, config_state_map)) | 94 GetDataTypesInState(iter->first, config_state_map)) |
85 << "State " << iter->first << " : " | 95 << "State " << iter->first << " : " |
86 << ModelTypeSetToString(iter->second) << " v.s. " | 96 << ModelTypeSetToString(iter->second) << " v.s. " |
87 << ModelTypeSetToString( | 97 << ModelTypeSetToString( |
88 GetDataTypesInState(iter->first, config_state_map)); | 98 GetDataTypesInState(iter->first, config_state_map)); |
89 } | 99 } |
90 } | 100 } |
91 return ready_types_; | 101 return ready_types_; |
92 } | 102 } |
93 | 103 |
94 void ActivateDirectoryDataType(ModelType type, | 104 void ActivateDirectoryDataType(syncer::ModelType type, |
95 ModelSafeGroup group, | 105 syncer::ModelSafeGroup group, |
96 ChangeProcessor* change_processor) override { | 106 ChangeProcessor* change_processor) override { |
97 activated_types_.Put(type); | 107 activated_types_.Put(type); |
98 } | 108 } |
99 void DeactivateDirectoryDataType(ModelType type) override { | 109 void DeactivateDirectoryDataType(syncer::ModelType type) override { |
100 activated_types_.Remove(type); | 110 activated_types_.Remove(type); |
101 } | 111 } |
102 | 112 |
103 void ActivateNonBlockingDataType( | 113 void ActivateNonBlockingDataType(syncer::ModelType type, |
104 ModelType type, | 114 std::unique_ptr<syncer_v2::ActivationContext> |
105 std::unique_ptr<ActivationContext> activation_context) override { | 115 activation_context) override { |
106 // TODO(stanisc): crbug.com/515962: Add test coverage. | 116 // TODO(stanisc): crbug.com/515962: Add test coverage. |
107 } | 117 } |
108 | 118 |
109 void DeactivateNonBlockingDataType(ModelType type) override { | 119 void DeactivateNonBlockingDataType(syncer::ModelType type) override { |
110 // TODO(stanisc): crbug.com/515962: Add test coverage. | 120 // TODO(stanisc): crbug.com/515962: Add test coverage. |
111 } | 121 } |
112 | 122 |
113 base::Callback<void(ModelTypeSet, ModelTypeSet)> last_ready_task() const { | 123 base::Callback<void(ModelTypeSet, ModelTypeSet)> last_ready_task() const { |
114 return last_ready_task_; | 124 return last_ready_task_; |
115 } | 125 } |
116 | 126 |
117 void set_expected_configure_types(DataTypeConfigState config_state, | 127 void set_expected_configure_types(DataTypeConfigState config_state, |
118 ModelTypeSet types) { | 128 ModelTypeSet types) { |
119 expected_configure_types_[config_state] = types; | 129 expected_configure_types_[config_state] = types; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 222 |
213 ModelTypeSet FakeDataTypeEncryptionHandler::GetEncryptedDataTypes() const { | 223 ModelTypeSet FakeDataTypeEncryptionHandler::GetEncryptedDataTypes() const { |
214 return encrypted_types_; | 224 return encrypted_types_; |
215 } | 225 } |
216 | 226 |
217 } // namespace | 227 } // namespace |
218 | 228 |
219 class TestDataTypeManager : public DataTypeManagerImpl { | 229 class TestDataTypeManager : public DataTypeManagerImpl { |
220 public: | 230 public: |
221 TestDataTypeManager( | 231 TestDataTypeManager( |
222 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, | 232 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 233 debug_info_listener, |
223 BackendDataTypeConfigurer* configurer, | 234 BackendDataTypeConfigurer* configurer, |
224 const DataTypeController::TypeMap* controllers, | 235 const DataTypeController::TypeMap* controllers, |
225 const DataTypeEncryptionHandler* encryption_handler, | 236 const DataTypeEncryptionHandler* encryption_handler, |
226 DataTypeManagerObserver* observer) | 237 DataTypeManagerObserver* observer) |
227 : DataTypeManagerImpl(debug_info_listener, | 238 : DataTypeManagerImpl(debug_info_listener, |
228 controllers, | 239 controllers, |
229 encryption_handler, | 240 encryption_handler, |
230 configurer, | 241 configurer, |
231 observer), | 242 observer), |
232 custom_priority_types_(ControlTypes()) {} | 243 custom_priority_types_(syncer::ControlTypes()) {} |
233 | 244 |
234 void set_priority_types(const ModelTypeSet& priority_types) { | 245 void set_priority_types(const ModelTypeSet& priority_types) { |
235 custom_priority_types_ = priority_types; | 246 custom_priority_types_ = priority_types; |
236 } | 247 } |
237 | 248 |
238 DataTypeManager::ConfigureResult configure_result() const { | 249 DataTypeManager::ConfigureResult configure_result() const { |
239 return configure_result_; | 250 return configure_result_; |
240 } | 251 } |
241 | 252 |
242 void OnModelAssociationDone( | 253 void OnModelAssociationDone( |
(...skipping 14 matching lines...) Expand all Loading... |
257 // The actual test harness class, parametrized on nigori state (i.e., tests are | 268 // The actual test harness class, parametrized on nigori state (i.e., tests are |
258 // run both configuring with nigori, and configuring without). | 269 // run both configuring with nigori, and configuring without). |
259 class SyncDataTypeManagerImplTest : public testing::Test { | 270 class SyncDataTypeManagerImplTest : public testing::Test { |
260 public: | 271 public: |
261 SyncDataTypeManagerImplTest() {} | 272 SyncDataTypeManagerImplTest() {} |
262 | 273 |
263 ~SyncDataTypeManagerImplTest() override {} | 274 ~SyncDataTypeManagerImplTest() override {} |
264 | 275 |
265 protected: | 276 protected: |
266 void SetUp() override { | 277 void SetUp() override { |
267 dtm_.reset(new TestDataTypeManager(WeakHandle<DataTypeDebugInfoListener>(), | 278 dtm_.reset(new TestDataTypeManager( |
268 &configurer_, &controllers_, | 279 syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(), &configurer_, |
269 &encryption_handler_, &observer_)); | 280 &controllers_, &encryption_handler_, &observer_)); |
270 } | 281 } |
271 | 282 |
272 void SetConfigureStartExpectation() { observer_.ExpectStart(); } | 283 void SetConfigureStartExpectation() { observer_.ExpectStart(); } |
273 | 284 |
274 void SetConfigureDoneExpectation(DataTypeManager::ConfigureStatus status, | 285 void SetConfigureDoneExpectation(DataTypeManager::ConfigureStatus status, |
275 const DataTypeStatusTable& status_table) { | 286 const DataTypeStatusTable& status_table) { |
276 DataTypeManager::ConfigureResult result; | 287 DataTypeManager::ConfigureResult result; |
277 result.status = status; | 288 result.status = status; |
278 result.data_type_status_table = status_table; | 289 result.data_type_status_table = status_table; |
279 observer_.ExpectDone(result); | 290 observer_.ExpectDone(result); |
280 } | 291 } |
281 | 292 |
282 // Configure the given DTM with the given desired types. | 293 // Configure the given DTM with the given desired types. |
283 void Configure(DataTypeManagerImpl* dtm, const ModelTypeSet& desired_types) { | 294 void Configure(DataTypeManagerImpl* dtm, const ModelTypeSet& desired_types) { |
284 dtm->Configure(desired_types, CONFIGURE_REASON_RECONFIGURATION); | 295 dtm->Configure(desired_types, syncer::CONFIGURE_REASON_RECONFIGURATION); |
285 } | 296 } |
286 | 297 |
287 // Finish downloading for the given DTM. Should be done only after | 298 // Finish downloading for the given DTM. Should be done only after |
288 // a call to Configure(). | 299 // a call to Configure(). |
289 void FinishDownload(const DataTypeManager& dtm, | 300 void FinishDownload(const DataTypeManager& dtm, |
290 ModelTypeSet types_to_configure, | 301 ModelTypeSet types_to_configure, |
291 ModelTypeSet failed_download_types) { | 302 ModelTypeSet failed_download_types) { |
292 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm.state()); | 303 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm.state()); |
293 ASSERT_FALSE(configurer_.last_ready_task().is_null()); | 304 ASSERT_FALSE(configurer_.last_ready_task().is_null()); |
294 configurer_.last_ready_task().Run( | 305 configurer_.last_ready_task().Run( |
295 Difference(types_to_configure, failed_download_types), | 306 syncer::Difference(types_to_configure, failed_download_types), |
296 failed_download_types); | 307 failed_download_types); |
297 } | 308 } |
298 | 309 |
299 // Adds a fake controller for the given type to |controllers_|. | 310 // Adds a fake controller for the given type to |controllers_|. |
300 // Should be called only before setting up the DTM. | 311 // Should be called only before setting up the DTM. |
301 void AddController(ModelType model_type) { | 312 void AddController(ModelType model_type) { |
302 controllers_[model_type] = | 313 controllers_[model_type] = |
303 base::MakeUnique<FakeDataTypeController>(model_type); | 314 base::MakeUnique<FakeDataTypeController>(model_type); |
304 } | 315 } |
305 | 316 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); | 886 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); |
876 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); | 887 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); |
877 | 888 |
878 // We've now configured bookmarks and (implicitly) the control types. | 889 // We've now configured bookmarks and (implicitly) the control types. |
879 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); | 890 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); |
880 observer_.ResetExpectations(); | 891 observer_.ResetExpectations(); |
881 | 892 |
882 // Pretend we were told to migrate all types. | 893 // Pretend we were told to migrate all types. |
883 ModelTypeSet to_migrate; | 894 ModelTypeSet to_migrate; |
884 to_migrate.Put(BOOKMARKS); | 895 to_migrate.Put(BOOKMARKS); |
885 to_migrate.PutAll(ControlTypes()); | 896 to_migrate.PutAll(syncer::ControlTypes()); |
886 | 897 |
887 SetConfigureStartExpectation(); | 898 SetConfigureStartExpectation(); |
888 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); | 899 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); |
889 dtm_->PurgeForMigration(to_migrate, CONFIGURE_REASON_MIGRATION); | 900 dtm_->PurgeForMigration(to_migrate, syncer::CONFIGURE_REASON_MIGRATION); |
890 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 901 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
891 | 902 |
892 // The DTM will call ConfigureDataTypes(), even though it is unnecessary. | 903 // The DTM will call ConfigureDataTypes(), even though it is unnecessary. |
893 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); | 904 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); |
894 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); | 905 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); |
895 observer_.ResetExpectations(); | 906 observer_.ResetExpectations(); |
896 | 907 |
897 // Re-enable the migrated types. | 908 // Re-enable the migrated types. |
898 SetConfigureStartExpectation(); | 909 SetConfigureStartExpectation(); |
899 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); | 910 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); |
(...skipping 13 matching lines...) Expand all Loading... |
913 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); | 924 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); |
914 Configure(dtm_.get(), ModelTypeSet(BOOKMARKS)); | 925 Configure(dtm_.get(), ModelTypeSet(BOOKMARKS)); |
915 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); | 926 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); |
916 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); | 927 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); |
917 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); | 928 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); |
918 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); | 929 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); |
919 observer_.ResetExpectations(); | 930 observer_.ResetExpectations(); |
920 | 931 |
921 // Purge the Nigori type. | 932 // Purge the Nigori type. |
922 SetConfigureStartExpectation(); | 933 SetConfigureStartExpectation(); |
923 dtm_->PurgeForMigration(ModelTypeSet(NIGORI), CONFIGURE_REASON_MIGRATION); | 934 dtm_->PurgeForMigration(ModelTypeSet(NIGORI), |
| 935 syncer::CONFIGURE_REASON_MIGRATION); |
924 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 936 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
925 observer_.ResetExpectations(); | 937 observer_.ResetExpectations(); |
926 | 938 |
927 // Before the backend configuration completes, ask for a different | 939 // Before the backend configuration completes, ask for a different |
928 // set of types. This request asks for | 940 // set of types. This request asks for |
929 // - BOOKMARKS: which is redundant because it was already enabled, | 941 // - BOOKMARKS: which is redundant because it was already enabled, |
930 // - PREFERENCES: which is new and will need to be downloaded, and | 942 // - PREFERENCES: which is new and will need to be downloaded, and |
931 // - NIGORI: (added implicitly because it is a control type) which | 943 // - NIGORI: (added implicitly because it is a control type) which |
932 // the DTM is part-way through purging. | 944 // the DTM is part-way through purging. |
933 Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES)); | 945 Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES)); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 GetController(BOOKMARKS)->state()); | 1167 GetController(BOOKMARKS)->state()); |
1156 | 1168 |
1157 // Make PREFERENCES association fail. | 1169 // Make PREFERENCES association fail. |
1158 GetController(PREFERENCES) | 1170 GetController(PREFERENCES) |
1159 ->FinishStart(DataTypeController::ASSOCIATION_FAILED); | 1171 ->FinishStart(DataTypeController::ASSOCIATION_FAILED); |
1160 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1172 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
1161 | 1173 |
1162 // Reconfigure without PREFERENCES after the BOOKMARKS download completes, | 1174 // Reconfigure without PREFERENCES after the BOOKMARKS download completes, |
1163 // then reconfigure with BOOKMARKS. | 1175 // then reconfigure with BOOKMARKS. |
1164 configurer_.set_expected_configure_types( | 1176 configurer_.set_expected_configure_types( |
1165 BackendDataTypeConfigurer::CONFIGURE_ACTIVE, ControlTypes()); | 1177 BackendDataTypeConfigurer::CONFIGURE_ACTIVE, syncer::ControlTypes()); |
1166 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); | 1178 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); |
1167 configurer_.set_expected_configure_types( | 1179 configurer_.set_expected_configure_types( |
1168 BackendDataTypeConfigurer::CONFIGURE_ACTIVE, ModelTypeSet(BOOKMARKS)); | 1180 BackendDataTypeConfigurer::CONFIGURE_ACTIVE, ModelTypeSet(BOOKMARKS)); |
1169 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); | 1181 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); |
1170 | 1182 |
1171 // Reconfigure with BOOKMARKS. | 1183 // Reconfigure with BOOKMARKS. |
1172 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); | 1184 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); |
1173 EXPECT_EQ(DataTypeController::ASSOCIATING, GetController(BOOKMARKS)->state()); | 1185 EXPECT_EQ(DataTypeController::ASSOCIATING, GetController(BOOKMARKS)->state()); |
1174 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); | 1186 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); |
1175 | 1187 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 | 1248 |
1237 TEST_F(SyncDataTypeManagerImplTest, FilterDesiredTypes) { | 1249 TEST_F(SyncDataTypeManagerImplTest, FilterDesiredTypes) { |
1238 AddController(BOOKMARKS); | 1250 AddController(BOOKMARKS); |
1239 | 1251 |
1240 ModelTypeSet types(BOOKMARKS, APPS); | 1252 ModelTypeSet types(BOOKMARKS, APPS); |
1241 dtm_->set_priority_types(AddControlTypesTo(types)); | 1253 dtm_->set_priority_types(AddControlTypesTo(types)); |
1242 | 1254 |
1243 SetConfigureStartExpectation(); | 1255 SetConfigureStartExpectation(); |
1244 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); | 1256 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); |
1245 | 1257 |
1246 ModelTypeSet expected_types = ControlTypes(); | 1258 ModelTypeSet expected_types = syncer::ControlTypes(); |
1247 expected_types.Put(BOOKMARKS); | 1259 expected_types.Put(BOOKMARKS); |
1248 // APPS is filtered out because there's no controller for it. | 1260 // APPS is filtered out because there's no controller for it. |
1249 configurer_.set_expected_configure_types( | 1261 configurer_.set_expected_configure_types( |
1250 BackendDataTypeConfigurer::CONFIGURE_ACTIVE, expected_types); | 1262 BackendDataTypeConfigurer::CONFIGURE_ACTIVE, expected_types); |
1251 Configure(dtm_.get(), types); | 1263 Configure(dtm_.get(), types); |
1252 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); | 1264 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); |
1253 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); | 1265 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); |
1254 | 1266 |
1255 dtm_->Stop(); | 1267 dtm_->Stop(); |
1256 EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state()); | 1268 EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state()); |
(...skipping 17 matching lines...) Expand all Loading... |
1274 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); // Reconfig for error. | 1286 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); // Reconfig for error. |
1275 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); // Reconfig for error. | 1287 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); // Reconfig for error. |
1276 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); | 1288 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); |
1277 EXPECT_EQ(DataTypeController::RUNNING, GetController(PREFERENCES)->state()); | 1289 EXPECT_EQ(DataTypeController::RUNNING, GetController(PREFERENCES)->state()); |
1278 EXPECT_EQ(DataTypeController::NOT_RUNNING, GetController(BOOKMARKS)->state()); | 1290 EXPECT_EQ(DataTypeController::NOT_RUNNING, GetController(BOOKMARKS)->state()); |
1279 | 1291 |
1280 observer_.ResetExpectations(); | 1292 observer_.ResetExpectations(); |
1281 | 1293 |
1282 // Re-enable bookmarks. | 1294 // Re-enable bookmarks. |
1283 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); | 1295 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); |
1284 dtm_->ReenableType(BOOKMARKS); | 1296 dtm_->ReenableType(syncer::BOOKMARKS); |
1285 | 1297 |
1286 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1298 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
1287 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); | 1299 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); |
1288 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); | 1300 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); |
1289 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1301 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
1290 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); | 1302 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); |
1291 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); | 1303 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); |
1292 EXPECT_EQ(DataTypeController::RUNNING, GetController(PREFERENCES)->state()); | 1304 EXPECT_EQ(DataTypeController::RUNNING, GetController(PREFERENCES)->state()); |
1293 EXPECT_EQ(DataTypeController::RUNNING, GetController(BOOKMARKS)->state()); | 1305 EXPECT_EQ(DataTypeController::RUNNING, GetController(BOOKMARKS)->state()); |
1294 | 1306 |
1295 // Should do nothing. | 1307 // Should do nothing. |
1296 dtm_->ReenableType(BOOKMARKS); | 1308 dtm_->ReenableType(syncer::BOOKMARKS); |
1297 } | 1309 } |
1298 | 1310 |
1299 TEST_F(SyncDataTypeManagerImplTest, UnreadyType) { | 1311 TEST_F(SyncDataTypeManagerImplTest, UnreadyType) { |
1300 AddController(BOOKMARKS); | 1312 AddController(BOOKMARKS); |
1301 GetController(BOOKMARKS)->SetReadyForStart(false); | 1313 GetController(BOOKMARKS)->SetReadyForStart(false); |
1302 | 1314 |
1303 // Bookmarks is never started due to being unready. | 1315 // Bookmarks is never started due to being unready. |
1304 SetConfigureStartExpectation(); | 1316 SetConfigureStartExpectation(); |
1305 SetConfigureDoneExpectation( | 1317 SetConfigureDoneExpectation( |
1306 DataTypeManager::OK, | 1318 DataTypeManager::OK, |
(...skipping 24 matching lines...) Expand all Loading... |
1331 observer_.ResetExpectations(); | 1343 observer_.ResetExpectations(); |
1332 dtm_->ReenableType(BOOKMARKS); | 1344 dtm_->ReenableType(BOOKMARKS); |
1333 | 1345 |
1334 dtm_->Stop(); | 1346 dtm_->Stop(); |
1335 EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state()); | 1347 EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state()); |
1336 EXPECT_TRUE(configurer_.activated_types().Empty()); | 1348 EXPECT_TRUE(configurer_.activated_types().Empty()); |
1337 } | 1349 } |
1338 | 1350 |
1339 TEST_F(SyncDataTypeManagerImplTest, ModelLoadError) { | 1351 TEST_F(SyncDataTypeManagerImplTest, ModelLoadError) { |
1340 AddController(BOOKMARKS); | 1352 AddController(BOOKMARKS); |
1341 GetController(BOOKMARKS)->SetModelLoadError( | 1353 GetController(BOOKMARKS)->SetModelLoadError(syncer::SyncError( |
1342 SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, "load error", BOOKMARKS)); | 1354 FROM_HERE, SyncError::DATATYPE_ERROR, "load error", BOOKMARKS)); |
1343 | 1355 |
1344 // Bookmarks is never started due to hitting a model load error. | 1356 // Bookmarks is never started due to hitting a model load error. |
1345 SetConfigureStartExpectation(); | 1357 SetConfigureStartExpectation(); |
1346 SetConfigureDoneExpectation( | 1358 SetConfigureDoneExpectation( |
1347 DataTypeManager::OK, | 1359 DataTypeManager::OK, |
1348 BuildStatusTable(ModelTypeSet(), ModelTypeSet(BOOKMARKS), ModelTypeSet(), | 1360 BuildStatusTable(ModelTypeSet(), ModelTypeSet(BOOKMARKS), ModelTypeSet(), |
1349 ModelTypeSet())); | 1361 ModelTypeSet())); |
1350 Configure(dtm_.get(), ModelTypeSet(BOOKMARKS)); | 1362 Configure(dtm_.get(), ModelTypeSet(BOOKMARKS)); |
1351 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); | 1363 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); |
1352 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); | 1364 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); |
1353 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); | 1365 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); |
1354 EXPECT_EQ(DataTypeController::NOT_RUNNING, GetController(BOOKMARKS)->state()); | 1366 EXPECT_EQ(DataTypeController::NOT_RUNNING, GetController(BOOKMARKS)->state()); |
1355 | 1367 |
1356 EXPECT_EQ(0U, configurer_.activated_types().Size()); | 1368 EXPECT_EQ(0U, configurer_.activated_types().Size()); |
1357 } | 1369 } |
1358 | 1370 |
1359 TEST_F(SyncDataTypeManagerImplTest, ErrorBeforeAssociation) { | 1371 TEST_F(SyncDataTypeManagerImplTest, ErrorBeforeAssociation) { |
1360 AddController(BOOKMARKS); | 1372 AddController(BOOKMARKS); |
1361 | 1373 |
1362 // Bookmarks is never started due to hitting a datatype error while the DTM | 1374 // Bookmarks is never started due to hitting a datatype error while the DTM |
1363 // is still downloading types. | 1375 // is still downloading types. |
1364 SetConfigureStartExpectation(); | 1376 SetConfigureStartExpectation(); |
1365 SetConfigureDoneExpectation( | 1377 SetConfigureDoneExpectation( |
1366 DataTypeManager::OK, | 1378 DataTypeManager::OK, |
1367 BuildStatusTable(ModelTypeSet(), ModelTypeSet(BOOKMARKS), ModelTypeSet(), | 1379 BuildStatusTable(ModelTypeSet(), ModelTypeSet(BOOKMARKS), ModelTypeSet(), |
1368 ModelTypeSet())); | 1380 ModelTypeSet())); |
1369 Configure(dtm_.get(), ModelTypeSet(BOOKMARKS)); | 1381 Configure(dtm_.get(), ModelTypeSet(BOOKMARKS)); |
1370 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); | 1382 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); |
1371 GetController(BOOKMARKS)->CreateErrorHandler()->OnUnrecoverableError( | 1383 GetController(BOOKMARKS)->CreateErrorHandler()->OnUnrecoverableError( |
1372 SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, "bookmarks error", | 1384 syncer::SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, "bookmarks error", |
1373 BOOKMARKS)); | 1385 BOOKMARKS)); |
1374 base::RunLoop().RunUntilIdle(); | 1386 base::RunLoop().RunUntilIdle(); |
1375 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); | 1387 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet()); |
1376 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); // Reconfig for error. | 1388 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); // Reconfig for error. |
1377 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); | 1389 EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state()); |
1378 EXPECT_EQ(DataTypeController::NOT_RUNNING, GetController(BOOKMARKS)->state()); | 1390 EXPECT_EQ(DataTypeController::NOT_RUNNING, GetController(BOOKMARKS)->state()); |
1379 | 1391 |
1380 EXPECT_EQ(0U, configurer_.activated_types().Size()); | 1392 EXPECT_EQ(0U, configurer_.activated_types().Size()); |
1381 } | 1393 } |
1382 | 1394 |
1383 TEST_F(SyncDataTypeManagerImplTest, AssociationNeverCompletes) { | 1395 TEST_F(SyncDataTypeManagerImplTest, AssociationNeverCompletes) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1561 AddController(BOOKMARKS); | 1573 AddController(BOOKMARKS); |
1562 AddController(PASSWORDS); | 1574 AddController(PASSWORDS); |
1563 | 1575 |
1564 SetConfigureStartExpectation(); | 1576 SetConfigureStartExpectation(); |
1565 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); | 1577 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); |
1566 configurer_.set_expected_configure_types( | 1578 configurer_.set_expected_configure_types( |
1567 BackendDataTypeConfigurer::CONFIGURE_CLEAN, | 1579 BackendDataTypeConfigurer::CONFIGURE_CLEAN, |
1568 AddControlTypesTo(ModelTypeSet(BOOKMARKS, PASSWORDS))); | 1580 AddControlTypesTo(ModelTypeSet(BOOKMARKS, PASSWORDS))); |
1569 | 1581 |
1570 dtm_->Configure(ModelTypeSet(BOOKMARKS, PASSWORDS), | 1582 dtm_->Configure(ModelTypeSet(BOOKMARKS, PASSWORDS), |
1571 CONFIGURE_REASON_CATCH_UP); | 1583 syncer::CONFIGURE_REASON_CATCH_UP); |
1572 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1584 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
1573 | 1585 |
1574 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); | 1586 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); |
1575 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PASSWORDS), ModelTypeSet()); | 1587 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PASSWORDS), ModelTypeSet()); |
1576 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1588 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
1577 | 1589 |
1578 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); | 1590 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); |
1579 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1591 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
1580 EXPECT_EQ(1U, configurer_.activated_types().Size()); | 1592 EXPECT_EQ(1U, configurer_.activated_types().Size()); |
1581 GetController(PASSWORDS)->FinishStart(DataTypeController::OK); | 1593 GetController(PASSWORDS)->FinishStart(DataTypeController::OK); |
(...skipping 12 matching lines...) Expand all Loading... |
1594 AddController(BOOKMARKS); | 1606 AddController(BOOKMARKS); |
1595 AddController(PASSWORDS); | 1607 AddController(PASSWORDS); |
1596 | 1608 |
1597 SetConfigureStartExpectation(); | 1609 SetConfigureStartExpectation(); |
1598 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); | 1610 SetConfigureDoneExpectation(DataTypeManager::OK, DataTypeStatusTable()); |
1599 | 1611 |
1600 // Configure (catch up) with one type. | 1612 // Configure (catch up) with one type. |
1601 configurer_.set_expected_configure_types( | 1613 configurer_.set_expected_configure_types( |
1602 BackendDataTypeConfigurer::CONFIGURE_CLEAN, | 1614 BackendDataTypeConfigurer::CONFIGURE_CLEAN, |
1603 AddControlTypesTo(ModelTypeSet(BOOKMARKS))); | 1615 AddControlTypesTo(ModelTypeSet(BOOKMARKS))); |
1604 dtm_->Configure(ModelTypeSet(BOOKMARKS), CONFIGURE_REASON_CATCH_UP); | 1616 dtm_->Configure(ModelTypeSet(BOOKMARKS), syncer::CONFIGURE_REASON_CATCH_UP); |
1605 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1617 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
1606 | 1618 |
1607 // Configure with both types before the first one completes. Both types should | 1619 // Configure with both types before the first one completes. Both types should |
1608 // end up in CONFIGURE_CLEAN. | 1620 // end up in CONFIGURE_CLEAN. |
1609 configurer_.set_expected_configure_types( | 1621 configurer_.set_expected_configure_types( |
1610 BackendDataTypeConfigurer::CONFIGURE_CLEAN, | 1622 BackendDataTypeConfigurer::CONFIGURE_CLEAN, |
1611 AddControlTypesTo(ModelTypeSet(BOOKMARKS, PASSWORDS))); | 1623 AddControlTypesTo(ModelTypeSet(BOOKMARKS, PASSWORDS))); |
1612 dtm_->Configure(ModelTypeSet(BOOKMARKS, PASSWORDS), | 1624 dtm_->Configure(ModelTypeSet(BOOKMARKS, PASSWORDS), |
1613 CONFIGURE_REASON_RECONFIGURATION); | 1625 syncer::CONFIGURE_REASON_RECONFIGURATION); |
1614 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1626 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
1615 | 1627 |
1616 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); | 1628 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); |
1617 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1629 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
1618 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); | 1630 FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet()); |
1619 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PASSWORDS), ModelTypeSet()); | 1631 FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PASSWORDS), ModelTypeSet()); |
1620 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1632 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
1621 | 1633 |
1622 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); | 1634 GetController(BOOKMARKS)->FinishStart(DataTypeController::OK); |
1623 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); | 1635 EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 EXPECT_EQ(DataTypeController::MODEL_STARTING, | 1683 EXPECT_EQ(DataTypeController::MODEL_STARTING, |
1672 GetController(PASSWORDS)->state()); | 1684 GetController(PASSWORDS)->state()); |
1673 EXPECT_EQ(0, GetController(BOOKMARKS)->register_with_backend_call_count()); | 1685 EXPECT_EQ(0, GetController(BOOKMARKS)->register_with_backend_call_count()); |
1674 EXPECT_EQ(0, GetController(PASSWORDS)->register_with_backend_call_count()); | 1686 EXPECT_EQ(0, GetController(PASSWORDS)->register_with_backend_call_count()); |
1675 | 1687 |
1676 dtm_->OnAllDataTypesReadyForConfigure(); | 1688 dtm_->OnAllDataTypesReadyForConfigure(); |
1677 EXPECT_EQ(0, GetController(BOOKMARKS)->register_with_backend_call_count()); | 1689 EXPECT_EQ(0, GetController(BOOKMARKS)->register_with_backend_call_count()); |
1678 EXPECT_EQ(1, GetController(PASSWORDS)->register_with_backend_call_count()); | 1690 EXPECT_EQ(1, GetController(PASSWORDS)->register_with_backend_call_count()); |
1679 } | 1691 } |
1680 | 1692 |
1681 } // namespace syncer | 1693 } // namespace sync_driver |
OLD | NEW |