| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/os_crypt/os_crypt.h" | 5 #include "components/os_crypt/os_crypt.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class OSCryptTest : public testing::Test { | 18 class OSCryptTest : public testing::Test { |
| 19 public: | 19 public: |
| 20 OSCryptTest() {} | 20 OSCryptTest() {} |
| 21 | 21 |
| 22 void SetUp() override { | 22 void SetUp() override { |
| 23 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
| 24 OSCrypt::UseMockKeychain(true); | 24 OSCrypt::UseMockKeychain(true); |
| 25 #endif | 25 #endif |
| 26 #if defined(USE_LIBSECRET) |
| 27 OSCrypt::UseMockKeyStorage(true); |
| 28 #endif |
| 26 } | 29 } |
| 27 | 30 |
| 28 private: | 31 private: |
| 29 DISALLOW_COPY_AND_ASSIGN(OSCryptTest); | 32 DISALLOW_COPY_AND_ASSIGN(OSCryptTest); |
| 30 }; | 33 }; |
| 31 | 34 |
| 32 TEST_F(OSCryptTest, String16EncryptionDecryption) { | 35 TEST_F(OSCryptTest, String16EncryptionDecryption) { |
| 33 base::string16 plaintext; | 36 base::string16 plaintext; |
| 34 base::string16 result; | 37 base::string16 result; |
| 35 std::string utf8_plaintext; | 38 std::string utf8_plaintext; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext)); | 140 ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext)); |
| 138 EXPECT_NE(plaintext, ciphertext); | 141 EXPECT_NE(plaintext, ciphertext); |
| 139 ASSERT_LT(4UL, ciphertext.size()); | 142 ASSERT_LT(4UL, ciphertext.size()); |
| 140 ciphertext[3] = ciphertext[3] + 1; | 143 ciphertext[3] = ciphertext[3] + 1; |
| 141 EXPECT_FALSE(OSCrypt::DecryptString(ciphertext, &result)); | 144 EXPECT_FALSE(OSCrypt::DecryptString(ciphertext, &result)); |
| 142 EXPECT_NE(plaintext, result); | 145 EXPECT_NE(plaintext, result); |
| 143 EXPECT_TRUE(result.empty()); | 146 EXPECT_TRUE(result.empty()); |
| 144 } | 147 } |
| 145 | 148 |
| 146 } // namespace | 149 } // namespace |
| OLD | NEW |