Chromium Code Reviews| 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" |
| 11 #include "chrome/browser/sync/engine/nigori_util.h" | 11 #include "chrome/browser/sync/engine/nigori_util.h" |
| 12 #include "chrome/browser/sync/engine/syncer.h" | 12 #include "chrome/browser/sync/engine/syncer.h" |
| 13 #include "chrome/browser/sync/engine/syncer_util.h" | 13 #include "chrome/browser/sync/engine/syncer_util.h" |
| 14 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 14 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 15 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 15 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 16 #include "chrome/browser/sync/sessions/sync_session.h" | 16 #include "chrome/browser/sync/sessions/sync_session.h" |
| 17 #include "chrome/browser/sync/syncable/directory_manager.h" | 17 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 18 #include "chrome/browser/sync/syncable/syncable.h" | 18 #include "chrome/browser/sync/syncable/syncable.h" |
| 19 #include "chrome/browser/sync/syncable/syncable_id.h" | 19 #include "chrome/browser/sync/syncable/syncable_id.h" |
| 20 #include "chrome/browser/sync/test/engine/fake_model_worker.h" | 20 #include "chrome/browser/sync/test/engine/fake_model_worker.h" |
| 21 #include "chrome/browser/sync/test/engine/syncer_command_test.h" | 21 #include "chrome/browser/sync/test/engine/syncer_command_test.h" |
| 22 #include "chrome/browser/sync/test/engine/test_id_factory.h" | 22 #include "chrome/browser/sync/test/engine/test_id_factory.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 namespace browser_sync { | 25 namespace browser_sync { |
| 26 | 26 |
| 27 using sessions::SyncSession; | 27 using sessions::SyncSession; |
| 28 using std::string; | 28 using std::string; |
| 29 using syncable::Entry; | 29 using syncable::Entry; |
| 30 using syncable::GetAllRealModelTypes; | |
| 31 using syncable::Id; | 30 using syncable::Id; |
| 32 using syncable::MutableEntry; | 31 using syncable::MutableEntry; |
| 33 using syncable::ReadTransaction; | 32 using syncable::ReadTransaction; |
| 34 using syncable::ScopedDirLookup; | 33 using syncable::ScopedDirLookup; |
| 35 using syncable::UNITTEST; | 34 using syncable::UNITTEST; |
| 36 using syncable::WriteTransaction; | 35 using syncable::WriteTransaction; |
| 37 | 36 |
| 38 namespace { | 37 namespace { |
| 39 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { | 38 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { |
| 40 sync_pb::EntitySpecifics result; | 39 sync_pb::EntitySpecifics result; |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 << "conflict"; | 419 << "conflict"; |
| 421 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 420 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
| 422 << "The undecryptable password update shouldn't be applied"; | 421 << "The undecryptable password update shouldn't be applied"; |
| 423 } | 422 } |
| 424 } | 423 } |
| 425 | 424 |
| 426 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { | 425 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { |
| 427 // Storing the cryptographer separately is bad, but for this test we | 426 // Storing the cryptographer separately is bad, but for this test we |
| 428 // know it's safe. | 427 // know it's safe. |
| 429 Cryptographer* cryptographer; | 428 Cryptographer* cryptographer; |
| 430 syncable::ModelTypeSet encrypted_types; | 429 syncable::ModelEnumSet encrypted_types; |
| 431 encrypted_types.insert(syncable::PASSWORDS); | 430 encrypted_types.Put(syncable::PASSWORDS); |
| 432 encrypted_types.insert(syncable::NIGORI); | 431 encrypted_types.Put(syncable::NIGORI); |
| 433 { | 432 { |
| 434 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 433 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 435 ASSERT_TRUE(dir.good()); | 434 ASSERT_TRUE(dir.good()); |
| 436 ReadTransaction trans(FROM_HERE, dir); | 435 ReadTransaction trans(FROM_HERE, dir); |
| 437 cryptographer = | 436 cryptographer = |
| 438 session()->context()->directory_manager()->GetCryptographer(&trans); | 437 session()->context()->directory_manager()->GetCryptographer(&trans); |
| 439 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); | 438 EXPECT_TRUE(encrypted_types.Equals(cryptographer->GetEncryptedTypes())); |
| 440 } | 439 } |
| 441 | 440 |
| 442 // Nigori node updates should update the Cryptographer. | 441 // Nigori node updates should update the Cryptographer. |
| 443 Cryptographer other_cryptographer; | 442 Cryptographer other_cryptographer; |
| 444 KeyParams params = {"localhost", "dummy", "foobar"}; | 443 KeyParams params = {"localhost", "dummy", "foobar"}; |
| 445 other_cryptographer.AddKey(params); | 444 other_cryptographer.AddKey(params); |
| 446 | 445 |
| 447 sync_pb::EntitySpecifics specifics; | 446 sync_pb::EntitySpecifics specifics; |
| 448 sync_pb::NigoriSpecifics* nigori = | 447 sync_pb::NigoriSpecifics* nigori = |
| 449 specifics.MutableExtension(sync_pb::nigori); | 448 specifics.MutableExtension(sync_pb::nigori); |
| 450 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 449 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| 451 nigori->set_encrypt_bookmarks(true); | 450 nigori->set_encrypt_bookmarks(true); |
| 452 encrypted_types.insert(syncable::BOOKMARKS); | 451 encrypted_types.Put(syncable::BOOKMARKS); |
| 453 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), | 452 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), |
| 454 specifics, true); | 453 specifics, true); |
| 455 EXPECT_FALSE(cryptographer->has_pending_keys()); | 454 EXPECT_FALSE(cryptographer->has_pending_keys()); |
| 456 | 455 |
| 457 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); | 456 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); |
| 458 apply_updates_command_.ExecuteImpl(session()); | 457 apply_updates_command_.ExecuteImpl(session()); |
| 459 | 458 |
| 460 sessions::StatusController* status = session()->mutable_status_controller(); | 459 sessions::StatusController* status = session()->mutable_status_controller(); |
| 461 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 460 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
| 462 ASSERT_TRUE(status->update_progress()); | 461 ASSERT_TRUE(status->update_progress()); |
| 463 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) | 462 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) |
| 464 << "All updates should have been attempted"; | 463 << "All updates should have been attempted"; |
| 465 ASSERT_TRUE(status->conflict_progress()); | 464 ASSERT_TRUE(status->conflict_progress()); |
| 466 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) | 465 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
| 467 << "The nigori update shouldn't be in conflict"; | 466 << "The nigori update shouldn't be in conflict"; |
| 468 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 467 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
| 469 << "The nigori update should be applied"; | 468 << "The nigori update should be applied"; |
| 470 | 469 |
| 471 EXPECT_FALSE(cryptographer->is_ready()); | 470 EXPECT_FALSE(cryptographer->is_ready()); |
| 472 EXPECT_TRUE(cryptographer->has_pending_keys()); | 471 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 473 EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes()); | 472 EXPECT_TRUE( |
|
Nicolas Zea
2011/12/08 01:49:37
ExpectTrue(cryptographer->GetEncryptedTypes()
akalin
2011/12/09 19:10:10
Indented 4 spaces instead
| |
| 473 cryptographer->GetEncryptedTypes() | |
| 474 .Equals(syncable::ModelEnumSet::All())); | |
| 474 } | 475 } |
| 475 | 476 |
| 476 TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) { | 477 TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) { |
| 477 // Storing the cryptographer separately is bad, but for this test we | 478 // Storing the cryptographer separately is bad, but for this test we |
| 478 // know it's safe. | 479 // know it's safe. |
| 479 Cryptographer* cryptographer; | 480 Cryptographer* cryptographer; |
| 480 syncable::ModelTypeSet encrypted_types; | 481 syncable::ModelEnumSet encrypted_types; |
| 481 encrypted_types.insert(syncable::PASSWORDS); | 482 encrypted_types.Put(syncable::PASSWORDS); |
| 482 encrypted_types.insert(syncable::NIGORI); | 483 encrypted_types.Put(syncable::NIGORI); |
| 483 { | 484 { |
| 484 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 485 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 485 ASSERT_TRUE(dir.good()); | 486 ASSERT_TRUE(dir.good()); |
| 486 ReadTransaction trans(FROM_HERE, dir); | 487 ReadTransaction trans(FROM_HERE, dir); |
| 487 cryptographer = | 488 cryptographer = |
| 488 session()->context()->directory_manager()->GetCryptographer(&trans); | 489 session()->context()->directory_manager()->GetCryptographer(&trans); |
| 489 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); | 490 EXPECT_TRUE(encrypted_types.Equals(cryptographer->GetEncryptedTypes())); |
| 490 } | 491 } |
| 491 | 492 |
| 492 // Nigori node updates should update the Cryptographer. | 493 // Nigori node updates should update the Cryptographer. |
| 493 Cryptographer other_cryptographer; | 494 Cryptographer other_cryptographer; |
| 494 KeyParams params = {"localhost", "dummy", "foobar"}; | 495 KeyParams params = {"localhost", "dummy", "foobar"}; |
| 495 other_cryptographer.AddKey(params); | 496 other_cryptographer.AddKey(params); |
| 496 | 497 |
| 497 sync_pb::EntitySpecifics specifics; | 498 sync_pb::EntitySpecifics specifics; |
| 498 sync_pb::NigoriSpecifics* nigori = | 499 sync_pb::NigoriSpecifics* nigori = |
| 499 specifics.MutableExtension(sync_pb::nigori); | 500 specifics.MutableExtension(sync_pb::nigori); |
| 500 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 501 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| 501 nigori->set_encrypt_sessions(true); | 502 nigori->set_encrypt_sessions(true); |
| 502 nigori->set_encrypt_themes(true); | 503 nigori->set_encrypt_themes(true); |
| 503 encrypted_types.insert(syncable::SESSIONS); | 504 encrypted_types.Put(syncable::SESSIONS); |
| 504 encrypted_types.insert(syncable::THEMES); | 505 encrypted_types.Put(syncable::THEMES); |
| 505 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), | 506 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), |
| 506 specifics, true); | 507 specifics, true); |
| 507 EXPECT_FALSE(cryptographer->has_pending_keys()); | 508 EXPECT_FALSE(cryptographer->has_pending_keys()); |
| 508 | 509 |
| 509 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); | 510 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); |
| 510 apply_updates_command_.ExecuteImpl(session()); | 511 apply_updates_command_.ExecuteImpl(session()); |
| 511 | 512 |
| 512 sessions::StatusController* status = session()->mutable_status_controller(); | 513 sessions::StatusController* status = session()->mutable_status_controller(); |
| 513 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 514 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
| 514 ASSERT_TRUE(status->update_progress()); | 515 ASSERT_TRUE(status->update_progress()); |
| 515 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) | 516 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) |
| 516 << "All updates should have been attempted"; | 517 << "All updates should have been attempted"; |
| 517 ASSERT_TRUE(status->conflict_progress()); | 518 ASSERT_TRUE(status->conflict_progress()); |
| 518 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) | 519 EXPECT_EQ(0, status->conflict_progress()->ConflictingItemsSize()) |
| 519 << "The nigori update shouldn't be in conflict"; | 520 << "The nigori update shouldn't be in conflict"; |
| 520 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 521 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
| 521 << "The nigori update should be applied"; | 522 << "The nigori update should be applied"; |
| 522 | 523 |
| 523 EXPECT_FALSE(cryptographer->is_ready()); | 524 EXPECT_FALSE(cryptographer->is_ready()); |
| 524 EXPECT_TRUE(cryptographer->has_pending_keys()); | 525 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 525 EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes()); | 526 EXPECT_TRUE(syncable::ModelEnumSet::All().Equals( |
| 527 cryptographer->GetEncryptedTypes())); | |
| 526 } | 528 } |
| 527 | 529 |
| 528 TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { | 530 TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { |
| 529 // Storing the cryptographer separately is bad, but for this test we | 531 // Storing the cryptographer separately is bad, but for this test we |
| 530 // know it's safe. | 532 // know it's safe. |
| 531 Cryptographer* cryptographer; | 533 Cryptographer* cryptographer; |
| 532 syncable::ModelTypeSet encrypted_types; | 534 syncable::ModelEnumSet encrypted_types; |
| 533 encrypted_types.insert(syncable::PASSWORDS); | 535 encrypted_types.Put(syncable::PASSWORDS); |
| 534 encrypted_types.insert(syncable::NIGORI); | 536 encrypted_types.Put(syncable::NIGORI); |
| 535 { | 537 { |
| 536 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 538 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 537 ASSERT_TRUE(dir.good()); | 539 ASSERT_TRUE(dir.good()); |
| 538 ReadTransaction trans(FROM_HERE, dir); | 540 ReadTransaction trans(FROM_HERE, dir); |
| 539 cryptographer = | 541 cryptographer = |
| 540 session()->context()->directory_manager()->GetCryptographer(&trans); | 542 session()->context()->directory_manager()->GetCryptographer(&trans); |
| 541 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); | 543 EXPECT_TRUE(encrypted_types.Equals(cryptographer->GetEncryptedTypes())); |
| 542 | 544 |
| 543 | 545 |
| 544 // With default encrypted_types, this should be true. | 546 // With default encrypted_types, this should be true. |
| 545 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 547 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| 546 | 548 |
| 547 Syncer::UnsyncedMetaHandles handles; | 549 Syncer::UnsyncedMetaHandles handles; |
| 548 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 550 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| 549 EXPECT_TRUE(handles.empty()); | 551 EXPECT_TRUE(handles.empty()); |
| 550 } | 552 } |
| 551 | 553 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 569 syncable::BOOKMARKS, NULL); | 571 syncable::BOOKMARKS, NULL); |
| 570 } | 572 } |
| 571 | 573 |
| 572 KeyParams params = {"localhost", "dummy", "foobar"}; | 574 KeyParams params = {"localhost", "dummy", "foobar"}; |
| 573 cryptographer->AddKey(params); | 575 cryptographer->AddKey(params); |
| 574 sync_pb::EntitySpecifics specifics; | 576 sync_pb::EntitySpecifics specifics; |
| 575 sync_pb::NigoriSpecifics* nigori = | 577 sync_pb::NigoriSpecifics* nigori = |
| 576 specifics.MutableExtension(sync_pb::nigori); | 578 specifics.MutableExtension(sync_pb::nigori); |
| 577 cryptographer->GetKeys(nigori->mutable_encrypted()); | 579 cryptographer->GetKeys(nigori->mutable_encrypted()); |
| 578 nigori->set_encrypt_bookmarks(true); | 580 nigori->set_encrypt_bookmarks(true); |
| 579 encrypted_types.insert(syncable::BOOKMARKS); | 581 encrypted_types.Put(syncable::BOOKMARKS); |
| 580 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), | 582 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), |
| 581 specifics, true); | 583 specifics, true); |
| 582 EXPECT_FALSE(cryptographer->has_pending_keys()); | 584 EXPECT_FALSE(cryptographer->has_pending_keys()); |
| 583 EXPECT_TRUE(cryptographer->is_ready()); | 585 EXPECT_TRUE(cryptographer->is_ready()); |
| 584 | 586 |
| 585 { | 587 { |
| 586 // Ensure we have unsynced nodes that aren't properly encrypted. | 588 // Ensure we have unsynced nodes that aren't properly encrypted. |
| 587 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 589 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 588 ASSERT_TRUE(dir.good()); | 590 ASSERT_TRUE(dir.good()); |
| 589 ReadTransaction trans(FROM_HERE, dir); | 591 ReadTransaction trans(FROM_HERE, dir); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 611 << "The nigori update should be applied"; | 613 << "The nigori update should be applied"; |
| 612 EXPECT_FALSE(cryptographer->has_pending_keys()); | 614 EXPECT_FALSE(cryptographer->has_pending_keys()); |
| 613 EXPECT_TRUE(cryptographer->is_ready()); | 615 EXPECT_TRUE(cryptographer->is_ready()); |
| 614 { | 616 { |
| 615 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 617 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 616 ASSERT_TRUE(dir.good()); | 618 ASSERT_TRUE(dir.good()); |
| 617 ReadTransaction trans(FROM_HERE, dir); | 619 ReadTransaction trans(FROM_HERE, dir); |
| 618 | 620 |
| 619 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes | 621 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes |
| 620 // should be encrypted now. | 622 // should be encrypted now. |
| 621 EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes()); | 623 EXPECT_TRUE(syncable::ModelEnumSet::All().Equals( |
| 624 cryptographer->GetEncryptedTypes())); | |
| 622 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 625 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| 623 | 626 |
| 624 Syncer::UnsyncedMetaHandles handles; | 627 Syncer::UnsyncedMetaHandles handles; |
| 625 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 628 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| 626 EXPECT_EQ(2*batch_s+1, handles.size()); | 629 EXPECT_EQ(2*batch_s+1, handles.size()); |
| 627 } | 630 } |
| 628 } | 631 } |
| 629 | 632 |
| 630 TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { | 633 TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { |
| 631 // Storing the cryptographer separately is bad, but for this test we | 634 // Storing the cryptographer separately is bad, but for this test we |
| 632 // know it's safe. | 635 // know it's safe. |
| 633 Cryptographer* cryptographer; | 636 Cryptographer* cryptographer; |
| 634 syncable::ModelTypeSet encrypted_types; | 637 syncable::ModelEnumSet encrypted_types; |
| 635 encrypted_types.insert(syncable::PASSWORDS); | 638 encrypted_types.Put(syncable::PASSWORDS); |
| 636 encrypted_types.insert(syncable::NIGORI); | 639 encrypted_types.Put(syncable::NIGORI); |
| 637 { | 640 { |
| 638 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 641 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 639 ASSERT_TRUE(dir.good()); | 642 ASSERT_TRUE(dir.good()); |
| 640 ReadTransaction trans(FROM_HERE, dir); | 643 ReadTransaction trans(FROM_HERE, dir); |
| 641 cryptographer = | 644 cryptographer = |
| 642 session()->context()->directory_manager()->GetCryptographer(&trans); | 645 session()->context()->directory_manager()->GetCryptographer(&trans); |
| 643 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); | 646 EXPECT_TRUE(encrypted_types.Equals(cryptographer->GetEncryptedTypes())); |
| 644 | 647 |
| 645 | 648 |
| 646 // With default encrypted_types, this should be true. | 649 // With default encrypted_types, this should be true. |
| 647 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 650 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| 648 | 651 |
| 649 Syncer::UnsyncedMetaHandles handles; | 652 Syncer::UnsyncedMetaHandles handles; |
| 650 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 653 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| 651 EXPECT_TRUE(handles.empty()); | 654 EXPECT_TRUE(handles.empty()); |
| 652 } | 655 } |
| 653 | 656 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 674 // We encrypt with new keys, triggering the local cryptographer to be unready | 677 // We encrypt with new keys, triggering the local cryptographer to be unready |
| 675 // and unable to decrypt data (once updated). | 678 // and unable to decrypt data (once updated). |
| 676 Cryptographer other_cryptographer; | 679 Cryptographer other_cryptographer; |
| 677 KeyParams params = {"localhost", "dummy", "foobar"}; | 680 KeyParams params = {"localhost", "dummy", "foobar"}; |
| 678 other_cryptographer.AddKey(params); | 681 other_cryptographer.AddKey(params); |
| 679 sync_pb::EntitySpecifics specifics; | 682 sync_pb::EntitySpecifics specifics; |
| 680 sync_pb::NigoriSpecifics* nigori = | 683 sync_pb::NigoriSpecifics* nigori = |
| 681 specifics.MutableExtension(sync_pb::nigori); | 684 specifics.MutableExtension(sync_pb::nigori); |
| 682 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 685 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| 683 nigori->set_encrypt_bookmarks(true); | 686 nigori->set_encrypt_bookmarks(true); |
| 684 encrypted_types.insert(syncable::BOOKMARKS); | 687 encrypted_types.Put(syncable::BOOKMARKS); |
| 685 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), | 688 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), |
| 686 specifics, true); | 689 specifics, true); |
| 687 EXPECT_FALSE(cryptographer->has_pending_keys()); | 690 EXPECT_FALSE(cryptographer->has_pending_keys()); |
| 688 | 691 |
| 689 { | 692 { |
| 690 // Ensure we have unsynced nodes that aren't properly encrypted. | 693 // Ensure we have unsynced nodes that aren't properly encrypted. |
| 691 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 694 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 692 ASSERT_TRUE(dir.good()); | 695 ASSERT_TRUE(dir.good()); |
| 693 ReadTransaction trans(FROM_HERE, dir); | 696 ReadTransaction trans(FROM_HERE, dir); |
| 694 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 697 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 718 EXPECT_TRUE(cryptographer->has_pending_keys()); | 721 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 719 { | 722 { |
| 720 // Ensure the unsynced nodes are still not encrypted. | 723 // Ensure the unsynced nodes are still not encrypted. |
| 721 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 724 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 722 ASSERT_TRUE(dir.good()); | 725 ASSERT_TRUE(dir.good()); |
| 723 ReadTransaction trans(FROM_HERE, dir); | 726 ReadTransaction trans(FROM_HERE, dir); |
| 724 | 727 |
| 725 // 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 |
| 726 // changes. | 729 // changes. |
| 727 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 730 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
| 728 encrypted_types.clear(); | 731 encrypted_types.Clear(); |
| 729 encrypted_types.insert(syncable::PASSWORDS); | 732 encrypted_types.Put(syncable::PASSWORDS); |
| 730 encrypted_types.insert(syncable::BOOKMARKS); | 733 encrypted_types.Put(syncable::BOOKMARKS); |
| 731 EXPECT_EQ(GetAllRealModelTypes(), cryptographer->GetEncryptedTypes()); | 734 EXPECT_TRUE(syncable::ModelEnumSet().All().Equals( |
| 735 cryptographer->GetEncryptedTypes())); | |
| 732 | 736 |
| 733 Syncer::UnsyncedMetaHandles handles; | 737 Syncer::UnsyncedMetaHandles handles; |
| 734 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 738 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| 735 EXPECT_EQ(2*batch_s+1, handles.size()); | 739 EXPECT_EQ(2*batch_s+1, handles.size()); |
| 736 } | 740 } |
| 737 } | 741 } |
| 738 | 742 |
| 739 } // namespace browser_sync | 743 } // namespace browser_sync |
| OLD | NEW |