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