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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_ |
6 #define CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 11 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 | 13 |
| 14 using ::testing::Invoke; |
| 15 using ::testing::_; |
| 16 |
14 namespace chromeos { | 17 namespace chromeos { |
15 | 18 |
16 class MockCryptohomeLibrary : public CryptohomeLibrary { | 19 class MockCryptohomeLibrary : public CryptohomeLibrary { |
17 public: | 20 public: |
18 MockCryptohomeLibrary() {} | 21 MockCryptohomeLibrary() { |
| 22 ON_CALL(*this, AsyncCheckKey(_, _, _)) |
| 23 .WillByDefault(Invoke(this, &MockCryptohomeLibrary::TwoString)); |
| 24 ON_CALL(*this, AsyncMigrateKey(_, _, _, _)) |
| 25 .WillByDefault(Invoke(this, &MockCryptohomeLibrary::ThreeString)); |
| 26 ON_CALL(*this, AsyncMount(_, _, _)) |
| 27 .WillByDefault(Invoke(this, &MockCryptohomeLibrary::TwoString)); |
| 28 ON_CALL(*this, AsyncMountForBwsi(_)) |
| 29 .WillByDefault(Invoke(this, &MockCryptohomeLibrary::ZeroString)); |
| 30 ON_CALL(*this, AsyncRemove(_, _)) |
| 31 .WillByDefault(Invoke(this, &MockCryptohomeLibrary::OneString)); |
| 32 } |
19 virtual ~MockCryptohomeLibrary() {} | 33 virtual ~MockCryptohomeLibrary() {} |
20 MOCK_METHOD2(CheckKey, bool(const std::string& user_email, | 34 MOCK_METHOD2(CheckKey, bool(const std::string& user_email, |
21 const std::string& passhash)); | 35 const std::string& passhash)); |
22 MOCK_METHOD3(AsyncCheckKey, bool(const std::string& user_email, | 36 MOCK_METHOD3(AsyncCheckKey, bool(const std::string& user_email, |
23 const std::string& passhash, | 37 const std::string& passhash, |
24 Delegate* callback)); | 38 Delegate* callback)); |
25 MOCK_METHOD3(MigrateKey, bool(const std::string& user_email, | 39 MOCK_METHOD3(MigrateKey, bool(const std::string& user_email, |
26 const std::string& old_hash, | 40 const std::string& old_hash, |
27 const std::string& new_hash)); | 41 const std::string& new_hash)); |
28 MOCK_METHOD4(AsyncMigrateKey, bool(const std::string& user_email, | 42 MOCK_METHOD4(AsyncMigrateKey, bool(const std::string& user_email, |
29 const std::string& old_hash, | 43 const std::string& old_hash, |
30 const std::string& new_hash, | 44 const std::string& new_hash, |
31 Delegate* callback)); | 45 Delegate* callback)); |
32 MOCK_METHOD3(Mount, bool(const std::string& user_email, | 46 MOCK_METHOD3(Mount, bool(const std::string& user_email, |
33 const std::string& passhash, | 47 const std::string& passhash, |
34 int* error_code)); | 48 int* error_code)); |
35 MOCK_METHOD3(AsyncMount, bool(const std::string& user_email, | 49 MOCK_METHOD3(AsyncMount, bool(const std::string& user_email, |
36 const std::string& passhash, | 50 const std::string& passhash, |
37 Delegate* callback)); | 51 Delegate* callback)); |
38 MOCK_METHOD1(MountForBwsi, bool(int*)); | 52 MOCK_METHOD1(MountForBwsi, bool(int*)); |
39 MOCK_METHOD1(AsyncMountForBwsi, bool(Delegate* callback)); | 53 MOCK_METHOD1(AsyncMountForBwsi, bool(Delegate* callback)); |
40 MOCK_METHOD1(Remove, bool(const std::string& user_email)); | 54 MOCK_METHOD1(Remove, bool(const std::string& user_email)); |
41 MOCK_METHOD2(AsyncRemove, bool(const std::string& user_email, Delegate* d)); | 55 MOCK_METHOD2(AsyncRemove, bool(const std::string& user_email, Delegate* d)); |
42 MOCK_METHOD0(IsMounted, bool(void)); | 56 MOCK_METHOD0(IsMounted, bool(void)); |
43 MOCK_METHOD0(GetSystemSalt, CryptohomeBlob(void)); | 57 MOCK_METHOD0(GetSystemSalt, CryptohomeBlob(void)); |
| 58 |
| 59 void SetAsyncBehavior(bool outcome, int code) { |
| 60 outcome_ = outcome; |
| 61 code_ = code; |
| 62 } |
| 63 |
| 64 bool ThreeString(const std::string& user_email, |
| 65 const std::string& old_hash, |
| 66 const std::string& new_hash, |
| 67 Delegate* d) { |
| 68 d->OnComplete(outcome_, code_); |
| 69 return true; |
| 70 } |
| 71 |
| 72 bool TwoString(const std::string& user_email, |
| 73 const std::string& passhash, |
| 74 Delegate* d) { |
| 75 d->OnComplete(outcome_, code_); |
| 76 return true; |
| 77 } |
| 78 |
| 79 bool OneString(const std::string& user_email, Delegate* d) { |
| 80 d->OnComplete(outcome_, code_); |
| 81 return true; |
| 82 } |
| 83 |
| 84 bool ZeroString(Delegate* d) { |
| 85 d->OnComplete(outcome_, code_); |
| 86 return true; |
| 87 } |
| 88 |
| 89 private: |
| 90 bool outcome_; |
| 91 int code_; |
| 92 DISALLOW_COPY_AND_ASSIGN(MockCryptohomeLibrary); |
44 }; | 93 }; |
45 } // namespace chromeos | 94 } // namespace chromeos |
46 | 95 |
47 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_ | 96 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_ |
OLD | NEW |