Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / glue / model_association_manager_unittest.cc
blob3789b390fc1719b0de194fee804f6c87b71fa940
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
3 // found in the LICENSE file.
5 #include "base/callback.h"
6 #include "base/message_loop/message_loop.h"
7 #include "chrome/browser/sync/glue/fake_data_type_controller.h"
8 #include "chrome/browser/sync/glue/model_association_manager.h"
9 #include "content/public/test/test_browser_thread.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 using ::testing::_;
14 namespace browser_sync {
15 class MockModelAssociationResultProcessor :
16 public ModelAssociationResultProcessor {
17 public:
18 MockModelAssociationResultProcessor() {}
19 ~MockModelAssociationResultProcessor() {}
20 MOCK_METHOD2(OnSingleDataTypeAssociationDone,
21 void(syncer::ModelType type,
22 const syncer::DataTypeAssociationStats& association_stats));
23 MOCK_METHOD1(OnModelAssociationDone, void(
24 const DataTypeManager::ConfigureResult& result));
27 FakeDataTypeController* GetController(
28 const DataTypeController::TypeMap& controllers,
29 syncer::ModelType model_type) {
30 DataTypeController::TypeMap::const_iterator it =
31 controllers.find(model_type);
32 if (it == controllers.end()) {
33 return NULL;
35 return (FakeDataTypeController*)(it->second.get());
38 ACTION_P(VerifyResult, expected_result) {
39 EXPECT_EQ(arg0.status, expected_result.status);
40 EXPECT_TRUE(arg0.requested_types.Equals(expected_result.requested_types));
41 EXPECT_EQ(arg0.failed_data_types.size(),
42 expected_result.failed_data_types.size());
44 if (arg0.failed_data_types.size() ==
45 expected_result.failed_data_types.size()) {
46 std::map<syncer::ModelType, syncer::SyncError>::const_iterator it1, it2;
47 for (it1 = arg0.failed_data_types.begin(),
48 it2 = expected_result.failed_data_types.begin();
49 it1 != arg0.failed_data_types.end();
50 ++it1, ++it2) {
51 EXPECT_EQ((*it1).first, (*it2).first);
55 EXPECT_TRUE(arg0.unfinished_data_types.Equals(
56 expected_result.unfinished_data_types));
59 class SyncModelAssociationManagerTest : public testing::Test {
60 public:
61 SyncModelAssociationManagerTest() :
62 ui_thread_(content::BrowserThread::UI, &ui_loop_) {
65 protected:
66 base::MessageLoopForUI ui_loop_;
67 content::TestBrowserThread ui_thread_;
68 MockModelAssociationResultProcessor result_processor_;
69 DataTypeController::TypeMap controllers_;
72 // Start a type and make sure ModelAssociationManager callst the |Start|
73 // method and calls the callback when it is done.
74 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) {
75 controllers_[syncer::BOOKMARKS] =
76 new FakeDataTypeController(syncer::BOOKMARKS);
77 controllers_[syncer::APPS] =
78 new FakeDataTypeController(syncer::APPS);
79 ModelAssociationManager model_association_manager(&controllers_,
80 &result_processor_);
81 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS);
82 DataTypeManager::ConfigureResult expected_result(
83 DataTypeManager::OK,
84 types,
85 std::map<syncer::ModelType, syncer::SyncError>(),
86 syncer::ModelTypeSet(),
87 syncer::ModelTypeSet());
88 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
89 WillOnce(VerifyResult(expected_result));
91 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
92 DataTypeController::NOT_RUNNING);
93 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(),
94 DataTypeController::NOT_RUNNING);
96 // Initialize() kicks off model loading.
97 model_association_manager.Initialize(types);
99 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
100 DataTypeController::MODEL_LOADED);
101 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(),
102 DataTypeController::MODEL_LOADED);
104 model_association_manager.StartAssociationAsync(types);
106 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
107 DataTypeController::ASSOCIATING);
108 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(),
109 DataTypeController::ASSOCIATING);
110 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
111 DataTypeController::OK);
112 GetController(controllers_, syncer::APPS)->FinishStart(
113 DataTypeController::OK);
116 // Start a type and call stop before it finishes associating.
117 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) {
118 controllers_[syncer::BOOKMARKS] =
119 new FakeDataTypeController(syncer::BOOKMARKS);
120 ModelAssociationManager model_association_manager(
121 &controllers_,
122 &result_processor_);
124 syncer::ModelTypeSet types;
125 types.Put(syncer::BOOKMARKS);
127 DataTypeManager::ConfigureResult expected_result(
128 DataTypeManager::ABORTED,
129 types,
130 std::map<syncer::ModelType, syncer::SyncError>(),
131 syncer::ModelTypeSet(syncer::BOOKMARKS),
132 syncer::ModelTypeSet());
134 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
135 WillOnce(VerifyResult(expected_result));
137 model_association_manager.Initialize(types);
138 model_association_manager.StartAssociationAsync(types);
140 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
141 DataTypeController::ASSOCIATING);
142 model_association_manager.Stop();
143 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
144 DataTypeController::NOT_RUNNING);
147 // Start a type, let it finish and then call stop.
148 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) {
149 controllers_[syncer::BOOKMARKS] =
150 new FakeDataTypeController(syncer::BOOKMARKS);
151 ModelAssociationManager model_association_manager(
152 &controllers_,
153 &result_processor_);
154 syncer::ModelTypeSet types;
155 types.Put(syncer::BOOKMARKS);
156 DataTypeManager::ConfigureResult expected_result(
157 DataTypeManager::OK,
158 types,
159 std::map<syncer::ModelType, syncer::SyncError>(),
160 syncer::ModelTypeSet(),
161 syncer::ModelTypeSet());
162 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
163 WillOnce(VerifyResult(expected_result));
165 model_association_manager.Initialize(types);
166 model_association_manager.StartAssociationAsync(types);
168 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
169 DataTypeController::ASSOCIATING);
170 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
171 DataTypeController::OK);
173 model_association_manager.Stop();
174 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
175 DataTypeController::NOT_RUNNING);
178 // Make a type fail model association and verify correctness.
179 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) {
180 controllers_[syncer::BOOKMARKS] =
181 new FakeDataTypeController(syncer::BOOKMARKS);
182 ModelAssociationManager model_association_manager(
183 &controllers_,
184 &result_processor_);
185 syncer::ModelTypeSet types;
186 types.Put(syncer::BOOKMARKS);
187 std::map<syncer::ModelType, syncer::SyncError> errors;
188 syncer::SyncError error(FROM_HERE,
189 syncer::SyncError::DATATYPE_ERROR,
190 "Failed",
191 syncer::BOOKMARKS);
192 errors[syncer::BOOKMARKS] = error;
193 DataTypeManager::ConfigureResult expected_result(
194 DataTypeManager::PARTIAL_SUCCESS,
195 types,
196 errors,
197 syncer::ModelTypeSet(),
198 syncer::ModelTypeSet());
199 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
200 WillOnce(VerifyResult(expected_result));
202 model_association_manager.Initialize(types);
203 model_association_manager.StartAssociationAsync(types);
205 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
206 DataTypeController::ASSOCIATING);
207 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
208 DataTypeController::ASSOCIATION_FAILED);
209 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
210 DataTypeController::NOT_RUNNING);
213 // Ensure configuring stops when a type returns a unrecoverable error.
214 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) {
215 controllers_[syncer::BOOKMARKS] =
216 new FakeDataTypeController(syncer::BOOKMARKS);
217 ModelAssociationManager model_association_manager(
218 &controllers_,
219 &result_processor_);
220 syncer::ModelTypeSet types;
221 types.Put(syncer::BOOKMARKS);
222 std::map<syncer::ModelType, syncer::SyncError> errors;
223 syncer::SyncError error(FROM_HERE,
224 syncer::SyncError::DATATYPE_ERROR,
225 "Failed",
226 syncer::BOOKMARKS);
227 errors[syncer::BOOKMARKS] = error;
228 DataTypeManager::ConfigureResult expected_result(
229 DataTypeManager::UNRECOVERABLE_ERROR,
230 types,
231 errors,
232 syncer::ModelTypeSet(),
233 syncer::ModelTypeSet());
234 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
235 WillOnce(VerifyResult(expected_result));
237 model_association_manager.Initialize(types);
239 model_association_manager.StartAssociationAsync(types);
241 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
242 DataTypeController::ASSOCIATING);
243 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
244 DataTypeController::UNRECOVERABLE_ERROR);
247 TEST_F(SyncModelAssociationManagerTest, InitializeWhileLoading) {
248 controllers_[syncer::BOOKMARKS] =
249 new FakeDataTypeController(syncer::BOOKMARKS);
250 controllers_[syncer::THEMES] =
251 new FakeDataTypeController(syncer::THEMES);
253 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad();
254 ModelAssociationManager model_association_manager(&controllers_,
255 &result_processor_);
256 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::THEMES);
258 syncer::ModelTypeSet expected_types_waiting_to_load;
259 expected_types_waiting_to_load.Put(syncer::BOOKMARKS);
260 DataTypeManager::ConfigureResult expected_result_partially_done(
261 DataTypeManager::PARTIAL_SUCCESS,
262 types,
263 std::map<syncer::ModelType, syncer::SyncError>(),
264 expected_types_waiting_to_load,
265 syncer::ModelTypeSet());
267 model_association_manager.Initialize(types);
269 model_association_manager.StartAssociationAsync(types);
271 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
272 WillOnce(VerifyResult(expected_result_partially_done));
274 // THEMES finishes associating here.
275 GetController(controllers_, syncer::THEMES)->FinishStart(
276 DataTypeController::OK);
278 base::OneShotTimer<ModelAssociationManager>* timer =
279 model_association_manager.GetTimerForTesting();
281 base::Closure task = timer->user_task();
282 timer->Stop();
283 task.Run(); // Bookmark load times out here.
285 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
286 DataTypeController::MODEL_STARTING);
288 model_association_manager.Initialize(types);
290 DataTypeManager::ConfigureResult expected_result_done(
291 DataTypeManager::OK,
292 types,
293 std::map<syncer::ModelType, syncer::SyncError>(),
294 syncer::ModelTypeSet(),
295 syncer::ModelTypeSet());
296 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
297 WillOnce(VerifyResult(expected_result_done));
299 model_association_manager.StartAssociationAsync(types);
301 GetController(controllers_,
302 syncer::BOOKMARKS)->SimulateModelLoadFinishing();
303 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
304 DataTypeController::OK);
307 // Start 2 types. One of which timeout loading. Ensure that type is
308 // fully configured eventually.
309 TEST_F(SyncModelAssociationManagerTest, ModelStartWithSlowType) {
310 controllers_[syncer::BOOKMARKS] =
311 new FakeDataTypeController(syncer::BOOKMARKS);
312 controllers_[syncer::APPS] =
313 new FakeDataTypeController(syncer::APPS);
314 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad();
315 ModelAssociationManager model_association_manager(&controllers_,
316 &result_processor_);
317 syncer::ModelTypeSet types;
318 types.Put(syncer::BOOKMARKS);
319 types.Put(syncer::APPS);
321 syncer::ModelTypeSet expected_types_unfinished;
322 expected_types_unfinished.Put(syncer::BOOKMARKS);
323 DataTypeManager::ConfigureResult expected_result_partially_done(
324 DataTypeManager::PARTIAL_SUCCESS,
325 types,
326 std::map<syncer::ModelType, syncer::SyncError>(),
327 expected_types_unfinished,
328 syncer::ModelTypeSet());
330 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
331 WillOnce(VerifyResult(expected_result_partially_done));
333 model_association_manager.Initialize(types);
334 model_association_manager.StartAssociationAsync(types);
336 // Simulate delayed loading of bookmark model.
337 GetController(controllers_, syncer::APPS)->FinishStart(
338 DataTypeController::OK);
340 base::OneShotTimer<ModelAssociationManager>* timer =
341 model_association_manager.GetTimerForTesting();
343 // Note: Independent of the timeout value this test is not flaky.
344 // The reason is timer posts a task which would never be executed
345 // as we don't let the message loop run.
346 base::Closure task = timer->user_task();
347 timer->Stop();
348 task.Run();
350 EXPECT_EQ(DataTypeController::MODEL_STARTING,
351 GetController(controllers_, syncer::BOOKMARKS)->state());
352 GetController(controllers_,
353 syncer::BOOKMARKS)->SimulateModelLoadFinishing();
354 EXPECT_EQ(DataTypeController::ASSOCIATING,
355 GetController(controllers_, syncer::BOOKMARKS)->state());
356 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
357 DataTypeController::OK);
358 EXPECT_EQ(DataTypeController::RUNNING,
359 GetController(controllers_, syncer::BOOKMARKS)->state());
362 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) {
363 controllers_[syncer::BOOKMARKS] =
364 new FakeDataTypeController(syncer::BOOKMARKS);
365 controllers_[syncer::APPS] =
366 new FakeDataTypeController(syncer::APPS);
367 ModelAssociationManager model_association_manager(&controllers_,
368 &result_processor_);
369 syncer::ModelTypeSet types;
370 types.Put(syncer::BOOKMARKS);
371 types.Put(syncer::APPS);
373 DataTypeManager::ConfigureResult result_1st(
374 DataTypeManager::OK,
375 syncer::ModelTypeSet(syncer::BOOKMARKS),
376 std::map<syncer::ModelType, syncer::SyncError>(),
377 syncer::ModelTypeSet(),
378 syncer::ModelTypeSet());
379 DataTypeManager::ConfigureResult result_2nd(
380 DataTypeManager::OK,
381 syncer::ModelTypeSet(syncer::APPS),
382 std::map<syncer::ModelType, syncer::SyncError>(),
383 syncer::ModelTypeSet(),
384 syncer::ModelTypeSet());
385 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
386 Times(2).
387 WillOnce(VerifyResult(result_1st)).
388 WillOnce(VerifyResult(result_2nd));
390 model_association_manager.Initialize(types);
392 // Start BOOKMARKS first.
393 model_association_manager.StartAssociationAsync(
394 syncer::ModelTypeSet(syncer::BOOKMARKS));
395 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
396 DataTypeController::ASSOCIATING);
397 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(),
398 DataTypeController::MODEL_LOADED);
400 // Finish BOOKMARKS association.
401 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
402 DataTypeController::OK);
403 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
404 DataTypeController::RUNNING);
405 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(),
406 DataTypeController::MODEL_LOADED);
408 // Start APPS next.
409 model_association_manager.StartAssociationAsync(
410 syncer::ModelTypeSet(syncer::APPS));
411 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(),
412 DataTypeController::ASSOCIATING);
413 GetController(controllers_, syncer::APPS)->FinishStart(
414 DataTypeController::OK);
415 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(),
416 DataTypeController::RUNNING);
419 // Test that model that failed to load between initialization and association
420 // is reported and stopped properly.
421 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) {
422 controllers_[syncer::BOOKMARKS] =
423 new FakeDataTypeController(syncer::BOOKMARKS);
424 GetController(controllers_, syncer::BOOKMARKS)->SetModelLoadError(
425 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
426 "", syncer::BOOKMARKS));
427 ModelAssociationManager model_association_manager(
428 &controllers_,
429 &result_processor_);
430 syncer::ModelTypeSet types;
431 types.Put(syncer::BOOKMARKS);
432 std::map<syncer::ModelType, syncer::SyncError> errors;
433 syncer::SyncError error(FROM_HERE,
434 syncer::SyncError::DATATYPE_ERROR,
435 "Failed",
436 syncer::BOOKMARKS);
437 errors[syncer::BOOKMARKS] = error;
438 DataTypeManager::ConfigureResult expected_result(
439 DataTypeManager::PARTIAL_SUCCESS,
440 types,
441 errors,
442 syncer::ModelTypeSet(),
443 syncer::ModelTypeSet());
444 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
445 WillOnce(VerifyResult(expected_result));
447 model_association_manager.Initialize(types);
448 EXPECT_EQ(DataTypeController::DISABLED,
449 GetController(controllers_, syncer::BOOKMARKS)->state());
450 model_association_manager.StartAssociationAsync(types);
451 EXPECT_EQ(DataTypeController::NOT_RUNNING,
452 GetController(controllers_, syncer::BOOKMARKS)->state());
455 // Test that a slow type is stopped if it fails to load when association
456 // manager is in IDLE mode.
457 TEST_F(SyncModelAssociationManagerTest, SlowTypeFailToLoadInIdleMode) {
458 controllers_[syncer::BOOKMARKS] =
459 new FakeDataTypeController(syncer::BOOKMARKS);
460 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad();
461 GetController(controllers_, syncer::BOOKMARKS)->SetModelLoadError(
462 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
463 "", syncer::BOOKMARKS));
464 ModelAssociationManager model_association_manager(&controllers_,
465 &result_processor_);
466 syncer::ModelTypeSet types;
467 types.Put(syncer::BOOKMARKS);
469 DataTypeManager::ConfigureResult expected_result_partially_done(
470 DataTypeManager::PARTIAL_SUCCESS,
471 types,
472 std::map<syncer::ModelType, syncer::SyncError>(),
473 types,
474 syncer::ModelTypeSet());
475 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
476 WillOnce(VerifyResult(expected_result_partially_done));
478 model_association_manager.Initialize(types);
479 model_association_manager.StartAssociationAsync(types);
481 base::OneShotTimer<ModelAssociationManager>* timer =
482 model_association_manager.GetTimerForTesting();
483 base::Closure task = timer->user_task();
484 timer->Stop();
485 task.Run();
487 EXPECT_EQ(DataTypeController::MODEL_STARTING,
488 GetController(controllers_, syncer::BOOKMARKS)->state());
489 GetController(controllers_,
490 syncer::BOOKMARKS)->SimulateModelLoadFinishing();
491 // Failed DTC is stopped in IDLE mode.
492 EXPECT_EQ(DataTypeController::NOT_RUNNING,
493 GetController(controllers_, syncer::BOOKMARKS)->state());
496 // Test that a slow type is reported and stopped if it fails to load when
497 // association manager is in INITIALIZED_TO_CONFIGURE mode.
498 TEST_F(SyncModelAssociationManagerTest,
499 SlowTypeFailToLoadInInitToConfigureMode) {
500 controllers_[syncer::BOOKMARKS] =
501 new FakeDataTypeController(syncer::BOOKMARKS);
502 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad();
503 GetController(controllers_, syncer::BOOKMARKS)->SetModelLoadError(
504 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
505 "", syncer::BOOKMARKS));
506 ModelAssociationManager model_association_manager(&controllers_,
507 &result_processor_);
508 syncer::ModelTypeSet types;
509 types.Put(syncer::BOOKMARKS);
511 // 1st configuration.
512 DataTypeManager::ConfigureResult first_result(
513 DataTypeManager::PARTIAL_SUCCESS,
514 types,
515 std::map<syncer::ModelType, syncer::SyncError>(),
516 types,
517 syncer::ModelTypeSet());
518 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
519 WillOnce(VerifyResult(first_result));
520 model_association_manager.Initialize(types);
521 model_association_manager.StartAssociationAsync(types);
522 base::OneShotTimer<ModelAssociationManager>* timer =
523 model_association_manager.GetTimerForTesting();
524 base::Closure task = timer->user_task();
525 timer->Stop();
526 task.Run();
527 EXPECT_EQ(DataTypeController::MODEL_STARTING,
528 GetController(controllers_, syncer::BOOKMARKS)->state());
530 // 2nd configuration.
531 std::map<syncer::ModelType, syncer::SyncError> error;
532 error[syncer::BOOKMARKS] =
533 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
534 "", syncer::BOOKMARKS);
535 DataTypeManager::ConfigureResult second_result(
536 DataTypeManager::PARTIAL_SUCCESS, types, error, syncer::ModelTypeSet(),
537 syncer::ModelTypeSet());
538 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
539 WillOnce(VerifyResult(second_result));
540 model_association_manager.Initialize(types);
541 GetController(controllers_,
542 syncer::BOOKMARKS)->SimulateModelLoadFinishing();
543 model_association_manager.StartAssociationAsync(types);
544 EXPECT_EQ(DataTypeController::NOT_RUNNING,
545 GetController(controllers_, syncer::BOOKMARKS)->state());
548 // Test that a slow type is stopped if it fails to associate when association
549 // manager is in IDLE mode.
550 TEST_F(SyncModelAssociationManagerTest, SlowTypeFailToAssociateInIdleMode) {
551 controllers_[syncer::BOOKMARKS] =
552 new FakeDataTypeController(syncer::BOOKMARKS);
553 ModelAssociationManager model_association_manager(&controllers_,
554 &result_processor_);
555 syncer::ModelTypeSet types;
556 types.Put(syncer::BOOKMARKS);
558 DataTypeManager::ConfigureResult expected_result_partially_done(
559 DataTypeManager::PARTIAL_SUCCESS,
560 types,
561 std::map<syncer::ModelType, syncer::SyncError>(),
562 types,
563 syncer::ModelTypeSet());
564 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
565 WillOnce(VerifyResult(expected_result_partially_done));
567 model_association_manager.Initialize(types);
568 model_association_manager.StartAssociationAsync(types);
570 base::OneShotTimer<ModelAssociationManager>* timer =
571 model_association_manager.GetTimerForTesting();
572 base::Closure task = timer->user_task();
573 timer->Stop();
574 task.Run();
576 EXPECT_EQ(DataTypeController::ASSOCIATING,
577 GetController(controllers_, syncer::BOOKMARKS)->state());
578 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
579 DataTypeController::ASSOCIATION_FAILED);
580 // Failed DTC is stopped in IDLE mode.
581 EXPECT_EQ(DataTypeController::NOT_RUNNING,
582 GetController(controllers_, syncer::BOOKMARKS)->state());
585 // Test that a slow type is reported and stopped if it fails to associate when
586 // association manager is in INITIALIZED_TO_CONFIGURE mode.
587 TEST_F(SyncModelAssociationManagerTest,
588 SlowTypeFailToAssociateInInitToConfigureMode) {
589 controllers_[syncer::BOOKMARKS] =
590 new FakeDataTypeController(syncer::BOOKMARKS);
591 ModelAssociationManager model_association_manager(&controllers_,
592 &result_processor_);
593 syncer::ModelTypeSet types;
594 types.Put(syncer::BOOKMARKS);
596 // 1st configuration.
597 DataTypeManager::ConfigureResult first_result(
598 DataTypeManager::PARTIAL_SUCCESS,
599 types,
600 std::map<syncer::ModelType, syncer::SyncError>(),
601 types,
602 syncer::ModelTypeSet());
603 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
604 WillOnce(VerifyResult(first_result));
605 model_association_manager.Initialize(types);
606 model_association_manager.StartAssociationAsync(types);
607 base::OneShotTimer<ModelAssociationManager>* timer =
608 model_association_manager.GetTimerForTesting();
609 base::Closure task = timer->user_task();
610 timer->Stop();
611 task.Run();
612 EXPECT_EQ(DataTypeController::ASSOCIATING,
613 GetController(controllers_, syncer::BOOKMARKS)->state());
615 // 2nd configuration.
616 std::map<syncer::ModelType, syncer::SyncError> error;
617 error[syncer::BOOKMARKS] =
618 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
619 "", syncer::BOOKMARKS);
620 DataTypeManager::ConfigureResult second_result(
621 DataTypeManager::PARTIAL_SUCCESS, types, error, syncer::ModelTypeSet(),
622 syncer::ModelTypeSet());
623 EXPECT_CALL(result_processor_, OnModelAssociationDone(_)).
624 WillOnce(VerifyResult(second_result));
625 model_association_manager.Initialize(types);
626 GetController(controllers_, syncer::BOOKMARKS)->FinishStart(
627 DataTypeController::ASSOCIATION_FAILED);
628 model_association_manager.StartAssociationAsync(types);
629 EXPECT_EQ(DataTypeController::NOT_RUNNING,
630 GetController(controllers_, syncer::BOOKMARKS)->state());
633 } // namespace browser_sync