Mandoline: Disable slimming paint
[chromium-blink-merge.git] / remoting / protocol / protocol_mock_objects.h
blobb3fca8ed0ecbb9eccb1cbeea4c0ed8373e3a83be
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, HostStub* host_stub);
36 ~MockConnectionToClient() override;
38 MOCK_METHOD1(Init, void(Session* session));
39 MOCK_METHOD0(video_stub, VideoStub*());
40 MOCK_METHOD0(client_stub, ClientStub*());
41 MOCK_METHOD0(session, Session*());
42 MOCK_METHOD0(Disconnect, void());
44 void set_clipboard_stub(ClipboardStub* clipboard_stub) override {
45 clipboard_stub_ = clipboard_stub;
47 void set_host_stub(HostStub* host_stub) override { host_stub_ = host_stub; }
48 void set_input_stub(InputStub* input_stub) override {
49 input_stub_ = input_stub;
52 void set_video_feedback_stub(
53 VideoFeedbackStub* video_feedback_stub) override {
54 video_feedback_stub_ = video_feedback_stub;
57 ClipboardStub* clipboard_stub() { return clipboard_stub_; }
58 HostStub* host_stub() { return host_stub_; }
59 InputStub* input_stub() { return input_stub_; }
60 VideoFeedbackStub* video_feedback_stub() { return video_feedback_stub_; }
62 private:
63 ClipboardStub* clipboard_stub_;
64 HostStub* host_stub_;
65 InputStub* input_stub_;
66 VideoFeedbackStub* video_feedback_stub_;
68 DISALLOW_COPY_AND_ASSIGN(MockConnectionToClient);
71 class MockConnectionToClientEventHandler
72 : public ConnectionToClient::EventHandler {
73 public:
74 MockConnectionToClientEventHandler();
75 ~MockConnectionToClientEventHandler() override;
77 MOCK_METHOD1(OnConnectionAuthenticating,
78 void(ConnectionToClient* connection));
79 MOCK_METHOD1(OnConnectionAuthenticated, void(ConnectionToClient* connection));
80 MOCK_METHOD1(OnConnectionChannelsConnected,
81 void(ConnectionToClient* connection));
82 MOCK_METHOD2(OnConnectionClosed,
83 void(ConnectionToClient* connection, ErrorCode error));
84 MOCK_METHOD2(OnEventTimestamp,
85 void(ConnectionToClient* connection, int64 timestamp));
86 MOCK_METHOD3(OnRouteChange,
87 void(ConnectionToClient* connection,
88 const std::string& channel_name,
89 const TransportRoute& route));
91 private:
92 DISALLOW_COPY_AND_ASSIGN(MockConnectionToClientEventHandler);
95 class MockClipboardStub : public ClipboardStub {
96 public:
97 MockClipboardStub();
98 ~MockClipboardStub() override;
100 MOCK_METHOD1(InjectClipboardEvent, void(const ClipboardEvent& event));
102 private:
103 DISALLOW_COPY_AND_ASSIGN(MockClipboardStub);
106 class MockCursorShapeChangeCallback {
107 public:
108 MockCursorShapeChangeCallback();
109 virtual ~MockCursorShapeChangeCallback();
111 MOCK_METHOD1(CursorShapeChangedPtr, void(CursorShapeInfo* info));
112 void CursorShapeChanged(scoped_ptr<CursorShapeInfo> info);
114 private:
115 DISALLOW_COPY_AND_ASSIGN(MockCursorShapeChangeCallback);
118 class MockInputStub : public InputStub {
119 public:
120 MockInputStub();
121 ~MockInputStub() override;
123 MOCK_METHOD1(InjectKeyEvent, void(const KeyEvent& event));
124 MOCK_METHOD1(InjectTextEvent, void(const TextEvent& event));
125 MOCK_METHOD1(InjectMouseEvent, void(const MouseEvent& event));
126 MOCK_METHOD1(InjectTouchEvent, void(const TouchEvent& event));
128 private:
129 DISALLOW_COPY_AND_ASSIGN(MockInputStub);
132 class MockHostStub : public HostStub {
133 public:
134 MockHostStub();
135 ~MockHostStub() override;
137 MOCK_METHOD1(NotifyClientResolution,
138 void(const ClientResolution& resolution));
139 MOCK_METHOD1(ControlVideo, void(const VideoControl& video_control));
140 MOCK_METHOD1(ControlAudio, void(const AudioControl& audio_control));
141 MOCK_METHOD1(SetCapabilities, void(const Capabilities& capabilities));
142 MOCK_METHOD1(RequestPairing, void(const PairingRequest& pairing_request));
143 MOCK_METHOD1(DeliverClientMessage, void(const ExtensionMessage& message));
145 private:
146 DISALLOW_COPY_AND_ASSIGN(MockHostStub);
149 class MockClientStub : public ClientStub {
150 public:
151 MockClientStub();
152 ~MockClientStub() override;
154 // ClientStub mock implementation.
155 MOCK_METHOD1(SetCapabilities, void(const Capabilities& capabilities));
156 MOCK_METHOD1(SetPairingResponse,
157 void(const PairingResponse& pairing_response));
158 MOCK_METHOD1(DeliverHostMessage, void(const ExtensionMessage& message));
160 // ClipboardStub mock implementation.
161 MOCK_METHOD1(InjectClipboardEvent, void(const ClipboardEvent& event));
163 // CursorShapeStub mock implementation.
164 MOCK_METHOD1(SetCursorShape, void(const CursorShapeInfo& cursor_shape));
166 private:
167 DISALLOW_COPY_AND_ASSIGN(MockClientStub);
170 class MockCursorShapeStub : public CursorShapeStub {
171 public:
172 MockCursorShapeStub();
173 ~MockCursorShapeStub() override;
175 MOCK_METHOD1(SetCursorShape, void(const CursorShapeInfo& cursor_shape));
177 private:
178 DISALLOW_COPY_AND_ASSIGN(MockCursorShapeStub);
181 class MockVideoStub : public VideoStub {
182 public:
183 MockVideoStub();
184 ~MockVideoStub() override;
186 MOCK_METHOD2(ProcessVideoPacketPtr,
187 void(const VideoPacket* video_packet,
188 const base::Closure& done));
189 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet,
190 const base::Closure& done) override {
191 ProcessVideoPacketPtr(video_packet.get(), done);
194 private:
195 DISALLOW_COPY_AND_ASSIGN(MockVideoStub);
198 class MockSession : public Session {
199 public:
200 MockSession();
201 ~MockSession() override;
203 MOCK_METHOD1(SetEventHandler, void(Session::EventHandler* event_handler));
204 MOCK_METHOD0(error, ErrorCode());
205 MOCK_METHOD0(GetTransportChannelFactory, StreamChannelFactory*());
206 MOCK_METHOD0(GetMultiplexedChannelFactory, StreamChannelFactory*());
207 MOCK_METHOD0(jid, const std::string&());
208 MOCK_METHOD0(candidate_config, const CandidateSessionConfig*());
209 MOCK_METHOD0(config, const SessionConfig&());
210 MOCK_METHOD1(set_config_ptr, void(const SessionConfig* config));
211 void set_config(scoped_ptr<SessionConfig> config) override {
212 set_config_ptr(config.get());
214 MOCK_METHOD0(initiator_token, const std::string&());
215 MOCK_METHOD1(set_initiator_token, void(const std::string& initiator_token));
216 MOCK_METHOD0(receiver_token, const std::string&());
217 MOCK_METHOD1(set_receiver_token, void(const std::string& receiver_token));
218 MOCK_METHOD1(set_shared_secret, void(const std::string& secret));
219 MOCK_METHOD0(shared_secret, const std::string&());
220 MOCK_METHOD0(Close, void());
222 private:
223 DISALLOW_COPY_AND_ASSIGN(MockSession);
226 class MockSessionManager : public SessionManager {
227 public:
228 MockSessionManager();
229 ~MockSessionManager() override;
231 MOCK_METHOD2(Init, void(SignalStrategy*, Listener*));
232 MOCK_METHOD3(ConnectPtr,
233 Session*(const std::string& host_jid,
234 Authenticator* authenticator,
235 CandidateSessionConfig* config));
236 MOCK_METHOD0(Close, void());
237 MOCK_METHOD1(set_authenticator_factory_ptr,
238 void(AuthenticatorFactory* factory));
239 scoped_ptr<Session> Connect(
240 const std::string& host_jid,
241 scoped_ptr<Authenticator> authenticator,
242 scoped_ptr<CandidateSessionConfig> config) override {
243 return make_scoped_ptr(
244 ConnectPtr(host_jid, authenticator.get(), config.get()));
246 void set_authenticator_factory(
247 scoped_ptr<AuthenticatorFactory> authenticator_factory) override {
248 set_authenticator_factory_ptr(authenticator_factory.release());
251 private:
252 DISALLOW_COPY_AND_ASSIGN(MockSessionManager);
255 // Simple delegate that caches information on paired clients in memory.
256 class MockPairingRegistryDelegate : public PairingRegistry::Delegate {
257 public:
258 MockPairingRegistryDelegate();
259 ~MockPairingRegistryDelegate() override;
261 // PairingRegistry::Delegate implementation.
262 scoped_ptr<base::ListValue> LoadAll() override;
263 bool DeleteAll() override;
264 protocol::PairingRegistry::Pairing Load(
265 const std::string& client_id) override;
266 bool Save(const protocol::PairingRegistry::Pairing& pairing) override;
267 bool Delete(const std::string& client_id) override;
269 private:
270 typedef std::map<std::string, protocol::PairingRegistry::Pairing> Pairings;
271 Pairings pairings_;
274 class SynchronousPairingRegistry : public PairingRegistry {
275 public:
276 explicit SynchronousPairingRegistry(scoped_ptr<Delegate> delegate);
278 protected:
279 ~SynchronousPairingRegistry() override;
281 // Runs tasks synchronously instead of posting them to |task_runner|.
282 void PostTask(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
283 const tracked_objects::Location& from_here,
284 const base::Closure& task) override;
287 } // namespace protocol
288 } // namespace remoting
290 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_