Chromium Code Reviews| Index: sync/internal_api/sync_encryption_handler_impl_unittest.cc |
| diff --git a/sync/internal_api/sync_encryption_handler_impl_unittest.cc b/sync/internal_api/sync_encryption_handler_impl_unittest.cc |
| index 829ecd2cb9b4d5e775b53e446cce3035b0f1d3f7..afe31a9ae2abcb249d93a5d5d59faf288b9a4f33 100644 |
| --- a/sync/internal_api/sync_encryption_handler_impl_unittest.cc |
| +++ b/sync/internal_api/sync_encryption_handler_impl_unittest.cc |
| @@ -59,6 +59,8 @@ class SyncEncryptionHandlerObserverMock |
| MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT |
| MOCK_METHOD2(OnPassphraseTypeChanged, void(PassphraseType, |
| base::Time)); // NOLINT |
| + MOCK_METHOD1(OnLocalSetCustomPassphrase, |
| + void(const SyncEncryptionHandler::NigoriState&)); // NOLINT |
| }; |
| google::protobuf::RepeatedPtrField<google::protobuf::string> |
| @@ -1552,8 +1554,13 @@ TEST_F(SyncEncryptionHandlerImplTest, SetCustomPassAfterMigration) { |
| OnCryptographerStateChanged(_)).Times(AnyNumber()); |
| EXPECT_CALL(*observer(), |
| OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _)); |
| + SyncEncryptionHandler::NigoriState captured_nigori_state; |
| + EXPECT_CALL(*observer(), OnLocalSetCustomPassphrase(_)) |
| + .WillOnce(testing::SaveArg<0>(&captured_nigori_state)); |
| + std::string captured_bootstrap_token; |
| EXPECT_CALL(*observer(), |
| - OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| + OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)) |
| + .WillOnce(testing::SaveArg<0>(&captured_bootstrap_token)); |
| EXPECT_CALL(*observer(), |
| OnPassphraseAccepted()); |
| EXPECT_CALL(*observer(), |
| @@ -1561,6 +1568,9 @@ TEST_F(SyncEncryptionHandlerImplTest, SetCustomPassAfterMigration) { |
| EXPECT_CALL(*observer(), |
| OnEncryptionComplete()).Times(2); |
| encryption_handler()->SetEncryptionPassphrase(kNewKey, true); |
| + Mock::VerifyAndClearExpectations(observer()); |
| + |
| + EXPECT_FALSE(captured_bootstrap_token.empty()); |
| EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); |
| EXPECT_TRUE(GetCryptographer()->is_ready()); |
| EXPECT_EQ(encryption_handler()->GetPassphraseType(), CUSTOM_PASSPHRASE); |
| @@ -1588,6 +1598,22 @@ TEST_F(SyncEncryptionHandlerImplTest, SetCustomPassAfterMigration) { |
| sync_pb::EncryptedData new_encrypted; |
| new_cryptographer.EncryptString("string", &new_encrypted); |
| EXPECT_TRUE(GetCryptographer()->CanDecryptUsingDefaultKey(new_encrypted)); |
| + |
| + // Now verify that we can restore the current state using the captured |
|
maniscalco
2015/06/10 22:01:45
I'm interested in your opinion on how to test this
Nicolas Zea
2015/06/11 17:43:07
I'm okay with this. One question I have though is
maniscalco
2015/06/15 16:49:18
I've moved the verification to a new helper method
|
| + // bootstrap token and nigori state. |
| + TearDown(); |
| + test_user_share_.SetUp(); |
| + encryption_handler_.reset(new SyncEncryptionHandlerImpl( |
| + user_share(), &encryptor_, captured_bootstrap_token, std::string())); |
| + encryption_handler_->AddObserver(&observer_); |
| + EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber()); |
| + EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true)).Times(AnyNumber()); |
| + EXPECT_CALL(*observer(), OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _)); |
| + EXPECT_CALL(*observer(), OnEncryptionComplete()); |
| + encryption_handler_->RestoreNigori(captured_nigori_state); |
| + encryption_handler()->Init(); |
| + Mock::VerifyAndClearExpectations(observer()); |
| + VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kNewKey); |
| } |
| // Test that if a client without a keystore key (e.g. one without keystore |
| @@ -1660,6 +1686,8 @@ TEST_F(SyncEncryptionHandlerImplTest, |
| EXPECT_CALL(*observer(), |
| OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _)); |
| EXPECT_CALL(*observer(), |
| + OnLocalSetCustomPassphrase(_)); |
| + EXPECT_CALL(*observer(), |
| OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| EXPECT_CALL(*observer(), |
| OnPassphraseAccepted()); |