| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
| 6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
| 7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
| 8 | 8 |
| 9 #include "components/sync/core_impl/sync_manager_impl.h" | 9 #include "components/sync/core_impl/sync_manager_impl.h" |
| 10 | 10 |
| (...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 | 1149 |
| 1150 void ExpectPassphraseAcceptance() { | 1150 void ExpectPassphraseAcceptance() { |
| 1151 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1151 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1152 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1152 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1153 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1153 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1154 } | 1154 } |
| 1155 | 1155 |
| 1156 void SetImplicitPassphraseAndCheck(const std::string& passphrase) { | 1156 void SetImplicitPassphraseAndCheck(const std::string& passphrase) { |
| 1157 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, | 1157 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
| 1158 false); | 1158 false); |
| 1159 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1159 EXPECT_EQ(PassphraseType::IMPLICIT_PASSPHRASE, |
| 1160 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | 1160 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1161 } | 1161 } |
| 1162 | 1162 |
| 1163 void SetCustomPassphraseAndCheck(const std::string& passphrase) { | 1163 void SetCustomPassphraseAndCheck(const std::string& passphrase) { |
| 1164 EXPECT_CALL(encryption_observer_, | 1164 EXPECT_CALL(encryption_observer_, |
| 1165 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _)); | 1165 OnPassphraseTypeChanged(PassphraseType::CUSTOM_PASSPHRASE, _)); |
| 1166 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, | 1166 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
| 1167 true); | 1167 true); |
| 1168 EXPECT_EQ(CUSTOM_PASSPHRASE, | 1168 EXPECT_EQ(PassphraseType::CUSTOM_PASSPHRASE, |
| 1169 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | 1169 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1170 } | 1170 } |
| 1171 | 1171 |
| 1172 bool HasUnrecoverableError() { | 1172 bool HasUnrecoverableError() { |
| 1173 return mock_unrecoverable_error_handler_.invocation_count() > 0; | 1173 return mock_unrecoverable_error_handler_.invocation_count() > 0; |
| 1174 } | 1174 } |
| 1175 | 1175 |
| 1176 private: | 1176 private: |
| 1177 // Needed by |sync_manager_|. | 1177 // Needed by |sync_manager_|. |
| 1178 base::MessageLoop message_loop_; | 1178 base::MessageLoop message_loop_; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1492 sync_pb::NigoriSpecifics nigori; | 1492 sync_pb::NigoriSpecifics nigori; |
| 1493 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); | 1493 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
| 1494 cryptographer->SetPendingKeys(nigori.encryption_keybag()); | 1494 cryptographer->SetPendingKeys(nigori.encryption_keybag()); |
| 1495 EXPECT_TRUE(cryptographer->has_pending_keys()); | 1495 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 1496 node.SetNigoriSpecifics(nigori); | 1496 node.SetNigoriSpecifics(nigori); |
| 1497 } | 1497 } |
| 1498 EXPECT_CALL(encryption_observer_, | 1498 EXPECT_CALL(encryption_observer_, |
| 1499 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1499 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1500 ExpectPassphraseAcceptance(); | 1500 ExpectPassphraseAcceptance(); |
| 1501 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); | 1501 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); |
| 1502 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1502 EXPECT_EQ(PassphraseType::IMPLICIT_PASSPHRASE, |
| 1503 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | 1503 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1504 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); | 1504 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 1505 { | 1505 { |
| 1506 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1506 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1507 Cryptographer* cryptographer = trans.GetCryptographer(); | 1507 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1508 EXPECT_TRUE(cryptographer->is_ready()); | 1508 EXPECT_TRUE(cryptographer->is_ready()); |
| 1509 // Verify we're encrypting with the new key. | 1509 // Verify we're encrypting with the new key. |
| 1510 sync_pb::EncryptedData encrypted; | 1510 sync_pb::EncryptedData encrypted; |
| 1511 cryptographer->GetKeys(&encrypted); | 1511 cryptographer->GetKeys(&encrypted); |
| 1512 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); | 1512 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 EXPECT_EQ(BaseNode::INIT_OK, node.InitTypeRoot(NIGORI)); | 1610 EXPECT_EQ(BaseNode::INIT_OK, node.InitTypeRoot(NIGORI)); |
| 1611 sync_pb::NigoriSpecifics nigori; | 1611 sync_pb::NigoriSpecifics nigori; |
| 1612 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); | 1612 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
| 1613 cryptographer->SetPendingKeys(nigori.encryption_keybag()); | 1613 cryptographer->SetPendingKeys(nigori.encryption_keybag()); |
| 1614 EXPECT_TRUE(cryptographer->has_pending_keys()); | 1614 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 1615 nigori.set_keybag_is_frozen(true); | 1615 nigori.set_keybag_is_frozen(true); |
| 1616 node.SetNigoriSpecifics(nigori); | 1616 node.SetNigoriSpecifics(nigori); |
| 1617 } | 1617 } |
| 1618 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1618 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1619 EXPECT_CALL(encryption_observer_, | 1619 EXPECT_CALL(encryption_observer_, |
| 1620 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _)); | 1620 OnPassphraseTypeChanged(PassphraseType::CUSTOM_PASSPHRASE, _)); |
| 1621 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)); | 1621 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)); |
| 1622 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); | 1622 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 1623 sync_manager_.GetEncryptionHandler()->Init(); | 1623 sync_manager_.GetEncryptionHandler()->Init(); |
| 1624 EXPECT_CALL(encryption_observer_, | 1624 EXPECT_CALL(encryption_observer_, |
| 1625 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1625 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1626 ExpectPassphraseAcceptance(); | 1626 ExpectPassphraseAcceptance(); |
| 1627 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); | 1627 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); |
| 1628 EXPECT_EQ(CUSTOM_PASSPHRASE, | 1628 EXPECT_EQ(PassphraseType::CUSTOM_PASSPHRASE, |
| 1629 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | 1629 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1630 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); | 1630 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 1631 { | 1631 { |
| 1632 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1632 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1633 Cryptographer* cryptographer = trans.GetCryptographer(); | 1633 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1634 EXPECT_TRUE(cryptographer->is_ready()); | 1634 EXPECT_TRUE(cryptographer->is_ready()); |
| 1635 // Verify we're encrypting with the new key. | 1635 // Verify we're encrypting with the new key. |
| 1636 sync_pb::EncryptedData encrypted; | 1636 sync_pb::EncryptedData encrypted; |
| 1637 cryptographer->GetKeys(&encrypted); | 1637 cryptographer->GetKeys(&encrypted); |
| 1638 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); | 1638 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); |
| (...skipping 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3342 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3342 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3343 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3343 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3344 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3344 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3345 // task is to ensure that SyncManagerImpl reported initialization failure in | 3345 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3346 // OnInitializationComplete callback. | 3346 // OnInitializationComplete callback. |
| 3347 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3347 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3348 EXPECT_FALSE(initialization_succeeded_); | 3348 EXPECT_FALSE(initialization_succeeded_); |
| 3349 } | 3349 } |
| 3350 | 3350 |
| 3351 } // namespace syncer | 3351 } // namespace syncer |
| OLD | NEW |