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 #ifndef REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_
6 #define REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_
11 #include "base/location.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/values.h"
14 #include "net/base/ip_endpoint.h"
15 #include "remoting/proto/internal.pb.h"
16 #include "remoting/proto/video.pb.h"
17 #include "remoting/protocol/authenticator.h"
18 #include "remoting/protocol/client_stub.h"
19 #include "remoting/protocol/clipboard_stub.h"
20 #include "remoting/protocol/connection_to_client.h"
21 #include "remoting/protocol/host_stub.h"
22 #include "remoting/protocol/input_stub.h"
23 #include "remoting/protocol/pairing_registry.h"
24 #include "remoting/protocol/session.h"
25 #include "remoting/protocol/session_manager.h"
26 #include "remoting/protocol/transport.h"
27 #include "remoting/protocol/video_stub.h"
28 #include "testing/gmock/include/gmock/gmock.h"
33 class MockConnectionToClient
: public ConnectionToClient
{
35 MockConnectionToClient(Session
* session
,
37 virtual ~MockConnectionToClient();
39 MOCK_METHOD1(Init
, void(Session
* session
));
40 MOCK_METHOD0(video_stub
, VideoStub
*());
41 MOCK_METHOD0(client_stub
, ClientStub
*());
42 MOCK_METHOD0(session
, Session
*());
43 MOCK_METHOD0(Disconnect
, void());
45 void set_clipboard_stub(ClipboardStub
* clipboard_stub
) override
{
46 clipboard_stub_
= clipboard_stub
;
48 void set_host_stub(HostStub
* host_stub
) override
{ host_stub_
= host_stub
; }
49 void set_input_stub(InputStub
* input_stub
) override
{
50 input_stub_
= input_stub
;
53 ClipboardStub
* clipboard_stub() { return clipboard_stub_
; }
54 HostStub
* host_stub() { return host_stub_
; }
55 InputStub
* input_stub() { return input_stub_
; }
58 ClipboardStub
* clipboard_stub_
;
60 InputStub
* input_stub_
;
62 DISALLOW_COPY_AND_ASSIGN(MockConnectionToClient
);
65 class MockConnectionToClientEventHandler
:
66 public ConnectionToClient::EventHandler
{
68 MockConnectionToClientEventHandler();
69 virtual ~MockConnectionToClientEventHandler();
71 MOCK_METHOD1(OnConnectionAuthenticating
,
72 void(ConnectionToClient
* connection
));
73 MOCK_METHOD1(OnConnectionAuthenticated
, void(ConnectionToClient
* connection
));
74 MOCK_METHOD1(OnConnectionChannelsConnected
,
75 void(ConnectionToClient
* connection
));
76 MOCK_METHOD2(OnConnectionClosed
, void(ConnectionToClient
* connection
,
78 MOCK_METHOD2(OnEventTimestamp
,
79 void(ConnectionToClient
* connection
, int64 timestamp
));
80 MOCK_METHOD3(OnRouteChange
, void(ConnectionToClient
* connection
,
81 const std::string
& channel_name
,
82 const TransportRoute
& route
));
85 DISALLOW_COPY_AND_ASSIGN(MockConnectionToClientEventHandler
);
88 class MockClipboardStub
: public ClipboardStub
{
91 virtual ~MockClipboardStub();
93 MOCK_METHOD1(InjectClipboardEvent
, void(const ClipboardEvent
& event
));
96 DISALLOW_COPY_AND_ASSIGN(MockClipboardStub
);
99 class MockCursorShapeChangeCallback
{
101 MockCursorShapeChangeCallback();
102 virtual ~MockCursorShapeChangeCallback();
104 MOCK_METHOD1(CursorShapeChangedPtr
, void(CursorShapeInfo
* info
));
105 void CursorShapeChanged(scoped_ptr
<CursorShapeInfo
> info
);
108 DISALLOW_COPY_AND_ASSIGN(MockCursorShapeChangeCallback
);
111 class MockInputStub
: public InputStub
{
114 virtual ~MockInputStub();
116 MOCK_METHOD1(InjectKeyEvent
, void(const KeyEvent
& event
));
117 MOCK_METHOD1(InjectTextEvent
, void(const TextEvent
& event
));
118 MOCK_METHOD1(InjectMouseEvent
, void(const MouseEvent
& event
));
121 DISALLOW_COPY_AND_ASSIGN(MockInputStub
);
124 class MockHostStub
: public HostStub
{
127 virtual ~MockHostStub();
129 MOCK_METHOD1(NotifyClientResolution
,
130 void(const ClientResolution
& resolution
));
131 MOCK_METHOD1(ControlVideo
, void(const VideoControl
& video_control
));
132 MOCK_METHOD1(ControlAudio
, void(const AudioControl
& audio_control
));
133 MOCK_METHOD1(SetCapabilities
, void(const Capabilities
& capabilities
));
134 MOCK_METHOD1(RequestPairing
,
135 void(const PairingRequest
& pairing_request
));
136 MOCK_METHOD1(DeliverClientMessage
, void(const ExtensionMessage
& message
));
139 DISALLOW_COPY_AND_ASSIGN(MockHostStub
);
142 class MockClientStub
: public ClientStub
{
145 virtual ~MockClientStub();
147 // ClientStub mock implementation.
148 MOCK_METHOD1(SetCapabilities
, void(const Capabilities
& capabilities
));
149 MOCK_METHOD1(SetPairingResponse
,
150 void(const PairingResponse
& pairing_response
));
151 MOCK_METHOD1(DeliverHostMessage
, void(const ExtensionMessage
& message
));
153 // ClipboardStub mock implementation.
154 MOCK_METHOD1(InjectClipboardEvent
, void(const ClipboardEvent
& event
));
156 // CursorShapeStub mock implementation.
157 MOCK_METHOD1(SetCursorShape
, void(const CursorShapeInfo
& cursor_shape
));
160 DISALLOW_COPY_AND_ASSIGN(MockClientStub
);
163 class MockCursorShapeStub
: public CursorShapeStub
{
165 MockCursorShapeStub();
166 virtual ~MockCursorShapeStub();
168 MOCK_METHOD1(SetCursorShape
, void(const CursorShapeInfo
& cursor_shape
));
171 DISALLOW_COPY_AND_ASSIGN(MockCursorShapeStub
);
174 class MockVideoStub
: public VideoStub
{
177 virtual ~MockVideoStub();
179 MOCK_METHOD2(ProcessVideoPacketPtr
, void(const VideoPacket
* video_packet
,
180 const base::Closure
& done
));
181 virtual void ProcessVideoPacket(scoped_ptr
<VideoPacket
> video_packet
,
182 const base::Closure
& done
) {
183 ProcessVideoPacketPtr(video_packet
.get(), done
);
187 DISALLOW_COPY_AND_ASSIGN(MockVideoStub
);
190 class MockSession
: public Session
{
193 virtual ~MockSession();
195 MOCK_METHOD1(SetEventHandler
, void(Session::EventHandler
* event_handler
));
196 MOCK_METHOD0(error
, ErrorCode());
197 MOCK_METHOD0(GetTransportChannelFactory
, StreamChannelFactory
*());
198 MOCK_METHOD0(GetMultiplexedChannelFactory
, StreamChannelFactory
*());
199 MOCK_METHOD0(jid
, const std::string
&());
200 MOCK_METHOD0(candidate_config
, const CandidateSessionConfig
*());
201 MOCK_METHOD0(config
, const SessionConfig
&());
202 MOCK_METHOD1(set_config
, void(const SessionConfig
& config
));
203 MOCK_METHOD0(initiator_token
, const std::string
&());
204 MOCK_METHOD1(set_initiator_token
, void(const std::string
& initiator_token
));
205 MOCK_METHOD0(receiver_token
, const std::string
&());
206 MOCK_METHOD1(set_receiver_token
, void(const std::string
& receiver_token
));
207 MOCK_METHOD1(set_shared_secret
, void(const std::string
& secret
));
208 MOCK_METHOD0(shared_secret
, const std::string
&());
209 MOCK_METHOD0(Close
, void());
212 DISALLOW_COPY_AND_ASSIGN(MockSession
);
215 class MockSessionManager
: public SessionManager
{
217 MockSessionManager();
218 virtual ~MockSessionManager();
220 MOCK_METHOD2(Init
, void(SignalStrategy
*, Listener
*));
221 MOCK_METHOD3(ConnectPtr
, Session
*(
222 const std::string
& host_jid
,
223 Authenticator
* authenticator
,
224 CandidateSessionConfig
* config
));
225 MOCK_METHOD0(Close
, void());
226 MOCK_METHOD1(set_authenticator_factory_ptr
,
227 void(AuthenticatorFactory
* factory
));
228 virtual scoped_ptr
<Session
> Connect(
229 const std::string
& host_jid
,
230 scoped_ptr
<Authenticator
> authenticator
,
231 scoped_ptr
<CandidateSessionConfig
> config
) {
232 return make_scoped_ptr(
233 ConnectPtr(host_jid
, authenticator
.get(), config
.get()));
235 virtual void set_authenticator_factory(
236 scoped_ptr
<AuthenticatorFactory
> authenticator_factory
) {
237 set_authenticator_factory_ptr(authenticator_factory
.release());
241 DISALLOW_COPY_AND_ASSIGN(MockSessionManager
);
244 // Simple delegate that caches information on paired clients in memory.
245 class MockPairingRegistryDelegate
: public PairingRegistry::Delegate
{
247 MockPairingRegistryDelegate();
248 ~MockPairingRegistryDelegate() override
;
250 // PairingRegistry::Delegate implementation.
251 scoped_ptr
<base::ListValue
> LoadAll() override
;
252 bool DeleteAll() override
;
253 protocol::PairingRegistry::Pairing
Load(
254 const std::string
& client_id
) override
;
255 bool Save(const protocol::PairingRegistry::Pairing
& pairing
) override
;
256 bool Delete(const std::string
& client_id
) override
;
259 typedef std::map
<std::string
, protocol::PairingRegistry::Pairing
> Pairings
;
263 class SynchronousPairingRegistry
: public PairingRegistry
{
265 explicit SynchronousPairingRegistry(scoped_ptr
<Delegate
> delegate
);
268 ~SynchronousPairingRegistry() override
;
270 // Runs tasks synchronously instead of posting them to |task_runner|.
271 void PostTask(const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
272 const tracked_objects::Location
& from_here
,
273 const base::Closure
& task
) override
;
276 } // namespace protocol
277 } // namespace remoting
279 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_