Revert of Remove OneClickSigninHelper since it is no longer used. (patchset #5 id...
[chromium-blink-merge.git] / remoting / protocol / protocol_mock_objects.h
blob758151fa24ceb6f1a0d95b3368ad5ad6b1ea5abc
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 void set_clipboard_stub(ClipboardStub* clipboard_stub) override {
46 clipboard_stub_ = clipboard_stub;
48 void set_host_stub(HostStub* host_stub) override { host_stub_ = host_stub; }
49 void set_input_stub(InputStub* input_stub) override {
50 input_stub_ = input_stub;
53 void set_video_feedback_stub(
54 VideoFeedbackStub* video_feedback_stub) override {
55 video_feedback_stub_ = video_feedback_stub;
58 ClipboardStub* clipboard_stub() { return clipboard_stub_; }
59 HostStub* host_stub() { return host_stub_; }
60 InputStub* input_stub() { return input_stub_; }
61 VideoFeedbackStub* video_feedback_stub() { return video_feedback_stub_; }
63 private:
64 ClipboardStub* clipboard_stub_;
65 HostStub* host_stub_;
66 InputStub* input_stub_;
67 VideoFeedbackStub* video_feedback_stub_;
69 DISALLOW_COPY_AND_ASSIGN(MockConnectionToClient);
72 class MockConnectionToClientEventHandler :
73 public ConnectionToClient::EventHandler {
74 public:
75 MockConnectionToClientEventHandler();
76 virtual ~MockConnectionToClientEventHandler();
78 MOCK_METHOD1(OnConnectionAuthenticating,
79 void(ConnectionToClient* connection));
80 MOCK_METHOD1(OnConnectionAuthenticated, void(ConnectionToClient* connection));
81 MOCK_METHOD1(OnConnectionChannelsConnected,
82 void(ConnectionToClient* connection));
83 MOCK_METHOD2(OnConnectionClosed, void(ConnectionToClient* connection,
84 ErrorCode error));
85 MOCK_METHOD2(OnEventTimestamp,
86 void(ConnectionToClient* connection, int64 timestamp));
87 MOCK_METHOD3(OnRouteChange, 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 virtual ~MockClipboardStub();
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 virtual ~MockInputStub();
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 virtual ~MockHostStub();
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,
143 void(const PairingRequest& pairing_request));
144 MOCK_METHOD1(DeliverClientMessage, void(const ExtensionMessage& message));
146 private:
147 DISALLOW_COPY_AND_ASSIGN(MockHostStub);
150 class MockClientStub : public ClientStub {
151 public:
152 MockClientStub();
153 virtual ~MockClientStub();
155 // ClientStub mock implementation.
156 MOCK_METHOD1(SetCapabilities, void(const Capabilities& capabilities));
157 MOCK_METHOD1(SetPairingResponse,
158 void(const PairingResponse& pairing_response));
159 MOCK_METHOD1(DeliverHostMessage, void(const ExtensionMessage& message));
161 // ClipboardStub mock implementation.
162 MOCK_METHOD1(InjectClipboardEvent, void(const ClipboardEvent& event));
164 // CursorShapeStub mock implementation.
165 MOCK_METHOD1(SetCursorShape, void(const CursorShapeInfo& cursor_shape));
167 private:
168 DISALLOW_COPY_AND_ASSIGN(MockClientStub);
171 class MockCursorShapeStub : public CursorShapeStub {
172 public:
173 MockCursorShapeStub();
174 virtual ~MockCursorShapeStub();
176 MOCK_METHOD1(SetCursorShape, void(const CursorShapeInfo& cursor_shape));
178 private:
179 DISALLOW_COPY_AND_ASSIGN(MockCursorShapeStub);
182 class MockVideoStub : public VideoStub {
183 public:
184 MockVideoStub();
185 virtual ~MockVideoStub();
187 MOCK_METHOD2(ProcessVideoPacketPtr, void(const VideoPacket* video_packet,
188 const base::Closure& done));
189 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet,
190 const base::Closure& done) {
191 ProcessVideoPacketPtr(video_packet.get(), done);
194 private:
195 DISALLOW_COPY_AND_ASSIGN(MockVideoStub);
198 class MockSession : public Session {
199 public:
200 MockSession();
201 virtual ~MockSession();
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, void(const SessionConfig& config));
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 virtual ~MockSessionManager();
228 MOCK_METHOD2(Init, void(SignalStrategy*, Listener*));
229 MOCK_METHOD3(ConnectPtr, Session*(
230 const std::string& host_jid,
231 Authenticator* authenticator,
232 CandidateSessionConfig* config));
233 MOCK_METHOD0(Close, void());
234 MOCK_METHOD1(set_authenticator_factory_ptr,
235 void(AuthenticatorFactory* factory));
236 virtual scoped_ptr<Session> Connect(
237 const std::string& host_jid,
238 scoped_ptr<Authenticator> authenticator,
239 scoped_ptr<CandidateSessionConfig> config) {
240 return make_scoped_ptr(
241 ConnectPtr(host_jid, authenticator.get(), config.get()));
243 virtual void set_authenticator_factory(
244 scoped_ptr<AuthenticatorFactory> authenticator_factory) {
245 set_authenticator_factory_ptr(authenticator_factory.release());
248 private:
249 DISALLOW_COPY_AND_ASSIGN(MockSessionManager);
252 // Simple delegate that caches information on paired clients in memory.
253 class MockPairingRegistryDelegate : public PairingRegistry::Delegate {
254 public:
255 MockPairingRegistryDelegate();
256 ~MockPairingRegistryDelegate() override;
258 // PairingRegistry::Delegate implementation.
259 scoped_ptr<base::ListValue> LoadAll() override;
260 bool DeleteAll() override;
261 protocol::PairingRegistry::Pairing Load(
262 const std::string& client_id) override;
263 bool Save(const protocol::PairingRegistry::Pairing& pairing) override;
264 bool Delete(const std::string& client_id) override;
266 private:
267 typedef std::map<std::string, protocol::PairingRegistry::Pairing> Pairings;
268 Pairings pairings_;
271 class SynchronousPairingRegistry : public PairingRegistry {
272 public:
273 explicit SynchronousPairingRegistry(scoped_ptr<Delegate> delegate);
275 protected:
276 ~SynchronousPairingRegistry() override;
278 // Runs tasks synchronously instead of posting them to |task_runner|.
279 void PostTask(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
280 const tracked_objects::Location& from_here,
281 const base::Closure& task) override;
284 } // namespace protocol
285 } // namespace remoting
287 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_