| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_homedir_methods.h" | 5 #include "chromeos/cryptohome/mock_homedir_methods.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "chromeos/cryptohome/cryptohome_parameters.h" | 9 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 10 #include "chromeos/cryptohome/mock_async_method_caller.h" | 10 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 11 | 11 |
| 12 using ::testing::Invoke; | 12 using ::testing::Invoke; |
| 13 using ::testing::WithArgs; | 13 using ::testing::WithArgs; |
| 14 using ::testing::_; | 14 using ::testing::_; |
| 15 | 15 |
| 16 namespace cryptohome { | 16 namespace cryptohome { |
| 17 | 17 |
| 18 MockHomedirMethods::MockHomedirMethods() | 18 MockHomedirMethods::MockHomedirMethods() = default; |
| 19 : success_(false), return_code_(cryptohome::MOUNT_ERROR_NONE) {} | 19 MockHomedirMethods::~MockHomedirMethods() = default; |
| 20 | |
| 21 MockHomedirMethods::~MockHomedirMethods() {} | |
| 22 | 20 |
| 23 void MockHomedirMethods::SetUp(bool success, MountError return_code) { | 21 void MockHomedirMethods::SetUp(bool success, MountError return_code) { |
| 24 success_ = success; | 22 success_ = success; |
| 25 return_code_ = return_code; | 23 return_code_ = return_code; |
| 26 ON_CALL(*this, GetKeyDataEx(_, _, _)).WillByDefault( | 24 ON_CALL(*this, GetKeyDataEx(_, _, _)).WillByDefault( |
| 27 WithArgs<2>(Invoke(this, &MockHomedirMethods::DoGetDataCallback))); | 25 WithArgs<2>(Invoke(this, &MockHomedirMethods::DoGetDataCallback))); |
| 28 ON_CALL(*this, CheckKeyEx(_, _, _)).WillByDefault( | 26 ON_CALL(*this, CheckKeyEx(_, _, _)).WillByDefault( |
| 29 WithArgs<2>(Invoke(this, &MockHomedirMethods::DoCallback))); | 27 WithArgs<2>(Invoke(this, &MockHomedirMethods::DoCallback))); |
| 30 ON_CALL(*this, MountEx(_, _, _, _)).WillByDefault( | 28 ON_CALL(*this, MountEx(_, _, _, _)).WillByDefault( |
| 31 WithArgs<3>(Invoke(this, &MockHomedirMethods::DoMountCallback))); | 29 WithArgs<3>(Invoke(this, &MockHomedirMethods::DoMountCallback))); |
| 32 ON_CALL(*this, AddKeyEx(_, _, _, _, _)).WillByDefault( | 30 ON_CALL(*this, AddKeyEx(_, _, _, _, _)) |
| 33 WithArgs<4>(Invoke(this, &MockHomedirMethods::DoCallback))); | 31 .WillByDefault( |
| 32 WithArgs<4>(Invoke(this, &MockHomedirMethods::DoAddKeyCallback))); |
| 34 ON_CALL(*this, UpdateKeyEx(_, _, _, _, _)).WillByDefault( | 33 ON_CALL(*this, UpdateKeyEx(_, _, _, _, _)).WillByDefault( |
| 35 WithArgs<4>(Invoke(this, &MockHomedirMethods::DoCallback))); | 34 WithArgs<4>(Invoke(this, &MockHomedirMethods::DoCallback))); |
| 36 ON_CALL(*this, RemoveKeyEx(_, _, _, _)).WillByDefault( | 35 ON_CALL(*this, RemoveKeyEx(_, _, _, _)).WillByDefault( |
| 37 WithArgs<3>(Invoke(this, &MockHomedirMethods::DoCallback))); | 36 WithArgs<3>(Invoke(this, &MockHomedirMethods::DoCallback))); |
| 38 } | 37 } |
| 39 | 38 |
| 40 void MockHomedirMethods::DoCallback(const Callback& callback) { | 39 void MockHomedirMethods::DoCallback(const Callback& callback) { |
| 41 callback.Run(success_, return_code_); | 40 callback.Run(success_, return_code_); |
| 42 } | 41 } |
| 43 | 42 |
| 44 void MockHomedirMethods::DoGetDataCallback(const GetKeyDataCallback& callback) { | 43 void MockHomedirMethods::DoGetDataCallback(const GetKeyDataCallback& callback) { |
| 45 callback.Run(success_, return_code_, std::vector<KeyDefinition>()); | 44 callback.Run(success_, return_code_, std::vector<KeyDefinition>()); |
| 46 } | 45 } |
| 47 | 46 |
| 48 void MockHomedirMethods::DoMountCallback(const MountCallback& callback) { | 47 void MockHomedirMethods::DoMountCallback(const MountCallback& callback) { |
| 49 callback.Run( | 48 callback.Run( |
| 50 success_, return_code_, MockAsyncMethodCaller::kFakeSanitizedUsername); | 49 success_, return_code_, MockAsyncMethodCaller::kFakeSanitizedUsername); |
| 50 if (!on_mount_called_.is_null()) |
| 51 on_mount_called_.Run(); |
| 52 } |
| 53 |
| 54 void MockHomedirMethods::DoAddKeyCallback(const Callback& callback) { |
| 55 callback.Run(success_, return_code_); |
| 56 if (!on_add_key_called_.is_null()) |
| 57 on_add_key_called_.Run(); |
| 51 } | 58 } |
| 52 | 59 |
| 53 } // namespace cryptohome | 60 } // namespace cryptohome |
| OLD | NEW |