| 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/mock_constraints.h" | 7 #include "content/shell/renderer/test_runner/mock_constraints.h" |
| 8 #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" |
| 9 #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" |
| 10 #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" | 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/WebMediaStreamSource.h" |
| 14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 15 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | 16 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
| 16 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" | 17 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" |
| 17 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" | 18 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" |
| 18 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" | 19 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" |
| 19 #include "third_party/WebKit/public/platform/WebString.h" | 20 #include "third_party/WebKit/public/platform/WebString.h" |
| 20 #include "third_party/WebKit/public/platform/WebVector.h" | 21 #include "third_party/WebKit/public/platform/WebVector.h" |
| 21 | 22 |
| 22 using namespace blink; | 23 using namespace blink; |
| 23 | 24 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 private: | 141 private: |
| 141 WebRTCPeerConnectionHandlerClient* client_; | 142 WebRTCPeerConnectionHandlerClient* client_; |
| 142 WebTestDelegate* delegate_; | 143 WebTestDelegate* delegate_; |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 ///////////////////// | 146 ///////////////////// |
| 146 | 147 |
| 147 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() { | 148 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() { |
| 148 } | 149 } |
| 149 | 150 |
| 151 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() { |
| 152 } |
| 153 |
| 150 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( | 154 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( |
| 151 WebRTCPeerConnectionHandlerClient* client, | 155 WebRTCPeerConnectionHandlerClient* client, |
| 152 TestInterfaces* interfaces) | 156 TestInterfaces* interfaces) |
| 153 : client_(client), | 157 : client_(client), |
| 154 stopped_(false), | 158 stopped_(false), |
| 155 stream_count_(0), | 159 stream_count_(0), |
| 156 interfaces_(interfaces) { | 160 interfaces_(interfaces) { |
| 157 } | 161 } |
| 158 | 162 |
| 159 bool MockWebRTCPeerConnectionHandler::initialize( | 163 bool MockWebRTCPeerConnectionHandler::initialize( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 interfaces_->GetDelegate()->PostTask( | 220 interfaces_->GetDelegate()->PostTask( |
| 217 new RTCVoidRequestTask(this, request, true)); | 221 new RTCVoidRequestTask(this, request, true)); |
| 218 } else | 222 } else |
| 219 interfaces_->GetDelegate()->PostTask( | 223 interfaces_->GetDelegate()->PostTask( |
| 220 new RTCVoidRequestTask(this, request, false)); | 224 new RTCVoidRequestTask(this, request, false)); |
| 221 } | 225 } |
| 222 | 226 |
| 223 void MockWebRTCPeerConnectionHandler::setRemoteDescription( | 227 void MockWebRTCPeerConnectionHandler::setRemoteDescription( |
| 224 const WebRTCVoidRequest& request, | 228 const WebRTCVoidRequest& request, |
| 225 const WebRTCSessionDescription& remote_description) { | 229 const WebRTCSessionDescription& remote_description) { |
| 230 |
| 226 if (!remote_description.isNull() && remote_description.sdp() == "remote") { | 231 if (!remote_description.isNull() && remote_description.sdp() == "remote") { |
| 232 UpdateRemoteStreams(); |
| 227 remote_description_ = remote_description; | 233 remote_description_ = remote_description; |
| 228 interfaces_->GetDelegate()->PostTask( | 234 interfaces_->GetDelegate()->PostTask( |
| 229 new RTCVoidRequestTask(this, request, true)); | 235 new RTCVoidRequestTask(this, request, true)); |
| 230 } else | 236 } else |
| 231 interfaces_->GetDelegate()->PostTask( | 237 interfaces_->GetDelegate()->PostTask( |
| 232 new RTCVoidRequestTask(this, request, false)); | 238 new RTCVoidRequestTask(this, request, false)); |
| 233 } | 239 } |
| 234 | 240 |
| 241 void MockWebRTCPeerConnectionHandler::UpdateRemoteStreams() { |
| 242 // Find all removed streams. |
| 243 // Set the readyState of the remote tracks to ended, remove them from the |
| 244 // stream and notify the client. |
| 245 StreamMap::iterator removed_it = remote_streams_.begin(); |
| 246 while (removed_it != remote_streams_.end()) { |
| 247 if (local_streams_.find(removed_it->first) != local_streams_.end()) { |
| 248 removed_it++; |
| 249 continue; |
| 250 } |
| 251 |
| 252 // The stream have been removed. Loop through all tracks and set the |
| 253 // source as ended and remove them from the stream. |
| 254 blink::WebMediaStream stream = removed_it->second; |
| 255 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; |
| 256 stream.audioTracks(audio_tracks); |
| 257 for (size_t i = 0; i < audio_tracks.size(); ++i) { |
| 258 audio_tracks[i].source().setReadyState( |
| 259 blink::WebMediaStreamSource::ReadyStateEnded); |
| 260 stream.removeTrack(audio_tracks[i]); |
| 261 } |
| 262 |
| 263 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 264 stream.videoTracks(video_tracks); |
| 265 for (size_t i = 0; i < video_tracks.size(); ++i) { |
| 266 video_tracks[i].source().setReadyState( |
| 267 blink::WebMediaStreamSource::ReadyStateEnded); |
| 268 stream.removeTrack(video_tracks[i]); |
| 269 } |
| 270 client_->didRemoveRemoteStream(stream); |
| 271 remote_streams_.erase(removed_it++); |
| 272 } |
| 273 |
| 274 // Find all new streams; |
| 275 // Create new sources and tracks and notify the client about the new stream. |
| 276 StreamMap::iterator added_it = local_streams_.begin(); |
| 277 while (added_it != local_streams_.end()) { |
| 278 if (remote_streams_.find(added_it->first) != remote_streams_.end()) { |
| 279 added_it++; |
| 280 continue; |
| 281 } |
| 282 |
| 283 const blink::WebMediaStream& stream = added_it->second; |
| 284 |
| 285 blink::WebVector<blink::WebMediaStreamTrack> local_audio_tracks; |
| 286 stream.audioTracks(local_audio_tracks); |
| 287 blink::WebVector<blink::WebMediaStreamTrack> |
| 288 remote_audio_tracks(local_audio_tracks.size()); |
| 289 |
| 290 for (size_t i = 0; i < local_audio_tracks.size(); ++i) { |
| 291 blink::WebMediaStreamSource webkit_source; |
| 292 webkit_source.initialize(local_audio_tracks[i].id(), |
| 293 blink::WebMediaStreamSource::TypeAudio, |
| 294 local_audio_tracks[i].id()); |
| 295 remote_audio_tracks[i].initialize(webkit_source); |
| 296 } |
| 297 |
| 298 blink::WebVector<blink::WebMediaStreamTrack> local_video_tracks; |
| 299 stream.videoTracks(local_video_tracks); |
| 300 blink::WebVector<blink::WebMediaStreamTrack> |
| 301 remote_video_tracks(local_video_tracks.size()); |
| 302 for (size_t i = 0; i < local_video_tracks.size(); ++i) { |
| 303 blink::WebMediaStreamSource webkit_source; |
| 304 webkit_source.initialize(local_video_tracks[i].id(), |
| 305 blink::WebMediaStreamSource::TypeVideo, |
| 306 local_video_tracks[i].id()); |
| 307 remote_video_tracks[i].initialize(webkit_source); |
| 308 } |
| 309 |
| 310 blink::WebMediaStream new_remote_stream; |
| 311 new_remote_stream.initialize(remote_audio_tracks, |
| 312 remote_video_tracks); |
| 313 remote_streams_[added_it->first] = new_remote_stream; |
| 314 client_->didAddRemoteStream(new_remote_stream); |
| 315 ++added_it; |
| 316 } |
| 317 } |
| 318 |
| 235 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::localDescription() { | 319 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::localDescription() { |
| 236 return local_description_; | 320 return local_description_; |
| 237 } | 321 } |
| 238 | 322 |
| 239 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::remoteDescription() { | 323 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::remoteDescription() { |
| 240 return remote_description_; | 324 return remote_description_; |
| 241 } | 325 } |
| 242 | 326 |
| 243 bool MockWebRTCPeerConnectionHandler::updateICE( | 327 bool MockWebRTCPeerConnectionHandler::updateICE( |
| 244 const WebRTCConfiguration& configuration, | 328 const WebRTCConfiguration& configuration, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 256 const WebRTCVoidRequest& request, | 340 const WebRTCVoidRequest& request, |
| 257 const WebRTCICECandidate& ice_candidate) { | 341 const WebRTCICECandidate& ice_candidate) { |
| 258 interfaces_->GetDelegate()->PostTask( | 342 interfaces_->GetDelegate()->PostTask( |
| 259 new RTCVoidRequestTask(this, request, true)); | 343 new RTCVoidRequestTask(this, request, true)); |
| 260 return true; | 344 return true; |
| 261 } | 345 } |
| 262 | 346 |
| 263 bool MockWebRTCPeerConnectionHandler::addStream( | 347 bool MockWebRTCPeerConnectionHandler::addStream( |
| 264 const WebMediaStream& stream, | 348 const WebMediaStream& stream, |
| 265 const WebMediaConstraints& constraints) { | 349 const WebMediaConstraints& constraints) { |
| 350 if (local_streams_.find(stream.id().utf8()) != local_streams_.end()) |
| 351 return false; |
| 266 ++stream_count_; | 352 ++stream_count_; |
| 267 client_->negotiationNeeded(); | 353 client_->negotiationNeeded(); |
| 354 local_streams_[stream.id().utf8()] = stream; |
| 268 return true; | 355 return true; |
| 269 } | 356 } |
| 270 | 357 |
| 271 void MockWebRTCPeerConnectionHandler::removeStream( | 358 void MockWebRTCPeerConnectionHandler::removeStream( |
| 272 const WebMediaStream& stream) { | 359 const WebMediaStream& stream) { |
| 273 --stream_count_; | 360 --stream_count_; |
| 361 local_streams_.erase(stream.id().utf8()); |
| 274 client_->negotiationNeeded(); | 362 client_->negotiationNeeded(); |
| 275 } | 363 } |
| 276 | 364 |
| 277 void MockWebRTCPeerConnectionHandler::getStats( | 365 void MockWebRTCPeerConnectionHandler::getStats( |
| 278 const WebRTCStatsRequest& request) { | 366 const WebRTCStatsRequest& request) { |
| 279 WebRTCStatsResponse response = request.createResponse(); | 367 WebRTCStatsResponse response = request.createResponse(); |
| 280 double current_date = | 368 double current_date = |
| 281 interfaces_->GetDelegate()->GetCurrentTimeInMillisecond(); | 369 interfaces_->GetDelegate()->GetCurrentTimeInMillisecond(); |
| 282 if (request.hasSelector()) { | 370 if (request.hasSelector()) { |
| 283 // FIXME: There is no check that the fetched values are valid. | 371 // FIXME: There is no check that the fetched values are valid. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 311 const WebMediaStreamTrack& track) { | 399 const WebMediaStreamTrack& track) { |
| 312 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); | 400 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); |
| 313 } | 401 } |
| 314 | 402 |
| 315 void MockWebRTCPeerConnectionHandler::stop() { | 403 void MockWebRTCPeerConnectionHandler::stop() { |
| 316 stopped_ = true; | 404 stopped_ = true; |
| 317 task_list_.RevokeAll(); | 405 task_list_.RevokeAll(); |
| 318 } | 406 } |
| 319 | 407 |
| 320 } // namespace content | 408 } // namespace content |
| OLD | NEW |