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" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_, syncable::BOOKMARKS)->state(), |
209 DataTypeController::MODEL_LOADED); | 209 DataTypeController::MODEL_LOADED); |
210 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 210 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( |
211 DataTypeController::UNRECOVERABLE_ERROR); | 211 DataTypeController::UNRECOVERABLE_ERROR); |
212 } | 212 } |
213 | 213 |
214 TEST_F(ModelAssociationManagerTest, InitializeAbortsLoad) { | |
215 controllers_[syncable::BOOKMARKS] = | |
216 new FakeDataTypeController(syncable::BOOKMARKS); | |
217 controllers_[syncable::THEMES] = | |
218 new FakeDataTypeController(syncable::THEMES); | |
219 | |
220 GetController(controllers_, syncable::BOOKMARKS)->SetDelayModelLoad(); | |
221 ModelAssociationManager model_association_manager(&controllers_, | |
222 &result_processor_); | |
223 syncable::ModelTypeSet types(syncable::BOOKMARKS, syncable::THEMES); | |
224 | |
225 syncable::ModelTypeSet expected_types_waiting_to_load; | |
226 expected_types_waiting_to_load.Put(syncable::BOOKMARKS); | |
227 DataTypeManager::ConfigureResult expected_result_partially_done( | |
228 DataTypeManager::PARTIAL_SUCCESS, | |
229 types, | |
230 std::list<csync::SyncError>(), | |
231 expected_types_waiting_to_load); | |
232 | |
233 model_association_manager.Initialize(types); | |
234 model_association_manager.StopDisabledTypes(); | |
235 | |
236 model_association_manager.StartAssociationAsync(); | |
237 | |
238 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | |
239 WillOnce(VerifyResult(expected_result_partially_done)); | |
240 | |
241 base::OneShotTimer<ModelAssociationManager>* timer = | |
242 model_association_manager.GetTimerForTesting(); | |
243 | |
244 base::Closure task = timer->user_task(); | |
245 timer->Stop(); | |
246 task.Run(); // Bookmark load times out here. | |
247 | |
248 // Apps finishes associating here. | |
249 GetController(controllers_, syncable::THEMES)->FinishStart( | |
250 DataTypeController::OK); | |
251 | |
252 // At this point, BOOKMARKS is still waiting to load (as evidenced by | |
253 // expected_result_partially_done). If we schedule another Initialize (which | |
254 // could happen in practice due to reconfiguration), this should abort | |
255 // BOOKMARKS. Aborting will call ModelLoadCallback, but the | |
256 // ModelAssociationManager should be smart enough to know that this is not due | |
257 // to the type having completed loading. | |
258 EXPECT_CALL(result_processor_, OnTypesLoaded()).Times(0); | |
259 | |
260 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | |
261 DataTypeController::MODEL_STARTING); | |
262 | |
263 model_association_manager.Initialize(types); | |
264 EXPECT_EQ(GetController(controllers_, syncable::BOOKMARKS)->state(), | |
265 DataTypeController::NOT_RUNNING); | |
266 | |
267 DataTypeManager::ConfigureResult expected_result_done( | |
268 DataTypeManager::OK, | |
269 types, | |
270 std::list<csync::SyncError>(), | |
271 syncable::ModelTypeSet()); | |
272 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)). | |
273 WillOnce(VerifyResult(expected_result_done)); | |
274 | |
275 model_association_manager.StopDisabledTypes(); | |
276 model_association_manager.StartAssociationAsync(); | |
277 | |
278 GetController(controllers_, | |
279 syncable::BOOKMARKS)->SimulateModelLoadFinishing(); | |
280 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | |
281 DataTypeController::OK); | |
282 } | |
283 | |
284 // Start 2 types. One of which timeout loading. Ensure that type is | 214 // Start 2 types. One of which timeout loading. Ensure that type is |
285 // fully configured eventually. | 215 // fully configured eventually. |
286 TEST_F(ModelAssociationManagerTest, ModelStartWithSlowLoadingType) { | 216 TEST_F(ModelAssociationManagerTest, ModelStartWithSlowLoadingType) { |
287 controllers_[syncable::BOOKMARKS] = | 217 controllers_[syncable::BOOKMARKS] = |
288 new FakeDataTypeController(syncable::BOOKMARKS); | 218 new FakeDataTypeController(syncable::BOOKMARKS); |
289 controllers_[syncable::APPS] = | 219 controllers_[syncable::APPS] = |
290 new FakeDataTypeController(syncable::APPS); | 220 new FakeDataTypeController(syncable::APPS); |
291 GetController(controllers_, syncable::BOOKMARKS)->SetDelayModelLoad(); | 221 GetController(controllers_, syncable::BOOKMARKS)->SetDelayModelLoad(); |
292 ModelAssociationManager model_association_manager(&controllers_, | 222 ModelAssociationManager model_association_manager(&controllers_, |
293 &result_processor_); | 223 &result_processor_); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 274 |
345 GetController(controllers_, | 275 GetController(controllers_, |
346 syncable::BOOKMARKS)->SimulateModelLoadFinishing(); | 276 syncable::BOOKMARKS)->SimulateModelLoadFinishing(); |
347 | 277 |
348 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( | 278 GetController(controllers_, syncable::BOOKMARKS)->FinishStart( |
349 DataTypeController::OK); | 279 DataTypeController::OK); |
350 } | 280 } |
351 | 281 |
352 | 282 |
353 } // namespace browser_sync | 283 } // namespace browser_sync |
| 284 |
OLD | NEW |