Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / remoting / protocol / protocol_mock_objects.h
blob0feb5e9ec1a19d05b027c4239750d6fa000c922b
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_METHOD0(initiator_token, const std::string&());
211 MOCK_METHOD1(set_initiator_token, void(const std::string& initiator_token));
212 MOCK_METHOD0(receiver_token, const std::string&());
213 MOCK_METHOD1(set_receiver_token, void(const std::string& receiver_token));
214 MOCK_METHOD1(set_shared_secret, void(const std::string& secret));
215 MOCK_METHOD0(shared_secret, const std::string&());
216 MOCK_METHOD0(Close, void());
218 private:
219 DISALLOW_COPY_AND_ASSIGN(MockSession);
222 class MockSessionManager : public SessionManager {
223 public:
224 MockSessionManager();
225 ~MockSessionManager() override;
227 MOCK_METHOD2(Init, void(SignalStrategy*, Listener*));
228 void set_protocol_config(scoped_ptr<CandidateSessionConfig> config) override {
230 MOCK_METHOD2(ConnectPtr,
231 Session*(const std::string& host_jid,
232 Authenticator* authenticator));
233 MOCK_METHOD0(Close, void());
234 MOCK_METHOD1(set_authenticator_factory_ptr,
235 void(AuthenticatorFactory* factory));
236 scoped_ptr<Session> Connect(
237 const std::string& host_jid,
238 scoped_ptr<Authenticator> authenticator) override {
239 return make_scoped_ptr(ConnectPtr(host_jid, authenticator.get()));
241 void set_authenticator_factory(
242 scoped_ptr<AuthenticatorFactory> authenticator_factory) override {
243 set_authenticator_factory_ptr(authenticator_factory.release());
246 private:
247 DISALLOW_COPY_AND_ASSIGN(MockSessionManager);
250 // Simple delegate that caches information on paired clients in memory.
251 class MockPairingRegistryDelegate : public PairingRegistry::Delegate {
252 public:
253 MockPairingRegistryDelegate();
254 ~MockPairingRegistryDelegate() override;
256 // PairingRegistry::Delegate implementation.
257 scoped_ptr<base::ListValue> LoadAll() override;
258 bool DeleteAll() override;
259 protocol::PairingRegistry::Pairing Load(
260 const std::string& client_id) override;
261 bool Save(const protocol::PairingRegistry::Pairing& pairing) override;
262 bool Delete(const std::string& client_id) override;
264 private:
265 typedef std::map<std::string, protocol::PairingRegistry::Pairing> Pairings;
266 Pairings pairings_;
269 class SynchronousPairingRegistry : public PairingRegistry {
270 public:
271 explicit SynchronousPairingRegistry(scoped_ptr<Delegate> delegate);
273 protected:
274 ~SynchronousPairingRegistry() override;
276 // Runs tasks synchronously instead of posting them to |task_runner|.
277 void PostTask(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
278 const tracked_objects::Location& from_here,
279 const base::Closure& task) override;
282 } // namespace protocol
283 } // namespace remoting
285 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_