1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_
#define REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_
#include <map>
#include <string>
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/values.h"
#include "net/base/ip_endpoint.h"
#include "remoting/proto/internal.pb.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/authenticator.h"
#include "remoting/protocol/client_stub.h"
#include "remoting/protocol/clipboard_stub.h"
#include "remoting/protocol/connection_to_client.h"
#include "remoting/protocol/host_stub.h"
#include "remoting/protocol/input_stub.h"
#include "remoting/protocol/pairing_registry.h"
#include "remoting/protocol/session.h"
#include "remoting/protocol/session_manager.h"
#include "remoting/protocol/transport.h"
#include "remoting/protocol/video_stub.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace remoting {
namespace protocol {
class MockConnectionToClient : public ConnectionToClient {
public:
MockConnectionToClient(Session* session, HostStub* host_stub);
~MockConnectionToClient() override;
MOCK_METHOD1(Init, void(Session* session));
MOCK_METHOD0(video_stub, VideoStub*());
MOCK_METHOD0(client_stub, ClientStub*());
MOCK_METHOD0(session, Session*());
MOCK_METHOD0(Disconnect, void());
void set_clipboard_stub(ClipboardStub* clipboard_stub) override {
clipboard_stub_ = clipboard_stub;
}
void set_host_stub(HostStub* host_stub) override { host_stub_ = host_stub; }
void set_input_stub(InputStub* input_stub) override {
input_stub_ = input_stub;
}
void set_video_feedback_stub(
VideoFeedbackStub* video_feedback_stub) override {
video_feedback_stub_ = video_feedback_stub;
}
ClipboardStub* clipboard_stub() { return clipboard_stub_; }
HostStub* host_stub() { return host_stub_; }
InputStub* input_stub() { return input_stub_; }
VideoFeedbackStub* video_feedback_stub() { return video_feedback_stub_; }
private:
ClipboardStub* clipboard_stub_;
HostStub* host_stub_;
InputStub* input_stub_;
VideoFeedbackStub* video_feedback_stub_;
DISALLOW_COPY_AND_ASSIGN(MockConnectionToClient);
};
class MockConnectionToClientEventHandler
: public ConnectionToClient::EventHandler {
public:
MockConnectionToClientEventHandler();
~MockConnectionToClientEventHandler() override;
MOCK_METHOD1(OnConnectionAuthenticating,
void(ConnectionToClient* connection));
MOCK_METHOD1(OnConnectionAuthenticated, void(ConnectionToClient* connection));
MOCK_METHOD1(OnConnectionChannelsConnected,
void(ConnectionToClient* connection));
MOCK_METHOD2(OnConnectionClosed,
void(ConnectionToClient* connection, ErrorCode error));
MOCK_METHOD2(OnEventTimestamp,
void(ConnectionToClient* connection, int64 timestamp));
MOCK_METHOD3(OnRouteChange,
void(ConnectionToClient* connection,
const std::string& channel_name,
const TransportRoute& route));
private:
DISALLOW_COPY_AND_ASSIGN(MockConnectionToClientEventHandler);
};
class MockClipboardStub : public ClipboardStub {
public:
MockClipboardStub();
~MockClipboardStub() override;
MOCK_METHOD1(InjectClipboardEvent, void(const ClipboardEvent& event));
private:
DISALLOW_COPY_AND_ASSIGN(MockClipboardStub);
};
class MockCursorShapeChangeCallback {
public:
MockCursorShapeChangeCallback();
virtual ~MockCursorShapeChangeCallback();
MOCK_METHOD1(CursorShapeChangedPtr, void(CursorShapeInfo* info));
void CursorShapeChanged(scoped_ptr<CursorShapeInfo> info);
private:
DISALLOW_COPY_AND_ASSIGN(MockCursorShapeChangeCallback);
};
class MockInputStub : public InputStub {
public:
MockInputStub();
~MockInputStub() override;
MOCK_METHOD1(InjectKeyEvent, void(const KeyEvent& event));
MOCK_METHOD1(InjectTextEvent, void(const TextEvent& event));
MOCK_METHOD1(InjectMouseEvent, void(const MouseEvent& event));
MOCK_METHOD1(InjectTouchEvent, void(const TouchEvent& event));
private:
DISALLOW_COPY_AND_ASSIGN(MockInputStub);
};
class MockHostStub : public HostStub {
public:
MockHostStub();
~MockHostStub() override;
MOCK_METHOD1(NotifyClientResolution,
void(const ClientResolution& resolution));
MOCK_METHOD1(ControlVideo, void(const VideoControl& video_control));
MOCK_METHOD1(ControlAudio, void(const AudioControl& audio_control));
MOCK_METHOD1(SetCapabilities, void(const Capabilities& capabilities));
MOCK_METHOD1(RequestPairing, void(const PairingRequest& pairing_request));
MOCK_METHOD1(DeliverClientMessage, void(const ExtensionMessage& message));
private:
DISALLOW_COPY_AND_ASSIGN(MockHostStub);
};
class MockClientStub : public ClientStub {
public:
MockClientStub();
~MockClientStub() override;
// ClientStub mock implementation.
MOCK_METHOD1(SetCapabilities, void(const Capabilities& capabilities));
MOCK_METHOD1(SetPairingResponse,
void(const PairingResponse& pairing_response));
MOCK_METHOD1(DeliverHostMessage, void(const ExtensionMessage& message));
// ClipboardStub mock implementation.
MOCK_METHOD1(InjectClipboardEvent, void(const ClipboardEvent& event));
// CursorShapeStub mock implementation.
MOCK_METHOD1(SetCursorShape, void(const CursorShapeInfo& cursor_shape));
private:
DISALLOW_COPY_AND_ASSIGN(MockClientStub);
};
class MockCursorShapeStub : public CursorShapeStub {
public:
MockCursorShapeStub();
~MockCursorShapeStub() override;
MOCK_METHOD1(SetCursorShape, void(const CursorShapeInfo& cursor_shape));
private:
DISALLOW_COPY_AND_ASSIGN(MockCursorShapeStub);
};
class MockVideoStub : public VideoStub {
public:
MockVideoStub();
~MockVideoStub() override;
MOCK_METHOD2(ProcessVideoPacketPtr,
void(const VideoPacket* video_packet,
const base::Closure& done));
void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet,
const base::Closure& done) override {
ProcessVideoPacketPtr(video_packet.get(), done);
}
private:
DISALLOW_COPY_AND_ASSIGN(MockVideoStub);
};
class MockSession : public Session {
public:
MockSession();
~MockSession() override;
MOCK_METHOD1(SetEventHandler, void(Session::EventHandler* event_handler));
MOCK_METHOD0(error, ErrorCode());
MOCK_METHOD0(GetTransportChannelFactory, StreamChannelFactory*());
MOCK_METHOD0(GetMultiplexedChannelFactory, StreamChannelFactory*());
MOCK_METHOD0(jid, const std::string&());
MOCK_METHOD0(candidate_config, const CandidateSessionConfig*());
MOCK_METHOD0(config, const SessionConfig&());
MOCK_METHOD1(set_config, void(const SessionConfig& config));
MOCK_METHOD0(initiator_token, const std::string&());
MOCK_METHOD1(set_initiator_token, void(const std::string& initiator_token));
MOCK_METHOD0(receiver_token, const std::string&());
MOCK_METHOD1(set_receiver_token, void(const std::string& receiver_token));
MOCK_METHOD1(set_shared_secret, void(const std::string& secret));
MOCK_METHOD0(shared_secret, const std::string&());
MOCK_METHOD0(Close, void());
private:
DISALLOW_COPY_AND_ASSIGN(MockSession);
};
class MockSessionManager : public SessionManager {
public:
MockSessionManager();
~MockSessionManager() override;
MOCK_METHOD2(Init, void(SignalStrategy*, Listener*));
MOCK_METHOD3(ConnectPtr,
Session*(const std::string& host_jid,
Authenticator* authenticator,
CandidateSessionConfig* config));
MOCK_METHOD0(Close, void());
MOCK_METHOD1(set_authenticator_factory_ptr,
void(AuthenticatorFactory* factory));
scoped_ptr<Session> Connect(
const std::string& host_jid,
scoped_ptr<Authenticator> authenticator,
scoped_ptr<CandidateSessionConfig> config) override {
return make_scoped_ptr(
ConnectPtr(host_jid, authenticator.get(), config.get()));
}
void set_authenticator_factory(
scoped_ptr<AuthenticatorFactory> authenticator_factory) override {
set_authenticator_factory_ptr(authenticator_factory.release());
}
private:
DISALLOW_COPY_AND_ASSIGN(MockSessionManager);
};
// Simple delegate that caches information on paired clients in memory.
class MockPairingRegistryDelegate : public PairingRegistry::Delegate {
public:
MockPairingRegistryDelegate();
~MockPairingRegistryDelegate() override;
// PairingRegistry::Delegate implementation.
scoped_ptr<base::ListValue> LoadAll() override;
bool DeleteAll() override;
protocol::PairingRegistry::Pairing Load(
const std::string& client_id) override;
bool Save(const protocol::PairingRegistry::Pairing& pairing) override;
bool Delete(const std::string& client_id) override;
private:
typedef std::map<std::string, protocol::PairingRegistry::Pairing> Pairings;
Pairings pairings_;
};
class SynchronousPairingRegistry : public PairingRegistry {
public:
explicit SynchronousPairingRegistry(scoped_ptr<Delegate> delegate);
protected:
~SynchronousPairingRegistry() override;
// Runs tasks synchronously instead of posting them to |task_runner|.
void PostTask(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
const tracked_objects::Location& from_here,
const base::Closure& task) override;
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_PROTOCOL_MOCK_OBJECTS_H_
|