Roll src/third_party/WebKit 2dc4bc6:34469ea (svn 182261:182277)
[chromium-blink-merge.git] / remoting / protocol / protocol_mock_objects.h
blob281860482968f15ee47122ba03d0f7de2efee62e
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_
8 #include <map>
9 #include <string>
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"
30 namespace remoting {
31 namespace protocol {
33 class MockConnectionToClient : public ConnectionToClient {
34 public:
35 MockConnectionToClient(Session* session,
36 HostStub* host_stub);
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 private:
46 DISALLOW_COPY_AND_ASSIGN(MockConnectionToClient);
49 class MockConnectionToClientEventHandler :
50 public ConnectionToClient::EventHandler {
51 public:
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,
61 ErrorCode error));
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));
68 private:
69 DISALLOW_COPY_AND_ASSIGN(MockConnectionToClientEventHandler);
72 class MockClipboardStub : public ClipboardStub {
73 public:
74 MockClipboardStub();
75 virtual ~MockClipboardStub();
77 MOCK_METHOD1(InjectClipboardEvent, void(const ClipboardEvent& event));
79 private:
80 DISALLOW_COPY_AND_ASSIGN(MockClipboardStub);
83 class MockCursorShapeChangeCallback {
84 public:
85 MockCursorShapeChangeCallback();
86 virtual ~MockCursorShapeChangeCallback();
88 MOCK_METHOD1(CursorShapeChangedPtr, void(CursorShapeInfo* info));
89 void CursorShapeChanged(scoped_ptr<CursorShapeInfo> info);
91 private:
92 DISALLOW_COPY_AND_ASSIGN(MockCursorShapeChangeCallback);
95 class MockInputStub : public InputStub {
96 public:
97 MockInputStub();
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));
104 private:
105 DISALLOW_COPY_AND_ASSIGN(MockInputStub);
108 class MockHostStub : public HostStub {
109 public:
110 MockHostStub();
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));
122 private:
123 DISALLOW_COPY_AND_ASSIGN(MockHostStub);
126 class MockClientStub : public ClientStub {
127 public:
128 MockClientStub();
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));
143 private:
144 DISALLOW_COPY_AND_ASSIGN(MockClientStub);
147 class MockVideoStub : public VideoStub {
148 public:
149 MockVideoStub();
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);
159 private:
160 DISALLOW_COPY_AND_ASSIGN(MockVideoStub);
163 class MockSession : public Session {
164 public:
165 MockSession();
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());
184 private:
185 DISALLOW_COPY_AND_ASSIGN(MockSession);
188 class MockSessionManager : public SessionManager {
189 public:
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());
213 private:
214 DISALLOW_COPY_AND_ASSIGN(MockSessionManager);
217 // Simple delegate that caches information on paired clients in memory.
218 class MockPairingRegistryDelegate : public PairingRegistry::Delegate {
219 public:
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;
231 private:
232 typedef std::map<std::string, protocol::PairingRegistry::Pairing> Pairings;
233 Pairings pairings_;
236 class SynchronousPairingRegistry : public PairingRegistry {
237 public:
238 explicit SynchronousPairingRegistry(scoped_ptr<Delegate> delegate);
240 protected:
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_