OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 #ifndef REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_CLIENT_H_ |
| 6 #define REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_CLIENT_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/callback_forward.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "remoting/host/security_key/remote_security_key_ipc_client.h" |
| 15 |
| 16 namespace IPC { |
| 17 class Channel; |
| 18 class Message; |
| 19 } // IPC |
| 20 |
| 21 namespace remoting { |
| 22 |
| 23 // Simulates the RemoteSecurityKeyIpcClient and provides access to data members |
| 24 // for testing. This class is used for scenarios which require an IPC channel |
| 25 // as well as for tests which only need callbacks activated. |
| 26 class FakeRemoteSecurityKeyIpcClient : public RemoteSecurityKeyIpcClient { |
| 27 public: |
| 28 explicit FakeRemoteSecurityKeyIpcClient( |
| 29 const base::Closure& channel_event_callback); |
| 30 ~FakeRemoteSecurityKeyIpcClient() override; |
| 31 |
| 32 // RemoteSecurityKeyIpcClient interface. |
| 33 bool WaitForSecurityKeyIpcServerChannel() override; |
| 34 void EstablishIpcConnection( |
| 35 const base::Closure& connection_ready_callback, |
| 36 const base::Closure& connection_error_callback) override; |
| 37 bool SendSecurityKeyRequest( |
| 38 const std::string& request_payload, |
| 39 const ResponseCallback& response_callback) override; |
| 40 void CloseIpcConnection() override; |
| 41 |
| 42 // Connects as a client to the |channel_name| IPC Channel. |
| 43 bool ConnectViaIpc(const std::string& channel_name); |
| 44 |
| 45 // Override of SendSecurityKeyRequest() interface method for tests which use |
| 46 // an IPC channel for testing. |
| 47 void SendSecurityKeyRequestViaIpc(const std::string& request_payload); |
| 48 |
| 49 base::WeakPtr<FakeRemoteSecurityKeyIpcClient> AsWeakPtr(); |
| 50 |
| 51 const std::string& last_message_received() const { |
| 52 return last_message_received_; |
| 53 } |
| 54 |
| 55 bool ipc_channel_connected() { return ipc_channel_connected_; } |
| 56 |
| 57 void set_wait_for_ipc_channel_return_value(bool return_value) { |
| 58 wait_for_ipc_channel_return_value_ = return_value; |
| 59 } |
| 60 |
| 61 void set_establish_ipc_connection_should_succeed(bool should_succeed) { |
| 62 establish_ipc_connection_should_succeed_ = should_succeed; |
| 63 } |
| 64 |
| 65 void set_send_security_request_should_succeed(bool should_succeed) { |
| 66 send_security_request_should_succeed_ = should_succeed; |
| 67 } |
| 68 |
| 69 void set_security_key_response_payload(const std::string& response_payload) { |
| 70 security_key_response_payload_ = response_payload; |
| 71 } |
| 72 |
| 73 private: |
| 74 // IPC::Listener implementation. |
| 75 bool OnMessageReceived(const IPC::Message& message) override; |
| 76 void OnChannelConnected(int32_t peer_pid) override; |
| 77 void OnChannelError() override; |
| 78 |
| 79 // Handles the initial IPC message used to establish a side channel with this |
| 80 // IPC Client instance. |
| 81 void OnConnectionDetails(const std::string& request_data); |
| 82 |
| 83 // Handles security key response IPC messages. |
| 84 void OnSecurityKeyResponse(const std::string& request_data); |
| 85 |
| 86 // Called when a change in the IPC channel state has occurred. |
| 87 base::Closure channel_event_callback_; |
| 88 |
| 89 // Used for sending/receiving security key messages between processes. |
| 90 std::unique_ptr<IPC::Channel> client_channel_; |
| 91 |
| 92 // Provides the contents of the last IPC message received. |
| 93 std::string last_message_received_; |
| 94 |
| 95 // Determines whether EstablishIpcConnection() returns success or failure. |
| 96 bool establish_ipc_connection_should_succeed_ = true; |
| 97 |
| 98 // Determines whether SendSecurityKeyRequest() returns success or failure. |
| 99 bool send_security_request_should_succeed_ = true; |
| 100 |
| 101 // Value returned by WaitForSecurityKeyIpcServerChannel() method. |
| 102 bool wait_for_ipc_channel_return_value_ = true; |
| 103 |
| 104 // Stores whether a connection to the server IPC channel is active. |
| 105 bool ipc_channel_connected_ = false; |
| 106 |
| 107 // Value returned by SendSecurityKeyRequest() method. |
| 108 std::string security_key_response_payload_; |
| 109 |
| 110 base::WeakPtrFactory<FakeRemoteSecurityKeyIpcClient> weak_factory_; |
| 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(FakeRemoteSecurityKeyIpcClient); |
| 113 }; |
| 114 |
| 115 } // namespace remoting |
| 116 |
| 117 #endif // REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_CLIENT_H_ |
OLD | NEW |