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