Chromium Code Reviews| Index: components/os_crypt/os_crypt_unittest.cc |
| diff --git a/components/os_crypt/os_crypt_unittest.cc b/components/os_crypt/os_crypt_unittest.cc |
| index 9837cbc29a0d8d1725056fdd79006e3e9e54e2ed..2f00f436765059014ee04bdf4807b7a6349e2c8d 100644 |
| --- a/components/os_crypt/os_crypt_unittest.cc |
| +++ b/components/os_crypt/os_crypt_unittest.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "build/build_config.h" |
| +#include "components/os_crypt/key_storage_mock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace { |
| @@ -19,16 +20,41 @@ class OSCryptTest : public testing::Test { |
| public: |
| OSCryptTest() {} |
| - void SetUp() override { |
| #if defined(OS_MACOSX) |
| - OSCrypt::UseMockKeychain(true); |
| + void SetUp() override { OSCrypt::UseMockKeychain(true); } |
|
Lei Zhang
2016/05/19 22:45:38
I'd highly prefer not to have two different implem
cfroussios
2016/05/20 16:44:52
Done.
|
| #endif |
| + |
| +#if defined(USE_LIBSECRET) |
| + void SetUp() override { |
| + key_storage_static_ = &key_storage_; |
| + UseMockKeyStorageForTesting(true, &GetKeyStorage, &GetPassword); |
| } |
| + void TearDown() override { |
| + key_storage_static_ = nullptr; |
| + UseMockKeyStorageForTesting(false, nullptr, nullptr); |
| + } |
| + |
| + protected: |
| + KeyStorageMock key_storage_; |
| + |
| + private: |
| + // Needed, so that we can return our |key_storage_| through static methods |
| + static KeyStorageMock* key_storage_static_; |
|
Lei Zhang
2016/05/19 22:45:38
Many places use s_foo_ here, like g_foo for global
cfroussios
2016/05/20 16:44:52
Done.
|
| + |
| + static KeyStorageLinux* GetKeyStorage() { return key_storage_static_; } |
| + |
| + static std::string* GetPassword() { return key_storage_static_->GetKeyPtr(); } |
| +#endif |
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(OSCryptTest); |
| }; |
| +#if defined(USE_LIBSECRET) |
| +KeyStorageMock* OSCryptTest::key_storage_static_ = nullptr; |
| +#endif |
| + |
| TEST_F(OSCryptTest, String16EncryptionDecryption) { |
| base::string16 plaintext; |
| base::string16 result; |