Revert of Revert of Roll android_tools f6e2370:2a860d8 (patchset #1 id:1 of https...
[chromium-blink-merge.git] / remoting / protocol / protocol_mock_objects.h
blob24db36d78f5d3e20406dbf20d749bc838597b0b6
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(OnEventTimestamp,
63 void(ConnectionToClient* connection, int64 timestamp));
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 MockCursorShapeStub : public CursorShapeStub {
148 public:
149 MockCursorShapeStub();
150 virtual ~MockCursorShapeStub();
152 MOCK_METHOD1(SetCursorShape, void(const CursorShapeInfo& cursor_shape));
154 private:
155 DISALLOW_COPY_AND_ASSIGN(MockCursorShapeStub);
158 class MockVideoStub : public VideoStub {
159 public:
160 MockVideoStub();
161 virtual ~MockVideoStub();
163 MOCK_METHOD2(ProcessVideoPacketPtr, void(const VideoPacket* video_packet,
164 const base::Closure& done));
165 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet,
166 const base::Closure& done) {
167 ProcessVideoPacketPtr(video_packet.get(), done);
170 private:
171 DISALLOW_COPY_AND_ASSIGN(MockVideoStub);
174 class MockSession : public Session {
175 public:
176 MockSession();
177 virtual ~MockSession();
179 MOCK_METHOD1(SetEventHandler, void(Session::EventHandler* event_handler));
180 MOCK_METHOD0(error, ErrorCode());
181 MOCK_METHOD0(GetTransportChannelFactory, StreamChannelFactory*());
182 MOCK_METHOD0(GetMultiplexedChannelFactory, StreamChannelFactory*());
183 MOCK_METHOD0(jid, const std::string&());
184 MOCK_METHOD0(candidate_config, const CandidateSessionConfig*());
185 MOCK_METHOD0(config, const SessionConfig&());
186 MOCK_METHOD1(set_config, void(const SessionConfig& config));
187 MOCK_METHOD0(initiator_token, const std::string&());
188 MOCK_METHOD1(set_initiator_token, void(const std::string& initiator_token));
189 MOCK_METHOD0(receiver_token, const std::string&());
190 MOCK_METHOD1(set_receiver_token, void(const std::string& receiver_token));
191 MOCK_METHOD1(set_shared_secret, void(const std::string& secret));
192 MOCK_METHOD0(shared_secret, const std::string&());
193 MOCK_METHOD0(Close, void());
195 private:
196 DISALLOW_COPY_AND_ASSIGN(MockSession);
199 class MockSessionManager : public SessionManager {
200 public:
201 MockSessionManager();
202 virtual ~MockSessionManager();
204 MOCK_METHOD2(Init, void(SignalStrategy*, Listener*));
205 MOCK_METHOD3(ConnectPtr, Session*(
206 const std::string& host_jid,
207 Authenticator* authenticator,
208 CandidateSessionConfig* config));
209 MOCK_METHOD0(Close, void());
210 MOCK_METHOD1(set_authenticator_factory_ptr,
211 void(AuthenticatorFactory* factory));
212 virtual scoped_ptr<Session> Connect(
213 const std::string& host_jid,
214 scoped_ptr<Authenticator> authenticator,
215 scoped_ptr<CandidateSessionConfig> config) {
216 return make_scoped_ptr(
217 ConnectPtr(host_jid, authenticator.get(), config.get()));
219 virtual void set_authenticator_factory(
220 scoped_ptr<AuthenticatorFactory> authenticator_factory) {
221 set_authenticator_factory_ptr(authenticator_factory.release());
224 private:
225 DISALLOW_COPY_AND_ASSIGN(MockSessionManager);
228 // Simple delegate that caches information on paired clients in memory.
229 class MockPairingRegistryDelegate : public PairingRegistry::Delegate {
230 public:
231 MockPairingRegistryDelegate();
232 ~MockPairingRegistryDelegate() override;
234 // PairingRegistry::Delegate implementation.
235 scoped_ptr<base::ListValue> LoadAll() override;
236 bool DeleteAll() override;
237 protocol::PairingRegistry::Pairing Load(
238 const std::string& client_id) override;
239 bool Save(const protocol::PairingRegistry::Pairing& pairing) override;
240 bool Delete(const std::string& client_id) override;
242 private:
243 typedef std::map<std::string, protocol::PairingRegistry::Pairing> Pairings;
244 Pairings pairings_;
247 class SynchronousPairingRegistry : public PairingRegistry {
248 public:
249 explicit SynchronousPairingRegistry(scoped_ptr<Delegate> delegate);
251 protected:
252 ~SynchronousPairingRegistry() override;
254 // Runs tasks synchronously instead of posting them to |task_runner|.
255 void PostTask(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
256 const tracked_objects::Location& from_here,
257 const base::Closure& task) override;
260 } // namespace protocol
261 } // namespace remoting
263 #endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_