| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/sync_driver/model_association_manager.h" | |
| 6 | |
| 7 #include "base/callback.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "components/sync_driver/fake_data_type_controller.h" | |
| 10 #include "testing/gmock/include/gmock/gmock.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 using ::testing::_; | |
| 14 | |
| 15 namespace sync_driver { | |
| 16 | |
| 17 class MockModelAssociationManagerDelegate : | |
| 18 public ModelAssociationManagerDelegate { | |
| 19 public: | |
| 20 MockModelAssociationManagerDelegate() {} | |
| 21 ~MockModelAssociationManagerDelegate() {} | |
| 22 MOCK_METHOD0(OnAllDataTypesReadyForConfigure, void()); | |
| 23 MOCK_METHOD2(OnSingleDataTypeAssociationDone, | |
| 24 void(syncer::ModelType type, | |
| 25 const syncer::DataTypeAssociationStats& association_stats)); | |
| 26 MOCK_METHOD2(OnSingleDataTypeWillStop, | |
| 27 void(syncer::ModelType, const syncer::SyncError& error)); | |
| 28 MOCK_METHOD1(OnModelAssociationDone, void( | |
| 29 const DataTypeManager::ConfigureResult& result)); | |
| 30 }; | |
| 31 | |
| 32 FakeDataTypeController* GetController( | |
| 33 const DataTypeController::TypeMap& controllers, | |
| 34 syncer::ModelType model_type) { | |
| 35 DataTypeController::TypeMap::const_iterator it = | |
| 36 controllers.find(model_type); | |
| 37 if (it == controllers.end()) { | |
| 38 return NULL; | |
| 39 } | |
| 40 return static_cast<FakeDataTypeController*>(it->second.get()); | |
| 41 } | |
| 42 | |
| 43 ACTION_P(VerifyResult, expected_result) { | |
| 44 EXPECT_EQ(arg0.status, expected_result.status); | |
| 45 EXPECT_EQ(expected_result.requested_types, arg0.requested_types); | |
| 46 } | |
| 47 | |
| 48 class SyncModelAssociationManagerTest : public testing::Test { | |
| 49 public: | |
| 50 SyncModelAssociationManagerTest() { | |
| 51 } | |
| 52 | |
| 53 protected: | |
| 54 base::MessageLoopForUI ui_loop_; | |
| 55 MockModelAssociationManagerDelegate delegate_; | |
| 56 DataTypeController::TypeMap controllers_; | |
| 57 }; | |
| 58 | |
| 59 // Start a type and make sure ModelAssociationManager callst the |Start| | |
| 60 // method and calls the callback when it is done. | |
| 61 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { | |
| 62 controllers_[syncer::BOOKMARKS] = | |
| 63 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 64 controllers_[syncer::APPS] = | |
| 65 new FakeDataTypeController(syncer::APPS); | |
| 66 ModelAssociationManager model_association_manager(&controllers_, | |
| 67 &delegate_); | |
| 68 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | |
| 69 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | |
| 70 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | |
| 71 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | |
| 72 WillOnce(VerifyResult(expected_result)); | |
| 73 | |
| 74 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 75 DataTypeController::NOT_RUNNING); | |
| 76 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 77 DataTypeController::NOT_RUNNING); | |
| 78 | |
| 79 // Initialize() kicks off model loading. | |
| 80 model_association_manager.Initialize(types); | |
| 81 | |
| 82 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 83 DataTypeController::MODEL_LOADED); | |
| 84 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 85 DataTypeController::MODEL_LOADED); | |
| 86 | |
| 87 model_association_manager.StartAssociationAsync(types); | |
| 88 | |
| 89 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 90 DataTypeController::ASSOCIATING); | |
| 91 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 92 DataTypeController::ASSOCIATING); | |
| 93 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | |
| 94 DataTypeController::OK); | |
| 95 GetController(controllers_, syncer::APPS)->FinishStart( | |
| 96 DataTypeController::OK); | |
| 97 } | |
| 98 | |
| 99 // Start a type and call stop before it finishes associating. | |
| 100 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { | |
| 101 controllers_[syncer::BOOKMARKS] = | |
| 102 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 103 ModelAssociationManager model_association_manager( | |
| 104 &controllers_, | |
| 105 &delegate_); | |
| 106 | |
| 107 syncer::ModelTypeSet types; | |
| 108 types.Put(syncer::BOOKMARKS); | |
| 109 | |
| 110 DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, | |
| 111 types); | |
| 112 | |
| 113 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | |
| 114 WillOnce(VerifyResult(expected_result)); | |
| 115 EXPECT_CALL(delegate_, | |
| 116 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 117 | |
| 118 model_association_manager.Initialize(types); | |
| 119 model_association_manager.StartAssociationAsync(types); | |
| 120 | |
| 121 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 122 DataTypeController::ASSOCIATING); | |
| 123 model_association_manager.Stop(); | |
| 124 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 125 DataTypeController::NOT_RUNNING); | |
| 126 } | |
| 127 | |
| 128 // Start a type, let it finish and then call stop. | |
| 129 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { | |
| 130 controllers_[syncer::BOOKMARKS] = | |
| 131 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 132 ModelAssociationManager model_association_manager( | |
| 133 &controllers_, | |
| 134 &delegate_); | |
| 135 syncer::ModelTypeSet types; | |
| 136 types.Put(syncer::BOOKMARKS); | |
| 137 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | |
| 138 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | |
| 139 WillOnce(VerifyResult(expected_result)); | |
| 140 EXPECT_CALL(delegate_, | |
| 141 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 142 | |
| 143 model_association_manager.Initialize(types); | |
| 144 model_association_manager.StartAssociationAsync(types); | |
| 145 | |
| 146 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 147 DataTypeController::ASSOCIATING); | |
| 148 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | |
| 149 DataTypeController::OK); | |
| 150 | |
| 151 model_association_manager.Stop(); | |
| 152 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 153 DataTypeController::NOT_RUNNING); | |
| 154 } | |
| 155 | |
| 156 // Make a type fail model association and verify correctness. | |
| 157 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { | |
| 158 controllers_[syncer::BOOKMARKS] = | |
| 159 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 160 ModelAssociationManager model_association_manager( | |
| 161 &controllers_, | |
| 162 &delegate_); | |
| 163 syncer::ModelTypeSet types; | |
| 164 types.Put(syncer::BOOKMARKS); | |
| 165 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | |
| 166 EXPECT_CALL(delegate_, | |
| 167 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 168 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | |
| 169 WillOnce(VerifyResult(expected_result)); | |
| 170 | |
| 171 model_association_manager.Initialize(types); | |
| 172 model_association_manager.StartAssociationAsync(types); | |
| 173 | |
| 174 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 175 DataTypeController::ASSOCIATING); | |
| 176 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | |
| 177 DataTypeController::ASSOCIATION_FAILED); | |
| 178 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 179 DataTypeController::NOT_RUNNING); | |
| 180 } | |
| 181 | |
| 182 // Ensure configuring stops when a type returns a unrecoverable error. | |
| 183 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { | |
| 184 controllers_[syncer::BOOKMARKS] = | |
| 185 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 186 ModelAssociationManager model_association_manager( | |
| 187 &controllers_, | |
| 188 &delegate_); | |
| 189 syncer::ModelTypeSet types; | |
| 190 types.Put(syncer::BOOKMARKS); | |
| 191 DataTypeManager::ConfigureResult expected_result( | |
| 192 DataTypeManager::UNRECOVERABLE_ERROR, types); | |
| 193 EXPECT_CALL(delegate_, | |
| 194 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 195 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | |
| 196 WillOnce(VerifyResult(expected_result)); | |
| 197 | |
| 198 model_association_manager.Initialize(types); | |
| 199 | |
| 200 model_association_manager.StartAssociationAsync(types); | |
| 201 | |
| 202 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 203 DataTypeController::ASSOCIATING); | |
| 204 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | |
| 205 DataTypeController::UNRECOVERABLE_ERROR); | |
| 206 } | |
| 207 | |
| 208 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { | |
| 209 controllers_[syncer::BOOKMARKS] = | |
| 210 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 211 controllers_[syncer::APPS] = | |
| 212 new FakeDataTypeController(syncer::APPS); | |
| 213 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | |
| 214 ModelAssociationManager model_association_manager(&controllers_, | |
| 215 &delegate_); | |
| 216 syncer::ModelTypeSet types; | |
| 217 types.Put(syncer::BOOKMARKS); | |
| 218 types.Put(syncer::APPS); | |
| 219 | |
| 220 DataTypeManager::ConfigureResult expected_result_partially_done( | |
| 221 DataTypeManager::OK, types); | |
| 222 | |
| 223 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | |
| 224 WillOnce(VerifyResult(expected_result_partially_done)); | |
| 225 | |
| 226 model_association_manager.Initialize(types); | |
| 227 model_association_manager.StartAssociationAsync(types); | |
| 228 GetController(controllers_, syncer::APPS)->FinishStart( | |
| 229 DataTypeController::OK); | |
| 230 | |
| 231 EXPECT_CALL(delegate_, | |
| 232 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 233 model_association_manager.GetTimerForTesting()->user_task().Run(); | |
| 234 | |
| 235 EXPECT_EQ(DataTypeController::NOT_RUNNING, | |
| 236 GetController(controllers_, syncer::BOOKMARKS)->state()); | |
| 237 } | |
| 238 | |
| 239 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { | |
| 240 controllers_[syncer::BOOKMARKS] = | |
| 241 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 242 controllers_[syncer::APPS] = | |
| 243 new FakeDataTypeController(syncer::APPS); | |
| 244 ModelAssociationManager model_association_manager(&controllers_, | |
| 245 &delegate_); | |
| 246 syncer::ModelTypeSet types; | |
| 247 types.Put(syncer::BOOKMARKS); | |
| 248 types.Put(syncer::APPS); | |
| 249 | |
| 250 DataTypeManager::ConfigureResult result_1st( | |
| 251 DataTypeManager::OK, | |
| 252 syncer::ModelTypeSet(syncer::BOOKMARKS)); | |
| 253 DataTypeManager::ConfigureResult result_2nd( | |
| 254 DataTypeManager::OK, | |
| 255 syncer::ModelTypeSet(syncer::APPS)); | |
| 256 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | |
| 257 Times(2). | |
| 258 WillOnce(VerifyResult(result_1st)). | |
| 259 WillOnce(VerifyResult(result_2nd)); | |
| 260 | |
| 261 model_association_manager.Initialize(types); | |
| 262 | |
| 263 // Start BOOKMARKS first. | |
| 264 model_association_manager.StartAssociationAsync( | |
| 265 syncer::ModelTypeSet(syncer::BOOKMARKS)); | |
| 266 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 267 DataTypeController::ASSOCIATING); | |
| 268 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 269 DataTypeController::MODEL_LOADED); | |
| 270 | |
| 271 // Finish BOOKMARKS association. | |
| 272 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | |
| 273 DataTypeController::OK); | |
| 274 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 275 DataTypeController::RUNNING); | |
| 276 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 277 DataTypeController::MODEL_LOADED); | |
| 278 | |
| 279 // Start APPS next. | |
| 280 model_association_manager.StartAssociationAsync( | |
| 281 syncer::ModelTypeSet(syncer::APPS)); | |
| 282 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 283 DataTypeController::ASSOCIATING); | |
| 284 GetController(controllers_, syncer::APPS)->FinishStart( | |
| 285 DataTypeController::OK); | |
| 286 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 287 DataTypeController::RUNNING); | |
| 288 } | |
| 289 | |
| 290 // Test that model that failed to load between initialization and association | |
| 291 // is reported and stopped properly. | |
| 292 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { | |
| 293 controllers_[syncer::BOOKMARKS] = | |
| 294 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 295 GetController(controllers_, syncer::BOOKMARKS)->SetModelLoadError( | |
| 296 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, | |
| 297 "", syncer::BOOKMARKS)); | |
| 298 ModelAssociationManager model_association_manager( | |
| 299 &controllers_, | |
| 300 &delegate_); | |
| 301 syncer::ModelTypeSet types; | |
| 302 types.Put(syncer::BOOKMARKS); | |
| 303 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | |
| 304 EXPECT_CALL(delegate_, | |
| 305 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 306 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | |
| 307 WillOnce(VerifyResult(expected_result)); | |
| 308 | |
| 309 model_association_manager.Initialize(types); | |
| 310 EXPECT_EQ(DataTypeController::NOT_RUNNING, | |
| 311 GetController(controllers_, syncer::BOOKMARKS)->state()); | |
| 312 model_association_manager.StartAssociationAsync(types); | |
| 313 EXPECT_EQ(DataTypeController::NOT_RUNNING, | |
| 314 GetController(controllers_, syncer::BOOKMARKS)->state()); | |
| 315 } | |
| 316 | |
| 317 // Test that a runtime error is handled by stopping the type. | |
| 318 TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { | |
| 319 controllers_[syncer::BOOKMARKS] = | |
| 320 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 321 ModelAssociationManager model_association_manager( | |
| 322 &controllers_, | |
| 323 &delegate_); | |
| 324 syncer::ModelTypeSet types; | |
| 325 types.Put(syncer::BOOKMARKS); | |
| 326 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | |
| 327 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | |
| 328 WillOnce(VerifyResult(expected_result)); | |
| 329 | |
| 330 model_association_manager.Initialize(types); | |
| 331 model_association_manager.StartAssociationAsync(types); | |
| 332 | |
| 333 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 334 DataTypeController::ASSOCIATING); | |
| 335 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | |
| 336 DataTypeController::OK); | |
| 337 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 338 DataTypeController::RUNNING); | |
| 339 | |
| 340 testing::Mock::VerifyAndClearExpectations(&delegate_); | |
| 341 EXPECT_CALL(delegate_, | |
| 342 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 343 syncer::SyncError error(FROM_HERE, | |
| 344 syncer::SyncError::DATATYPE_ERROR, | |
| 345 "error", | |
| 346 syncer::BOOKMARKS); | |
| 347 GetController(controllers_, syncer::BOOKMARKS) | |
| 348 ->OnSingleDataTypeUnrecoverableError(error); | |
| 349 } | |
| 350 | |
| 351 TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { | |
| 352 controllers_[syncer::BOOKMARKS] = | |
| 353 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 354 controllers_[syncer::APPS] = | |
| 355 new FakeDataTypeController(syncer::APPS); | |
| 356 ModelAssociationManager model_association_manager(&controllers_, | |
| 357 &delegate_); | |
| 358 syncer::ModelTypeSet types; | |
| 359 types.Put(syncer::BOOKMARKS); | |
| 360 types.Put(syncer::APPS); | |
| 361 | |
| 362 syncer::ModelTypeSet expected_types_unfinished; | |
| 363 expected_types_unfinished.Put(syncer::BOOKMARKS); | |
| 364 DataTypeManager::ConfigureResult expected_result_partially_done( | |
| 365 DataTypeManager::OK, types); | |
| 366 | |
| 367 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | |
| 368 WillOnce(VerifyResult(expected_result_partially_done)); | |
| 369 | |
| 370 model_association_manager.Initialize(types); | |
| 371 model_association_manager.StartAssociationAsync(types); | |
| 372 GetController(controllers_, syncer::APPS)->FinishStart( | |
| 373 DataTypeController::OK); | |
| 374 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 375 DataTypeController::RUNNING); | |
| 376 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 377 DataTypeController::ASSOCIATING); | |
| 378 | |
| 379 EXPECT_CALL(delegate_, | |
| 380 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 381 model_association_manager.GetTimerForTesting()->user_task().Run(); | |
| 382 | |
| 383 EXPECT_EQ(DataTypeController::NOT_RUNNING, | |
| 384 GetController(controllers_, syncer::BOOKMARKS)->state()); | |
| 385 } | |
| 386 | |
| 387 // Test that OnAllDataTypesReadyForConfigure is called when all datatypes that | |
| 388 // require LoadModels before configuration are loaded. | |
| 389 TEST_F(SyncModelAssociationManagerTest, OnAllDataTypesReadyForConfigure) { | |
| 390 // Create two controllers with delayed model load. | |
| 391 controllers_[syncer::BOOKMARKS] = | |
| 392 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 393 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); | |
| 394 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | |
| 395 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); | |
| 396 | |
| 397 // APPS controller requires LoadModels complete before configure. | |
| 398 GetController(controllers_, syncer::APPS) | |
| 399 ->SetShouldLoadModelBeforeConfigure(true); | |
| 400 | |
| 401 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | |
| 402 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | |
| 403 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | |
| 404 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not | |
| 405 // loaded yet. | |
| 406 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | |
| 407 | |
| 408 model_association_manager.Initialize(types); | |
| 409 | |
| 410 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 411 DataTypeController::MODEL_STARTING); | |
| 412 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 413 DataTypeController::MODEL_STARTING); | |
| 414 | |
| 415 testing::Mock::VerifyAndClearExpectations(&delegate_); | |
| 416 | |
| 417 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | |
| 418 // Finish loading APPS. This should trigger OnAllDataTypesReadyForConfigure | |
| 419 // even though BOOKMARKS is not loaded yet. | |
| 420 GetController(controllers_, syncer::APPS)->SimulateModelLoadFinishing(); | |
| 421 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 422 DataTypeController::MODEL_STARTING); | |
| 423 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 424 DataTypeController::MODEL_LOADED); | |
| 425 | |
| 426 // Call ModelAssociationManager::Initialize with reduced set of datatypes. | |
| 427 // All datatypes in reduced set are already loaded. | |
| 428 // OnAllDataTypesReadyForConfigure() should be called. | |
| 429 testing::Mock::VerifyAndClearExpectations(&delegate_); | |
| 430 | |
| 431 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | |
| 432 syncer::ModelTypeSet reduced_types(syncer::APPS); | |
| 433 model_association_manager.Initialize(reduced_types); | |
| 434 } | |
| 435 | |
| 436 // Test that OnAllDataTypesReadyForConfigure() is called correctly after | |
| 437 // LoadModels fails for one of datatypes. | |
| 438 TEST_F(SyncModelAssociationManagerTest, | |
| 439 OnAllDataTypesReadyForConfigure_FailedLoadModels) { | |
| 440 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); | |
| 441 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); | |
| 442 | |
| 443 // APPS controller requires LoadModels complete before configure. | |
| 444 GetController(controllers_, syncer::APPS) | |
| 445 ->SetShouldLoadModelBeforeConfigure(true); | |
| 446 | |
| 447 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | |
| 448 syncer::ModelTypeSet types(syncer::APPS); | |
| 449 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | |
| 450 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not | |
| 451 // loaded yet. | |
| 452 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | |
| 453 | |
| 454 model_association_manager.Initialize(types); | |
| 455 | |
| 456 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 457 DataTypeController::MODEL_STARTING); | |
| 458 | |
| 459 testing::Mock::VerifyAndClearExpectations(&delegate_); | |
| 460 | |
| 461 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | |
| 462 // Simulate model load error for APPS and finish loading it. This should | |
| 463 // trigger OnAllDataTypesReadyForConfigure. | |
| 464 GetController(controllers_, syncer::APPS) | |
| 465 ->SetModelLoadError(syncer::SyncError( | |
| 466 FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "", syncer::APPS)); | |
| 467 GetController(controllers_, syncer::APPS)->SimulateModelLoadFinishing(); | |
| 468 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 469 DataTypeController::NOT_RUNNING); | |
| 470 } | |
| 471 | |
| 472 // Test that if one of the types fails while another is still being loaded then | |
| 473 // OnAllDataTypesReadyForConfgiure is still called correctly. | |
| 474 TEST_F(SyncModelAssociationManagerTest, | |
| 475 OnAllDataTypesReadyForConfigure_TypeFailedAfterLoadModels) { | |
| 476 // Create two controllers with delayed model load. Both should block | |
| 477 // configuration. | |
| 478 controllers_[syncer::BOOKMARKS] = | |
| 479 new FakeDataTypeController(syncer::BOOKMARKS); | |
| 480 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); | |
| 481 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | |
| 482 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); | |
| 483 | |
| 484 GetController(controllers_, syncer::BOOKMARKS) | |
| 485 ->SetShouldLoadModelBeforeConfigure(true); | |
| 486 GetController(controllers_, syncer::APPS) | |
| 487 ->SetShouldLoadModelBeforeConfigure(true); | |
| 488 | |
| 489 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | |
| 490 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | |
| 491 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | |
| 492 | |
| 493 // Apps will finish loading but bookmarks won't. | |
| 494 // OnAllDataTypesReadyForConfigure shouldn't be called. | |
| 495 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | |
| 496 | |
| 497 model_association_manager.Initialize(types); | |
| 498 | |
| 499 GetController(controllers_, syncer::APPS)->SimulateModelLoadFinishing(); | |
| 500 | |
| 501 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 502 DataTypeController::MODEL_STARTING); | |
| 503 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | |
| 504 DataTypeController::MODEL_LOADED); | |
| 505 | |
| 506 testing::Mock::VerifyAndClearExpectations(&delegate_); | |
| 507 | |
| 508 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | |
| 509 | |
| 510 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::APPS, _)); | |
| 511 // Apps datatype reports failure. | |
| 512 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", | |
| 513 syncer::APPS); | |
| 514 GetController(controllers_, syncer::APPS) | |
| 515 ->OnSingleDataTypeUnrecoverableError(error); | |
| 516 | |
| 517 testing::Mock::VerifyAndClearExpectations(&delegate_); | |
| 518 | |
| 519 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | |
| 520 // Finish loading BOOKMARKS. This should trigger | |
| 521 // OnAllDataTypesReadyForConfigure(). | |
| 522 GetController(controllers_, syncer::BOOKMARKS)->SimulateModelLoadFinishing(); | |
| 523 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | |
| 524 DataTypeController::MODEL_LOADED); | |
| 525 } | |
| 526 | |
| 527 } // namespace sync_driver | |
| OLD | NEW |