OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "chrome/browser/sync/engine/apply_updates_command.h" | 10 #include "chrome/browser/sync/engine/apply_updates_command.h" |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 << "conflict"; | 419 << "conflict"; |
420 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 420 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
421 << "The undecryptable password update shouldn't be applied"; | 421 << "The undecryptable password update shouldn't be applied"; |
422 } | 422 } |
423 } | 423 } |
424 | 424 |
425 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { | 425 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { |
426 // Storing the cryptographer separately is bad, but for this test we | 426 // Storing the cryptographer separately is bad, but for this test we |
427 // know it's safe. | 427 // know it's safe. |
428 Cryptographer* cryptographer; | 428 Cryptographer* cryptographer; |
429 syncable::ModelEnumSet encrypted_types; | 429 syncable::ModelTypeSet encrypted_types; |
430 encrypted_types.Put(syncable::PASSWORDS); | 430 encrypted_types.Put(syncable::PASSWORDS); |
431 encrypted_types.Put(syncable::NIGORI); | 431 encrypted_types.Put(syncable::NIGORI); |
432 { | 432 { |
433 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 433 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
434 ASSERT_TRUE(dir.good()); | 434 ASSERT_TRUE(dir.good()); |
435 ReadTransaction trans(FROM_HERE, dir); | 435 ReadTransaction trans(FROM_HERE, dir); |
436 cryptographer = | 436 cryptographer = |
437 session()->context()->directory_manager()->GetCryptographer(&trans); | 437 session()->context()->directory_manager()->GetCryptographer(&trans); |
438 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); | 438 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); |
439 } | 439 } |
(...skipping 24 matching lines...) Expand all Loading... |
464 ASSERT_TRUE(status->conflict_progress()); | 464 ASSERT_TRUE(status->conflict_progress()); |
465 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) | 465 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
466 << "The nigori update shouldn't be in conflict"; | 466 << "The nigori update shouldn't be in conflict"; |
467 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 467 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
468 << "The nigori update should be applied"; | 468 << "The nigori update should be applied"; |
469 | 469 |
470 EXPECT_FALSE(cryptographer->is_ready()); | 470 EXPECT_FALSE(cryptographer->is_ready()); |
471 EXPECT_TRUE(cryptographer->has_pending_keys()); | 471 EXPECT_TRUE(cryptographer->has_pending_keys()); |
472 EXPECT_TRUE( | 472 EXPECT_TRUE( |
473 cryptographer->GetEncryptedTypes() | 473 cryptographer->GetEncryptedTypes() |
474 .Equals(syncable::ModelEnumSet::All())); | 474 .Equals(syncable::ModelTypeSet::All())); |
475 } | 475 } |
476 | 476 |
477 TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) { | 477 TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) { |
478 // Storing the cryptographer separately is bad, but for this test we | 478 // Storing the cryptographer separately is bad, but for this test we |
479 // know it's safe. | 479 // know it's safe. |
480 Cryptographer* cryptographer; | 480 Cryptographer* cryptographer; |
481 syncable::ModelEnumSet encrypted_types; | 481 syncable::ModelTypeSet encrypted_types; |
482 encrypted_types.Put(syncable::PASSWORDS); | 482 encrypted_types.Put(syncable::PASSWORDS); |
483 encrypted_types.Put(syncable::NIGORI); | 483 encrypted_types.Put(syncable::NIGORI); |
484 { | 484 { |
485 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 485 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
486 ASSERT_TRUE(dir.good()); | 486 ASSERT_TRUE(dir.good()); |
487 ReadTransaction trans(FROM_HERE, dir); | 487 ReadTransaction trans(FROM_HERE, dir); |
488 cryptographer = | 488 cryptographer = |
489 session()->context()->directory_manager()->GetCryptographer(&trans); | 489 session()->context()->directory_manager()->GetCryptographer(&trans); |
490 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); | 490 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); |
491 } | 491 } |
(...skipping 26 matching lines...) Expand all Loading... |
518 ASSERT_TRUE(status->conflict_progress()); | 518 ASSERT_TRUE(status->conflict_progress()); |
519 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) | 519 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
520 << "The nigori update shouldn't be in conflict"; | 520 << "The nigori update shouldn't be in conflict"; |
521 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 521 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
522 << "The nigori update should be applied"; | 522 << "The nigori update should be applied"; |
523 | 523 |
524 EXPECT_FALSE(cryptographer->is_ready()); | 524 EXPECT_FALSE(cryptographer->is_ready()); |
525 EXPECT_TRUE(cryptographer->has_pending_keys()); | 525 EXPECT_TRUE(cryptographer->has_pending_keys()); |
526 EXPECT_TRUE( | 526 EXPECT_TRUE( |
527 cryptographer->GetEncryptedTypes() | 527 cryptographer->GetEncryptedTypes() |
528 .Equals(syncable::ModelEnumSet::All())); | 528 .Equals(syncable::ModelTypeSet::All())); |
529 } | 529 } |
530 | 530 |
531 TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { | 531 TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { |
532 // Storing the cryptographer separately is bad, but for this test we | 532 // Storing the cryptographer separately is bad, but for this test we |
533 // know it's safe. | 533 // know it's safe. |
534 Cryptographer* cryptographer; | 534 Cryptographer* cryptographer; |
535 syncable::ModelEnumSet encrypted_types; | 535 syncable::ModelTypeSet encrypted_types; |
536 encrypted_types.Put(syncable::PASSWORDS); | 536 encrypted_types.Put(syncable::PASSWORDS); |
537 encrypted_types.Put(syncable::NIGORI); | 537 encrypted_types.Put(syncable::NIGORI); |
538 { | 538 { |
539 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 539 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
540 ASSERT_TRUE(dir.good()); | 540 ASSERT_TRUE(dir.good()); |
541 ReadTransaction trans(FROM_HERE, dir); | 541 ReadTransaction trans(FROM_HERE, dir); |
542 cryptographer = | 542 cryptographer = |
543 session()->context()->directory_manager()->GetCryptographer(&trans); | 543 session()->context()->directory_manager()->GetCryptographer(&trans); |
544 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); | 544 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); |
545 | 545 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 << "The nigori update should be applied"; | 614 << "The nigori update should be applied"; |
615 EXPECT_FALSE(cryptographer->has_pending_keys()); | 615 EXPECT_FALSE(cryptographer->has_pending_keys()); |
616 EXPECT_TRUE(cryptographer->is_ready()); | 616 EXPECT_TRUE(cryptographer->is_ready()); |
617 { | 617 { |
618 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 618 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
619 ASSERT_TRUE(dir.good()); | 619 ASSERT_TRUE(dir.good()); |
620 ReadTransaction trans(FROM_HERE, dir); | 620 ReadTransaction trans(FROM_HERE, dir); |
621 | 621 |
622 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes | 622 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes |
623 // should be encrypted now. | 623 // should be encrypted now. |
624 EXPECT_TRUE(syncable::ModelEnumSet::All().Equals( | 624 EXPECT_TRUE(syncable::ModelTypeSet::All().Equals( |
625 cryptographer->GetEncryptedTypes())); | 625 cryptographer->GetEncryptedTypes())); |
626 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 626 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
627 | 627 |
628 Syncer::UnsyncedMetaHandles handles; | 628 Syncer::UnsyncedMetaHandles handles; |
629 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 629 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
630 EXPECT_EQ(2*batch_s+1, handles.size()); | 630 EXPECT_EQ(2*batch_s+1, handles.size()); |
631 } | 631 } |
632 } | 632 } |
633 | 633 |
634 TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { | 634 TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { |
635 // Storing the cryptographer separately is bad, but for this test we | 635 // Storing the cryptographer separately is bad, but for this test we |
636 // know it's safe. | 636 // know it's safe. |
637 Cryptographer* cryptographer; | 637 Cryptographer* cryptographer; |
638 syncable::ModelEnumSet encrypted_types; | 638 syncable::ModelTypeSet encrypted_types; |
639 encrypted_types.Put(syncable::PASSWORDS); | 639 encrypted_types.Put(syncable::PASSWORDS); |
640 encrypted_types.Put(syncable::NIGORI); | 640 encrypted_types.Put(syncable::NIGORI); |
641 { | 641 { |
642 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 642 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
643 ASSERT_TRUE(dir.good()); | 643 ASSERT_TRUE(dir.good()); |
644 ReadTransaction trans(FROM_HERE, dir); | 644 ReadTransaction trans(FROM_HERE, dir); |
645 cryptographer = | 645 cryptographer = |
646 session()->context()->directory_manager()->GetCryptographer(&trans); | 646 session()->context()->directory_manager()->GetCryptographer(&trans); |
647 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); | 647 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); |
648 | 648 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 ReadTransaction trans(FROM_HERE, dir); | 726 ReadTransaction trans(FROM_HERE, dir); |
727 | 727 |
728 // Since we're in conflict, the specifics don't reflect the unapplied | 728 // Since we're in conflict, the specifics don't reflect the unapplied |
729 // changes. | 729 // changes. |
730 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 730 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
731 encrypted_types.Clear(); | 731 encrypted_types.Clear(); |
732 encrypted_types.Put(syncable::PASSWORDS); | 732 encrypted_types.Put(syncable::PASSWORDS); |
733 encrypted_types.Put(syncable::BOOKMARKS); | 733 encrypted_types.Put(syncable::BOOKMARKS); |
734 EXPECT_TRUE( | 734 EXPECT_TRUE( |
735 cryptographer->GetEncryptedTypes().Equals( | 735 cryptographer->GetEncryptedTypes().Equals( |
736 syncable::ModelEnumSet().All())); | 736 syncable::ModelTypeSet().All())); |
737 | 737 |
738 Syncer::UnsyncedMetaHandles handles; | 738 Syncer::UnsyncedMetaHandles handles; |
739 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 739 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
740 EXPECT_EQ(2*batch_s+1, handles.size()); | 740 EXPECT_EQ(2*batch_s+1, handles.size()); |
741 } | 741 } |
742 } | 742 } |
743 | 743 |
744 } // namespace browser_sync | 744 } // namespace browser_sync |
OLD | NEW |