Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc

Issue 316093005: test_runner: Migrate MockWebRTCPeerConnectionHandler to Chromium C++ style (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 #include "content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler .h"
6
7 #include "content/shell/renderer/test_runner/TestInterfaces.h"
8 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
9 #include "content/shell/renderer/test_runner/mock_constraints.h"
10 #include "content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h"
11 #include "content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.h"
12 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
13 #include "third_party/WebKit/public/platform/WebMediaStream.h"
14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
15 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h"
16 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h "
17 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h"
18 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h"
19 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/platform/WebVector.h"
21
22 using namespace blink;
23
24 namespace content {
25
26 class RTCSessionDescriptionRequestSuccededTask
27 : public WebMethodTask<MockWebRTCPeerConnectionHandler> {
28 public:
29 RTCSessionDescriptionRequestSuccededTask(
30 MockWebRTCPeerConnectionHandler* object,
31 const WebRTCSessionDescriptionRequest& request,
32 const WebRTCSessionDescription& result)
33 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object),
34 request_(request),
35 result_(result) {}
36
37 virtual void runIfValid() OVERRIDE { request_.requestSucceeded(result_); }
38
39 private:
40 WebRTCSessionDescriptionRequest request_;
41 WebRTCSessionDescription result_;
42 };
43
44 class RTCSessionDescriptionRequestFailedTask
45 : public WebMethodTask<MockWebRTCPeerConnectionHandler> {
46 public:
47 RTCSessionDescriptionRequestFailedTask(
48 MockWebRTCPeerConnectionHandler* object,
49 const WebRTCSessionDescriptionRequest& request)
50 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object),
51 request_(request) {}
52
53 virtual void runIfValid() OVERRIDE { request_.requestFailed("TEST_ERROR"); }
54
55 private:
56 WebRTCSessionDescriptionRequest request_;
57 };
58
59 class RTCStatsRequestSucceededTask
60 : public WebMethodTask<MockWebRTCPeerConnectionHandler> {
61 public:
62 RTCStatsRequestSucceededTask(MockWebRTCPeerConnectionHandler* object,
63 const blink::WebRTCStatsRequest& request,
64 const blink::WebRTCStatsResponse& response)
65 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object),
66 request_(request),
67 response_(response) {}
68
69 virtual void runIfValid() OVERRIDE { request_.requestSucceeded(response_); }
70
71 private:
72 blink::WebRTCStatsRequest request_;
73 blink::WebRTCStatsResponse response_;
74 };
75
76 class RTCVoidRequestTask
77 : public WebMethodTask<MockWebRTCPeerConnectionHandler> {
78 public:
79 RTCVoidRequestTask(MockWebRTCPeerConnectionHandler* object,
80 const WebRTCVoidRequest& request,
81 bool succeeded)
82 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object),
83 request_(request),
84 succeeded_(succeeded) {}
85
86 virtual void runIfValid() OVERRIDE {
87 if (succeeded_)
88 request_.requestSucceeded();
89 else
90 request_.requestFailed("TEST_ERROR");
91 }
92
93 private:
94 WebRTCVoidRequest request_;
95 bool succeeded_;
96 };
97
98 class RTCPeerConnectionStateTask
99 : public WebMethodTask<MockWebRTCPeerConnectionHandler> {
100 public:
101 RTCPeerConnectionStateTask(
102 MockWebRTCPeerConnectionHandler* object,
103 WebRTCPeerConnectionHandlerClient* client,
104 WebRTCPeerConnectionHandlerClient::ICEConnectionState connection_state,
105 WebRTCPeerConnectionHandlerClient::ICEGatheringState gathering_state)
106 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object),
107 client_(client),
108 connection_state_(connection_state),
109 gathering_state_(gathering_state) {}
110
111 virtual void runIfValid() OVERRIDE {
112 client_->didChangeICEGatheringState(gathering_state_);
113 client_->didChangeICEConnectionState(connection_state_);
114 }
115
116 private:
117 WebRTCPeerConnectionHandlerClient* client_;
118 WebRTCPeerConnectionHandlerClient::ICEConnectionState connection_state_;
119 WebRTCPeerConnectionHandlerClient::ICEGatheringState gathering_state_;
120 };
121
122 class RemoteDataChannelTask
123 : public WebMethodTask<MockWebRTCPeerConnectionHandler> {
124 public:
125 RemoteDataChannelTask(MockWebRTCPeerConnectionHandler* object,
126 WebRTCPeerConnectionHandlerClient* client,
127 WebTestDelegate* delegate)
128 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object),
129 client_(client),
130 delegate_(delegate) {}
131
132 virtual void runIfValid() OVERRIDE {
133 WebRTCDataChannelInit init;
134 WebRTCDataChannelHandler* remote_data_channel =
135 new MockWebRTCDataChannelHandler(
136 "MockRemoteDataChannel", init, delegate_);
137 client_->didAddRemoteDataChannel(remote_data_channel);
138 }
139
140 private:
141 WebRTCPeerConnectionHandlerClient* client_;
142 WebTestDelegate* delegate_;
143 };
144
145 /////////////////////
146
147 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() {
148 }
149
150 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler(
151 WebRTCPeerConnectionHandlerClient* client,
152 TestInterfaces* interfaces)
153 : client_(client),
154 stopped_(false),
155 stream_count_(0),
156 interfaces_(interfaces) {
157 }
158
159 bool MockWebRTCPeerConnectionHandler::initialize(
160 const WebRTCConfiguration& configuration,
161 const WebMediaConstraints& constraints) {
162 if (MockConstraints::VerifyConstraints(constraints)) {
163 interfaces_->delegate()->postTask(new RTCPeerConnectionStateTask(
164 this,
165 client_,
166 WebRTCPeerConnectionHandlerClient::ICEConnectionStateCompleted,
167 WebRTCPeerConnectionHandlerClient::ICEGatheringStateComplete));
168 return true;
169 }
170
171 return false;
172 }
173
174 void MockWebRTCPeerConnectionHandler::createOffer(
175 const WebRTCSessionDescriptionRequest& request,
176 const WebMediaConstraints& constraints) {
177 WebString should_succeed;
178 if (constraints.getMandatoryConstraintValue("succeed", should_succeed) &&
179 should_succeed == "true") {
180 WebRTCSessionDescription session_description;
181 session_description.initialize("offer", "local");
182 interfaces_->delegate()->postTask(
183 new RTCSessionDescriptionRequestSuccededTask(
184 this, request, session_description));
185 } else
186 interfaces_->delegate()->postTask(
187 new RTCSessionDescriptionRequestFailedTask(this, request));
188 }
189
190 void MockWebRTCPeerConnectionHandler::createAnswer(
191 const WebRTCSessionDescriptionRequest& request,
192 const WebMediaConstraints& constraints) {
193 if (!remote_description_.isNull()) {
194 WebRTCSessionDescription session_description;
195 session_description.initialize("answer", "local");
196 interfaces_->delegate()->postTask(
197 new RTCSessionDescriptionRequestSuccededTask(
198 this, request, session_description));
199 } else
200 interfaces_->delegate()->postTask(
201 new RTCSessionDescriptionRequestFailedTask(this, request));
202 }
203
204 void MockWebRTCPeerConnectionHandler::setLocalDescription(
205 const WebRTCVoidRequest& request,
206 const WebRTCSessionDescription& local_description) {
207 if (!local_description.isNull() && local_description.sdp() == "local") {
208 local_description_ = local_description;
209 interfaces_->delegate()->postTask(
210 new RTCVoidRequestTask(this, request, true));
211 } else
212 interfaces_->delegate()->postTask(
213 new RTCVoidRequestTask(this, request, false));
214 }
215
216 void MockWebRTCPeerConnectionHandler::setRemoteDescription(
217 const WebRTCVoidRequest& request,
218 const WebRTCSessionDescription& remote_description) {
219 if (!remote_description.isNull() && remote_description.sdp() == "remote") {
220 remote_description_ = remote_description;
221 interfaces_->delegate()->postTask(
222 new RTCVoidRequestTask(this, request, true));
223 } else
224 interfaces_->delegate()->postTask(
225 new RTCVoidRequestTask(this, request, false));
226 }
227
228 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::localDescription() {
229 return local_description_;
230 }
231
232 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::remoteDescription() {
233 return remote_description_;
234 }
235
236 bool MockWebRTCPeerConnectionHandler::updateICE(
237 const WebRTCConfiguration& configuration,
238 const WebMediaConstraints& constraints) {
239 return true;
240 }
241
242 bool MockWebRTCPeerConnectionHandler::addICECandidate(
243 const WebRTCICECandidate& ice_candidate) {
244 client_->didGenerateICECandidate(ice_candidate);
245 return true;
246 }
247
248 bool MockWebRTCPeerConnectionHandler::addICECandidate(
249 const WebRTCVoidRequest& request,
250 const WebRTCICECandidate& ice_candidate) {
251 interfaces_->delegate()->postTask(
252 new RTCVoidRequestTask(this, request, true));
253 return true;
254 }
255
256 bool MockWebRTCPeerConnectionHandler::addStream(
257 const WebMediaStream& stream,
258 const WebMediaConstraints& constraints) {
259 ++stream_count_;
260 client_->negotiationNeeded();
261 return true;
262 }
263
264 void MockWebRTCPeerConnectionHandler::removeStream(
265 const WebMediaStream& stream) {
266 --stream_count_;
267 client_->negotiationNeeded();
268 }
269
270 void MockWebRTCPeerConnectionHandler::getStats(
271 const WebRTCStatsRequest& request) {
272 WebRTCStatsResponse response = request.createResponse();
273 double current_date = interfaces_->delegate()->getCurrentTimeInMillisecond();
274 if (request.hasSelector()) {
275 // FIXME: There is no check that the fetched values are valid.
276 size_t report_index =
277 response.addReport("Mock video", "ssrc", current_date);
278 response.addStatistic(report_index, "type", "video");
279 } else {
280 for (int i = 0; i < stream_count_; ++i) {
281 size_t report_index =
282 response.addReport("Mock audio", "ssrc", current_date);
283 response.addStatistic(report_index, "type", "audio");
284 report_index = response.addReport("Mock video", "ssrc", current_date);
285 response.addStatistic(report_index, "type", "video");
286 }
287 }
288 interfaces_->delegate()->postTask(
289 new RTCStatsRequestSucceededTask(this, request, response));
290 }
291
292 WebRTCDataChannelHandler* MockWebRTCPeerConnectionHandler::createDataChannel(
293 const WebString& label,
294 const blink::WebRTCDataChannelInit& init) {
295 interfaces_->delegate()->postTask(
296 new RemoteDataChannelTask(this, client_, interfaces_->delegate()));
297
298 return new MockWebRTCDataChannelHandler(label, init, interfaces_->delegate());
299 }
300
301 WebRTCDTMFSenderHandler* MockWebRTCPeerConnectionHandler::createDTMFSender(
302 const WebMediaStreamTrack& track) {
303 return new MockWebRTCDTMFSenderHandler(track, interfaces_->delegate());
304 }
305
306 void MockWebRTCPeerConnectionHandler::stop() {
307 stopped_ = true;
308 }
309
310 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698