| 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 "components/test_runner/mock_webrtc_peer_connection_handler.h" | 5 #include "components/test_runner/mock_webrtc_peer_connection_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "components/test_runner/mock_webrtc_data_channel_handler.h" | 15 #include "components/test_runner/mock_webrtc_data_channel_handler.h" |
| 16 #include "components/test_runner/mock_webrtc_dtmf_sender_handler.h" | 16 #include "components/test_runner/mock_webrtc_dtmf_sender_handler.h" |
| 17 #include "components/test_runner/test_interfaces.h" | 17 #include "components/test_runner/test_interfaces.h" |
| 18 #include "components/test_runner/web_task.h" | |
| 19 #include "components/test_runner/web_test_delegate.h" | 18 #include "components/test_runner/web_test_delegate.h" |
| 20 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 19 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 21 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 22 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 21 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 23 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" | 22 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" |
| 24 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | 23 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
| 25 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" | 24 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" |
| 26 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" | 25 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" |
| 27 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" | 26 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" |
| 28 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" | 27 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 void MockWebRTCPeerConnectionHandler::ReportInitializeCompleted() { | 128 void MockWebRTCPeerConnectionHandler::ReportInitializeCompleted() { |
| 130 client_->didChangeICEGatheringState( | 129 client_->didChangeICEGatheringState( |
| 131 WebRTCPeerConnectionHandlerClient::ICEGatheringStateComplete); | 130 WebRTCPeerConnectionHandlerClient::ICEGatheringStateComplete); |
| 132 client_->didChangeICEConnectionState( | 131 client_->didChangeICEConnectionState( |
| 133 WebRTCPeerConnectionHandlerClient::ICEConnectionStateCompleted); | 132 WebRTCPeerConnectionHandlerClient::ICEConnectionStateCompleted); |
| 134 } | 133 } |
| 135 | 134 |
| 136 bool MockWebRTCPeerConnectionHandler::initialize( | 135 bool MockWebRTCPeerConnectionHandler::initialize( |
| 137 const WebRTCConfiguration& configuration, | 136 const WebRTCConfiguration& configuration, |
| 138 const WebMediaConstraints& constraints) { | 137 const WebMediaConstraints& constraints) { |
| 139 interfaces_->GetDelegate()->PostTask(new WebCallbackTask( | 138 interfaces_->GetDelegate()->PostTask( |
| 140 base::Bind(&MockWebRTCPeerConnectionHandler::ReportInitializeCompleted, | 139 base::Bind(&MockWebRTCPeerConnectionHandler::ReportInitializeCompleted, |
| 141 weak_factory_.GetWeakPtr()))); | 140 weak_factory_.GetWeakPtr())); |
| 142 return true; | 141 return true; |
| 143 } | 142 } |
| 144 | 143 |
| 145 void MockWebRTCPeerConnectionHandler::createOffer( | 144 void MockWebRTCPeerConnectionHandler::createOffer( |
| 146 const WebRTCSessionDescriptionRequest& request, | 145 const WebRTCSessionDescriptionRequest& request, |
| 147 const WebMediaConstraints& constraints) { | 146 const WebMediaConstraints& constraints) { |
| 148 PostRequestFailure(request); | 147 PostRequestFailure(request); |
| 149 } | 148 } |
| 150 | 149 |
| 151 void MockWebRTCPeerConnectionHandler::PostRequestResult( | 150 void MockWebRTCPeerConnectionHandler::PostRequestResult( |
| 152 const WebRTCSessionDescriptionRequest& request, | 151 const WebRTCSessionDescriptionRequest& request, |
| 153 const WebRTCSessionDescription& session_description) { | 152 const WebRTCSessionDescription& session_description) { |
| 154 interfaces_->GetDelegate()->PostTask(new WebCallbackTask( | 153 interfaces_->GetDelegate()->PostTask( |
| 155 base::Bind(&WebRTCSessionDescriptionRequest::requestSucceeded, | 154 base::Bind(&WebRTCSessionDescriptionRequest::requestSucceeded, |
| 156 base::Owned(new WebRTCSessionDescriptionRequest(request)), | 155 base::Owned(new WebRTCSessionDescriptionRequest(request)), |
| 157 session_description))); | 156 session_description)); |
| 158 } | 157 } |
| 159 | 158 |
| 160 void MockWebRTCPeerConnectionHandler::PostRequestFailure( | 159 void MockWebRTCPeerConnectionHandler::PostRequestFailure( |
| 161 const WebRTCSessionDescriptionRequest& request) { | 160 const WebRTCSessionDescriptionRequest& request) { |
| 162 interfaces_->GetDelegate()->PostTask(new WebCallbackTask( | 161 interfaces_->GetDelegate()->PostTask( |
| 163 base::Bind(&WebRTCSessionDescriptionRequest::requestFailed, | 162 base::Bind(&WebRTCSessionDescriptionRequest::requestFailed, |
| 164 base::Owned(new WebRTCSessionDescriptionRequest(request)), | 163 base::Owned(new WebRTCSessionDescriptionRequest(request)), |
| 165 WebString("TEST_ERROR")))); | 164 WebString("TEST_ERROR"))); |
| 166 } | 165 } |
| 167 | 166 |
| 168 void MockWebRTCPeerConnectionHandler::PostRequestResult( | 167 void MockWebRTCPeerConnectionHandler::PostRequestResult( |
| 169 const WebRTCVoidRequest& request) { | 168 const WebRTCVoidRequest& request) { |
| 170 interfaces_->GetDelegate()->PostTask(new WebCallbackTask( | 169 interfaces_->GetDelegate()->PostTask( |
| 171 base::Bind(&WebRTCVoidRequest::requestSucceeded, | 170 base::Bind(&WebRTCVoidRequest::requestSucceeded, |
| 172 base::Owned(new WebRTCVoidRequest(request))))); | 171 base::Owned(new WebRTCVoidRequest(request)))); |
| 173 } | 172 } |
| 174 | 173 |
| 175 void MockWebRTCPeerConnectionHandler::PostRequestFailure( | 174 void MockWebRTCPeerConnectionHandler::PostRequestFailure( |
| 176 const WebRTCVoidRequest& request) { | 175 const WebRTCVoidRequest& request) { |
| 177 interfaces_->GetDelegate()->PostTask(new WebCallbackTask(base::Bind( | 176 interfaces_->GetDelegate()->PostTask(base::Bind( |
| 178 &WebRTCVoidRequest::requestFailed, | 177 &WebRTCVoidRequest::requestFailed, |
| 179 base::Owned(new WebRTCVoidRequest(request)), WebString("TEST_ERROR")))); | 178 base::Owned(new WebRTCVoidRequest(request)), WebString("TEST_ERROR"))); |
| 180 } | 179 } |
| 181 | 180 |
| 182 void MockWebRTCPeerConnectionHandler::createOffer( | 181 void MockWebRTCPeerConnectionHandler::createOffer( |
| 183 const WebRTCSessionDescriptionRequest& request, | 182 const WebRTCSessionDescriptionRequest& request, |
| 184 const blink::WebRTCOfferOptions& options) { | 183 const blink::WebRTCOfferOptions& options) { |
| 185 if (options.iceRestart() && options.voiceActivityDetection() && | 184 if (options.iceRestart() && options.voiceActivityDetection() && |
| 186 options.offerToReceiveAudio() > 0 && options.offerToReceiveVideo() > 0) { | 185 options.offerToReceiveAudio() > 0 && options.offerToReceiveVideo() > 0) { |
| 187 WebRTCSessionDescription session_description; | 186 WebRTCSessionDescription session_description; |
| 188 session_description.initialize("offer", "local"); | 187 session_description.initialize("offer", "local"); |
| 189 PostRequestResult(request, session_description); | 188 PostRequestResult(request, session_description); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 for (int i = 0; i < stream_count_; ++i) { | 379 for (int i = 0; i < stream_count_; ++i) { |
| 381 MockWebRTCLegacyStats audio_stats("Mock audio", "ssrc", current_date); | 380 MockWebRTCLegacyStats audio_stats("Mock audio", "ssrc", current_date); |
| 382 audio_stats.addStatistic("type", "audio"); | 381 audio_stats.addStatistic("type", "audio"); |
| 383 response.addStats(audio_stats); | 382 response.addStats(audio_stats); |
| 384 | 383 |
| 385 MockWebRTCLegacyStats video_stats("Mock video", "ssrc", current_date); | 384 MockWebRTCLegacyStats video_stats("Mock video", "ssrc", current_date); |
| 386 video_stats.addStatistic("type", "video"); | 385 video_stats.addStatistic("type", "video"); |
| 387 response.addStats(video_stats); | 386 response.addStats(video_stats); |
| 388 } | 387 } |
| 389 } | 388 } |
| 390 interfaces_->GetDelegate()->PostTask(new WebCallbackTask( | 389 interfaces_->GetDelegate()->PostTask( |
| 391 base::Bind(&blink::WebRTCStatsRequest::requestSucceeded, | 390 base::Bind(&blink::WebRTCStatsRequest::requestSucceeded, |
| 392 base::Owned(new WebRTCStatsRequest(request)), response))); | 391 base::Owned(new WebRTCStatsRequest(request)), response)); |
| 393 } | 392 } |
| 394 | 393 |
| 395 void MockWebRTCPeerConnectionHandler::ReportCreationOfDataChannel() { | 394 void MockWebRTCPeerConnectionHandler::ReportCreationOfDataChannel() { |
| 396 WebRTCDataChannelInit init; | 395 WebRTCDataChannelInit init; |
| 397 WebRTCDataChannelHandler* remote_data_channel = | 396 WebRTCDataChannelHandler* remote_data_channel = |
| 398 new MockWebRTCDataChannelHandler("MockRemoteDataChannel", init, | 397 new MockWebRTCDataChannelHandler("MockRemoteDataChannel", init, |
| 399 interfaces_->GetDelegate()); | 398 interfaces_->GetDelegate()); |
| 400 client_->didAddRemoteDataChannel(remote_data_channel); | 399 client_->didAddRemoteDataChannel(remote_data_channel); |
| 401 } | 400 } |
| 402 | 401 |
| 403 WebRTCDataChannelHandler* MockWebRTCPeerConnectionHandler::createDataChannel( | 402 WebRTCDataChannelHandler* MockWebRTCPeerConnectionHandler::createDataChannel( |
| 404 const WebString& label, | 403 const WebString& label, |
| 405 const blink::WebRTCDataChannelInit& init) { | 404 const blink::WebRTCDataChannelInit& init) { |
| 406 interfaces_->GetDelegate()->PostTask(new WebCallbackTask( | 405 interfaces_->GetDelegate()->PostTask( |
| 407 base::Bind(&MockWebRTCPeerConnectionHandler::ReportCreationOfDataChannel, | 406 base::Bind(&MockWebRTCPeerConnectionHandler::ReportCreationOfDataChannel, |
| 408 weak_factory_.GetWeakPtr()))); | 407 weak_factory_.GetWeakPtr())); |
| 409 | 408 |
| 410 // TODO(lukasza): Unclear if it is okay to return a different object than the | 409 // TODO(lukasza): Unclear if it is okay to return a different object than the |
| 411 // one created in ReportCreationOfDataChannel. | 410 // one created in ReportCreationOfDataChannel. |
| 412 return new MockWebRTCDataChannelHandler( | 411 return new MockWebRTCDataChannelHandler( |
| 413 label, init, interfaces_->GetDelegate()); | 412 label, init, interfaces_->GetDelegate()); |
| 414 } | 413 } |
| 415 | 414 |
| 416 WebRTCDTMFSenderHandler* MockWebRTCPeerConnectionHandler::createDTMFSender( | 415 WebRTCDTMFSenderHandler* MockWebRTCPeerConnectionHandler::createDTMFSender( |
| 417 const WebMediaStreamTrack& track) { | 416 const WebMediaStreamTrack& track) { |
| 418 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); | 417 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); |
| 419 } | 418 } |
| 420 | 419 |
| 421 void MockWebRTCPeerConnectionHandler::stop() { | 420 void MockWebRTCPeerConnectionHandler::stop() { |
| 422 stopped_ = true; | 421 stopped_ = true; |
| 423 weak_factory_.InvalidateWeakPtrs(); | 422 weak_factory_.InvalidateWeakPtrs(); |
| 424 } | 423 } |
| 425 | 424 |
| 426 } // namespace test_runner | 425 } // namespace test_runner |
| OLD | NEW |