Reland: media-internals: Simplify the code path for creating a media log entry
[chromium-blink-merge.git] / chromeos / cryptohome / mock_async_method_caller.cc
blob7f39eef4f20a46b6b671b28ecb8b2f0be29caa1a
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;
9 using ::testing::_;
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[] =
18 "challenge_response";
20 MockAsyncMethodCaller::MockAsyncMethodCaller()
21 : success_(false), return_code_(cryptohome::MOUNT_ERROR_NONE) {
24 MockAsyncMethodCaller::~MockAsyncMethodCaller() {}
26 void MockAsyncMethodCaller::SetUp(bool success, MountError return_code) {
27 success_ = success;
28 return_code_ = return_code;
29 ON_CALL(*this, AsyncCheckKey(_, _, _))
30 .WillByDefault(
31 WithArgs<2>(Invoke(this, &MockAsyncMethodCaller::DoCallback)));
32 ON_CALL(*this, AsyncMigrateKey(_, _, _, _))
33 .WillByDefault(
34 WithArgs<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback)));
35 ON_CALL(*this, AsyncMount(_, _, _, _))
36 .WillByDefault(
37 WithArgs<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback)));
38 ON_CALL(*this, AsyncAddKey(_, _, _, _))
39 .WillByDefault(
40 WithArgs<3>(Invoke(this, &MockAsyncMethodCaller::DoCallback)));
41 ON_CALL(*this, AsyncMountGuest(_))
42 .WillByDefault(
43 WithArgs<0>(Invoke(this, &MockAsyncMethodCaller::DoCallback)));
44 ON_CALL(*this, AsyncRemove(_, _))
45 .WillByDefault(
46 WithArgs<1>(Invoke(this, &MockAsyncMethodCaller::DoCallback)));
47 ON_CALL(*this, AsyncTpmAttestationCreateEnrollRequest(_, _))
48 .WillByDefault(
49 WithArgs<1>(Invoke(this,
50 &MockAsyncMethodCaller::FakeCreateEnrollRequest)));
51 ON_CALL(*this, AsyncTpmAttestationEnroll(_, _, _))
52 .WillByDefault(
53 WithArgs<2>(Invoke(this, &MockAsyncMethodCaller::DoCallback)));
54 ON_CALL(*this, AsyncTpmAttestationCreateCertRequest(_, _, _, _, _))
55 .WillByDefault(
56 WithArgs<4>(Invoke(this,
57 &MockAsyncMethodCaller::FakeCreateCertRequest)));
58 ON_CALL(*this, AsyncTpmAttestationFinishCertRequest(_, _, _, _, _))
59 .WillByDefault(
60 WithArgs<4>(Invoke(this,
61 &MockAsyncMethodCaller::FakeFinishCertRequest)));
62 ON_CALL(*this, AsyncGetSanitizedUsername(_, _))
63 .WillByDefault(
64 WithArgs<1>(Invoke(this,
65 &MockAsyncMethodCaller::
66 FakeGetSanitizedUsername)));
67 ON_CALL(*this, TpmAttestationSignEnterpriseChallenge(_, _, _, _, _, _, _, _))
68 .WillByDefault(
69 WithArgs<7>(Invoke(this,
70 &MockAsyncMethodCaller::FakeEnterpriseChallenge)));
71 ON_CALL(*this, TpmAttestationRegisterKey(_, _, _, _))
72 .WillByDefault(
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