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(OnConnectionAuthenticated
, void(ConnectionToClient
* connection
));
56 MOCK_METHOD1(OnConnectionChannelsConnected
,
57 void(ConnectionToClient
* connection
));
58 MOCK_METHOD2(OnConnectionClosed
, void(ConnectionToClient
* connection
,
60 MOCK_METHOD2(OnSequenceNumberUpdated
, void(ConnectionToClient
* connection
,
61 int64 sequence_number
));
62 MOCK_METHOD3(OnRouteChange
, void(ConnectionToClient
* connection
,
63 const std::string
& channel_name
,
64 const TransportRoute
& route
));
67 DISALLOW_COPY_AND_ASSIGN(MockConnectionToClientEventHandler
);
70 class MockClipboardStub
: public ClipboardStub
{
73 virtual ~MockClipboardStub();
75 MOCK_METHOD1(InjectClipboardEvent
, void(const ClipboardEvent
& event
));
78 DISALLOW_COPY_AND_ASSIGN(MockClipboardStub
);
81 class MockCursorShapeChangeCallback
{
83 MockCursorShapeChangeCallback();
84 virtual ~MockCursorShapeChangeCallback();
86 MOCK_METHOD1(CursorShapeChangedPtr
, void(CursorShapeInfo
* info
));
87 void CursorShapeChanged(scoped_ptr
<CursorShapeInfo
> info
);
90 DISALLOW_COPY_AND_ASSIGN(MockCursorShapeChangeCallback
);
93 class MockInputStub
: public InputStub
{
96 virtual ~MockInputStub();
98 MOCK_METHOD1(InjectKeyEvent
, void(const KeyEvent
& event
));
99 MOCK_METHOD1(InjectMouseEvent
, void(const MouseEvent
& event
));
102 DISALLOW_COPY_AND_ASSIGN(MockInputStub
);
105 class MockHostStub
: public HostStub
{
108 virtual ~MockHostStub();
110 MOCK_METHOD1(NotifyClientResolution
,
111 void(const ClientResolution
& resolution
));
112 MOCK_METHOD1(ControlVideo
, void(const VideoControl
& video_control
));
113 MOCK_METHOD1(ControlAudio
, void(const AudioControl
& audio_control
));
114 MOCK_METHOD1(SetCapabilities
, void(const Capabilities
& capabilities
));
115 MOCK_METHOD1(RequestPairing
,
116 void(const PairingRequest
& pairing_request
));
119 DISALLOW_COPY_AND_ASSIGN(MockHostStub
);
122 class MockClientStub
: public ClientStub
{
125 virtual ~MockClientStub();
127 // ClientStub mock implementation.
128 MOCK_METHOD1(SetCapabilities
, void(const Capabilities
& capabilities
));
129 MOCK_METHOD1(SetPairingResponse
,
130 void(const PairingResponse
& pairing_response
));
132 // ClipboardStub mock implementation.
133 MOCK_METHOD1(InjectClipboardEvent
, void(const ClipboardEvent
& event
));
135 // CursorShapeStub mock implementation.
136 MOCK_METHOD1(SetCursorShape
, void(const CursorShapeInfo
& cursor_shape
));
139 DISALLOW_COPY_AND_ASSIGN(MockClientStub
);
142 class MockVideoStub
: public VideoStub
{
145 virtual ~MockVideoStub();
147 MOCK_METHOD2(ProcessVideoPacketPtr
, void(const VideoPacket
* video_packet
,
148 const base::Closure
& done
));
149 virtual void ProcessVideoPacket(scoped_ptr
<VideoPacket
> video_packet
,
150 const base::Closure
& done
) {
151 ProcessVideoPacketPtr(video_packet
.get(), done
);
155 DISALLOW_COPY_AND_ASSIGN(MockVideoStub
);
158 class MockSession
: public Session
{
161 virtual ~MockSession();
163 MOCK_METHOD1(SetEventHandler
, void(Session::EventHandler
* event_handler
));
164 MOCK_METHOD0(error
, ErrorCode());
165 MOCK_METHOD0(GetTransportChannelFactory
, ChannelFactory
*());
166 MOCK_METHOD0(GetMultiplexedChannelFactory
, ChannelFactory
*());
167 MOCK_METHOD0(jid
, const std::string
&());
168 MOCK_METHOD0(candidate_config
, const CandidateSessionConfig
*());
169 MOCK_METHOD0(config
, const SessionConfig
&());
170 MOCK_METHOD1(set_config
, void(const SessionConfig
& config
));
171 MOCK_METHOD0(initiator_token
, const std::string
&());
172 MOCK_METHOD1(set_initiator_token
, void(const std::string
& initiator_token
));
173 MOCK_METHOD0(receiver_token
, const std::string
&());
174 MOCK_METHOD1(set_receiver_token
, void(const std::string
& receiver_token
));
175 MOCK_METHOD1(set_shared_secret
, void(const std::string
& secret
));
176 MOCK_METHOD0(shared_secret
, const std::string
&());
177 MOCK_METHOD0(Close
, void());
180 DISALLOW_COPY_AND_ASSIGN(MockSession
);
183 class MockSessionManager
: public SessionManager
{
185 MockSessionManager();
186 virtual ~MockSessionManager();
188 MOCK_METHOD2(Init
, void(SignalStrategy
*, Listener
*));
189 MOCK_METHOD3(ConnectPtr
, Session
*(
190 const std::string
& host_jid
,
191 Authenticator
* authenticator
,
192 CandidateSessionConfig
* config
));
193 MOCK_METHOD0(Close
, void());
194 MOCK_METHOD1(set_authenticator_factory_ptr
,
195 void(AuthenticatorFactory
* factory
));
196 virtual scoped_ptr
<Session
> Connect(
197 const std::string
& host_jid
,
198 scoped_ptr
<Authenticator
> authenticator
,
199 scoped_ptr
<CandidateSessionConfig
> config
) {
200 return scoped_ptr
<Session
>(ConnectPtr(
201 host_jid
, authenticator
.get(), config
.get()));
203 virtual void set_authenticator_factory(
204 scoped_ptr
<AuthenticatorFactory
> authenticator_factory
) {
205 set_authenticator_factory_ptr(authenticator_factory
.release());
209 DISALLOW_COPY_AND_ASSIGN(MockSessionManager
);
212 // Simple delegate that caches information on paired clients in memory.
213 class MockPairingRegistryDelegate
: public PairingRegistry::Delegate
{
215 MockPairingRegistryDelegate();
216 virtual ~MockPairingRegistryDelegate();
218 // PairingRegistry::Delegate implementation.
219 virtual scoped_ptr
<base::ListValue
> LoadAll() OVERRIDE
;
220 virtual bool DeleteAll() OVERRIDE
;
221 virtual protocol::PairingRegistry::Pairing
Load(
222 const std::string
& client_id
) OVERRIDE
;
223 virtual bool Save(const protocol::PairingRegistry::Pairing
& pairing
) OVERRIDE
;
224 virtual bool Delete(const std::string
& client_id
) OVERRIDE
;
227 typedef std::map
<std::string
, protocol::PairingRegistry::Pairing
> Pairings
;
231 class SynchronousPairingRegistry
: public PairingRegistry
{
233 explicit SynchronousPairingRegistry(scoped_ptr
<Delegate
> delegate
);
236 virtual ~SynchronousPairingRegistry();
238 // Runs tasks synchronously instead of posting them to |task_runner|.
239 virtual void PostTask(
240 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
241 const tracked_objects::Location
& from_here
,
242 const base::Closure
& task
) OVERRIDE
;
245 } // namespace protocol
246 } // namespace remoting
248 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_