| 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() | |
| 19 : success_(false), return_code_(cryptohome::MOUNT_ERROR_NONE) {} | |
| 20 | |
| 21 MockHomedirMethods::~MockHomedirMethods() {} | |
| 22 | |
| 23 void MockHomedirMethods::SetUp(bool success, MountError return_code) { | 18 void MockHomedirMethods::SetUp(bool success, MountError return_code) { |
| 24 success_ = success; | 19 success_ = success; |
| 25 return_code_ = return_code; | 20 return_code_ = return_code; |
| 26 ON_CALL(*this, GetKeyDataEx(_, _, _)).WillByDefault( | 21 ON_CALL(*this, GetKeyDataEx(_, _, _)).WillByDefault( |
| 27 WithArgs<2>(Invoke(this, &MockHomedirMethods::DoGetDataCallback))); | 22 WithArgs<2>(Invoke(this, &MockHomedirMethods::DoGetDataCallback))); |
| 28 ON_CALL(*this, CheckKeyEx(_, _, _)).WillByDefault( | 23 ON_CALL(*this, CheckKeyEx(_, _, _)).WillByDefault( |
| 29 WithArgs<2>(Invoke(this, &MockHomedirMethods::DoCallback))); | 24 WithArgs<2>(Invoke(this, &MockHomedirMethods::DoCallback))); |
| 30 ON_CALL(*this, MountEx(_, _, _, _)).WillByDefault( | 25 ON_CALL(*this, MountEx(_, _, _, _)).WillByDefault( |
| 31 WithArgs<3>(Invoke(this, &MockHomedirMethods::DoMountCallback))); | 26 WithArgs<3>(Invoke(this, &MockHomedirMethods::DoMountCallback))); |
| 32 ON_CALL(*this, AddKeyEx(_, _, _, _, _)).WillByDefault( | 27 ON_CALL(*this, AddKeyEx(_, _, _, _, _)) |
| 33 WithArgs<4>(Invoke(this, &MockHomedirMethods::DoCallback))); | 28 .WillByDefault( |
| 29 WithArgs<4>(Invoke(this, &MockHomedirMethods::DoAddKeyCallback))); |
| 34 ON_CALL(*this, UpdateKeyEx(_, _, _, _, _)).WillByDefault( | 30 ON_CALL(*this, UpdateKeyEx(_, _, _, _, _)).WillByDefault( |
| 35 WithArgs<4>(Invoke(this, &MockHomedirMethods::DoCallback))); | 31 WithArgs<4>(Invoke(this, &MockHomedirMethods::DoCallback))); |
| 36 ON_CALL(*this, RemoveKeyEx(_, _, _, _)).WillByDefault( | 32 ON_CALL(*this, RemoveKeyEx(_, _, _, _)).WillByDefault( |
| 37 WithArgs<3>(Invoke(this, &MockHomedirMethods::DoCallback))); | 33 WithArgs<3>(Invoke(this, &MockHomedirMethods::DoCallback))); |
| 38 } | 34 } |
| 39 | 35 |
| 40 void MockHomedirMethods::DoCallback(const Callback& callback) { | 36 void MockHomedirMethods::DoCallback(const Callback& callback) { |
| 41 callback.Run(success_, return_code_); | 37 callback.Run(success_, return_code_); |
| 42 } | 38 } |
| 43 | 39 |
| 44 void MockHomedirMethods::DoGetDataCallback(const GetKeyDataCallback& callback) { | 40 void MockHomedirMethods::DoGetDataCallback(const GetKeyDataCallback& callback) { |
| 45 callback.Run(success_, return_code_, std::vector<KeyDefinition>()); | 41 callback.Run(success_, return_code_, std::vector<KeyDefinition>()); |
| 46 } | 42 } |
| 47 | 43 |
| 48 void MockHomedirMethods::DoMountCallback(const MountCallback& callback) { | 44 void MockHomedirMethods::DoMountCallback(const MountCallback& callback) { |
| 49 callback.Run( | 45 callback.Run( |
| 50 success_, return_code_, MockAsyncMethodCaller::kFakeSanitizedUsername); | 46 success_, return_code_, MockAsyncMethodCaller::kFakeSanitizedUsername); |
| 47 if (!on_mount_called_.is_null()) |
| 48 on_mount_called_.Run(); |
| 49 } |
| 50 |
| 51 void MockHomedirMethods::DoAddKeyCallback(const Callback& callback) { |
| 52 callback.Run(success_, return_code_); |
| 53 if (!on_add_key_called_.is_null()) |
| 54 on_add_key_called_.Run(); |
| 51 } | 55 } |
| 52 | 56 |
| 53 } // namespace cryptohome | 57 } // namespace cryptohome |
| OLD | NEW |