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