OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chromeos/cryptohome/mock_async_method_caller.h" | 5 #include "chromeos/cryptohome/mock_async_method_caller.h" |
6 | 6 |
7 using ::testing::Invoke; | 7 using ::testing::Invoke; |
8 using ::testing::WithArgs; | 8 using ::testing::WithArgs; |
9 using ::testing::_; | 9 using ::testing::_; |
10 | 10 |
11 namespace cryptohome { | 11 namespace cryptohome { |
12 | 12 |
| 13 const char* MockAsyncMethodCaller::kFakeAttestationEnrollRequest = "enrollreq"; |
| 14 const char* MockAsyncMethodCaller::kFakeAttestationCertRequest = "certreq"; |
| 15 const char* MockAsyncMethodCaller::kFakeAttestationCert = "cert"; |
| 16 |
13 MockAsyncMethodCaller::MockAsyncMethodCaller() | 17 MockAsyncMethodCaller::MockAsyncMethodCaller() |
14 : success_(false), return_code_(cryptohome::MOUNT_ERROR_NONE) { | 18 : success_(false), return_code_(cryptohome::MOUNT_ERROR_NONE) { |
15 } | 19 } |
16 | 20 |
17 MockAsyncMethodCaller::~MockAsyncMethodCaller() {} | 21 MockAsyncMethodCaller::~MockAsyncMethodCaller() {} |
18 | 22 |
19 void MockAsyncMethodCaller::SetUp(bool success, MountError return_code) { | 23 void MockAsyncMethodCaller::SetUp(bool success, MountError return_code) { |
20 success_ = success; | 24 success_ = success; |
21 return_code_ = return_code; | 25 return_code_ = return_code; |
22 ON_CALL(*this, AsyncCheckKey(_, _, _)) | 26 ON_CALL(*this, AsyncCheckKey(_, _, _)) |
23 .WillByDefault( | 27 .WillByDefault( |
24 WithArgs<2>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); | 28 WithArgs<2>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); |
25 ON_CALL(*this, AsyncMigrateKey(_, _, _, _)) | 29 ON_CALL(*this, AsyncMigrateKey(_, _, _, _)) |
26 .WillByDefault( | 30 .WillByDefault( |
27 WithArgs<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); | 31 WithArgs<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); |
28 ON_CALL(*this, AsyncMount(_, _, _, _)) | 32 ON_CALL(*this, AsyncMount(_, _, _, _)) |
29 .WillByDefault( | 33 .WillByDefault( |
30 WithArgs<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); | 34 WithArgs<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); |
31 ON_CALL(*this, AsyncMountGuest(_)) | 35 ON_CALL(*this, AsyncMountGuest(_)) |
32 .WillByDefault( | 36 .WillByDefault( |
33 WithArgs<0>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); | 37 WithArgs<0>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); |
34 ON_CALL(*this, AsyncRemove(_, _)) | 38 ON_CALL(*this, AsyncRemove(_, _)) |
35 .WillByDefault( | 39 .WillByDefault( |
36 WithArgs<1>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); | 40 WithArgs<1>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); |
| 41 ON_CALL(*this, AsyncTpmAttestationCreateEnrollRequest(_)) |
| 42 .WillByDefault( |
| 43 WithArgs<0>(Invoke(this, |
| 44 &MockAsyncMethodCaller::FakeCreateEnrollRequest))); |
| 45 ON_CALL(*this, AsyncTpmAttestationEnroll(_, _)) |
| 46 .WillByDefault( |
| 47 WithArgs<1>(Invoke(this, &MockAsyncMethodCaller::DoCallback))); |
| 48 ON_CALL(*this, AsyncTpmAttestationCreateCertRequest(_, _)) |
| 49 .WillByDefault( |
| 50 WithArgs<1>(Invoke(this, |
| 51 &MockAsyncMethodCaller::FakeCreateCertRequest))); |
| 52 ON_CALL(*this, AsyncTpmAttestationFinishCertRequest(_, _)) |
| 53 .WillByDefault( |
| 54 WithArgs<1>(Invoke(this, |
| 55 &MockAsyncMethodCaller::FakeFinishCertRequest))); |
37 } | 56 } |
38 | 57 |
39 void MockAsyncMethodCaller::DoCallback(Callback callback) { | 58 void MockAsyncMethodCaller::DoCallback(Callback callback) { |
40 callback.Run(success_, return_code_); | 59 callback.Run(success_, return_code_); |
41 } | 60 } |
42 | 61 |
| 62 void MockAsyncMethodCaller::FakeCreateEnrollRequest( |
| 63 const DataCallback& callback) { |
| 64 callback.Run(success_, kFakeAttestationEnrollRequest); |
| 65 } |
| 66 |
| 67 void MockAsyncMethodCaller::FakeCreateCertRequest( |
| 68 const DataCallback& callback) { |
| 69 callback.Run(success_, kFakeAttestationCertRequest); |
| 70 } |
| 71 |
| 72 void MockAsyncMethodCaller::FakeFinishCertRequest( |
| 73 const DataCallback& callback) { |
| 74 callback.Run(success_, kFakeAttestationCert); |
| 75 } |
| 76 |
43 } // namespace cryptohome | 77 } // namespace cryptohome |
OLD | NEW |