| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "components/webdata/encryptor/encryptor.h" | 5 #include "components/webdata/encryptor/encryptor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class EncryptorTest : public testing::Test { | 15 class EncryptorTest : public testing::Test { |
| 16 public: | 16 public: |
| 17 EncryptorTest() {} | 17 EncryptorTest() {} |
| 18 | 18 |
| 19 virtual void SetUp() { | 19 virtual void SetUp() { |
| 20 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
| 21 Encryptor::UseMockKeychain(true); | 21 Encryptor::UseMockKeychain(true); |
| 22 #endif | 22 #endif |
| 23 } | 23 } |
| 24 | 24 |
| 25 private: | 25 private: |
| 26 DISALLOW_COPY_AND_ASSIGN(EncryptorTest); | 26 DISALLOW_COPY_AND_ASSIGN(EncryptorTest); |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 TEST_F(EncryptorTest, String16EncryptionDecryption) { | 29 TEST_F(EncryptorTest, String16EncryptionDecryption) { |
| 30 string16 plaintext; | 30 base::string16 plaintext; |
| 31 string16 result; | 31 base::string16 result; |
| 32 std::string utf8_plaintext; | 32 std::string utf8_plaintext; |
| 33 std::string utf8_result; | 33 std::string utf8_result; |
| 34 std::string ciphertext; | 34 std::string ciphertext; |
| 35 | 35 |
| 36 // Test borderline cases (empty strings). | 36 // Test borderline cases (empty strings). |
| 37 EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext)); | 37 EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext)); |
| 38 EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result)); | 38 EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result)); |
| 39 EXPECT_EQ(plaintext, result); | 39 EXPECT_EQ(plaintext, result); |
| 40 | 40 |
| 41 // Test a simple string. | 41 // Test a simple string. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); | 134 ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); |
| 135 EXPECT_NE(plaintext, ciphertext); | 135 EXPECT_NE(plaintext, ciphertext); |
| 136 ASSERT_LT(4UL, ciphertext.size()); | 136 ASSERT_LT(4UL, ciphertext.size()); |
| 137 ciphertext[3] = ciphertext[3] + 1; | 137 ciphertext[3] = ciphertext[3] + 1; |
| 138 EXPECT_FALSE(Encryptor::DecryptString(ciphertext, &result)); | 138 EXPECT_FALSE(Encryptor::DecryptString(ciphertext, &result)); |
| 139 EXPECT_NE(plaintext, result); | 139 EXPECT_NE(plaintext, result); |
| 140 EXPECT_TRUE(result.empty()); | 140 EXPECT_TRUE(result.empty()); |
| 141 } | 141 } |
| 142 | 142 |
| 143 } // namespace | 143 } // namespace |
| OLD | NEW |