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(OnSequenceNumberUpdated
, void(ConnectionToClient
* connection
,
63 int64 sequence_number
));
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 MockVideoStub
: public VideoStub
{
150 virtual ~MockVideoStub();
152 MOCK_METHOD2(ProcessVideoPacketPtr
, void(const VideoPacket
* video_packet
,
153 const base::Closure
& done
));
154 virtual void ProcessVideoPacket(scoped_ptr
<VideoPacket
> video_packet
,
155 const base::Closure
& done
) {
156 ProcessVideoPacketPtr(video_packet
.get(), done
);
160 DISALLOW_COPY_AND_ASSIGN(MockVideoStub
);
163 class MockSession
: public Session
{
166 virtual ~MockSession();
168 MOCK_METHOD1(SetEventHandler
, void(Session::EventHandler
* event_handler
));
169 MOCK_METHOD0(error
, ErrorCode());
170 MOCK_METHOD0(GetTransportChannelFactory
, StreamChannelFactory
*());
171 MOCK_METHOD0(GetMultiplexedChannelFactory
, StreamChannelFactory
*());
172 MOCK_METHOD0(jid
, const std::string
&());
173 MOCK_METHOD0(candidate_config
, const CandidateSessionConfig
*());
174 MOCK_METHOD0(config
, const SessionConfig
&());
175 MOCK_METHOD1(set_config
, void(const SessionConfig
& config
));
176 MOCK_METHOD0(initiator_token
, const std::string
&());
177 MOCK_METHOD1(set_initiator_token
, void(const std::string
& initiator_token
));
178 MOCK_METHOD0(receiver_token
, const std::string
&());
179 MOCK_METHOD1(set_receiver_token
, void(const std::string
& receiver_token
));
180 MOCK_METHOD1(set_shared_secret
, void(const std::string
& secret
));
181 MOCK_METHOD0(shared_secret
, const std::string
&());
182 MOCK_METHOD0(Close
, void());
185 DISALLOW_COPY_AND_ASSIGN(MockSession
);
188 class MockSessionManager
: public SessionManager
{
190 MockSessionManager();
191 virtual ~MockSessionManager();
193 MOCK_METHOD2(Init
, void(SignalStrategy
*, Listener
*));
194 MOCK_METHOD3(ConnectPtr
, Session
*(
195 const std::string
& host_jid
,
196 Authenticator
* authenticator
,
197 CandidateSessionConfig
* config
));
198 MOCK_METHOD0(Close
, void());
199 MOCK_METHOD1(set_authenticator_factory_ptr
,
200 void(AuthenticatorFactory
* factory
));
201 virtual scoped_ptr
<Session
> Connect(
202 const std::string
& host_jid
,
203 scoped_ptr
<Authenticator
> authenticator
,
204 scoped_ptr
<CandidateSessionConfig
> config
) {
205 return scoped_ptr
<Session
>(ConnectPtr(
206 host_jid
, authenticator
.get(), config
.get()));
208 virtual void set_authenticator_factory(
209 scoped_ptr
<AuthenticatorFactory
> authenticator_factory
) {
210 set_authenticator_factory_ptr(authenticator_factory
.release());
214 DISALLOW_COPY_AND_ASSIGN(MockSessionManager
);
217 // Simple delegate that caches information on paired clients in memory.
218 class MockPairingRegistryDelegate
: public PairingRegistry::Delegate
{
220 MockPairingRegistryDelegate();
221 virtual ~MockPairingRegistryDelegate();
223 // PairingRegistry::Delegate implementation.
224 virtual scoped_ptr
<base::ListValue
> LoadAll() OVERRIDE
;
225 virtual bool DeleteAll() OVERRIDE
;
226 virtual protocol::PairingRegistry::Pairing
Load(
227 const std::string
& client_id
) OVERRIDE
;
228 virtual bool Save(const protocol::PairingRegistry::Pairing
& pairing
) OVERRIDE
;
229 virtual bool Delete(const std::string
& client_id
) OVERRIDE
;
232 typedef std::map
<std::string
, protocol::PairingRegistry::Pairing
> Pairings
;
236 class SynchronousPairingRegistry
: public PairingRegistry
{
238 explicit SynchronousPairingRegistry(scoped_ptr
<Delegate
> delegate
);
241 virtual ~SynchronousPairingRegistry();
243 // Runs tasks synchronously instead of posting them to |task_runner|.
244 virtual void PostTask(
245 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
246 const tracked_objects::Location
& from_here
,
247 const base::Closure
& task
) OVERRIDE
;
250 } // namespace protocol
251 } // namespace remoting
253 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_