| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "chrome/browser/sync/glue/fake_data_type_controller.h" | 7 #include "chrome/browser/sync/glue/fake_data_type_controller.h" |
| 8 #include "chrome/browser/sync/glue/model_association_manager.h" | 8 #include "chrome/browser/sync/glue/model_association_manager.h" |
| 9 #include "content/public/test/test_browser_thread.h" | 9 #include "content/public/test/test_browser_thread.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using ::testing::_; | 13 using ::testing::_; |
| 14 namespace browser_sync { | 14 namespace browser_sync { |
| 15 class MockModelAssociationResultProcessor : | 15 class MockModelAssociationResultProcessor : |
| 16 public ModelAssociationResultProcessor { | 16 public ModelAssociationResultProcessor { |
| 17 public: | 17 public: |
| 18 MockModelAssociationResultProcessor() {} | 18 MockModelAssociationResultProcessor() {} |
| 19 ~MockModelAssociationResultProcessor() {} | 19 ~MockModelAssociationResultProcessor() {} |
| 20 MOCK_METHOD1(OnModelAssociationDone, void( | 20 MOCK_METHOD1(OnModelAssociationDone, void( |
| 21 const DataTypeManager::ConfigureResult& result)); | 21 const DataTypeManager::ConfigureResult& result)); |
| 22 MOCK_METHOD0(OnTypesLoaded, void()); | 22 MOCK_METHOD0(OnTypesLoaded, void()); |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 FakeDataTypeController* GetController( | 25 FakeDataTypeController* GetController( |
| 26 const DataTypeController::TypeMap& controllers, | 26 const DataTypeController::TypeMap& controllers, |
| 27 syncable::ModelType model_type) { | 27 syncer::ModelType model_type) { |
| 28 DataTypeController::TypeMap::const_iterator it = | 28 DataTypeController::TypeMap::const_iterator it = |
| 29 controllers.find(model_type); | 29 controllers.find(model_type); |
| 30 if (it == controllers.end()) { | 30 if (it == controllers.end()) { |
| 31 return NULL; | 31 return NULL; |
| 32 } | 32 } |
| 33 return (FakeDataTypeController*)(it->second.get()); | 33 return (FakeDataTypeController*)(it->second.get()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 ACTION_P(VerifyResult, expected_result) { | 36 ACTION_P(VerifyResult, expected_result) { |
| 37 EXPECT_EQ(arg0.status, expected_result.status); | 37 EXPECT_EQ(arg0.status, expected_result.status); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 62 protected: | 62 protected: |
| 63 MessageLoopForUI ui_loop_; | 63 MessageLoopForUI ui_loop_; |
| 64 content::TestBrowserThread ui_thread_; | 64 content::TestBrowserThread ui_thread_; |
| 65 MockModelAssociationResultProcessor result_processor_; | 65 MockModelAssociationResultProcessor result_processor_; |
| 66 DataTypeController::TypeMap controllers_; | 66 DataTypeController::TypeMap controllers_; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 // Start a type and make sure ModelAssociationManager callst the |Start| | 69 // Start a type and make sure ModelAssociationManager callst the |Start| |
| 70 // method and calls the callback when it is done. | 70 // method and calls the callback when it is done. |
| 71 TEST_F(ModelAssociationManagerTest, SimpleModelStart) { | 71 TEST_F(ModelAssociationManagerTest, SimpleModelStart) { |
| 72 controllers_[syncable::BOOKMARKS] = | 72 controllers_[syncer::BOOKMARKS] = |
| 73 new FakeDataTypeController(syncable::BOOKMARKS); | 73 new FakeDataTypeController(syncer::BOOKMARKS); |
| 74 ModelAssociationManager model_association_manager(&controllers_, | 74 ModelAssociationManager model_association_manager(&controllers_, |
| 75 &result_processor_); | 75 &result_processor_); |
| 76 syncable::ModelTypeSet types; | 76 syncer::ModelTypeSet types; |
| 77 types.Put(syncable::BOOKMARKS); | 77 types.Put(syncer::BOOKMARKS); |
| 78 DataTypeManager::ConfigureResult expected_result( | 78 DataTypeManager::ConfigureResult expected_result( |
| 79 DataTypeManager::OK, | 79 DataTypeManager::OK, |
| 80 types, | 80 types, |
| 81 std::list<syncer::SyncError>(), | 81 std::list<syncer::SyncError>(), |
| 82 syncable::ModelTypeSet()); | 82 syncer::ModelTypeSet()); |
| 83 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 83 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
| 84 WillOnce(VerifyResult(expected_result)); | 84 WillOnce(VerifyResult(expected_result)); |
| 85 | 85 |
| 86 model_association_manager.Initialize(types); | 86 model_association_manager.Initialize(types); |
| 87 model_association_manager.StopDisabledTypes(); | 87 model_association_manager.StopDisabledTypes(); |
| 88 model_association_manager.StartAssociationAsync(); | 88 model_association_manager.StartAssociationAsync(); |
| 89 | 89 |
| 90 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 90 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 91 DataTypeController::MODEL_LOADED); | 91 DataTypeController::MODEL_LOADED); |
| 92 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 92 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
| 93 DataTypeController::OK); | 93 DataTypeController::OK); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Start a type and call stop before it finishes associating. | 96 // Start a type and call stop before it finishes associating. |
| 97 TEST_F(ModelAssociationManagerTest, StopModelBeforeFinish) { | 97 TEST_F(ModelAssociationManagerTest, StopModelBeforeFinish) { |
| 98 controllers_[syncable::BOOKMARKS] = | 98 controllers_[syncer::BOOKMARKS] = |
| 99 new FakeDataTypeController(syncable::BOOKMARKS); | 99 new FakeDataTypeController(syncer::BOOKMARKS); |
| 100 ModelAssociationManager model_association_manager(&controllers_, | 100 ModelAssociationManager model_association_manager(&controllers_, |
| 101 &result_processor_); | 101 &result_processor_); |
| 102 | 102 |
| 103 syncable::ModelTypeSet types; | 103 syncer::ModelTypeSet types; |
| 104 types.Put(syncable::BOOKMARKS); | 104 types.Put(syncer::BOOKMARKS); |
| 105 | 105 |
| 106 DataTypeManager::ConfigureResult expected_result( | 106 DataTypeManager::ConfigureResult expected_result( |
| 107 DataTypeManager::ABORTED, | 107 DataTypeManager::ABORTED, |
| 108 types, | 108 types, |
| 109 std::list<syncer::SyncError>(), | 109 std::list<syncer::SyncError>(), |
| 110 syncable::ModelTypeSet()); | 110 syncer::ModelTypeSet()); |
| 111 | 111 |
| 112 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 112 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
| 113 WillOnce(VerifyResult(expected_result)); | 113 WillOnce(VerifyResult(expected_result)); |
| 114 | 114 |
| 115 model_association_manager.Initialize(types); | 115 model_association_manager.Initialize(types); |
| 116 model_association_manager.StopDisabledTypes(); | 116 model_association_manager.StopDisabledTypes(); |
| 117 model_association_manager.StartAssociationAsync(); | 117 model_association_manager.StartAssociationAsync(); |
| 118 | 118 |
| 119 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 119 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 120 DataTypeController::MODEL_LOADED); | 120 DataTypeController::MODEL_LOADED); |
| 121 model_association_manager.Stop(); | 121 model_association_manager.Stop(); |
| 122 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 122 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 123 DataTypeController::NOT_RUNNING); | 123 DataTypeController::NOT_RUNNING); |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Start a type, let it finish and then call stop. | 126 // Start a type, let it finish and then call stop. |
| 127 TEST_F(ModelAssociationManagerTest, StopAfterFinish) { | 127 TEST_F(ModelAssociationManagerTest, StopAfterFinish) { |
| 128 controllers_[syncable::BOOKMARKS] = | 128 controllers_[syncer::BOOKMARKS] = |
| 129 new FakeDataTypeController(syncable::BOOKMARKS); | 129 new FakeDataTypeController(syncer::BOOKMARKS); |
| 130 ModelAssociationManager model_association_manager(&controllers_, | 130 ModelAssociationManager model_association_manager(&controllers_, |
| 131 &result_processor_); | 131 &result_processor_); |
| 132 syncable::ModelTypeSet types; | 132 syncer::ModelTypeSet types; |
| 133 types.Put(syncable::BOOKMARKS); | 133 types.Put(syncer::BOOKMARKS); |
| 134 DataTypeManager::ConfigureResult expected_result( | 134 DataTypeManager::ConfigureResult expected_result( |
| 135 DataTypeManager::OK, | 135 DataTypeManager::OK, |
| 136 types, | 136 types, |
| 137 std::list<syncer::SyncError>(), | 137 std::list<syncer::SyncError>(), |
| 138 syncable::ModelTypeSet()); | 138 syncer::ModelTypeSet()); |
| 139 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 139 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
| 140 WillOnce(VerifyResult(expected_result)); | 140 WillOnce(VerifyResult(expected_result)); |
| 141 | 141 |
| 142 model_association_manager.Initialize(types); | 142 model_association_manager.Initialize(types); |
| 143 model_association_manager.StopDisabledTypes(); | 143 model_association_manager.StopDisabledTypes(); |
| 144 model_association_manager.StartAssociationAsync(); | 144 model_association_manager.StartAssociationAsync(); |
| 145 | 145 |
| 146 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 146 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 147 DataTypeController::MODEL_LOADED); | 147 DataTypeController::MODEL_LOADED); |
| 148 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 148 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
| 149 DataTypeController::OK); | 149 DataTypeController::OK); |
| 150 | 150 |
| 151 model_association_manager.Stop(); | 151 model_association_manager.Stop(); |
| 152 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 152 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 153 DataTypeController::NOT_RUNNING); | 153 DataTypeController::NOT_RUNNING); |
| 154 } | 154 } |
| 155 | 155 |
| 156 // Make a type fail model association and verify correctness. | 156 // Make a type fail model association and verify correctness. |
| 157 TEST_F(ModelAssociationManagerTest, TypeFailModelAssociation) { | 157 TEST_F(ModelAssociationManagerTest, TypeFailModelAssociation) { |
| 158 controllers_[syncable::BOOKMARKS] = | 158 controllers_[syncer::BOOKMARKS] = |
| 159 new FakeDataTypeController(syncable::BOOKMARKS); | 159 new FakeDataTypeController(syncer::BOOKMARKS); |
| 160 ModelAssociationManager model_association_manager(&controllers_, | 160 ModelAssociationManager model_association_manager(&controllers_, |
| 161 &result_processor_); | 161 &result_processor_); |
| 162 syncable::ModelTypeSet types; | 162 syncer::ModelTypeSet types; |
| 163 types.Put(syncable::BOOKMARKS); | 163 types.Put(syncer::BOOKMARKS); |
| 164 std::list<syncer::SyncError> errors; | 164 std::list<syncer::SyncError> errors; |
| 165 syncer::SyncError error(FROM_HERE, "Failed", syncable::BOOKMARKS); | 165 syncer::SyncError error(FROM_HERE, "Failed", syncer::BOOKMARKS); |
| 166 errors.push_back(error); | 166 errors.push_back(error); |
| 167 DataTypeManager::ConfigureResult expected_result( | 167 DataTypeManager::ConfigureResult expected_result( |
| 168 DataTypeManager::PARTIAL_SUCCESS, | 168 DataTypeManager::PARTIAL_SUCCESS, |
| 169 types, | 169 types, |
| 170 errors, | 170 errors, |
| 171 syncable::ModelTypeSet()); | 171 syncer::ModelTypeSet()); |
| 172 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 172 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
| 173 WillOnce(VerifyResult(expected_result)); | 173 WillOnce(VerifyResult(expected_result)); |
| 174 | 174 |
| 175 model_association_manager.Initialize(types); | 175 model_association_manager.Initialize(types); |
| 176 model_association_manager.StopDisabledTypes(); | 176 model_association_manager.StopDisabledTypes(); |
| 177 model_association_manager.StartAssociationAsync(); | 177 model_association_manager.StartAssociationAsync(); |
| 178 | 178 |
| 179 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 179 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 180 DataTypeController::MODEL_LOADED); | 180 DataTypeController::MODEL_LOADED); |
| 181 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 181 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
| 182 DataTypeController::ASSOCIATION_FAILED); | 182 DataTypeController::ASSOCIATION_FAILED); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Ensure configuring stops when a type returns a unrecoverable error. | 185 // Ensure configuring stops when a type returns a unrecoverable error. |
| 186 TEST_F(ModelAssociationManagerTest, TypeReturnUnrecoverableError) { | 186 TEST_F(ModelAssociationManagerTest, TypeReturnUnrecoverableError) { |
| 187 controllers_[syncable::BOOKMARKS] = | 187 controllers_[syncer::BOOKMARKS] = |
| 188 new FakeDataTypeController(syncable::BOOKMARKS); | 188 new FakeDataTypeController(syncer::BOOKMARKS); |
| 189 ModelAssociationManager model_association_manager(&controllers_, | 189 ModelAssociationManager model_association_manager(&controllers_, |
| 190 &result_processor_); | 190 &result_processor_); |
| 191 syncable::ModelTypeSet types; | 191 syncer::ModelTypeSet types; |
| 192 types.Put(syncable::BOOKMARKS); | 192 types.Put(syncer::BOOKMARKS); |
| 193 std::list<syncer::SyncError> errors; | 193 std::list<syncer::SyncError> errors; |
| 194 syncer::SyncError error(FROM_HERE, "Failed", syncable::BOOKMARKS); | 194 syncer::SyncError error(FROM_HERE, "Failed", syncer::BOOKMARKS); |
| 195 errors.push_back(error); | 195 errors.push_back(error); |
| 196 DataTypeManager::ConfigureResult expected_result( | 196 DataTypeManager::ConfigureResult expected_result( |
| 197 DataTypeManager::UNRECOVERABLE_ERROR, | 197 DataTypeManager::UNRECOVERABLE_ERROR, |
| 198 types, | 198 types, |
| 199 errors, | 199 errors, |
| 200 syncable::ModelTypeSet()); | 200 syncer::ModelTypeSet()); |
| 201 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 201 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
| 202 WillOnce(VerifyResult(expected_result)); | 202 WillOnce(VerifyResult(expected_result)); |
| 203 | 203 |
| 204 model_association_manager.Initialize(types); | 204 model_association_manager.Initialize(types); |
| 205 model_association_manager.StopDisabledTypes(); | 205 model_association_manager.StopDisabledTypes(); |
| 206 model_association_manager.StartAssociationAsync(); | 206 model_association_manager.StartAssociationAsync(); |
| 207 | 207 |
| 208 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 208 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 209 DataTypeController::MODEL_LOADED); | 209 DataTypeController::MODEL_LOADED); |
| 210 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 210 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
| 211 DataTypeController::UNRECOVERABLE_ERROR); | 211 DataTypeController::UNRECOVERABLE_ERROR); |
| 212 } | 212 } |
| 213 | 213 |
| 214 TEST_F(ModelAssociationManagerTest, InitializeAbortsLoad) { | 214 TEST_F(ModelAssociationManagerTest, InitializeAbortsLoad) { |
| 215 controllers_[syncable::BOOKMARKS] = | 215 controllers_[syncer::BOOKMARKS] = |
| 216 new FakeDataTypeController(syncable::BOOKMARKS); | 216 new FakeDataTypeController(syncer::BOOKMARKS); |
| 217 controllers_[syncable::THEMES] = | 217 controllers_[syncer::THEMES] = |
| 218 new FakeDataTypeController(syncable::THEMES); | 218 new FakeDataTypeController(syncer::THEMES); |
| 219 | 219 |
| 220 GetController(controllers_, syncable::BOOKMARKS)->SetDelayModelLoad(); | 220 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
| 221 ModelAssociationManager model_association_manager(&controllers_, | 221 ModelAssociationManager model_association_manager(&controllers_, |
| 222 &result_processor_); | 222 &result_processor_); |
| 223 syncable::ModelTypeSet types(syncable::BOOKMARKS, syncable::THEMES); | 223 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::THEMES); |
| 224 | 224 |
| 225 syncable::ModelTypeSet expected_types_waiting_to_load; | 225 syncer::ModelTypeSet expected_types_waiting_to_load; |
| 226 expected_types_waiting_to_load.Put(syncable::BOOKMARKS); | 226 expected_types_waiting_to_load.Put(syncer::BOOKMARKS); |
| 227 DataTypeManager::ConfigureResult expected_result_partially_done( | 227 DataTypeManager::ConfigureResult expected_result_partially_done( |
| 228 DataTypeManager::PARTIAL_SUCCESS, | 228 DataTypeManager::PARTIAL_SUCCESS, |
| 229 types, | 229 types, |
| 230 std::list<syncer::SyncError>(), | 230 std::list<syncer::SyncError>(), |
| 231 expected_types_waiting_to_load); | 231 expected_types_waiting_to_load); |
| 232 | 232 |
| 233 model_association_manager.Initialize(types); | 233 model_association_manager.Initialize(types); |
| 234 model_association_manager.StopDisabledTypes(); | 234 model_association_manager.StopDisabledTypes(); |
| 235 | 235 |
| 236 model_association_manager.StartAssociationAsync(); | 236 model_association_manager.StartAssociationAsync(); |
| 237 | 237 |
| 238 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 238 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
| 239 WillOnce(VerifyResult(expected_result_partially_done)); | 239 WillOnce(VerifyResult(expected_result_partially_done)); |
| 240 | 240 |
| 241 base::OneShotTimer<ModelAssociationManager>* timer = | 241 base::OneShotTimer<ModelAssociationManager>* timer = |
| 242 model_association_manager.GetTimerForTesting(); | 242 model_association_manager.GetTimerForTesting(); |
| 243 | 243 |
| 244 base::Closure task = timer->user_task(); | 244 base::Closure task = timer->user_task(); |
| 245 timer->Stop(); | 245 timer->Stop(); |
| 246 task.Run(); // Bookmark load times out here. | 246 task.Run(); // Bookmark load times out here. |
| 247 | 247 |
| 248 // Apps finishes associating here. | 248 // Apps finishes associating here. |
| 249 GetController(controllers_, syncable::THEMES)->FinishStart( | 249 GetController(controllers_, syncer::THEMES)->FinishStart( |
| 250 DataTypeController::OK); | 250 DataTypeController::OK); |
| 251 | 251 |
| 252 // At this point, BOOKMARKS is still waiting to load (as evidenced by | 252 // At this point, BOOKMARKS is still waiting to load (as evidenced by |
| 253 // expected_result_partially_done). If we schedule another Initialize (which | 253 // expected_result_partially_done). If we schedule another Initialize (which |
| 254 // could happen in practice due to reconfiguration), this should abort | 254 // could happen in practice due to reconfiguration), this should abort |
| 255 // BOOKMARKS. Aborting will call ModelLoadCallback, but the | 255 // BOOKMARKS. Aborting will call ModelLoadCallback, but the |
| 256 // ModelAssociationManager should be smart enough to know that this is not due | 256 // ModelAssociationManager should be smart enough to know that this is not due |
| 257 // to the type having completed loading. | 257 // to the type having completed loading. |
| 258 EXPECT_CALL(result_processor_, OnTypesLoaded()).Times(0); | 258 EXPECT_CALL(result_processor_, OnTypesLoaded()).Times(0); |
| 259 | 259 |
| 260 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 260 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 261 DataTypeController::MODEL_STARTING); | 261 DataTypeController::MODEL_STARTING); |
| 262 | 262 |
| 263 model_association_manager.Initialize(types); | 263 model_association_manager.Initialize(types); |
| 264 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | 264 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 265 DataTypeController::NOT_RUNNING); | 265 DataTypeController::NOT_RUNNING); |
| 266 | 266 |
| 267 DataTypeManager::ConfigureResult expected_result_done( | 267 DataTypeManager::ConfigureResult expected_result_done( |
| 268 DataTypeManager::OK, | 268 DataTypeManager::OK, |
| 269 types, | 269 types, |
| 270 std::list<syncer::SyncError>(), | 270 std::list<syncer::SyncError>(), |
| 271 syncable::ModelTypeSet()); | 271 syncer::ModelTypeSet()); |
| 272 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 272 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
| 273 WillOnce(VerifyResult(expected_result_done)); | 273 WillOnce(VerifyResult(expected_result_done)); |
| 274 | 274 |
| 275 model_association_manager.StopDisabledTypes(); | 275 model_association_manager.StopDisabledTypes(); |
| 276 model_association_manager.StartAssociationAsync(); | 276 model_association_manager.StartAssociationAsync(); |
| 277 | 277 |
| 278 GetController(controllers_, | 278 GetController(controllers_, |
| 279 syncable::BOOKMARKS)->SimulateModelLoadFinishing(); | 279 syncer::BOOKMARKS)->SimulateModelLoadFinishing(); |
| 280 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 280 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
| 281 DataTypeController::OK); | 281 DataTypeController::OK); |
| 282 } | 282 } |
| 283 | 283 |
| 284 // Start 2 types. One of which timeout loading. Ensure that type is | 284 // Start 2 types. One of which timeout loading. Ensure that type is |
| 285 // fully configured eventually. | 285 // fully configured eventually. |
| 286 TEST_F(ModelAssociationManagerTest, ModelStartWithSlowLoadingType) { | 286 TEST_F(ModelAssociationManagerTest, ModelStartWithSlowLoadingType) { |
| 287 controllers_[syncable::BOOKMARKS] = | 287 controllers_[syncer::BOOKMARKS] = |
| 288 new FakeDataTypeController(syncable::BOOKMARKS); | 288 new FakeDataTypeController(syncer::BOOKMARKS); |
| 289 controllers_[syncable::APPS] = | 289 controllers_[syncer::APPS] = |
| 290 new FakeDataTypeController(syncable::APPS); | 290 new FakeDataTypeController(syncer::APPS); |
| 291 GetController(controllers_, syncable::BOOKMARKS)->SetDelayModelLoad(); | 291 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
| 292 ModelAssociationManager model_association_manager(&controllers_, | 292 ModelAssociationManager model_association_manager(&controllers_, |
| 293 &result_processor_); | 293 &result_processor_); |
| 294 syncable::ModelTypeSet types; | 294 syncer::ModelTypeSet types; |
| 295 types.Put(syncable::BOOKMARKS); | 295 types.Put(syncer::BOOKMARKS); |
| 296 types.Put(syncable::APPS); | 296 types.Put(syncer::APPS); |
| 297 | 297 |
| 298 syncable::ModelTypeSet expected_types_waiting_to_load; | 298 syncer::ModelTypeSet expected_types_waiting_to_load; |
| 299 expected_types_waiting_to_load.Put(syncable::BOOKMARKS); | 299 expected_types_waiting_to_load.Put(syncer::BOOKMARKS); |
| 300 DataTypeManager::ConfigureResult expected_result_partially_done( | 300 DataTypeManager::ConfigureResult expected_result_partially_done( |
| 301 DataTypeManager::PARTIAL_SUCCESS, | 301 DataTypeManager::PARTIAL_SUCCESS, |
| 302 types, | 302 types, |
| 303 std::list<syncer::SyncError>(), | 303 std::list<syncer::SyncError>(), |
| 304 expected_types_waiting_to_load); | 304 expected_types_waiting_to_load); |
| 305 | 305 |
| 306 DataTypeManager::ConfigureResult expected_result_done( | 306 DataTypeManager::ConfigureResult expected_result_done( |
| 307 DataTypeManager::OK, | 307 DataTypeManager::OK, |
| 308 types, | 308 types, |
| 309 std::list<syncer::SyncError>(), | 309 std::list<syncer::SyncError>(), |
| 310 syncable::ModelTypeSet()); | 310 syncer::ModelTypeSet()); |
| 311 | 311 |
| 312 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 312 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
| 313 WillOnce(VerifyResult(expected_result_partially_done)); | 313 WillOnce(VerifyResult(expected_result_partially_done)); |
| 314 EXPECT_CALL(result_processor_, OnTypesLoaded()); | 314 EXPECT_CALL(result_processor_, OnTypesLoaded()); |
| 315 | 315 |
| 316 model_association_manager.Initialize(types); | 316 model_association_manager.Initialize(types); |
| 317 model_association_manager.StopDisabledTypes(); | 317 model_association_manager.StopDisabledTypes(); |
| 318 model_association_manager.StartAssociationAsync(); | 318 model_association_manager.StartAssociationAsync(); |
| 319 | 319 |
| 320 base::OneShotTimer<ModelAssociationManager>* timer = | 320 base::OneShotTimer<ModelAssociationManager>* timer = |
| 321 model_association_manager.GetTimerForTesting(); | 321 model_association_manager.GetTimerForTesting(); |
| 322 | 322 |
| 323 // Note: Independent of the timeout value this test is not flaky. | 323 // Note: Independent of the timeout value this test is not flaky. |
| 324 // The reason is timer posts a task which would never be executed | 324 // The reason is timer posts a task which would never be executed |
| 325 // as we dont let the message loop run. | 325 // as we dont let the message loop run. |
| 326 base::Closure task = timer->user_task(); | 326 base::Closure task = timer->user_task(); |
| 327 timer->Stop(); | 327 timer->Stop(); |
| 328 task.Run(); | 328 task.Run(); |
| 329 | 329 |
| 330 // Simulate delayed loading of bookmark model. | 330 // Simulate delayed loading of bookmark model. |
| 331 GetController(controllers_, syncable::APPS)->FinishStart( | 331 GetController(controllers_, syncer::APPS)->FinishStart( |
| 332 DataTypeController::OK); | 332 DataTypeController::OK); |
| 333 | 333 |
| 334 GetController(controllers_, | 334 GetController(controllers_, |
| 335 syncable::BOOKMARKS)->SimulateModelLoadFinishing(); | 335 syncer::BOOKMARKS)->SimulateModelLoadFinishing(); |
| 336 | 336 |
| 337 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | 337 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). |
| 338 WillOnce(VerifyResult(expected_result_done)); | 338 WillOnce(VerifyResult(expected_result_done)); |
| 339 | 339 |
| 340 // Do it once more to associate bookmarks. | 340 // Do it once more to associate bookmarks. |
| 341 model_association_manager.Initialize(types); | 341 model_association_manager.Initialize(types); |
| 342 model_association_manager.StopDisabledTypes(); | 342 model_association_manager.StopDisabledTypes(); |
| 343 model_association_manager.StartAssociationAsync(); | 343 model_association_manager.StartAssociationAsync(); |
| 344 | 344 |
| 345 GetController(controllers_, | 345 GetController(controllers_, |
| 346 syncable::BOOKMARKS)->SimulateModelLoadFinishing(); | 346 syncer::BOOKMARKS)->SimulateModelLoadFinishing(); |
| 347 | 347 |
| 348 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 348 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
| 349 DataTypeController::OK); | 349 DataTypeController::OK); |
| 350 } | 350 } |
| 351 | 351 |
| 352 | 352 |
| 353 } // namespace browser_sync | 353 } // namespace browser_sync |
| OLD | NEW |