Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / remoting / protocol / protocol_mock_objects.h
blobd37b575e77a3bde74877629cdee545265ae8b110
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(GetQuicChannelFactory, StreamChannelFactory*());
208 MOCK_METHOD0(jid, const std::string&());
209 MOCK_METHOD0(candidate_config, const CandidateSessionConfig*());
210 MOCK_METHOD0(config, const SessionConfig&());
211 MOCK_METHOD0(initiator_token, const std::string&());
212 MOCK_METHOD1(set_initiator_token, void(const std::string& initiator_token));
213 MOCK_METHOD0(receiver_token, const std::string&());
214 MOCK_METHOD1(set_receiver_token, void(const std::string& receiver_token));
215 MOCK_METHOD1(set_shared_secret, void(const std::string& secret));
216 MOCK_METHOD0(shared_secret, const std::string&());
217 MOCK_METHOD0(Close, void());
219 private:
220 DISALLOW_COPY_AND_ASSIGN(MockSession);
223 class MockSessionManager : public SessionManager {
224 public:
225 MockSessionManager();
226 ~MockSessionManager() override;
228 MOCK_METHOD2(Init, void(SignalStrategy*, Listener*));
229 void set_protocol_config(scoped_ptr<CandidateSessionConfig> config) override {
231 MOCK_METHOD2(ConnectPtr,
232 Session*(const std::string& host_jid,
233 Authenticator* authenticator));
234 MOCK_METHOD0(Close, void());
235 MOCK_METHOD1(set_authenticator_factory_ptr,
236 void(AuthenticatorFactory* factory));
237 scoped_ptr<Session> Connect(
238 const std::string& host_jid,
239 scoped_ptr<Authenticator> authenticator) override {
240 return make_scoped_ptr(ConnectPtr(host_jid, authenticator.get()));
242 void set_authenticator_factory(
243 scoped_ptr<AuthenticatorFactory> authenticator_factory) override {
244 set_authenticator_factory_ptr(authenticator_factory.release());
247 private:
248 DISALLOW_COPY_AND_ASSIGN(MockSessionManager);
251 // Simple delegate that caches information on paired clients in memory.
252 class MockPairingRegistryDelegate : public PairingRegistry::Delegate {
253 public:
254 MockPairingRegistryDelegate();
255 ~MockPairingRegistryDelegate() override;
257 // PairingRegistry::Delegate implementation.
258 scoped_ptr<base::ListValue> LoadAll() override;
259 bool DeleteAll() override;
260 protocol::PairingRegistry::Pairing Load(
261 const std::string& client_id) override;
262 bool Save(const protocol::PairingRegistry::Pairing& pairing) override;
263 bool Delete(const std::string& client_id) override;
265 private:
266 typedef std::map<std::string, protocol::PairingRegistry::Pairing> Pairings;
267 Pairings pairings_;
270 class SynchronousPairingRegistry : public PairingRegistry {
271 public:
272 explicit SynchronousPairingRegistry(scoped_ptr<Delegate> delegate);
274 protected:
275 ~SynchronousPairingRegistry() override;
277 // Runs tasks synchronously instead of posting them to |task_runner|.
278 void PostTask(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
279 const tracked_objects::Location& from_here,
280 const base::Closure& task) override;
283 } // namespace protocol
284 } // namespace remoting
286 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_