Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: components/sync/driver/glue/sync_backend_host_impl_unittest.cc

Issue 2641523004: [Sync] Make directory types registration explicit in ModelTypeRegistry (Closed)
Patch Set: Address comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/glue/sync_backend_host_impl.h" 5 #include "components/sync/driver/glue/sync_backend_host_impl.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 EXPECT_TRUE( 316 EXPECT_TRUE(
317 fake_manager_->GetTypesWithEmptyProgressMarkerToken(ControlTypes()) 317 fake_manager_->GetTypesWithEmptyProgressMarkerToken(ControlTypes())
318 .Empty()); 318 .Empty());
319 319
320 ModelTypeSet ready_types = ConfigureDataTypes(); 320 ModelTypeSet ready_types = ConfigureDataTypes();
321 // Nigori is always downloaded so won't be ready. 321 // Nigori is always downloaded so won't be ready.
322 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types); 322 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types);
323 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( 323 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll(
324 Difference(enabled_types_, ControlTypes()))); 324 Difference(enabled_types_, ControlTypes())));
325 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 325 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
326 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
327 EXPECT_TRUE( 326 EXPECT_TRUE(
328 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 327 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
329 .Empty()); 328 .Empty());
330 } 329 }
331 330
332 // Test the restart after setting up sync scenario. No enabled types should be 331 // Test the restart after setting up sync scenario. No enabled types should be
333 // downloaded or cleaned. 332 // downloaded or cleaned.
334 TEST_F(SyncEngineTest, Restart) { 333 TEST_F(SyncEngineTest, Restart) {
335 sync_prefs_->SetFirstSetupComplete(); 334 sync_prefs_->SetFirstSetupComplete();
336 ModelTypeSet all_but_nigori = enabled_types_; 335 ModelTypeSet all_but_nigori = enabled_types_;
337 fake_manager_factory_->set_progress_marker_types(enabled_types_); 336 fake_manager_factory_->set_progress_marker_types(enabled_types_);
338 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_); 337 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_);
339 InitializeBackend(true); 338 InitializeBackend(true);
340 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 339 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
341 EXPECT_TRUE( 340 EXPECT_TRUE(
342 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_) 341 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_)
343 .Empty()); 342 .Empty());
344 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 343 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
345 EXPECT_TRUE( 344 EXPECT_TRUE(
346 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 345 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
347 .Empty()); 346 .Empty());
348 347
349 ModelTypeSet ready_types = ConfigureDataTypes(); 348 ModelTypeSet ready_types = ConfigureDataTypes();
350 EXPECT_EQ(enabled_types_, ready_types); 349 EXPECT_EQ(enabled_types_, ready_types);
351 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 350 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
352 EXPECT_TRUE( 351 EXPECT_TRUE(
353 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_) 352 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_)
354 .Empty()); 353 .Empty());
355 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 354 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
356 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
357 EXPECT_TRUE( 355 EXPECT_TRUE(
358 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 356 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
359 .Empty()); 357 .Empty());
360 } 358 }
361 359
362 // Test a sync restart scenario where some types had never finished configuring. 360 // Test a sync restart scenario where some types had never finished configuring.
363 // The partial types should be purged, then reconfigured properly. 361 // The partial types should be purged, then reconfigured properly.
364 TEST_F(SyncEngineTest, PartialTypes) { 362 TEST_F(SyncEngineTest, PartialTypes) {
365 sync_prefs_->SetFirstSetupComplete(); 363 sync_prefs_->SetFirstSetupComplete();
366 // Set sync manager behavior before passing it down. All types have progress 364 // Set sync manager behavior before passing it down. All types have progress
(...skipping 15 matching lines...) Expand all
382 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)); 380 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_));
383 381
384 // Now do the actual configuration, which should download and apply bookmarks. 382 // Now do the actual configuration, which should download and apply bookmarks.
385 ModelTypeSet ready_types = ConfigureDataTypes(); 383 ModelTypeSet ready_types = ConfigureDataTypes();
386 EXPECT_EQ(full_types, ready_types); 384 EXPECT_EQ(full_types, ready_types);
387 EXPECT_TRUE( 385 EXPECT_TRUE(
388 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_) 386 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_)
389 .Empty()); 387 .Empty());
390 EXPECT_EQ(partial_types, fake_manager_->GetAndResetDownloadedTypes()); 388 EXPECT_EQ(partial_types, fake_manager_->GetAndResetDownloadedTypes());
391 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 389 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
392 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
393 EXPECT_TRUE( 390 EXPECT_TRUE(
394 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 391 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
395 .Empty()); 392 .Empty());
396 } 393 }
397 394
398 // Test the behavior when we lose the sync db. Although we already have types 395 // Test the behavior when we lose the sync db. Although we already have types
399 // enabled, we should re-download all of them because we lost their data. 396 // enabled, we should re-download all of them because we lost their data.
400 TEST_F(SyncEngineTest, LostDB) { 397 TEST_F(SyncEngineTest, LostDB) {
401 sync_prefs_->SetFirstSetupComplete(); 398 sync_prefs_->SetFirstSetupComplete();
402 // Initialization should fetch the Nigori node. Everything else should be 399 // Initialization should fetch the Nigori node. Everything else should be
(...skipping 14 matching lines...) Expand all
417 // The actual configuration should redownload and apply all the enabled types. 414 // The actual configuration should redownload and apply all the enabled types.
418 ModelTypeSet ready_types = ConfigureDataTypes(); 415 ModelTypeSet ready_types = ConfigureDataTypes();
419 // Nigori is always downloaded so won't be ready. 416 // Nigori is always downloaded so won't be ready.
420 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types); 417 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types);
421 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( 418 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll(
422 Difference(enabled_types_, ControlTypes()))); 419 Difference(enabled_types_, ControlTypes())));
423 EXPECT_TRUE( 420 EXPECT_TRUE(
424 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_) 421 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_)
425 .Empty()); 422 .Empty());
426 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 423 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
427 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
428 EXPECT_TRUE( 424 EXPECT_TRUE(
429 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 425 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
430 .Empty()); 426 .Empty());
431 } 427 }
432 428
433 TEST_F(SyncEngineTest, DisableTypes) { 429 TEST_F(SyncEngineTest, DisableTypes) {
434 // Simulate first time sync. 430 // Simulate first time sync.
435 InitializeBackend(true); 431 InitializeBackend(true);
436 fake_manager_->GetAndResetPurgedTypes(); 432 fake_manager_->GetAndResetPurgedTypes();
437 ModelTypeSet ready_types = ConfigureDataTypes(); 433 ModelTypeSet ready_types = ConfigureDataTypes();
(...skipping 14 matching lines...) Expand all
452 enabled_types_.RemoveAll(disabled_types); 448 enabled_types_.RemoveAll(disabled_types);
453 ready_types = ConfigureDataTypes(); 449 ready_types = ConfigureDataTypes();
454 450
455 // Only those datatypes disabled should be cleaned. Nothing should be 451 // Only those datatypes disabled should be cleaned. Nothing should be
456 // downloaded. 452 // downloaded.
457 EXPECT_EQ(enabled_types_, ready_types); 453 EXPECT_EQ(enabled_types_, ready_types);
458 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 454 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
459 EXPECT_EQ(disabled_types, 455 EXPECT_EQ(disabled_types,
460 Intersection(fake_manager_->GetAndResetPurgedTypes(), old_types)); 456 Intersection(fake_manager_->GetAndResetPurgedTypes(), old_types));
461 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 457 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
462 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
463 EXPECT_TRUE( 458 EXPECT_TRUE(
464 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 459 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
465 .Empty()); 460 .Empty());
466 } 461 }
467 462
468 TEST_F(SyncEngineTest, AddTypes) { 463 TEST_F(SyncEngineTest, AddTypes) {
469 // Simulate first time sync. 464 // Simulate first time sync.
470 InitializeBackend(true); 465 InitializeBackend(true);
471 fake_manager_->GetAndResetPurgedTypes(); 466 fake_manager_->GetAndResetPurgedTypes();
472 ModelTypeSet ready_types = ConfigureDataTypes(); 467 ModelTypeSet ready_types = ConfigureDataTypes();
(...skipping 15 matching lines...) Expand all
488 483
489 // Only those datatypes added should be downloaded (plus nigori). Nothing 484 // Only those datatypes added should be downloaded (plus nigori). Nothing
490 // should be cleaned aside from the disabled types. 485 // should be cleaned aside from the disabled types.
491 new_types.Put(NIGORI); 486 new_types.Put(NIGORI);
492 EXPECT_EQ(Difference(enabled_types_, new_types), ready_types); 487 EXPECT_EQ(Difference(enabled_types_, new_types), ready_types);
493 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); 488 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes());
494 EXPECT_TRUE( 489 EXPECT_TRUE(
495 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_) 490 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_)
496 .Empty()); 491 .Empty());
497 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 492 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
498 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
499 EXPECT_TRUE( 493 EXPECT_TRUE(
500 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 494 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
501 .Empty()); 495 .Empty());
502 } 496 }
503 497
504 // And and disable in the same configuration. 498 // And and disable in the same configuration.
505 TEST_F(SyncEngineTest, AddDisableTypes) { 499 TEST_F(SyncEngineTest, AddDisableTypes) {
506 // Simulate first time sync. 500 // Simulate first time sync.
507 InitializeBackend(true); 501 InitializeBackend(true);
508 fake_manager_->GetAndResetPurgedTypes(); 502 fake_manager_->GetAndResetPurgedTypes();
(...skipping 18 matching lines...) Expand all
527 ready_types = ConfigureDataTypes(); 521 ready_types = ConfigureDataTypes();
528 522
529 // Only those datatypes added should be downloaded (plus nigori). Nothing 523 // Only those datatypes added should be downloaded (plus nigori). Nothing
530 // should be cleaned aside from the disabled types. 524 // should be cleaned aside from the disabled types.
531 new_types.Put(NIGORI); 525 new_types.Put(NIGORI);
532 EXPECT_EQ(Difference(enabled_types_, new_types), ready_types); 526 EXPECT_EQ(Difference(enabled_types_, new_types), ready_types);
533 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); 527 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes());
534 EXPECT_EQ(disabled_types, 528 EXPECT_EQ(disabled_types,
535 Intersection(fake_manager_->GetAndResetPurgedTypes(), old_types)); 529 Intersection(fake_manager_->GetAndResetPurgedTypes(), old_types));
536 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 530 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
537 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
538 EXPECT_EQ(disabled_types, 531 EXPECT_EQ(disabled_types,
539 fake_manager_->GetTypesWithEmptyProgressMarkerToken(old_types)); 532 fake_manager_->GetTypesWithEmptyProgressMarkerToken(old_types));
540 } 533 }
541 534
542 // Test restarting the browser to newly supported datatypes. The new datatypes 535 // Test restarting the browser to newly supported datatypes. The new datatypes
543 // should be downloaded on the configuration after backend initialization. 536 // should be downloaded on the configuration after backend initialization.
544 TEST_F(SyncEngineTest, NewlySupportedTypes) { 537 TEST_F(SyncEngineTest, NewlySupportedTypes) {
545 sync_prefs_->SetFirstSetupComplete(); 538 sync_prefs_->SetFirstSetupComplete();
546 // Set sync manager behavior before passing it down. All types have progress 539 // Set sync manager behavior before passing it down. All types have progress
547 // markers and initial sync ended except the new types. 540 // markers and initial sync ended except the new types.
(...skipping 15 matching lines...) Expand all
563 // Downloads and applies the new types (plus nigori). 556 // Downloads and applies the new types (plus nigori).
564 ModelTypeSet ready_types = ConfigureDataTypes(); 557 ModelTypeSet ready_types = ConfigureDataTypes();
565 558
566 new_types.Put(NIGORI); 559 new_types.Put(NIGORI);
567 EXPECT_EQ(Difference(old_types, ModelTypeSet(NIGORI)), ready_types); 560 EXPECT_EQ(Difference(old_types, ModelTypeSet(NIGORI)), ready_types);
568 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); 561 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes());
569 EXPECT_TRUE( 562 EXPECT_TRUE(
570 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_) 563 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_)
571 .Empty()); 564 .Empty());
572 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 565 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
573 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
574 EXPECT_TRUE( 566 EXPECT_TRUE(
575 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 567 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
576 .Empty()); 568 .Empty());
577 } 569 }
578 570
579 // Test the newly supported types scenario, but with the presence of partial 571 // Test the newly supported types scenario, but with the presence of partial
580 // types as well. Both partial and newly supported types should be downloaded 572 // types as well. Both partial and newly supported types should be downloaded
581 // the configuration. 573 // the configuration.
582 TEST_F(SyncEngineTest, NewlySupportedTypesWithPartialTypes) { 574 TEST_F(SyncEngineTest, NewlySupportedTypesWithPartialTypes) {
583 sync_prefs_->SetFirstSetupComplete(); 575 sync_prefs_->SetFirstSetupComplete();
(...skipping 21 matching lines...) Expand all
605 // Downloads and applies the new types and partial types (which includes 597 // Downloads and applies the new types and partial types (which includes
606 // nigori anyways). 598 // nigori anyways).
607 ModelTypeSet ready_types = ConfigureDataTypes(); 599 ModelTypeSet ready_types = ConfigureDataTypes();
608 EXPECT_EQ(full_types, ready_types); 600 EXPECT_EQ(full_types, ready_types);
609 EXPECT_EQ(Union(new_types, partial_types), 601 EXPECT_EQ(Union(new_types, partial_types),
610 fake_manager_->GetAndResetDownloadedTypes()); 602 fake_manager_->GetAndResetDownloadedTypes());
611 EXPECT_TRUE( 603 EXPECT_TRUE(
612 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_) 604 Intersection(fake_manager_->GetAndResetPurgedTypes(), enabled_types_)
613 .Empty()); 605 .Empty());
614 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 606 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
615 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
616 EXPECT_TRUE( 607 EXPECT_TRUE(
617 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 608 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
618 .Empty()); 609 .Empty());
619 } 610 }
620 611
621 // Verify that downloading control types only downloads those types that do 612 // Verify that downloading control types only downloads those types that do
622 // not have initial sync ended set. 613 // not have initial sync ended set.
623 TEST_F(SyncEngineTest, DownloadControlTypes) { 614 TEST_F(SyncEngineTest, DownloadControlTypes) {
624 sync_prefs_->SetFirstSetupComplete(); 615 sync_prefs_->SetFirstSetupComplete();
625 // Set sync manager behavior before passing it down. Experiments and device 616 // Set sync manager behavior before passing it down. Experiments and device
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 backend_->StopSyncingForShutdown(); 800 backend_->StopSyncingForShutdown();
810 // Verify that call to DeactivateNonBlockingDataType doesn't assert. 801 // Verify that call to DeactivateNonBlockingDataType doesn't assert.
811 backend_->DeactivateNonBlockingDataType(AUTOFILL); 802 backend_->DeactivateNonBlockingDataType(AUTOFILL);
812 backend_->Shutdown(STOP_SYNC); 803 backend_->Shutdown(STOP_SYNC);
813 backend_.reset(); 804 backend_.reset();
814 } 805 }
815 806
816 } // namespace 807 } // namespace
817 808
818 } // namespace syncer 809 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/glue/sync_backend_host_impl.cc ('k') | components/sync/driver/model_association_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698