| 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/model_association_manager.h" | 5 #include "components/sync/driver/model_association_manager.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ptr_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" |
| 9 #include "components/sync/driver/fake_data_type_controller.h" | 11 #include "components/sync/driver/fake_data_type_controller.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 14 |
| 13 using ::testing::_; | 15 using ::testing::_; |
| 14 | 16 |
| 15 namespace sync_driver { | 17 namespace sync_driver { |
| 16 | 18 |
| 17 class MockModelAssociationManagerDelegate | 19 class MockModelAssociationManagerDelegate |
| 18 : public ModelAssociationManagerDelegate { | 20 : public ModelAssociationManagerDelegate { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 protected: | 53 protected: |
| 52 base::MessageLoopForUI ui_loop_; | 54 base::MessageLoopForUI ui_loop_; |
| 53 MockModelAssociationManagerDelegate delegate_; | 55 MockModelAssociationManagerDelegate delegate_; |
| 54 DataTypeController::TypeMap controllers_; | 56 DataTypeController::TypeMap controllers_; |
| 55 }; | 57 }; |
| 56 | 58 |
| 57 // Start a type and make sure ModelAssociationManager callst the |Start| | 59 // Start a type and make sure ModelAssociationManager callst the |Start| |
| 58 // method and calls the callback when it is done. | 60 // method and calls the callback when it is done. |
| 59 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { | 61 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { |
| 60 controllers_[syncer::BOOKMARKS] = | 62 controllers_[syncer::BOOKMARKS] = |
| 61 new FakeDataTypeController(syncer::BOOKMARKS); | 63 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 62 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); | 64 controllers_[syncer::APPS] = |
| 65 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 63 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 66 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 64 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | 67 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); |
| 65 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 68 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 66 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 69 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
| 67 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 70 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 68 .WillOnce(VerifyResult(expected_result)); | 71 .WillOnce(VerifyResult(expected_result)); |
| 69 | 72 |
| 70 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 73 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 71 DataTypeController::NOT_RUNNING); | 74 DataTypeController::NOT_RUNNING); |
| 72 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 75 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 88 DataTypeController::ASSOCIATING); | 91 DataTypeController::ASSOCIATING); |
| 89 GetController(controllers_, syncer::BOOKMARKS) | 92 GetController(controllers_, syncer::BOOKMARKS) |
| 90 ->FinishStart(DataTypeController::OK); | 93 ->FinishStart(DataTypeController::OK); |
| 91 GetController(controllers_, syncer::APPS) | 94 GetController(controllers_, syncer::APPS) |
| 92 ->FinishStart(DataTypeController::OK); | 95 ->FinishStart(DataTypeController::OK); |
| 93 } | 96 } |
| 94 | 97 |
| 95 // Start a type and call stop before it finishes associating. | 98 // Start a type and call stop before it finishes associating. |
| 96 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { | 99 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { |
| 97 controllers_[syncer::BOOKMARKS] = | 100 controllers_[syncer::BOOKMARKS] = |
| 98 new FakeDataTypeController(syncer::BOOKMARKS); | 101 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 99 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 102 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 100 | 103 |
| 101 syncer::ModelTypeSet types; | 104 syncer::ModelTypeSet types; |
| 102 types.Put(syncer::BOOKMARKS); | 105 types.Put(syncer::BOOKMARKS); |
| 103 | 106 |
| 104 DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, | 107 DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, |
| 105 types); | 108 types); |
| 106 | 109 |
| 107 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 110 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 108 .WillOnce(VerifyResult(expected_result)); | 111 .WillOnce(VerifyResult(expected_result)); |
| 109 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 112 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 110 | 113 |
| 111 model_association_manager.Initialize(types); | 114 model_association_manager.Initialize(types); |
| 112 model_association_manager.StartAssociationAsync(types); | 115 model_association_manager.StartAssociationAsync(types); |
| 113 | 116 |
| 114 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 117 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 115 DataTypeController::ASSOCIATING); | 118 DataTypeController::ASSOCIATING); |
| 116 model_association_manager.Stop(); | 119 model_association_manager.Stop(); |
| 117 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 120 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 118 DataTypeController::NOT_RUNNING); | 121 DataTypeController::NOT_RUNNING); |
| 119 } | 122 } |
| 120 | 123 |
| 121 // Start a type, let it finish and then call stop. | 124 // Start a type, let it finish and then call stop. |
| 122 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { | 125 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { |
| 123 controllers_[syncer::BOOKMARKS] = | 126 controllers_[syncer::BOOKMARKS] = |
| 124 new FakeDataTypeController(syncer::BOOKMARKS); | 127 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 125 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 128 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 126 syncer::ModelTypeSet types; | 129 syncer::ModelTypeSet types; |
| 127 types.Put(syncer::BOOKMARKS); | 130 types.Put(syncer::BOOKMARKS); |
| 128 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 131 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 129 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 132 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 130 .WillOnce(VerifyResult(expected_result)); | 133 .WillOnce(VerifyResult(expected_result)); |
| 131 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 134 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 132 | 135 |
| 133 model_association_manager.Initialize(types); | 136 model_association_manager.Initialize(types); |
| 134 model_association_manager.StartAssociationAsync(types); | 137 model_association_manager.StartAssociationAsync(types); |
| 135 | 138 |
| 136 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 139 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 137 DataTypeController::ASSOCIATING); | 140 DataTypeController::ASSOCIATING); |
| 138 GetController(controllers_, syncer::BOOKMARKS) | 141 GetController(controllers_, syncer::BOOKMARKS) |
| 139 ->FinishStart(DataTypeController::OK); | 142 ->FinishStart(DataTypeController::OK); |
| 140 | 143 |
| 141 model_association_manager.Stop(); | 144 model_association_manager.Stop(); |
| 142 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 145 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 143 DataTypeController::NOT_RUNNING); | 146 DataTypeController::NOT_RUNNING); |
| 144 } | 147 } |
| 145 | 148 |
| 146 // Make a type fail model association and verify correctness. | 149 // Make a type fail model association and verify correctness. |
| 147 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { | 150 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { |
| 148 controllers_[syncer::BOOKMARKS] = | 151 controllers_[syncer::BOOKMARKS] = |
| 149 new FakeDataTypeController(syncer::BOOKMARKS); | 152 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 150 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 153 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 151 syncer::ModelTypeSet types; | 154 syncer::ModelTypeSet types; |
| 152 types.Put(syncer::BOOKMARKS); | 155 types.Put(syncer::BOOKMARKS); |
| 153 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 156 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 154 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 157 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 155 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 158 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 156 .WillOnce(VerifyResult(expected_result)); | 159 .WillOnce(VerifyResult(expected_result)); |
| 157 | 160 |
| 158 model_association_manager.Initialize(types); | 161 model_association_manager.Initialize(types); |
| 159 model_association_manager.StartAssociationAsync(types); | 162 model_association_manager.StartAssociationAsync(types); |
| 160 | 163 |
| 161 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 164 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 162 DataTypeController::ASSOCIATING); | 165 DataTypeController::ASSOCIATING); |
| 163 GetController(controllers_, syncer::BOOKMARKS) | 166 GetController(controllers_, syncer::BOOKMARKS) |
| 164 ->FinishStart(DataTypeController::ASSOCIATION_FAILED); | 167 ->FinishStart(DataTypeController::ASSOCIATION_FAILED); |
| 165 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 168 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 166 DataTypeController::NOT_RUNNING); | 169 DataTypeController::NOT_RUNNING); |
| 167 } | 170 } |
| 168 | 171 |
| 169 // Ensure configuring stops when a type returns a unrecoverable error. | 172 // Ensure configuring stops when a type returns a unrecoverable error. |
| 170 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { | 173 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { |
| 171 controllers_[syncer::BOOKMARKS] = | 174 controllers_[syncer::BOOKMARKS] = |
| 172 new FakeDataTypeController(syncer::BOOKMARKS); | 175 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 173 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 176 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 174 syncer::ModelTypeSet types; | 177 syncer::ModelTypeSet types; |
| 175 types.Put(syncer::BOOKMARKS); | 178 types.Put(syncer::BOOKMARKS); |
| 176 DataTypeManager::ConfigureResult expected_result( | 179 DataTypeManager::ConfigureResult expected_result( |
| 177 DataTypeManager::UNRECOVERABLE_ERROR, types); | 180 DataTypeManager::UNRECOVERABLE_ERROR, types); |
| 178 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 181 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 179 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 182 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 180 .WillOnce(VerifyResult(expected_result)); | 183 .WillOnce(VerifyResult(expected_result)); |
| 181 | 184 |
| 182 model_association_manager.Initialize(types); | 185 model_association_manager.Initialize(types); |
| 183 | 186 |
| 184 model_association_manager.StartAssociationAsync(types); | 187 model_association_manager.StartAssociationAsync(types); |
| 185 | 188 |
| 186 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 189 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 187 DataTypeController::ASSOCIATING); | 190 DataTypeController::ASSOCIATING); |
| 188 GetController(controllers_, syncer::BOOKMARKS) | 191 GetController(controllers_, syncer::BOOKMARKS) |
| 189 ->FinishStart(DataTypeController::UNRECOVERABLE_ERROR); | 192 ->FinishStart(DataTypeController::UNRECOVERABLE_ERROR); |
| 190 } | 193 } |
| 191 | 194 |
| 192 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { | 195 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { |
| 193 controllers_[syncer::BOOKMARKS] = | 196 controllers_[syncer::BOOKMARKS] = |
| 194 new FakeDataTypeController(syncer::BOOKMARKS); | 197 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 195 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); | 198 controllers_[syncer::APPS] = |
| 199 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 196 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | 200 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
| 197 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 201 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 198 syncer::ModelTypeSet types; | 202 syncer::ModelTypeSet types; |
| 199 types.Put(syncer::BOOKMARKS); | 203 types.Put(syncer::BOOKMARKS); |
| 200 types.Put(syncer::APPS); | 204 types.Put(syncer::APPS); |
| 201 | 205 |
| 202 DataTypeManager::ConfigureResult expected_result_partially_done( | 206 DataTypeManager::ConfigureResult expected_result_partially_done( |
| 203 DataTypeManager::OK, types); | 207 DataTypeManager::OK, types); |
| 204 | 208 |
| 205 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 209 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 206 .WillOnce(VerifyResult(expected_result_partially_done)); | 210 .WillOnce(VerifyResult(expected_result_partially_done)); |
| 207 | 211 |
| 208 model_association_manager.Initialize(types); | 212 model_association_manager.Initialize(types); |
| 209 model_association_manager.StartAssociationAsync(types); | 213 model_association_manager.StartAssociationAsync(types); |
| 210 GetController(controllers_, syncer::APPS) | 214 GetController(controllers_, syncer::APPS) |
| 211 ->FinishStart(DataTypeController::OK); | 215 ->FinishStart(DataTypeController::OK); |
| 212 | 216 |
| 213 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 217 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 214 model_association_manager.GetTimerForTesting()->user_task().Run(); | 218 model_association_manager.GetTimerForTesting()->user_task().Run(); |
| 215 | 219 |
| 216 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 220 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 217 GetController(controllers_, syncer::BOOKMARKS)->state()); | 221 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 218 } | 222 } |
| 219 | 223 |
| 220 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { | 224 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { |
| 221 controllers_[syncer::BOOKMARKS] = | 225 controllers_[syncer::BOOKMARKS] = |
| 222 new FakeDataTypeController(syncer::BOOKMARKS); | 226 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 223 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); | 227 controllers_[syncer::APPS] = |
| 228 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 224 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 229 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 225 syncer::ModelTypeSet types; | 230 syncer::ModelTypeSet types; |
| 226 types.Put(syncer::BOOKMARKS); | 231 types.Put(syncer::BOOKMARKS); |
| 227 types.Put(syncer::APPS); | 232 types.Put(syncer::APPS); |
| 228 | 233 |
| 229 DataTypeManager::ConfigureResult result_1st( | 234 DataTypeManager::ConfigureResult result_1st( |
| 230 DataTypeManager::OK, syncer::ModelTypeSet(syncer::BOOKMARKS)); | 235 DataTypeManager::OK, syncer::ModelTypeSet(syncer::BOOKMARKS)); |
| 231 DataTypeManager::ConfigureResult result_2nd( | 236 DataTypeManager::ConfigureResult result_2nd( |
| 232 DataTypeManager::OK, syncer::ModelTypeSet(syncer::APPS)); | 237 DataTypeManager::OK, syncer::ModelTypeSet(syncer::APPS)); |
| 233 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 238 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 261 GetController(controllers_, syncer::APPS) | 266 GetController(controllers_, syncer::APPS) |
| 262 ->FinishStart(DataTypeController::OK); | 267 ->FinishStart(DataTypeController::OK); |
| 263 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 268 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 264 DataTypeController::RUNNING); | 269 DataTypeController::RUNNING); |
| 265 } | 270 } |
| 266 | 271 |
| 267 // Test that model that failed to load between initialization and association | 272 // Test that model that failed to load between initialization and association |
| 268 // is reported and stopped properly. | 273 // is reported and stopped properly. |
| 269 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { | 274 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { |
| 270 controllers_[syncer::BOOKMARKS] = | 275 controllers_[syncer::BOOKMARKS] = |
| 271 new FakeDataTypeController(syncer::BOOKMARKS); | 276 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 272 GetController(controllers_, syncer::BOOKMARKS) | 277 GetController(controllers_, syncer::BOOKMARKS) |
| 273 ->SetModelLoadError(syncer::SyncError( | 278 ->SetModelLoadError(syncer::SyncError( |
| 274 FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "", syncer::BOOKMARKS)); | 279 FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "", syncer::BOOKMARKS)); |
| 275 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 280 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 276 syncer::ModelTypeSet types; | 281 syncer::ModelTypeSet types; |
| 277 types.Put(syncer::BOOKMARKS); | 282 types.Put(syncer::BOOKMARKS); |
| 278 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 283 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 279 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 284 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 280 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 285 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 281 .WillOnce(VerifyResult(expected_result)); | 286 .WillOnce(VerifyResult(expected_result)); |
| 282 | 287 |
| 283 model_association_manager.Initialize(types); | 288 model_association_manager.Initialize(types); |
| 284 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 289 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 285 GetController(controllers_, syncer::BOOKMARKS)->state()); | 290 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 286 model_association_manager.StartAssociationAsync(types); | 291 model_association_manager.StartAssociationAsync(types); |
| 287 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 292 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 288 GetController(controllers_, syncer::BOOKMARKS)->state()); | 293 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 289 } | 294 } |
| 290 | 295 |
| 291 // Test that a runtime error is handled by stopping the type. | 296 // Test that a runtime error is handled by stopping the type. |
| 292 TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { | 297 TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { |
| 293 controllers_[syncer::BOOKMARKS] = | 298 controllers_[syncer::BOOKMARKS] = |
| 294 new FakeDataTypeController(syncer::BOOKMARKS); | 299 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 295 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 300 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 296 syncer::ModelTypeSet types; | 301 syncer::ModelTypeSet types; |
| 297 types.Put(syncer::BOOKMARKS); | 302 types.Put(syncer::BOOKMARKS); |
| 298 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 303 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 299 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 304 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 300 .WillOnce(VerifyResult(expected_result)); | 305 .WillOnce(VerifyResult(expected_result)); |
| 301 | 306 |
| 302 model_association_manager.Initialize(types); | 307 model_association_manager.Initialize(types); |
| 303 model_association_manager.StartAssociationAsync(types); | 308 model_association_manager.StartAssociationAsync(types); |
| 304 | 309 |
| 305 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 310 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 306 DataTypeController::ASSOCIATING); | 311 DataTypeController::ASSOCIATING); |
| 307 GetController(controllers_, syncer::BOOKMARKS) | 312 GetController(controllers_, syncer::BOOKMARKS) |
| 308 ->FinishStart(DataTypeController::OK); | 313 ->FinishStart(DataTypeController::OK); |
| 309 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 314 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 310 DataTypeController::RUNNING); | 315 DataTypeController::RUNNING); |
| 311 | 316 |
| 312 testing::Mock::VerifyAndClearExpectations(&delegate_); | 317 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 313 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 318 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 314 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", | 319 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", |
| 315 syncer::BOOKMARKS); | 320 syncer::BOOKMARKS); |
| 316 GetController(controllers_, syncer::BOOKMARKS) | 321 GetController(controllers_, syncer::BOOKMARKS) |
| 317 ->OnSingleDataTypeUnrecoverableError(error); | 322 ->CreateErrorHandler() |
| 323 ->OnUnrecoverableError(error); |
| 324 base::RunLoop().RunUntilIdle(); |
| 318 } | 325 } |
| 319 | 326 |
| 320 TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { | 327 TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { |
| 321 controllers_[syncer::BOOKMARKS] = | 328 controllers_[syncer::BOOKMARKS] = |
| 322 new FakeDataTypeController(syncer::BOOKMARKS); | 329 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 323 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); | 330 controllers_[syncer::APPS] = |
| 331 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 324 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 332 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 325 syncer::ModelTypeSet types; | 333 syncer::ModelTypeSet types; |
| 326 types.Put(syncer::BOOKMARKS); | 334 types.Put(syncer::BOOKMARKS); |
| 327 types.Put(syncer::APPS); | 335 types.Put(syncer::APPS); |
| 328 | 336 |
| 329 syncer::ModelTypeSet expected_types_unfinished; | 337 syncer::ModelTypeSet expected_types_unfinished; |
| 330 expected_types_unfinished.Put(syncer::BOOKMARKS); | 338 expected_types_unfinished.Put(syncer::BOOKMARKS); |
| 331 DataTypeManager::ConfigureResult expected_result_partially_done( | 339 DataTypeManager::ConfigureResult expected_result_partially_done( |
| 332 DataTypeManager::OK, types); | 340 DataTypeManager::OK, types); |
| 333 | 341 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 348 | 356 |
| 349 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 357 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 350 GetController(controllers_, syncer::BOOKMARKS)->state()); | 358 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 351 } | 359 } |
| 352 | 360 |
| 353 // Test that OnAllDataTypesReadyForConfigure is called when all datatypes that | 361 // Test that OnAllDataTypesReadyForConfigure is called when all datatypes that |
| 354 // require LoadModels before configuration are loaded. | 362 // require LoadModels before configuration are loaded. |
| 355 TEST_F(SyncModelAssociationManagerTest, OnAllDataTypesReadyForConfigure) { | 363 TEST_F(SyncModelAssociationManagerTest, OnAllDataTypesReadyForConfigure) { |
| 356 // Create two controllers with delayed model load. | 364 // Create two controllers with delayed model load. |
| 357 controllers_[syncer::BOOKMARKS] = | 365 controllers_[syncer::BOOKMARKS] = |
| 358 new FakeDataTypeController(syncer::BOOKMARKS); | 366 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 359 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); | 367 controllers_[syncer::APPS] = |
| 368 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 360 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | 369 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
| 361 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); | 370 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); |
| 362 | 371 |
| 363 // APPS controller requires LoadModels complete before configure. | 372 // APPS controller requires LoadModels complete before configure. |
| 364 GetController(controllers_, syncer::APPS) | 373 GetController(controllers_, syncer::APPS) |
| 365 ->SetShouldLoadModelBeforeConfigure(true); | 374 ->SetShouldLoadModelBeforeConfigure(true); |
| 366 | 375 |
| 367 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 376 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 368 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | 377 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); |
| 369 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 378 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 396 | 405 |
| 397 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 406 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
| 398 syncer::ModelTypeSet reduced_types(syncer::APPS); | 407 syncer::ModelTypeSet reduced_types(syncer::APPS); |
| 399 model_association_manager.Initialize(reduced_types); | 408 model_association_manager.Initialize(reduced_types); |
| 400 } | 409 } |
| 401 | 410 |
| 402 // Test that OnAllDataTypesReadyForConfigure() is called correctly after | 411 // Test that OnAllDataTypesReadyForConfigure() is called correctly after |
| 403 // LoadModels fails for one of datatypes. | 412 // LoadModels fails for one of datatypes. |
| 404 TEST_F(SyncModelAssociationManagerTest, | 413 TEST_F(SyncModelAssociationManagerTest, |
| 405 OnAllDataTypesReadyForConfigure_FailedLoadModels) { | 414 OnAllDataTypesReadyForConfigure_FailedLoadModels) { |
| 406 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); | 415 controllers_[syncer::APPS] = |
| 416 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 407 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); | 417 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); |
| 408 | 418 |
| 409 // APPS controller requires LoadModels complete before configure. | 419 // APPS controller requires LoadModels complete before configure. |
| 410 GetController(controllers_, syncer::APPS) | 420 GetController(controllers_, syncer::APPS) |
| 411 ->SetShouldLoadModelBeforeConfigure(true); | 421 ->SetShouldLoadModelBeforeConfigure(true); |
| 412 | 422 |
| 413 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 423 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 414 syncer::ModelTypeSet types(syncer::APPS); | 424 syncer::ModelTypeSet types(syncer::APPS); |
| 415 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 425 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 416 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not | 426 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not |
| (...skipping 18 matching lines...) Expand all Loading... |
| 435 DataTypeController::NOT_RUNNING); | 445 DataTypeController::NOT_RUNNING); |
| 436 } | 446 } |
| 437 | 447 |
| 438 // Test that if one of the types fails while another is still being loaded then | 448 // Test that if one of the types fails while another is still being loaded then |
| 439 // OnAllDataTypesReadyForConfgiure is still called correctly. | 449 // OnAllDataTypesReadyForConfgiure is still called correctly. |
| 440 TEST_F(SyncModelAssociationManagerTest, | 450 TEST_F(SyncModelAssociationManagerTest, |
| 441 OnAllDataTypesReadyForConfigure_TypeFailedAfterLoadModels) { | 451 OnAllDataTypesReadyForConfigure_TypeFailedAfterLoadModels) { |
| 442 // Create two controllers with delayed model load. Both should block | 452 // Create two controllers with delayed model load. Both should block |
| 443 // configuration. | 453 // configuration. |
| 444 controllers_[syncer::BOOKMARKS] = | 454 controllers_[syncer::BOOKMARKS] = |
| 445 new FakeDataTypeController(syncer::BOOKMARKS); | 455 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 446 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); | 456 controllers_[syncer::APPS] = |
| 457 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 447 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | 458 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
| 448 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); | 459 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); |
| 449 | 460 |
| 450 GetController(controllers_, syncer::BOOKMARKS) | 461 GetController(controllers_, syncer::BOOKMARKS) |
| 451 ->SetShouldLoadModelBeforeConfigure(true); | 462 ->SetShouldLoadModelBeforeConfigure(true); |
| 452 GetController(controllers_, syncer::APPS) | 463 GetController(controllers_, syncer::APPS) |
| 453 ->SetShouldLoadModelBeforeConfigure(true); | 464 ->SetShouldLoadModelBeforeConfigure(true); |
| 454 | 465 |
| 455 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 466 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 456 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | 467 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 471 | 482 |
| 472 testing::Mock::VerifyAndClearExpectations(&delegate_); | 483 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 473 | 484 |
| 474 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | 485 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); |
| 475 | 486 |
| 476 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::APPS, _)); | 487 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::APPS, _)); |
| 477 // Apps datatype reports failure. | 488 // Apps datatype reports failure. |
| 478 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", | 489 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", |
| 479 syncer::APPS); | 490 syncer::APPS); |
| 480 GetController(controllers_, syncer::APPS) | 491 GetController(controllers_, syncer::APPS) |
| 481 ->OnSingleDataTypeUnrecoverableError(error); | 492 ->CreateErrorHandler() |
| 493 ->OnUnrecoverableError(error); |
| 494 base::RunLoop().RunUntilIdle(); |
| 482 | 495 |
| 483 testing::Mock::VerifyAndClearExpectations(&delegate_); | 496 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 484 | 497 |
| 485 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 498 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
| 486 // Finish loading BOOKMARKS. This should trigger | 499 // Finish loading BOOKMARKS. This should trigger |
| 487 // OnAllDataTypesReadyForConfigure(). | 500 // OnAllDataTypesReadyForConfigure(). |
| 488 GetController(controllers_, syncer::BOOKMARKS)->SimulateModelLoadFinishing(); | 501 GetController(controllers_, syncer::BOOKMARKS)->SimulateModelLoadFinishing(); |
| 489 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 502 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 490 DataTypeController::MODEL_LOADED); | 503 DataTypeController::MODEL_LOADED); |
| 491 } | 504 } |
| 492 | 505 |
| 493 } // namespace sync_driver | 506 } // namespace sync_driver |
| OLD | NEW |