1 // Copyright (c) 2012 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.
5 #include "chromeos/cryptohome/mock_async_method_caller.h"
7 using ::testing::Invoke
;
8 using ::testing::WithArgs
;
11 namespace cryptohome
{
13 const char MockAsyncMethodCaller::kFakeAttestationEnrollRequest
[] = "enrollreq";
14 const char MockAsyncMethodCaller::kFakeAttestationCertRequest
[] = "certreq";
15 const char MockAsyncMethodCaller::kFakeAttestationCert
[] = "cert";
16 const char MockAsyncMethodCaller::kFakeSanitizedUsername
[] = "01234567890ABC";
17 const char MockAsyncMethodCaller::kFakeChallengeResponse
[] =
20 MockAsyncMethodCaller::MockAsyncMethodCaller()
21 : success_(false), return_code_(cryptohome::MOUNT_ERROR_NONE
) {
24 MockAsyncMethodCaller::~MockAsyncMethodCaller() {}
26 void MockAsyncMethodCaller::SetUp(bool success
, MountError return_code
) {
28 return_code_
= return_code
;
29 ON_CALL(*this, AsyncCheckKey(_
, _
, _
))
31 WithArgs
<2>(Invoke(this, &MockAsyncMethodCaller::DoCallback
)));
32 ON_CALL(*this, AsyncMigrateKey(_
, _
, _
, _
))
34 WithArgs
<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback
)));
35 ON_CALL(*this, AsyncMount(_
, _
, _
, _
))
37 WithArgs
<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback
)));
38 ON_CALL(*this, AsyncAddKey(_
, _
, _
, _
))
40 WithArgs
<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback
)));
41 ON_CALL(*this, AsyncMountGuest(_
))
43 WithArgs
<0>(Invoke(this, &MockAsyncMethodCaller::DoCallback
)));
44 ON_CALL(*this, AsyncRemove(_
, _
))
46 WithArgs
<1>(Invoke(this, &MockAsyncMethodCaller::DoCallback
)));
47 ON_CALL(*this, AsyncTpmAttestationCreateEnrollRequest(_
, _
))
49 WithArgs
<1>(Invoke(this,
50 &MockAsyncMethodCaller::FakeCreateEnrollRequest
)));
51 ON_CALL(*this, AsyncTpmAttestationEnroll(_
, _
, _
))
53 WithArgs
<2>(Invoke(this, &MockAsyncMethodCaller::DoCallback
)));
54 ON_CALL(*this, AsyncTpmAttestationCreateCertRequest(_
, _
, _
, _
, _
))
56 WithArgs
<4>(Invoke(this,
57 &MockAsyncMethodCaller::FakeCreateCertRequest
)));
58 ON_CALL(*this, AsyncTpmAttestationFinishCertRequest(_
, _
, _
, _
, _
))
60 WithArgs
<4>(Invoke(this,
61 &MockAsyncMethodCaller::FakeFinishCertRequest
)));
62 ON_CALL(*this, AsyncGetSanitizedUsername(_
, _
))
64 WithArgs
<1>(Invoke(this,
65 &MockAsyncMethodCaller::
66 FakeGetSanitizedUsername
)));
67 ON_CALL(*this, TpmAttestationSignEnterpriseChallenge(_
, _
, _
, _
, _
, _
, _
, _
))
69 WithArgs
<7>(Invoke(this,
70 &MockAsyncMethodCaller::FakeEnterpriseChallenge
)));
71 ON_CALL(*this, TpmAttestationRegisterKey(_
, _
, _
, _
))
73 WithArgs
<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback
)));
76 void MockAsyncMethodCaller::DoCallback(Callback callback
) {
77 callback
.Run(success_
, return_code_
);
80 void MockAsyncMethodCaller::FakeCreateEnrollRequest(
81 const DataCallback
& callback
) {
82 callback
.Run(success_
, kFakeAttestationEnrollRequest
);
85 void MockAsyncMethodCaller::FakeCreateCertRequest(
86 const DataCallback
& callback
) {
87 callback
.Run(success_
, kFakeAttestationCertRequest
);
90 void MockAsyncMethodCaller::FakeFinishCertRequest(
91 const DataCallback
& callback
) {
92 callback
.Run(success_
, kFakeAttestationCert
);
95 void MockAsyncMethodCaller::FakeGetSanitizedUsername(
96 const DataCallback
& callback
) {
97 callback
.Run(success_
, kFakeSanitizedUsername
);
100 void MockAsyncMethodCaller::FakeEnterpriseChallenge(
101 const DataCallback
& callback
) {
102 callback
.Run(success_
, kFakeChallengeResponse
);
105 } // namespace cryptohome