| 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 "sync/internal_api/sync_encryption_handler_impl.h" | 5 #include "sync/internal_api/sync_encryption_handler_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 class SyncEncryptionHandlerImplTest : public ::testing::Test { | 64 class SyncEncryptionHandlerImplTest : public ::testing::Test { |
| 65 public: | 65 public: |
| 66 SyncEncryptionHandlerImplTest() {} | 66 SyncEncryptionHandlerImplTest() {} |
| 67 virtual ~SyncEncryptionHandlerImplTest() {} | 67 virtual ~SyncEncryptionHandlerImplTest() {} |
| 68 | 68 |
| 69 virtual void SetUp() { | 69 virtual void SetUp() { |
| 70 test_user_share_.SetUp(); | 70 test_user_share_.SetUp(); |
| 71 SetUpEncryption(); | 71 SetUpEncryption(); |
| 72 CreateRootForType(NIGORI); | 72 TestUserShare::CreateRoot(NIGORI, user_share()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual void TearDown() { | 75 virtual void TearDown() { |
| 76 PumpLoop(); | 76 PumpLoop(); |
| 77 test_user_share_.TearDown(); | 77 test_user_share_.TearDown(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 protected: | 80 protected: |
| 81 void SetUpEncryption() { | 81 void SetUpEncryption() { |
| 82 encryption_handler_.reset( | 82 encryption_handler_.reset( |
| 83 new SyncEncryptionHandlerImpl(user_share(), | 83 new SyncEncryptionHandlerImpl(user_share(), |
| 84 &encryptor_, | 84 &encryptor_, |
| 85 "", "" /* bootstrap tokens */)); | 85 "", "" /* bootstrap tokens */)); |
| 86 encryption_handler_->AddObserver(&observer_); | 86 encryption_handler_->AddObserver(&observer_); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void CreateRootForType(ModelType model_type) { | |
| 90 syncer::syncable::Directory* directory = user_share()->directory.get(); | |
| 91 | |
| 92 std::string tag_name = ModelTypeToRootTag(model_type); | |
| 93 | |
| 94 syncable::WriteTransaction wtrans(FROM_HERE, syncable::UNITTEST, directory); | |
| 95 syncable::MutableEntry node(&wtrans, | |
| 96 syncable::CREATE, | |
| 97 wtrans.root_id(), | |
| 98 tag_name); | |
| 99 node.Put(syncable::UNIQUE_SERVER_TAG, tag_name); | |
| 100 node.Put(syncable::IS_DIR, true); | |
| 101 node.Put(syncable::SERVER_IS_DIR, false); | |
| 102 node.Put(syncable::IS_UNSYNCED, false); | |
| 103 node.Put(syncable::IS_UNAPPLIED_UPDATE, false); | |
| 104 node.Put(syncable::SERVER_VERSION, 20); | |
| 105 node.Put(syncable::BASE_VERSION, 20); | |
| 106 node.Put(syncable::IS_DEL, false); | |
| 107 node.Put(syncable::ID, ids_.MakeServer(tag_name)); | |
| 108 sync_pb::EntitySpecifics specifics; | |
| 109 syncer::AddDefaultFieldValue(model_type, &specifics); | |
| 110 node.Put(syncable::SPECIFICS, specifics); | |
| 111 } | |
| 112 | |
| 113 void PumpLoop() { | 89 void PumpLoop() { |
| 114 message_loop_.RunUntilIdle(); | 90 message_loop_.RunUntilIdle(); |
| 115 } | 91 } |
| 116 | 92 |
| 117 // Getters for tests. | 93 // Getters for tests. |
| 118 UserShare* user_share() { return test_user_share_.user_share(); } | 94 UserShare* user_share() { return test_user_share_.user_share(); } |
| 119 SyncEncryptionHandlerImpl* encryption_handler() { | 95 SyncEncryptionHandlerImpl* encryption_handler() { |
| 120 return encryption_handler_.get(); | 96 return encryption_handler_.get(); |
| 121 } | 97 } |
| 122 SyncEncryptionHandlerObserverMock* observer() { return &observer_; } | 98 SyncEncryptionHandlerObserverMock* observer() { return &observer_; } |
| (...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 | 1693 |
| 1718 // Verify we're still migrated and have proper encryption state. | 1694 // Verify we're still migrated and have proper encryption state. |
| 1719 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); | 1695 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); |
| 1720 EXPECT_TRUE(GetCryptographer()->is_ready()); | 1696 EXPECT_TRUE(GetCryptographer()->is_ready()); |
| 1721 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); | 1697 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); |
| 1722 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); | 1698 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); |
| 1723 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey); | 1699 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey); |
| 1724 } | 1700 } |
| 1725 | 1701 |
| 1726 } // namespace syncer | 1702 } // namespace syncer |
| OLD | NEW |