Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) { | 324 &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) { |
| 325 } | 325 } |
| 326 | 326 |
| 327 rtc::scoped_refptr<const RTCStatsReport> GetStatsReport() { | 327 rtc::scoped_refptr<const RTCStatsReport> GetStatsReport() { |
| 328 rtc::scoped_refptr<StatsCallback> callback = StatsCallback::Create(); | 328 rtc::scoped_refptr<StatsCallback> callback = StatsCallback::Create(); |
| 329 collector_->GetStatsReport(callback); | 329 collector_->GetStatsReport(callback); |
| 330 EXPECT_TRUE_WAIT(callback->report(), kGetStatsReportTimeoutMs); | 330 EXPECT_TRUE_WAIT(callback->report(), kGetStatsReportTimeoutMs); |
| 331 return callback->report(); | 331 return callback->report(); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void ExpectReportContainsCandidate( | 334 const RTCIceCandidateStats* ExpectReportContainsCandidate( |
| 335 const rtc::scoped_refptr<const RTCStatsReport>& report, | 335 const rtc::scoped_refptr<const RTCStatsReport>& report, |
| 336 const cricket::Candidate& candidate, | 336 const cricket::Candidate& candidate, |
| 337 bool is_local) { | 337 bool is_local) { |
| 338 const RTCStats* stats = | 338 const RTCStats* stats = report->Get("RTCIceCandidate_" + candidate.id()); |
| 339 report->Get("RTCIceCandidate_" + candidate.id()); | |
| 340 EXPECT_TRUE(stats); | 339 EXPECT_TRUE(stats); |
| 341 const RTCIceCandidateStats* candidate_stats; | 340 const RTCIceCandidateStats* candidate_stats; |
| 342 if (is_local) | 341 if (is_local) |
| 343 candidate_stats = &stats->cast_to<RTCLocalIceCandidateStats>(); | 342 candidate_stats = &stats->cast_to<RTCLocalIceCandidateStats>(); |
| 344 else | 343 else |
| 345 candidate_stats = &stats->cast_to<RTCRemoteIceCandidateStats>(); | 344 candidate_stats = &stats->cast_to<RTCRemoteIceCandidateStats>(); |
| 346 EXPECT_EQ(*candidate_stats->ip, candidate.address().ipaddr().ToString()); | 345 EXPECT_EQ(*candidate_stats->ip, candidate.address().ipaddr().ToString()); |
| 347 EXPECT_EQ(*candidate_stats->port, | 346 EXPECT_EQ(*candidate_stats->port, |
| 348 static_cast<int32_t>(candidate.address().port())); | 347 static_cast<int32_t>(candidate.address().port())); |
| 349 EXPECT_EQ(*candidate_stats->protocol, candidate.protocol()); | 348 EXPECT_EQ(*candidate_stats->protocol, candidate.protocol()); |
| 350 EXPECT_EQ(*candidate_stats->candidate_type, | 349 EXPECT_EQ(*candidate_stats->candidate_type, |
| 351 CandidateTypeToRTCIceCandidateType(candidate.type())); | 350 CandidateTypeToRTCIceCandidateType(candidate.type())); |
| 352 EXPECT_EQ(*candidate_stats->priority, | 351 EXPECT_EQ(*candidate_stats->priority, |
| 353 static_cast<int32_t>(candidate.priority())); | 352 static_cast<int32_t>(candidate.priority())); |
| 354 // TODO(hbos): Define candidate_stats->url. crbug.com/632723 | 353 // TODO(hbos): Define candidate_stats->url. crbug.com/632723 |
| 355 EXPECT_FALSE(candidate_stats->url.is_defined()); | 354 EXPECT_FALSE(candidate_stats->url.is_defined()); |
| 355 return candidate_stats; | |
| 356 } | |
| 357 | |
| 358 void ExpectReportContainsCandidatePair( | |
| 359 const rtc::scoped_refptr<const RTCStatsReport>& report, | |
| 360 const cricket::TransportStats& transport_stats) { | |
| 361 for (const auto& channel_stats : transport_stats.channel_stats) { | |
| 362 int connection_id = 0; | |
| 363 for (const cricket::ConnectionInfo& info : | |
| 364 channel_stats.connection_infos) { | |
| 365 const std::string& id = "RTCTransportChannel_" + | |
| 366 transport_stats.transport_name + "_" + | |
| 367 rtc::ToString<>(channel_stats.component) + "_Connection_" + | |
| 368 rtc::ToString<>(connection_id); | |
|
Taylor Brandstetter
2016/10/10 21:45:38
Should the test be relying on a specific ID format
hbos
2016/10/10 22:39:56
I think testing the ID format is a good way to ens
Taylor Brandstetter
2016/10/10 23:07:03
It is, but it means the test will need to be updat
| |
| 369 const RTCStats* stats = report->Get(id); | |
| 370 EXPECT_TRUE(stats); | |
| 371 const RTCIceCandidatePairStats& candidate_pair_stats = | |
| 372 stats->cast_to<RTCIceCandidatePairStats>(); | |
| 373 | |
| 374 // TODO(hbos): Define all the undefined |candidate_pair_stats| stats. | |
| 375 // crbug.com/633550 | |
| 376 EXPECT_FALSE(candidate_pair_stats.transport_id.is_defined()); | |
| 377 const RTCIceCandidateStats* local_candidate = | |
| 378 ExpectReportContainsCandidate(report, info.local_candidate, true); | |
| 379 EXPECT_EQ(*candidate_pair_stats.local_candidate_id, | |
| 380 local_candidate->id()); | |
| 381 const RTCIceCandidateStats* remote_candidate = | |
| 382 ExpectReportContainsCandidate(report, info.remote_candidate, false); | |
| 383 EXPECT_EQ(*candidate_pair_stats.remote_candidate_id, | |
| 384 remote_candidate->id()); | |
| 385 | |
| 386 EXPECT_FALSE(candidate_pair_stats.state.is_defined()); | |
| 387 EXPECT_FALSE(candidate_pair_stats.priority.is_defined()); | |
| 388 EXPECT_FALSE(candidate_pair_stats.nominated.is_defined()); | |
| 389 EXPECT_EQ(*candidate_pair_stats.writable, info.writable); | |
| 390 EXPECT_FALSE(candidate_pair_stats.readable.is_defined()); | |
| 391 EXPECT_EQ(*candidate_pair_stats.bytes_sent, | |
| 392 static_cast<uint64_t>(info.sent_total_bytes)); | |
| 393 EXPECT_EQ(*candidate_pair_stats.bytes_received, | |
| 394 static_cast<uint64_t>(info.recv_total_bytes)); | |
| 395 EXPECT_FALSE(candidate_pair_stats.total_rtt.is_defined()); | |
| 396 EXPECT_EQ(*candidate_pair_stats.current_rtt, | |
| 397 static_cast<double>(info.rtt) / 1000.0); | |
| 398 EXPECT_FALSE( | |
| 399 candidate_pair_stats.available_outgoing_bitrate.is_defined()); | |
| 400 EXPECT_FALSE( | |
| 401 candidate_pair_stats.available_incoming_bitrate.is_defined()); | |
| 402 EXPECT_FALSE(candidate_pair_stats.requests_received.is_defined()); | |
| 403 EXPECT_FALSE(candidate_pair_stats.requests_sent.is_defined()); | |
| 404 EXPECT_FALSE(candidate_pair_stats.responses_received.is_defined()); | |
| 405 EXPECT_FALSE(candidate_pair_stats.responses_sent.is_defined()); | |
| 406 EXPECT_FALSE( | |
| 407 candidate_pair_stats.retransmissions_received.is_defined()); | |
| 408 EXPECT_FALSE(candidate_pair_stats.retransmissions_sent.is_defined()); | |
| 409 EXPECT_FALSE( | |
| 410 candidate_pair_stats.consent_requests_received.is_defined()); | |
| 411 EXPECT_FALSE(candidate_pair_stats.consent_requests_sent.is_defined()); | |
| 412 EXPECT_FALSE( | |
| 413 candidate_pair_stats.consent_responses_received.is_defined()); | |
| 414 EXPECT_FALSE(candidate_pair_stats.consent_responses_sent.is_defined()); | |
| 415 } | |
| 416 } | |
| 356 } | 417 } |
| 357 | 418 |
| 358 void ExpectReportContainsCertificateInfo( | 419 void ExpectReportContainsCertificateInfo( |
| 359 const rtc::scoped_refptr<const RTCStatsReport>& report, | 420 const rtc::scoped_refptr<const RTCStatsReport>& report, |
| 360 const CertificateInfo& cert_info) { | 421 const CertificateInfo& cert_info) { |
| 361 for (size_t i = 0; i < cert_info.fingerprints.size(); ++i) { | 422 for (size_t i = 0; i < cert_info.fingerprints.size(); ++i) { |
| 362 const RTCStats* stats = report->Get( | 423 const RTCStats* stats = report->Get( |
| 363 "RTCCertificate_" + cert_info.fingerprints[i]); | 424 "RTCCertificate_" + cert_info.fingerprints[i]); |
| 364 EXPECT_TRUE(stats); | 425 EXPECT_TRUE(stats); |
| 365 const RTCCertificateStats& cert_stats = | 426 const RTCCertificateStats& cert_stats = |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 | 713 |
| 653 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 714 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 654 ExpectReportContainsCandidate(report, *a_local_host.get(), true); | 715 ExpectReportContainsCandidate(report, *a_local_host.get(), true); |
| 655 ExpectReportContainsCandidate(report, *a_remote_srflx.get(), false); | 716 ExpectReportContainsCandidate(report, *a_remote_srflx.get(), false); |
| 656 ExpectReportContainsCandidate(report, *a_local_prflx.get(), true); | 717 ExpectReportContainsCandidate(report, *a_local_prflx.get(), true); |
| 657 ExpectReportContainsCandidate(report, *a_remote_relay.get(), false); | 718 ExpectReportContainsCandidate(report, *a_remote_relay.get(), false); |
| 658 ExpectReportContainsCandidate(report, *b_local.get(), true); | 719 ExpectReportContainsCandidate(report, *b_local.get(), true); |
| 659 ExpectReportContainsCandidate(report, *b_remote.get(), false); | 720 ExpectReportContainsCandidate(report, *b_remote.get(), false); |
| 660 } | 721 } |
| 661 | 722 |
| 723 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { | |
| 724 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( | |
| 725 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | |
| 726 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( | |
| 727 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | |
| 728 | |
| 729 SessionStats session_stats; | |
| 730 | |
| 731 cricket::TransportChannelStats transport_channel_stats; | |
| 732 transport_channel_stats.connection_infos.push_back( | |
| 733 cricket::ConnectionInfo()); | |
| 734 transport_channel_stats.connection_infos[0].local_candidate = | |
| 735 *local_candidate.get(); | |
| 736 transport_channel_stats.connection_infos[0].remote_candidate = | |
| 737 *remote_candidate.get(); | |
| 738 session_stats.transport_stats["transport"].transport_name = "transport"; | |
| 739 session_stats.transport_stats["transport"].channel_stats.push_back( | |
| 740 transport_channel_stats); | |
| 741 | |
| 742 // Mock the session to return the desired candidates. | |
| 743 EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke( | |
| 744 [this, &session_stats](SessionStats* stats) { | |
| 745 *stats = session_stats; | |
| 746 return true; | |
| 747 })); | |
| 748 | |
| 749 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | |
| 750 ExpectReportContainsCandidatePair( | |
| 751 report, session_stats.transport_stats["transport"]); | |
| 752 } | |
| 753 | |
| 662 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { | 754 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { |
| 663 int64_t before = rtc::TimeUTCMicros(); | 755 int64_t before = rtc::TimeUTCMicros(); |
| 664 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 756 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 665 int64_t after = rtc::TimeUTCMicros(); | 757 int64_t after = rtc::TimeUTCMicros(); |
| 666 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), | 758 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), |
| 667 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; | 759 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; |
| 668 const RTCStats* stats = report->Get("RTCPeerConnection"); | 760 const RTCStats* stats = report->Get("RTCPeerConnection"); |
| 669 EXPECT_TRUE(stats); | 761 EXPECT_TRUE(stats); |
| 670 EXPECT_LE(before, stats->timestamp_us()); | 762 EXPECT_LE(before, stats->timestamp_us()); |
| 671 EXPECT_LE(stats->timestamp_us(), after); | 763 EXPECT_LE(stats->timestamp_us(), after); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | 810 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
| 719 }; | 811 }; |
| 720 | 812 |
| 721 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 813 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
| 722 collector_->VerifyThreadUsageAndResultsMerging(); | 814 collector_->VerifyThreadUsageAndResultsMerging(); |
| 723 } | 815 } |
| 724 | 816 |
| 725 } // namespace | 817 } // namespace |
| 726 | 818 |
| 727 } // namespace webrtc | 819 } // namespace webrtc |
| OLD | NEW |