| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/test_runner/mock_webrtc_peer_connection_handler.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include <string> | |
| 10 #include <utility> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/bind.h" | |
| 14 #include "base/bind_helpers.h" | |
| 15 #include "components/test_runner/mock_webrtc_data_channel_handler.h" | |
| 16 #include "components/test_runner/mock_webrtc_dtmf_sender_handler.h" | |
| 17 #include "components/test_runner/test_interfaces.h" | |
| 18 #include "components/test_runner/web_test_delegate.h" | |
| 19 #include "third_party/WebKit/public/platform/WebMediaStream.h" | |
| 20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | |
| 21 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
| 22 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" | |
| 23 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | |
| 24 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" | |
| 25 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" | |
| 26 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" | |
| 27 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" | |
| 28 #include "third_party/WebKit/public/platform/WebString.h" | |
| 29 #include "third_party/WebKit/public/platform/WebVector.h" | |
| 30 | |
| 31 using namespace blink; | |
| 32 | |
| 33 namespace test_runner { | |
| 34 | |
| 35 namespace { | |
| 36 | |
| 37 class MockWebRTCLegacyStats : public blink::WebRTCLegacyStats { | |
| 38 public: | |
| 39 class MemberIterator : public blink::WebRTCLegacyStatsMemberIterator { | |
| 40 public: | |
| 41 MemberIterator( | |
| 42 const std::vector<std::pair<std::string, std::string>>* values) | |
| 43 : values_(values) {} | |
| 44 | |
| 45 // blink::WebRTCLegacyStatsMemberIterator | |
| 46 bool isEnd() const override { return i >= values_->size(); } | |
| 47 void next() override { ++i; } | |
| 48 blink::WebString name() const override { | |
| 49 return blink::WebString::fromUTF8((*values_)[i].first); | |
| 50 } | |
| 51 blink::WebRTCLegacyStatsMemberType type() const override { | |
| 52 return blink::WebRTCLegacyStatsMemberTypeString; | |
| 53 } | |
| 54 int valueInt() const override { | |
| 55 NOTREACHED(); | |
| 56 return 0; | |
| 57 } | |
| 58 int64_t valueInt64() const override { | |
| 59 NOTREACHED(); | |
| 60 return 0; | |
| 61 } | |
| 62 float valueFloat() const override { | |
| 63 NOTREACHED(); | |
| 64 return 0.0f; | |
| 65 } | |
| 66 blink::WebString valueString() const override { | |
| 67 return blink::WebString::fromUTF8((*values_)[i].second); | |
| 68 } | |
| 69 bool valueBool() const override { | |
| 70 NOTREACHED(); | |
| 71 return false; | |
| 72 } | |
| 73 blink::WebString valueToString() const override { | |
| 74 return valueString(); | |
| 75 } | |
| 76 | |
| 77 private: | |
| 78 size_t i = 0; | |
| 79 const std::vector<std::pair<std::string, std::string>>* values_; | |
| 80 }; | |
| 81 | |
| 82 MockWebRTCLegacyStats(const char* id, const char* type_name, double timestamp) | |
| 83 : id_(id), type_name_(type_name), timestamp_(timestamp) {} | |
| 84 | |
| 85 // blink::WebRTCLegacyStats | |
| 86 blink::WebString id() const override { | |
| 87 return blink::WebString::fromUTF8(id_); | |
| 88 } | |
| 89 blink::WebString type() const override { | |
| 90 return blink::WebString::fromUTF8(type_name_); | |
| 91 } | |
| 92 double timestamp() const override { | |
| 93 return timestamp_; | |
| 94 } | |
| 95 blink::WebRTCLegacyStatsMemberIterator* iterator() const override { | |
| 96 return new MemberIterator(&values_); | |
| 97 } | |
| 98 | |
| 99 void addStatistic(const std::string& name, const std::string& value) { | |
| 100 values_.push_back(std::make_pair(name, value)); | |
| 101 } | |
| 102 | |
| 103 private: | |
| 104 const std::string id_; | |
| 105 const std::string type_name_; | |
| 106 const double timestamp_; | |
| 107 // (name, value) pairs. | |
| 108 std::vector<std::pair<std::string, std::string>> values_; | |
| 109 }; | |
| 110 | |
| 111 template<typename T> | |
| 112 WebVector<T> sequenceWithValue(T value) { | |
| 113 return WebVector<T>(&value, 1); | |
| 114 } | |
| 115 | |
| 116 class MockWebRTCStatsMember : public blink::WebRTCStatsMember { | |
| 117 public: | |
| 118 MockWebRTCStatsMember( | |
| 119 const std::string& name, blink::WebRTCStatsMemberType type) | |
| 120 : name_(name), type_(type) {} | |
| 121 | |
| 122 // blink::WebRTCStatsMember overrides. | |
| 123 blink::WebString name() const override { | |
| 124 return blink::WebString::fromUTF8(name_); | |
| 125 } | |
| 126 blink::WebRTCStatsMemberType type() const override { | |
| 127 return type_; | |
| 128 } | |
| 129 bool isDefined() const override { return true; } | |
| 130 bool valueBool() const override { return true; } | |
| 131 int32_t valueInt32() const override { return 42; } | |
| 132 uint32_t valueUint32() const override { return 42; } | |
| 133 int64_t valueInt64() const override { return 42; } | |
| 134 uint64_t valueUint64() const override { return 42; } | |
| 135 double valueDouble() const override { return 42.0; } | |
| 136 blink::WebString valueString() const override { | |
| 137 return blink::WebString::fromUTF8("42"); | |
| 138 } | |
| 139 WebVector<int> valueSequenceBool() const override { | |
| 140 return sequenceWithValue<int>(1); | |
| 141 } | |
| 142 WebVector<int32_t> valueSequenceInt32() const override { | |
| 143 return sequenceWithValue<int32_t>(42); | |
| 144 } | |
| 145 WebVector<uint32_t> valueSequenceUint32() const override { | |
| 146 return sequenceWithValue<uint32_t>(42); | |
| 147 } | |
| 148 WebVector<int64_t> valueSequenceInt64() const override { | |
| 149 return sequenceWithValue<int64_t>(42); | |
| 150 } | |
| 151 WebVector<uint64_t> valueSequenceUint64() const override { | |
| 152 return sequenceWithValue<uint64_t>(42); | |
| 153 } | |
| 154 WebVector<double> valueSequenceDouble() const override { | |
| 155 return sequenceWithValue<double>(42.0); | |
| 156 } | |
| 157 blink::WebVector<blink::WebString> valueSequenceString() const override { | |
| 158 return sequenceWithValue<blink::WebString>( | |
| 159 blink::WebString::fromUTF8("42")); | |
| 160 } | |
| 161 | |
| 162 private: | |
| 163 std::string name_; | |
| 164 blink::WebRTCStatsMemberType type_; | |
| 165 }; | |
| 166 | |
| 167 class MockWebRTCStats : public blink::WebRTCStats { | |
| 168 public: | |
| 169 MockWebRTCStats( | |
| 170 const std::string& id, const std::string& type, double timestamp) | |
| 171 : id_(id), type_(type), timestamp_(timestamp) { | |
| 172 } | |
| 173 | |
| 174 void addMember(const std::string& name, blink::WebRTCStatsMemberType type) { | |
| 175 members_.push_back(std::make_pair(name, type)); | |
| 176 } | |
| 177 | |
| 178 // blink::WebRTCStats overrides. | |
| 179 blink::WebString id() const override { | |
| 180 return blink::WebString::fromUTF8(id_); | |
| 181 } | |
| 182 blink::WebString type() const override { | |
| 183 return blink::WebString::fromUTF8(type_); | |
| 184 } | |
| 185 double timestamp() const override { | |
| 186 return timestamp_; | |
| 187 } | |
| 188 size_t membersCount() const override { | |
| 189 return members_.size(); | |
| 190 } | |
| 191 std::unique_ptr<WebRTCStatsMember> getMember(size_t i) const override { | |
| 192 return std::unique_ptr<WebRTCStatsMember>(new MockWebRTCStatsMember( | |
| 193 members_[i].first, members_[i].second)); | |
| 194 } | |
| 195 | |
| 196 private: | |
| 197 std::string id_; | |
| 198 std::string type_; | |
| 199 double timestamp_; | |
| 200 std::vector<std::pair<std::string, blink::WebRTCStatsMemberType>> members_; | |
| 201 }; | |
| 202 | |
| 203 class MockWebRTCStatsReport : public blink::WebRTCStatsReport { | |
| 204 public: | |
| 205 MockWebRTCStatsReport() : i_(0) {} | |
| 206 MockWebRTCStatsReport(const MockWebRTCStatsReport& other) | |
| 207 : stats_(other.stats_), i_(0) {} | |
| 208 | |
| 209 void AddStats(const MockWebRTCStats& stats) { | |
| 210 stats_.push_back(stats); | |
| 211 } | |
| 212 | |
| 213 // blink::WebRTCStatsReport overrides. | |
| 214 std::unique_ptr<blink::WebRTCStatsReport> copyHandle() const override { | |
| 215 // Because this is just a mock, we copy the underlying stats instead of | |
| 216 // referencing the same stats as the original report. | |
| 217 return std::unique_ptr<blink::WebRTCStatsReport>( | |
| 218 new MockWebRTCStatsReport(*this)); | |
| 219 } | |
| 220 std::unique_ptr<WebRTCStats> getStats(WebString id) const override { | |
| 221 for (const MockWebRTCStats& stats : stats_) { | |
| 222 if (stats.id() == id) | |
| 223 return std::unique_ptr<blink::WebRTCStats>(new MockWebRTCStats(stats)); | |
| 224 } | |
| 225 return nullptr; | |
| 226 } | |
| 227 std::unique_ptr<blink::WebRTCStats> next() override { | |
| 228 if (i_ >= stats_.size()) | |
| 229 return nullptr; | |
| 230 return std::unique_ptr<blink::WebRTCStats>( | |
| 231 new MockWebRTCStats(stats_[i_++])); | |
| 232 } | |
| 233 | |
| 234 private: | |
| 235 std::vector<MockWebRTCStats> stats_; | |
| 236 size_t i_; | |
| 237 }; | |
| 238 | |
| 239 } // namespace | |
| 240 | |
| 241 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() | |
| 242 : weak_factory_(this) {} | |
| 243 | |
| 244 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() { | |
| 245 } | |
| 246 | |
| 247 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( | |
| 248 WebRTCPeerConnectionHandlerClient* client, | |
| 249 TestInterfaces* interfaces) | |
| 250 : client_(client), | |
| 251 stopped_(false), | |
| 252 stream_count_(0), | |
| 253 interfaces_(interfaces), | |
| 254 weak_factory_(this) {} | |
| 255 | |
| 256 void MockWebRTCPeerConnectionHandler::ReportInitializeCompleted() { | |
| 257 client_->didChangeICEGatheringState( | |
| 258 WebRTCPeerConnectionHandlerClient::ICEGatheringStateComplete); | |
| 259 client_->didChangeICEConnectionState( | |
| 260 WebRTCPeerConnectionHandlerClient::ICEConnectionStateCompleted); | |
| 261 } | |
| 262 | |
| 263 bool MockWebRTCPeerConnectionHandler::initialize( | |
| 264 const WebRTCConfiguration& configuration, | |
| 265 const WebMediaConstraints& constraints) { | |
| 266 interfaces_->GetDelegate()->PostTask( | |
| 267 base::Bind(&MockWebRTCPeerConnectionHandler::ReportInitializeCompleted, | |
| 268 weak_factory_.GetWeakPtr())); | |
| 269 return true; | |
| 270 } | |
| 271 | |
| 272 void MockWebRTCPeerConnectionHandler::createOffer( | |
| 273 const WebRTCSessionDescriptionRequest& request, | |
| 274 const WebMediaConstraints& constraints) { | |
| 275 PostRequestFailure(request); | |
| 276 } | |
| 277 | |
| 278 void MockWebRTCPeerConnectionHandler::PostRequestResult( | |
| 279 const WebRTCSessionDescriptionRequest& request, | |
| 280 const WebRTCSessionDescription& session_description) { | |
| 281 interfaces_->GetDelegate()->PostTask( | |
| 282 base::Bind(&WebRTCSessionDescriptionRequest::requestSucceeded, | |
| 283 base::Owned(new WebRTCSessionDescriptionRequest(request)), | |
| 284 session_description)); | |
| 285 } | |
| 286 | |
| 287 void MockWebRTCPeerConnectionHandler::PostRequestFailure( | |
| 288 const WebRTCSessionDescriptionRequest& request) { | |
| 289 interfaces_->GetDelegate()->PostTask( | |
| 290 base::Bind(&WebRTCSessionDescriptionRequest::requestFailed, | |
| 291 base::Owned(new WebRTCSessionDescriptionRequest(request)), | |
| 292 WebString("TEST_ERROR"))); | |
| 293 } | |
| 294 | |
| 295 void MockWebRTCPeerConnectionHandler::PostRequestResult( | |
| 296 const WebRTCVoidRequest& request) { | |
| 297 interfaces_->GetDelegate()->PostTask( | |
| 298 base::Bind(&WebRTCVoidRequest::requestSucceeded, | |
| 299 base::Owned(new WebRTCVoidRequest(request)))); | |
| 300 } | |
| 301 | |
| 302 void MockWebRTCPeerConnectionHandler::PostRequestFailure( | |
| 303 const WebRTCVoidRequest& request) { | |
| 304 interfaces_->GetDelegate()->PostTask(base::Bind( | |
| 305 &WebRTCVoidRequest::requestFailed, | |
| 306 base::Owned(new WebRTCVoidRequest(request)), WebString("TEST_ERROR"))); | |
| 307 } | |
| 308 | |
| 309 void MockWebRTCPeerConnectionHandler::createOffer( | |
| 310 const WebRTCSessionDescriptionRequest& request, | |
| 311 const blink::WebRTCOfferOptions& options) { | |
| 312 if (options.iceRestart() && options.voiceActivityDetection() && | |
| 313 options.offerToReceiveAudio() > 0 && options.offerToReceiveVideo() > 0) { | |
| 314 WebRTCSessionDescription session_description; | |
| 315 session_description.initialize("offer", "local"); | |
| 316 PostRequestResult(request, session_description); | |
| 317 } else { | |
| 318 PostRequestFailure(request); | |
| 319 } | |
| 320 } | |
| 321 | |
| 322 void MockWebRTCPeerConnectionHandler::createAnswer( | |
| 323 const WebRTCSessionDescriptionRequest& request, | |
| 324 const WebMediaConstraints& constraints) { | |
| 325 if (!remote_description_.isNull()) { | |
| 326 WebRTCSessionDescription session_description; | |
| 327 session_description.initialize("answer", "local"); | |
| 328 PostRequestResult(request, session_description); | |
| 329 } else { | |
| 330 PostRequestFailure(request); | |
| 331 } | |
| 332 } | |
| 333 | |
| 334 void MockWebRTCPeerConnectionHandler::createAnswer( | |
| 335 const WebRTCSessionDescriptionRequest& request, | |
| 336 const blink::WebRTCAnswerOptions& options) { | |
| 337 if (options.voiceActivityDetection()) { | |
| 338 WebRTCSessionDescription session_description; | |
| 339 session_description.initialize("answer", "local"); | |
| 340 PostRequestResult(request, session_description); | |
| 341 } else { | |
| 342 PostRequestFailure(request); | |
| 343 } | |
| 344 } | |
| 345 | |
| 346 void MockWebRTCPeerConnectionHandler::setLocalDescription( | |
| 347 const WebRTCVoidRequest& request, | |
| 348 const WebRTCSessionDescription& local_description) { | |
| 349 if (!local_description.isNull() && local_description.sdp() == "local") { | |
| 350 local_description_ = local_description; | |
| 351 PostRequestResult(request); | |
| 352 } else { | |
| 353 PostRequestFailure(request); | |
| 354 } | |
| 355 } | |
| 356 | |
| 357 void MockWebRTCPeerConnectionHandler::setRemoteDescription( | |
| 358 const WebRTCVoidRequest& request, | |
| 359 const WebRTCSessionDescription& remote_description) { | |
| 360 | |
| 361 if (!remote_description.isNull() && remote_description.sdp() == "remote") { | |
| 362 UpdateRemoteStreams(); | |
| 363 remote_description_ = remote_description; | |
| 364 PostRequestResult(request); | |
| 365 } else | |
| 366 PostRequestFailure(request); | |
| 367 } | |
| 368 | |
| 369 void MockWebRTCPeerConnectionHandler::UpdateRemoteStreams() { | |
| 370 // Find all removed streams. | |
| 371 // Set the readyState of the remote tracks to ended, remove them from the | |
| 372 // stream and notify the client. | |
| 373 StreamMap::iterator removed_it = remote_streams_.begin(); | |
| 374 while (removed_it != remote_streams_.end()) { | |
| 375 if (local_streams_.find(removed_it->first) != local_streams_.end()) { | |
| 376 removed_it++; | |
| 377 continue; | |
| 378 } | |
| 379 | |
| 380 // The stream have been removed. Loop through all tracks and set the | |
| 381 // source as ended and remove them from the stream. | |
| 382 blink::WebMediaStream stream = removed_it->second; | |
| 383 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; | |
| 384 stream.audioTracks(audio_tracks); | |
| 385 for (size_t i = 0; i < audio_tracks.size(); ++i) { | |
| 386 audio_tracks[i].source().setReadyState( | |
| 387 blink::WebMediaStreamSource::ReadyStateEnded); | |
| 388 stream.removeTrack(audio_tracks[i]); | |
| 389 } | |
| 390 | |
| 391 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | |
| 392 stream.videoTracks(video_tracks); | |
| 393 for (size_t i = 0; i < video_tracks.size(); ++i) { | |
| 394 video_tracks[i].source().setReadyState( | |
| 395 blink::WebMediaStreamSource::ReadyStateEnded); | |
| 396 stream.removeTrack(video_tracks[i]); | |
| 397 } | |
| 398 client_->didRemoveRemoteStream(stream); | |
| 399 remote_streams_.erase(removed_it++); | |
| 400 } | |
| 401 | |
| 402 // Find all new streams; | |
| 403 // Create new sources and tracks and notify the client about the new stream. | |
| 404 StreamMap::iterator added_it = local_streams_.begin(); | |
| 405 while (added_it != local_streams_.end()) { | |
| 406 if (remote_streams_.find(added_it->first) != remote_streams_.end()) { | |
| 407 added_it++; | |
| 408 continue; | |
| 409 } | |
| 410 | |
| 411 const blink::WebMediaStream& stream = added_it->second; | |
| 412 | |
| 413 blink::WebVector<blink::WebMediaStreamTrack> local_audio_tracks; | |
| 414 stream.audioTracks(local_audio_tracks); | |
| 415 blink::WebVector<blink::WebMediaStreamTrack> | |
| 416 remote_audio_tracks(local_audio_tracks.size()); | |
| 417 | |
| 418 for (size_t i = 0; i < local_audio_tracks.size(); ++i) { | |
| 419 blink::WebMediaStreamSource webkit_source; | |
| 420 webkit_source.initialize(local_audio_tracks[i].id(), | |
| 421 blink::WebMediaStreamSource::TypeAudio, | |
| 422 local_audio_tracks[i].id(), | |
| 423 true /* remote */); | |
| 424 remote_audio_tracks[i].initialize(webkit_source); | |
| 425 } | |
| 426 | |
| 427 blink::WebVector<blink::WebMediaStreamTrack> local_video_tracks; | |
| 428 stream.videoTracks(local_video_tracks); | |
| 429 blink::WebVector<blink::WebMediaStreamTrack> | |
| 430 remote_video_tracks(local_video_tracks.size()); | |
| 431 for (size_t i = 0; i < local_video_tracks.size(); ++i) { | |
| 432 blink::WebMediaStreamSource webkit_source; | |
| 433 webkit_source.initialize(local_video_tracks[i].id(), | |
| 434 blink::WebMediaStreamSource::TypeVideo, | |
| 435 local_video_tracks[i].id(), | |
| 436 true /* remote */); | |
| 437 remote_video_tracks[i].initialize(webkit_source); | |
| 438 } | |
| 439 | |
| 440 blink::WebMediaStream new_remote_stream; | |
| 441 new_remote_stream.initialize(remote_audio_tracks, | |
| 442 remote_video_tracks); | |
| 443 remote_streams_[added_it->first] = new_remote_stream; | |
| 444 client_->didAddRemoteStream(new_remote_stream); | |
| 445 ++added_it; | |
| 446 } | |
| 447 } | |
| 448 | |
| 449 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::localDescription() { | |
| 450 return local_description_; | |
| 451 } | |
| 452 | |
| 453 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::remoteDescription() { | |
| 454 return remote_description_; | |
| 455 } | |
| 456 | |
| 457 WebRTCErrorType MockWebRTCPeerConnectionHandler::setConfiguration( | |
| 458 const WebRTCConfiguration& configuration) { | |
| 459 return WebRTCErrorType::kNone; | |
| 460 } | |
| 461 | |
| 462 bool MockWebRTCPeerConnectionHandler::addICECandidate( | |
| 463 const WebRTCICECandidate& ice_candidate) { | |
| 464 client_->didGenerateICECandidate(ice_candidate); | |
| 465 return true; | |
| 466 } | |
| 467 | |
| 468 bool MockWebRTCPeerConnectionHandler::addICECandidate( | |
| 469 const WebRTCVoidRequest& request, | |
| 470 const WebRTCICECandidate& ice_candidate) { | |
| 471 PostRequestResult(request); | |
| 472 return true; | |
| 473 } | |
| 474 | |
| 475 bool MockWebRTCPeerConnectionHandler::addStream( | |
| 476 const WebMediaStream& stream, | |
| 477 const WebMediaConstraints& constraints) { | |
| 478 if (local_streams_.find(stream.id().utf8()) != local_streams_.end()) | |
| 479 return false; | |
| 480 ++stream_count_; | |
| 481 client_->negotiationNeeded(); | |
| 482 local_streams_[stream.id().utf8()] = stream; | |
| 483 return true; | |
| 484 } | |
| 485 | |
| 486 void MockWebRTCPeerConnectionHandler::removeStream( | |
| 487 const WebMediaStream& stream) { | |
| 488 --stream_count_; | |
| 489 local_streams_.erase(stream.id().utf8()); | |
| 490 client_->negotiationNeeded(); | |
| 491 } | |
| 492 | |
| 493 void MockWebRTCPeerConnectionHandler::getStats( | |
| 494 const WebRTCStatsRequest& request) { | |
| 495 WebRTCStatsResponse response = request.createResponse(); | |
| 496 double current_date = | |
| 497 interfaces_->GetDelegate()->GetCurrentTimeInMillisecond(); | |
| 498 if (request.hasSelector()) { | |
| 499 // FIXME: There is no check that the fetched values are valid. | |
| 500 MockWebRTCLegacyStats stats("Mock video", "ssrc", current_date); | |
| 501 stats.addStatistic("type", "video"); | |
| 502 response.addStats(stats); | |
| 503 } else { | |
| 504 for (int i = 0; i < stream_count_; ++i) { | |
| 505 MockWebRTCLegacyStats audio_stats("Mock audio", "ssrc", current_date); | |
| 506 audio_stats.addStatistic("type", "audio"); | |
| 507 response.addStats(audio_stats); | |
| 508 | |
| 509 MockWebRTCLegacyStats video_stats("Mock video", "ssrc", current_date); | |
| 510 video_stats.addStatistic("type", "video"); | |
| 511 response.addStats(video_stats); | |
| 512 } | |
| 513 } | |
| 514 interfaces_->GetDelegate()->PostTask( | |
| 515 base::Bind(&blink::WebRTCStatsRequest::requestSucceeded, | |
| 516 base::Owned(new WebRTCStatsRequest(request)), response)); | |
| 517 } | |
| 518 | |
| 519 void MockWebRTCPeerConnectionHandler::getStats( | |
| 520 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) { | |
| 521 std::unique_ptr<MockWebRTCStatsReport> report(new MockWebRTCStatsReport()); | |
| 522 MockWebRTCStats stats("mock-stats-01", "mock-stats", 1234.0); | |
| 523 stats.addMember("bool", blink::WebRTCStatsMemberTypeBool); | |
| 524 stats.addMember("int32", blink::WebRTCStatsMemberTypeInt32); | |
| 525 stats.addMember("uint32", blink::WebRTCStatsMemberTypeUint32); | |
| 526 stats.addMember("int64", blink::WebRTCStatsMemberTypeInt64); | |
| 527 stats.addMember("uint64", blink::WebRTCStatsMemberTypeUint64); | |
| 528 stats.addMember("double", blink::WebRTCStatsMemberTypeDouble); | |
| 529 stats.addMember("string", blink::WebRTCStatsMemberTypeString); | |
| 530 stats.addMember("sequenceBool", blink::WebRTCStatsMemberTypeSequenceBool); | |
| 531 stats.addMember("sequenceInt32", blink::WebRTCStatsMemberTypeSequenceInt32); | |
| 532 stats.addMember("sequenceUint32", blink::WebRTCStatsMemberTypeSequenceUint32); | |
| 533 stats.addMember("sequenceInt64", blink::WebRTCStatsMemberTypeSequenceInt64); | |
| 534 stats.addMember("sequenceUint64", blink::WebRTCStatsMemberTypeSequenceUint64); | |
| 535 stats.addMember("sequenceDouble", blink::WebRTCStatsMemberTypeSequenceDouble); | |
| 536 stats.addMember("sequenceString", blink::WebRTCStatsMemberTypeSequenceString); | |
| 537 report->AddStats(stats); | |
| 538 callback->OnStatsDelivered(std::unique_ptr<blink::WebRTCStatsReport>( | |
| 539 report.release())); | |
| 540 } | |
| 541 | |
| 542 void MockWebRTCPeerConnectionHandler::ReportCreationOfDataChannel() { | |
| 543 WebRTCDataChannelInit init; | |
| 544 WebRTCDataChannelHandler* remote_data_channel = | |
| 545 new MockWebRTCDataChannelHandler("MockRemoteDataChannel", init, | |
| 546 interfaces_->GetDelegate()); | |
| 547 client_->didAddRemoteDataChannel(remote_data_channel); | |
| 548 } | |
| 549 | |
| 550 WebRTCDataChannelHandler* MockWebRTCPeerConnectionHandler::createDataChannel( | |
| 551 const WebString& label, | |
| 552 const blink::WebRTCDataChannelInit& init) { | |
| 553 interfaces_->GetDelegate()->PostTask( | |
| 554 base::Bind(&MockWebRTCPeerConnectionHandler::ReportCreationOfDataChannel, | |
| 555 weak_factory_.GetWeakPtr())); | |
| 556 | |
| 557 // TODO(lukasza): Unclear if it is okay to return a different object than the | |
| 558 // one created in ReportCreationOfDataChannel. | |
| 559 return new MockWebRTCDataChannelHandler( | |
| 560 label, init, interfaces_->GetDelegate()); | |
| 561 } | |
| 562 | |
| 563 WebRTCDTMFSenderHandler* MockWebRTCPeerConnectionHandler::createDTMFSender( | |
| 564 const WebMediaStreamTrack& track) { | |
| 565 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); | |
| 566 } | |
| 567 | |
| 568 void MockWebRTCPeerConnectionHandler::stop() { | |
| 569 stopped_ = true; | |
| 570 weak_factory_.InvalidateWeakPtrs(); | |
| 571 } | |
| 572 | |
| 573 } // namespace test_runner | |
| OLD | NEW |