• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 
14 using ::testing::Invoke;
15 using ::testing::WithArgs;
16 using ::testing::_;
17 
18 namespace chromeos {
19 
20 class MockCryptohomeLibrary : public CryptohomeLibrary {
21  public:
MockCryptohomeLibrary()22   MockCryptohomeLibrary() : outcome_(false), code_(0) {
23   }
~MockCryptohomeLibrary()24   virtual ~MockCryptohomeLibrary() {}
SetUp(bool outcome,int code)25   void SetUp(bool outcome, int code) {
26     outcome_ = outcome;
27     code_ = code;
28     ON_CALL(*this, AsyncCheckKey(_, _, _))
29         .WillByDefault(
30             WithArgs<2>(Invoke(this, &MockCryptohomeLibrary::DoCallback)));
31     ON_CALL(*this, AsyncMigrateKey(_, _, _, _))
32         .WillByDefault(
33             WithArgs<3>(Invoke(this, &MockCryptohomeLibrary::DoCallback)));
34     ON_CALL(*this, AsyncMount(_, _, _, _))
35         .WillByDefault(
36             WithArgs<3>(Invoke(this, &MockCryptohomeLibrary::DoCallback)));
37     ON_CALL(*this, AsyncMountForBwsi(_))
38         .WillByDefault(
39             WithArgs<0>(Invoke(this, &MockCryptohomeLibrary::DoCallback)));
40     ON_CALL(*this, AsyncRemove(_, _))
41         .WillByDefault(
42             WithArgs<1>(Invoke(this, &MockCryptohomeLibrary::DoCallback)));
43     ON_CALL(*this, AsyncDoAutomaticFreeDiskSpaceControl(_))
44         .WillByDefault(
45             WithArgs<0>(Invoke(this, &MockCryptohomeLibrary::DoCallback)));
46   }
47   MOCK_METHOD2(CheckKey, bool(const std::string& user_email,
48                               const std::string& passhash));
49   MOCK_METHOD3(AsyncCheckKey, bool(const std::string& user_email,
50                                    const std::string& passhash,
51                                    Delegate* callback));
52   MOCK_METHOD3(MigrateKey, bool(const std::string& user_email,
53                                 const std::string& old_hash,
54                                 const std::string& new_hash));
55   MOCK_METHOD4(AsyncMigrateKey, bool(const std::string& user_email,
56                                      const std::string& old_hash,
57                                      const std::string& new_hash,
58                                      Delegate* callback));
59   MOCK_METHOD3(Mount, bool(const std::string& user_email,
60                            const std::string& passhash,
61                            int* error_code));
62   MOCK_METHOD4(AsyncMount, bool(const std::string& user_email,
63                                 const std::string& passhash,
64                                 const bool create_if_missing,
65                                 Delegate* callback));
66   MOCK_METHOD1(MountForBwsi, bool(int*));
67   MOCK_METHOD1(AsyncMountForBwsi, bool(Delegate* callback));
68   MOCK_METHOD0(Unmount, bool(void));
69   MOCK_METHOD1(Remove, bool(const std::string& user_email));
70   MOCK_METHOD2(AsyncRemove, bool(const std::string& user_email, Delegate* d));
71   MOCK_METHOD0(IsMounted, bool(void));
72   MOCK_METHOD0(GetSystemSalt, CryptohomeBlob(void));
73   MOCK_METHOD1(AsyncDoAutomaticFreeDiskSpaceControl, bool(Delegate* callback));
74 
75   MOCK_METHOD0(TpmIsReady, bool(void));
76   MOCK_METHOD0(TpmIsEnabled, bool(void));
77   MOCK_METHOD0(TpmIsOwned, bool(void));
78   MOCK_METHOD0(TpmIsBeingOwned, bool(void));
79   MOCK_METHOD1(TpmGetPassword, bool(std::string* password));
80   MOCK_METHOD0(TpmCanAttemptOwnership, void(void));
81   MOCK_METHOD0(TpmClearStoredPassword, void(void));
82   MOCK_METHOD0(Pkcs11IsTpmTokenReady, bool(void));
83   MOCK_METHOD2(Pkcs11GetTpmTokenInfo, void(std::string*, std::string*));
84 
85   MOCK_METHOD2(InstallAttributesGet, bool(const std::string&, std::string*));
86   MOCK_METHOD2(InstallAttributesSet, bool(const std::string&,
87                                           const std::string&));
88   MOCK_METHOD0(InstallAttributesCount, int(void));
89   MOCK_METHOD0(InstallAttributesFinalize, bool(void));
90   MOCK_METHOD0(InstallAttributesIsReady, bool(void));
91   MOCK_METHOD0(InstallAttributesIsSecure, bool(void));
92   MOCK_METHOD0(InstallAttributesIsInvalid, bool(void));
93   MOCK_METHOD0(InstallAttributesIsFirstInstall, bool(void));
94 
SetAsyncBehavior(bool outcome,int code)95   void SetAsyncBehavior(bool outcome, int code) {
96     outcome_ = outcome;
97     code_ = code;
98   }
99 
DoCallback(Delegate * d)100   bool DoCallback(Delegate* d) {
101     d->OnComplete(outcome_, code_);
102     return true;
103   }
104 
105  private:
106   bool outcome_;
107   int code_;
108   DISALLOW_COPY_AND_ASSIGN(MockCryptohomeLibrary);
109 };
110 
111 }  // namespace chromeos
112 
113 #endif  // CHROME_BROWSER_CHROMEOS_CROS_MOCK_CRYPTOHOME_LIBRARY_H_
114