OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler
.h" | 5 #include "content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler
.h" |
6 | 6 |
7 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | |
8 #include "content/shell/renderer/test_runner/mock_constraints.h" | 7 #include "content/shell/renderer/test_runner/mock_constraints.h" |
9 #include "content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h" | 8 #include "content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h" |
10 #include "content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.h" | 9 #include "content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.h" |
11 #include "content/shell/renderer/test_runner/test_interfaces.h" | 10 #include "content/shell/renderer/test_runner/test_interfaces.h" |
| 11 #include "content/shell/renderer/test_runner/web_test_delegate.h" |
12 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 12 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
13 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 13 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
15 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | 15 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
16 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" | 16 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" |
17 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" | 17 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" |
18 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" | 18 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" |
19 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
20 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
21 | 21 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 : client_(client), | 153 : client_(client), |
154 stopped_(false), | 154 stopped_(false), |
155 stream_count_(0), | 155 stream_count_(0), |
156 interfaces_(interfaces) { | 156 interfaces_(interfaces) { |
157 } | 157 } |
158 | 158 |
159 bool MockWebRTCPeerConnectionHandler::initialize( | 159 bool MockWebRTCPeerConnectionHandler::initialize( |
160 const WebRTCConfiguration& configuration, | 160 const WebRTCConfiguration& configuration, |
161 const WebMediaConstraints& constraints) { | 161 const WebMediaConstraints& constraints) { |
162 if (MockConstraints::VerifyConstraints(constraints)) { | 162 if (MockConstraints::VerifyConstraints(constraints)) { |
163 interfaces_->GetDelegate()->postTask(new RTCPeerConnectionStateTask( | 163 interfaces_->GetDelegate()->PostTask(new RTCPeerConnectionStateTask( |
164 this, | 164 this, |
165 client_, | 165 client_, |
166 WebRTCPeerConnectionHandlerClient::ICEConnectionStateCompleted, | 166 WebRTCPeerConnectionHandlerClient::ICEConnectionStateCompleted, |
167 WebRTCPeerConnectionHandlerClient::ICEGatheringStateComplete)); | 167 WebRTCPeerConnectionHandlerClient::ICEGatheringStateComplete)); |
168 return true; | 168 return true; |
169 } | 169 } |
170 | 170 |
171 return false; | 171 return false; |
172 } | 172 } |
173 | 173 |
174 void MockWebRTCPeerConnectionHandler::createOffer( | 174 void MockWebRTCPeerConnectionHandler::createOffer( |
175 const WebRTCSessionDescriptionRequest& request, | 175 const WebRTCSessionDescriptionRequest& request, |
176 const WebMediaConstraints& constraints) { | 176 const WebMediaConstraints& constraints) { |
177 WebString should_succeed; | 177 WebString should_succeed; |
178 if (constraints.getMandatoryConstraintValue("succeed", should_succeed) && | 178 if (constraints.getMandatoryConstraintValue("succeed", should_succeed) && |
179 should_succeed == "true") { | 179 should_succeed == "true") { |
180 WebRTCSessionDescription session_description; | 180 WebRTCSessionDescription session_description; |
181 session_description.initialize("offer", "local"); | 181 session_description.initialize("offer", "local"); |
182 interfaces_->GetDelegate()->postTask( | 182 interfaces_->GetDelegate()->PostTask( |
183 new RTCSessionDescriptionRequestSuccededTask( | 183 new RTCSessionDescriptionRequestSuccededTask( |
184 this, request, session_description)); | 184 this, request, session_description)); |
185 } else | 185 } else |
186 interfaces_->GetDelegate()->postTask( | 186 interfaces_->GetDelegate()->PostTask( |
187 new RTCSessionDescriptionRequestFailedTask(this, request)); | 187 new RTCSessionDescriptionRequestFailedTask(this, request)); |
188 } | 188 } |
189 | 189 |
190 void MockWebRTCPeerConnectionHandler::createOffer( | 190 void MockWebRTCPeerConnectionHandler::createOffer( |
191 const WebRTCSessionDescriptionRequest& request, | 191 const WebRTCSessionDescriptionRequest& request, |
192 const blink::WebRTCOfferOptions& options) { | 192 const blink::WebRTCOfferOptions& options) { |
193 interfaces_->GetDelegate()->postTask( | 193 interfaces_->GetDelegate()->PostTask( |
194 new RTCSessionDescriptionRequestFailedTask(this, request)); | 194 new RTCSessionDescriptionRequestFailedTask(this, request)); |
195 } | 195 } |
196 | 196 |
197 void MockWebRTCPeerConnectionHandler::createAnswer( | 197 void MockWebRTCPeerConnectionHandler::createAnswer( |
198 const WebRTCSessionDescriptionRequest& request, | 198 const WebRTCSessionDescriptionRequest& request, |
199 const WebMediaConstraints& constraints) { | 199 const WebMediaConstraints& constraints) { |
200 if (!remote_description_.isNull()) { | 200 if (!remote_description_.isNull()) { |
201 WebRTCSessionDescription session_description; | 201 WebRTCSessionDescription session_description; |
202 session_description.initialize("answer", "local"); | 202 session_description.initialize("answer", "local"); |
203 interfaces_->GetDelegate()->postTask( | 203 interfaces_->GetDelegate()->PostTask( |
204 new RTCSessionDescriptionRequestSuccededTask( | 204 new RTCSessionDescriptionRequestSuccededTask( |
205 this, request, session_description)); | 205 this, request, session_description)); |
206 } else | 206 } else |
207 interfaces_->GetDelegate()->postTask( | 207 interfaces_->GetDelegate()->PostTask( |
208 new RTCSessionDescriptionRequestFailedTask(this, request)); | 208 new RTCSessionDescriptionRequestFailedTask(this, request)); |
209 } | 209 } |
210 | 210 |
211 void MockWebRTCPeerConnectionHandler::setLocalDescription( | 211 void MockWebRTCPeerConnectionHandler::setLocalDescription( |
212 const WebRTCVoidRequest& request, | 212 const WebRTCVoidRequest& request, |
213 const WebRTCSessionDescription& local_description) { | 213 const WebRTCSessionDescription& local_description) { |
214 if (!local_description.isNull() && local_description.sdp() == "local") { | 214 if (!local_description.isNull() && local_description.sdp() == "local") { |
215 local_description_ = local_description; | 215 local_description_ = local_description; |
216 interfaces_->GetDelegate()->postTask( | 216 interfaces_->GetDelegate()->PostTask( |
217 new RTCVoidRequestTask(this, request, true)); | 217 new RTCVoidRequestTask(this, request, true)); |
218 } else | 218 } else |
219 interfaces_->GetDelegate()->postTask( | 219 interfaces_->GetDelegate()->PostTask( |
220 new RTCVoidRequestTask(this, request, false)); | 220 new RTCVoidRequestTask(this, request, false)); |
221 } | 221 } |
222 | 222 |
223 void MockWebRTCPeerConnectionHandler::setRemoteDescription( | 223 void MockWebRTCPeerConnectionHandler::setRemoteDescription( |
224 const WebRTCVoidRequest& request, | 224 const WebRTCVoidRequest& request, |
225 const WebRTCSessionDescription& remote_description) { | 225 const WebRTCSessionDescription& remote_description) { |
226 if (!remote_description.isNull() && remote_description.sdp() == "remote") { | 226 if (!remote_description.isNull() && remote_description.sdp() == "remote") { |
227 remote_description_ = remote_description; | 227 remote_description_ = remote_description; |
228 interfaces_->GetDelegate()->postTask( | 228 interfaces_->GetDelegate()->PostTask( |
229 new RTCVoidRequestTask(this, request, true)); | 229 new RTCVoidRequestTask(this, request, true)); |
230 } else | 230 } else |
231 interfaces_->GetDelegate()->postTask( | 231 interfaces_->GetDelegate()->PostTask( |
232 new RTCVoidRequestTask(this, request, false)); | 232 new RTCVoidRequestTask(this, request, false)); |
233 } | 233 } |
234 | 234 |
235 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::localDescription() { | 235 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::localDescription() { |
236 return local_description_; | 236 return local_description_; |
237 } | 237 } |
238 | 238 |
239 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::remoteDescription() { | 239 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::remoteDescription() { |
240 return remote_description_; | 240 return remote_description_; |
241 } | 241 } |
242 | 242 |
243 bool MockWebRTCPeerConnectionHandler::updateICE( | 243 bool MockWebRTCPeerConnectionHandler::updateICE( |
244 const WebRTCConfiguration& configuration, | 244 const WebRTCConfiguration& configuration, |
245 const WebMediaConstraints& constraints) { | 245 const WebMediaConstraints& constraints) { |
246 return true; | 246 return true; |
247 } | 247 } |
248 | 248 |
249 bool MockWebRTCPeerConnectionHandler::addICECandidate( | 249 bool MockWebRTCPeerConnectionHandler::addICECandidate( |
250 const WebRTCICECandidate& ice_candidate) { | 250 const WebRTCICECandidate& ice_candidate) { |
251 client_->didGenerateICECandidate(ice_candidate); | 251 client_->didGenerateICECandidate(ice_candidate); |
252 return true; | 252 return true; |
253 } | 253 } |
254 | 254 |
255 bool MockWebRTCPeerConnectionHandler::addICECandidate( | 255 bool MockWebRTCPeerConnectionHandler::addICECandidate( |
256 const WebRTCVoidRequest& request, | 256 const WebRTCVoidRequest& request, |
257 const WebRTCICECandidate& ice_candidate) { | 257 const WebRTCICECandidate& ice_candidate) { |
258 interfaces_->GetDelegate()->postTask( | 258 interfaces_->GetDelegate()->PostTask( |
259 new RTCVoidRequestTask(this, request, true)); | 259 new RTCVoidRequestTask(this, request, true)); |
260 return true; | 260 return true; |
261 } | 261 } |
262 | 262 |
263 bool MockWebRTCPeerConnectionHandler::addStream( | 263 bool MockWebRTCPeerConnectionHandler::addStream( |
264 const WebMediaStream& stream, | 264 const WebMediaStream& stream, |
265 const WebMediaConstraints& constraints) { | 265 const WebMediaConstraints& constraints) { |
266 ++stream_count_; | 266 ++stream_count_; |
267 client_->negotiationNeeded(); | 267 client_->negotiationNeeded(); |
268 return true; | 268 return true; |
269 } | 269 } |
270 | 270 |
271 void MockWebRTCPeerConnectionHandler::removeStream( | 271 void MockWebRTCPeerConnectionHandler::removeStream( |
272 const WebMediaStream& stream) { | 272 const WebMediaStream& stream) { |
273 --stream_count_; | 273 --stream_count_; |
274 client_->negotiationNeeded(); | 274 client_->negotiationNeeded(); |
275 } | 275 } |
276 | 276 |
277 void MockWebRTCPeerConnectionHandler::getStats( | 277 void MockWebRTCPeerConnectionHandler::getStats( |
278 const WebRTCStatsRequest& request) { | 278 const WebRTCStatsRequest& request) { |
279 WebRTCStatsResponse response = request.createResponse(); | 279 WebRTCStatsResponse response = request.createResponse(); |
280 double current_date = | 280 double current_date = |
281 interfaces_->GetDelegate()->getCurrentTimeInMillisecond(); | 281 interfaces_->GetDelegate()->GetCurrentTimeInMillisecond(); |
282 if (request.hasSelector()) { | 282 if (request.hasSelector()) { |
283 // FIXME: There is no check that the fetched values are valid. | 283 // FIXME: There is no check that the fetched values are valid. |
284 size_t report_index = | 284 size_t report_index = |
285 response.addReport("Mock video", "ssrc", current_date); | 285 response.addReport("Mock video", "ssrc", current_date); |
286 response.addStatistic(report_index, "type", "video"); | 286 response.addStatistic(report_index, "type", "video"); |
287 } else { | 287 } else { |
288 for (int i = 0; i < stream_count_; ++i) { | 288 for (int i = 0; i < stream_count_; ++i) { |
289 size_t report_index = | 289 size_t report_index = |
290 response.addReport("Mock audio", "ssrc", current_date); | 290 response.addReport("Mock audio", "ssrc", current_date); |
291 response.addStatistic(report_index, "type", "audio"); | 291 response.addStatistic(report_index, "type", "audio"); |
292 report_index = response.addReport("Mock video", "ssrc", current_date); | 292 report_index = response.addReport("Mock video", "ssrc", current_date); |
293 response.addStatistic(report_index, "type", "video"); | 293 response.addStatistic(report_index, "type", "video"); |
294 } | 294 } |
295 } | 295 } |
296 interfaces_->GetDelegate()->postTask( | 296 interfaces_->GetDelegate()->PostTask( |
297 new RTCStatsRequestSucceededTask(this, request, response)); | 297 new RTCStatsRequestSucceededTask(this, request, response)); |
298 } | 298 } |
299 | 299 |
300 WebRTCDataChannelHandler* MockWebRTCPeerConnectionHandler::createDataChannel( | 300 WebRTCDataChannelHandler* MockWebRTCPeerConnectionHandler::createDataChannel( |
301 const WebString& label, | 301 const WebString& label, |
302 const blink::WebRTCDataChannelInit& init) { | 302 const blink::WebRTCDataChannelInit& init) { |
303 interfaces_->GetDelegate()->postTask( | 303 interfaces_->GetDelegate()->PostTask( |
304 new RemoteDataChannelTask(this, client_, interfaces_->GetDelegate())); | 304 new RemoteDataChannelTask(this, client_, interfaces_->GetDelegate())); |
305 | 305 |
306 return new MockWebRTCDataChannelHandler( | 306 return new MockWebRTCDataChannelHandler( |
307 label, init, interfaces_->GetDelegate()); | 307 label, init, interfaces_->GetDelegate()); |
308 } | 308 } |
309 | 309 |
310 WebRTCDTMFSenderHandler* MockWebRTCPeerConnectionHandler::createDTMFSender( | 310 WebRTCDTMFSenderHandler* MockWebRTCPeerConnectionHandler::createDTMFSender( |
311 const WebMediaStreamTrack& track) { | 311 const WebMediaStreamTrack& track) { |
312 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); | 312 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); |
313 } | 313 } |
314 | 314 |
315 void MockWebRTCPeerConnectionHandler::stop() { | 315 void MockWebRTCPeerConnectionHandler::stop() { |
316 stopped_ = true; | 316 stopped_ = true; |
317 task_list_.RevokeAll(); | 317 task_list_.RevokeAll(); |
318 } | 318 } |
319 | 319 |
320 } // namespace content | 320 } // namespace content |
OLD | NEW |