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());
46 DISALLOW_COPY_AND_ASSIGN(MockConnectionToClient
);
49 class MockConnectionToClientEventHandler
:
50 public ConnectionToClient::EventHandler
{
52 MockConnectionToClientEventHandler();
53 virtual ~MockConnectionToClientEventHandler();
55 MOCK_METHOD1(OnConnectionAuthenticating
,
56 void(ConnectionToClient
* connection
));
57 MOCK_METHOD1(OnConnectionAuthenticated
, void(ConnectionToClient
* connection
));
58 MOCK_METHOD1(OnConnectionChannelsConnected
,
59 void(ConnectionToClient
* connection
));
60 MOCK_METHOD2(OnConnectionClosed
, void(ConnectionToClient
* connection
,
62 MOCK_METHOD2(OnEventTimestamp
,
63 void(ConnectionToClient
* connection
, int64 timestamp
));
64 MOCK_METHOD3(OnRouteChange
, void(ConnectionToClient
* connection
,
65 const std::string
& channel_name
,
66 const TransportRoute
& route
));
69 DISALLOW_COPY_AND_ASSIGN(MockConnectionToClientEventHandler
);
72 class MockClipboardStub
: public ClipboardStub
{
75 virtual ~MockClipboardStub();
77 MOCK_METHOD1(InjectClipboardEvent
, void(const ClipboardEvent
& event
));
80 DISALLOW_COPY_AND_ASSIGN(MockClipboardStub
);
83 class MockCursorShapeChangeCallback
{
85 MockCursorShapeChangeCallback();
86 virtual ~MockCursorShapeChangeCallback();
88 MOCK_METHOD1(CursorShapeChangedPtr
, void(CursorShapeInfo
* info
));
89 void CursorShapeChanged(scoped_ptr
<CursorShapeInfo
> info
);
92 DISALLOW_COPY_AND_ASSIGN(MockCursorShapeChangeCallback
);
95 class MockInputStub
: public InputStub
{
98 virtual ~MockInputStub();
100 MOCK_METHOD1(InjectKeyEvent
, void(const KeyEvent
& event
));
101 MOCK_METHOD1(InjectTextEvent
, void(const TextEvent
& event
));
102 MOCK_METHOD1(InjectMouseEvent
, void(const MouseEvent
& event
));
105 DISALLOW_COPY_AND_ASSIGN(MockInputStub
);
108 class MockHostStub
: public HostStub
{
111 virtual ~MockHostStub();
113 MOCK_METHOD1(NotifyClientResolution
,
114 void(const ClientResolution
& resolution
));
115 MOCK_METHOD1(ControlVideo
, void(const VideoControl
& video_control
));
116 MOCK_METHOD1(ControlAudio
, void(const AudioControl
& audio_control
));
117 MOCK_METHOD1(SetCapabilities
, void(const Capabilities
& capabilities
));
118 MOCK_METHOD1(RequestPairing
,
119 void(const PairingRequest
& pairing_request
));
120 MOCK_METHOD1(DeliverClientMessage
, void(const ExtensionMessage
& message
));
123 DISALLOW_COPY_AND_ASSIGN(MockHostStub
);
126 class MockClientStub
: public ClientStub
{
129 virtual ~MockClientStub();
131 // ClientStub mock implementation.
132 MOCK_METHOD1(SetCapabilities
, void(const Capabilities
& capabilities
));
133 MOCK_METHOD1(SetPairingResponse
,
134 void(const PairingResponse
& pairing_response
));
135 MOCK_METHOD1(DeliverHostMessage
, void(const ExtensionMessage
& message
));
137 // ClipboardStub mock implementation.
138 MOCK_METHOD1(InjectClipboardEvent
, void(const ClipboardEvent
& event
));
140 // CursorShapeStub mock implementation.
141 MOCK_METHOD1(SetCursorShape
, void(const CursorShapeInfo
& cursor_shape
));
144 DISALLOW_COPY_AND_ASSIGN(MockClientStub
);
147 class MockCursorShapeStub
: public CursorShapeStub
{
149 MockCursorShapeStub();
150 virtual ~MockCursorShapeStub();
152 MOCK_METHOD1(SetCursorShape
, void(const CursorShapeInfo
& cursor_shape
));
155 DISALLOW_COPY_AND_ASSIGN(MockCursorShapeStub
);
158 class MockVideoStub
: public VideoStub
{
161 virtual ~MockVideoStub();
163 MOCK_METHOD2(ProcessVideoPacketPtr
, void(const VideoPacket
* video_packet
,
164 const base::Closure
& done
));
165 virtual void ProcessVideoPacket(scoped_ptr
<VideoPacket
> video_packet
,
166 const base::Closure
& done
) {
167 ProcessVideoPacketPtr(video_packet
.get(), done
);
171 DISALLOW_COPY_AND_ASSIGN(MockVideoStub
);
174 class MockSession
: public Session
{
177 virtual ~MockSession();
179 MOCK_METHOD1(SetEventHandler
, void(Session::EventHandler
* event_handler
));
180 MOCK_METHOD0(error
, ErrorCode());
181 MOCK_METHOD0(GetTransportChannelFactory
, StreamChannelFactory
*());
182 MOCK_METHOD0(GetMultiplexedChannelFactory
, StreamChannelFactory
*());
183 MOCK_METHOD0(jid
, const std::string
&());
184 MOCK_METHOD0(candidate_config
, const CandidateSessionConfig
*());
185 MOCK_METHOD0(config
, const SessionConfig
&());
186 MOCK_METHOD1(set_config
, void(const SessionConfig
& config
));
187 MOCK_METHOD0(initiator_token
, const std::string
&());
188 MOCK_METHOD1(set_initiator_token
, void(const std::string
& initiator_token
));
189 MOCK_METHOD0(receiver_token
, const std::string
&());
190 MOCK_METHOD1(set_receiver_token
, void(const std::string
& receiver_token
));
191 MOCK_METHOD1(set_shared_secret
, void(const std::string
& secret
));
192 MOCK_METHOD0(shared_secret
, const std::string
&());
193 MOCK_METHOD0(Close
, void());
196 DISALLOW_COPY_AND_ASSIGN(MockSession
);
199 class MockSessionManager
: public SessionManager
{
201 MockSessionManager();
202 virtual ~MockSessionManager();
204 MOCK_METHOD2(Init
, void(SignalStrategy
*, Listener
*));
205 MOCK_METHOD3(ConnectPtr
, Session
*(
206 const std::string
& host_jid
,
207 Authenticator
* authenticator
,
208 CandidateSessionConfig
* config
));
209 MOCK_METHOD0(Close
, void());
210 MOCK_METHOD1(set_authenticator_factory_ptr
,
211 void(AuthenticatorFactory
* factory
));
212 virtual scoped_ptr
<Session
> Connect(
213 const std::string
& host_jid
,
214 scoped_ptr
<Authenticator
> authenticator
,
215 scoped_ptr
<CandidateSessionConfig
> config
) {
216 return make_scoped_ptr(
217 ConnectPtr(host_jid
, authenticator
.get(), config
.get()));
219 virtual void set_authenticator_factory(
220 scoped_ptr
<AuthenticatorFactory
> authenticator_factory
) {
221 set_authenticator_factory_ptr(authenticator_factory
.release());
225 DISALLOW_COPY_AND_ASSIGN(MockSessionManager
);
228 // Simple delegate that caches information on paired clients in memory.
229 class MockPairingRegistryDelegate
: public PairingRegistry::Delegate
{
231 MockPairingRegistryDelegate();
232 ~MockPairingRegistryDelegate() override
;
234 // PairingRegistry::Delegate implementation.
235 scoped_ptr
<base::ListValue
> LoadAll() override
;
236 bool DeleteAll() override
;
237 protocol::PairingRegistry::Pairing
Load(
238 const std::string
& client_id
) override
;
239 bool Save(const protocol::PairingRegistry::Pairing
& pairing
) override
;
240 bool Delete(const std::string
& client_id
) override
;
243 typedef std::map
<std::string
, protocol::PairingRegistry::Pairing
> Pairings
;
247 class SynchronousPairingRegistry
: public PairingRegistry
{
249 explicit SynchronousPairingRegistry(scoped_ptr
<Delegate
> delegate
);
252 ~SynchronousPairingRegistry() override
;
254 // Runs tasks synchronously instead of posting them to |task_runner|.
255 void PostTask(const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
256 const tracked_objects::Location
& from_here
,
257 const base::Closure
& task
) override
;
260 } // namespace protocol
261 } // namespace remoting
263 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_