| 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/TestInterfaces.h" | |
| 8 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | 7 #include "content/shell/renderer/test_runner/WebTestDelegate.h" |
| 9 #include "content/shell/renderer/test_runner/mock_constraints.h" | 8 #include "content/shell/renderer/test_runner/mock_constraints.h" |
| 10 #include "content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h" | 9 #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" | 10 #include "content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.h" |
| 11 #include "content/shell/renderer/test_runner/test_interfaces.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_->delegate()->postTask(new RTCPeerConnectionStateTask( | 163 interfaces_->Delegate()->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_->delegate()->postTask( | 182 interfaces_->Delegate()->postTask( |
| 183 new RTCSessionDescriptionRequestSuccededTask( | 183 new RTCSessionDescriptionRequestSuccededTask( |
| 184 this, request, session_description)); | 184 this, request, session_description)); |
| 185 } else | 185 } else |
| 186 interfaces_->delegate()->postTask( | 186 interfaces_->Delegate()->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_->delegate()->postTask( | 193 interfaces_->Delegate()->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_->delegate()->postTask( | 203 interfaces_->Delegate()->postTask( |
| 204 new RTCSessionDescriptionRequestSuccededTask( | 204 new RTCSessionDescriptionRequestSuccededTask( |
| 205 this, request, session_description)); | 205 this, request, session_description)); |
| 206 } else | 206 } else |
| 207 interfaces_->delegate()->postTask( | 207 interfaces_->Delegate()->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_->delegate()->postTask( | 216 interfaces_->Delegate()->postTask( |
| 217 new RTCVoidRequestTask(this, request, true)); | 217 new RTCVoidRequestTask(this, request, true)); |
| 218 } else | 218 } else |
| 219 interfaces_->delegate()->postTask( | 219 interfaces_->Delegate()->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_->delegate()->postTask( | 228 interfaces_->Delegate()->postTask( |
| 229 new RTCVoidRequestTask(this, request, true)); | 229 new RTCVoidRequestTask(this, request, true)); |
| 230 } else | 230 } else |
| 231 interfaces_->delegate()->postTask( | 231 interfaces_->Delegate()->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_->delegate()->postTask( | 258 interfaces_->Delegate()->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 = interfaces_->delegate()->getCurrentTimeInMillisecond(); | 280 double current_date = interfaces_->Delegate()->getCurrentTimeInMillisecond(); |
| 281 if (request.hasSelector()) { | 281 if (request.hasSelector()) { |
| 282 // FIXME: There is no check that the fetched values are valid. | 282 // FIXME: There is no check that the fetched values are valid. |
| 283 size_t report_index = | 283 size_t report_index = |
| 284 response.addReport("Mock video", "ssrc", current_date); | 284 response.addReport("Mock video", "ssrc", current_date); |
| 285 response.addStatistic(report_index, "type", "video"); | 285 response.addStatistic(report_index, "type", "video"); |
| 286 } else { | 286 } else { |
| 287 for (int i = 0; i < stream_count_; ++i) { | 287 for (int i = 0; i < stream_count_; ++i) { |
| 288 size_t report_index = | 288 size_t report_index = |
| 289 response.addReport("Mock audio", "ssrc", current_date); | 289 response.addReport("Mock audio", "ssrc", current_date); |
| 290 response.addStatistic(report_index, "type", "audio"); | 290 response.addStatistic(report_index, "type", "audio"); |
| 291 report_index = response.addReport("Mock video", "ssrc", current_date); | 291 report_index = response.addReport("Mock video", "ssrc", current_date); |
| 292 response.addStatistic(report_index, "type", "video"); | 292 response.addStatistic(report_index, "type", "video"); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 interfaces_->delegate()->postTask( | 295 interfaces_->Delegate()->postTask( |
| 296 new RTCStatsRequestSucceededTask(this, request, response)); | 296 new RTCStatsRequestSucceededTask(this, request, response)); |
| 297 } | 297 } |
| 298 | 298 |
| 299 WebRTCDataChannelHandler* MockWebRTCPeerConnectionHandler::createDataChannel( | 299 WebRTCDataChannelHandler* MockWebRTCPeerConnectionHandler::createDataChannel( |
| 300 const WebString& label, | 300 const WebString& label, |
| 301 const blink::WebRTCDataChannelInit& init) { | 301 const blink::WebRTCDataChannelInit& init) { |
| 302 interfaces_->delegate()->postTask( | 302 interfaces_->Delegate()->postTask( |
| 303 new RemoteDataChannelTask(this, client_, interfaces_->delegate())); | 303 new RemoteDataChannelTask(this, client_, interfaces_->Delegate())); |
| 304 | 304 |
| 305 return new MockWebRTCDataChannelHandler(label, init, interfaces_->delegate()); | 305 return new MockWebRTCDataChannelHandler(label, init, interfaces_->Delegate()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 WebRTCDTMFSenderHandler* MockWebRTCPeerConnectionHandler::createDTMFSender( | 308 WebRTCDTMFSenderHandler* MockWebRTCPeerConnectionHandler::createDTMFSender( |
| 309 const WebMediaStreamTrack& track) { | 309 const WebMediaStreamTrack& track) { |
| 310 return new MockWebRTCDTMFSenderHandler(track, interfaces_->delegate()); | 310 return new MockWebRTCDTMFSenderHandler(track, interfaces_->Delegate()); |
| 311 } | 311 } |
| 312 | 312 |
| 313 void MockWebRTCPeerConnectionHandler::stop() { | 313 void MockWebRTCPeerConnectionHandler::stop() { |
| 314 stopped_ = true; | 314 stopped_ = true; |
| 315 task_list_.revokeAll(); | 315 task_list_.revokeAll(); |
| 316 } | 316 } |
| 317 | 317 |
| 318 } // namespace content | 318 } // namespace content |
| OLD | NEW |