| 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 RTCStatsCollectorTest() | 321 RTCStatsCollectorTest() |
| 322 : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()), | 322 : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()), |
| 323 collector_(RTCStatsCollector::Create( | 323 collector_(RTCStatsCollector::Create( |
| 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 int64_t after = rtc::TimeUTCMicros(); |
| 332 for (const RTCStats& stats : *callback->report()) { |
| 333 EXPECT_LE(stats.timestamp_us(), after); |
| 334 } |
| 331 return callback->report(); | 335 return callback->report(); |
| 332 } | 336 } |
| 333 | 337 |
| 334 const RTCIceCandidateStats* ExpectReportContainsCandidate( | 338 const RTCIceCandidateStats* ExpectReportContainsCandidate( |
| 335 const rtc::scoped_refptr<const RTCStatsReport>& report, | 339 const rtc::scoped_refptr<const RTCStatsReport>& report, |
| 336 const cricket::Candidate& candidate, | 340 const cricket::Candidate& candidate, |
| 337 bool is_local) { | 341 bool is_local) { |
| 338 const RTCStats* stats = report->Get("RTCIceCandidate_" + candidate.id()); | 342 const RTCStats* stats = report->Get("RTCIceCandidate_" + candidate.id()); |
| 339 EXPECT_TRUE(stats); | 343 EXPECT_TRUE(stats); |
| 340 const RTCIceCandidateStats* candidate_stats; | 344 const RTCIceCandidateStats* candidate_stats; |
| 341 if (is_local) | 345 if (is_local) |
| 342 candidate_stats = &stats->cast_to<RTCLocalIceCandidateStats>(); | 346 candidate_stats = &stats->cast_to<RTCLocalIceCandidateStats>(); |
| 343 else | 347 else |
| 344 candidate_stats = &stats->cast_to<RTCRemoteIceCandidateStats>(); | 348 candidate_stats = &stats->cast_to<RTCRemoteIceCandidateStats>(); |
| 345 EXPECT_EQ(*candidate_stats->ip, candidate.address().ipaddr().ToString()); | 349 EXPECT_EQ(*candidate_stats->ip, candidate.address().ipaddr().ToString()); |
| 346 EXPECT_EQ(*candidate_stats->port, | 350 EXPECT_EQ(*candidate_stats->port, |
| 347 static_cast<int32_t>(candidate.address().port())); | 351 static_cast<int32_t>(candidate.address().port())); |
| 348 EXPECT_EQ(*candidate_stats->protocol, candidate.protocol()); | 352 EXPECT_EQ(*candidate_stats->protocol, candidate.protocol()); |
| 349 EXPECT_EQ(*candidate_stats->candidate_type, | 353 EXPECT_EQ(*candidate_stats->candidate_type, |
| 350 CandidateTypeToRTCIceCandidateType(candidate.type())); | 354 CandidateTypeToRTCIceCandidateTypeForTesting(candidate.type())); |
| 351 EXPECT_EQ(*candidate_stats->priority, | 355 EXPECT_EQ(*candidate_stats->priority, |
| 352 static_cast<int32_t>(candidate.priority())); | 356 static_cast<int32_t>(candidate.priority())); |
| 353 // TODO(hbos): Define candidate_stats->url. crbug.com/632723 | 357 // TODO(hbos): Define candidate_stats->url. crbug.com/632723 |
| 354 EXPECT_FALSE(candidate_stats->url.is_defined()); | 358 EXPECT_FALSE(candidate_stats->url.is_defined()); |
| 355 return candidate_stats; | 359 return candidate_stats; |
| 356 } | 360 } |
| 357 | 361 |
| 358 void ExpectReportContainsCandidatePair( | 362 void ExpectReportContainsCandidatePair( |
| 359 const rtc::scoped_refptr<const RTCStatsReport>& report, | 363 const rtc::scoped_refptr<const RTCStatsReport>& report, |
| 360 const cricket::TransportStats& transport_stats) { | 364 const cricket::TransportStats& transport_stats) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 EXPECT_EQ(*cert_stats.base64_certificate, cert_info.pems[i]); | 435 EXPECT_EQ(*cert_stats.base64_certificate, cert_info.pems[i]); |
| 432 if (i + 1 < cert_info.fingerprints.size()) { | 436 if (i + 1 < cert_info.fingerprints.size()) { |
| 433 EXPECT_EQ(*cert_stats.issuer_certificate_id, | 437 EXPECT_EQ(*cert_stats.issuer_certificate_id, |
| 434 "RTCCertificate_" + cert_info.fingerprints[i + 1]); | 438 "RTCCertificate_" + cert_info.fingerprints[i + 1]); |
| 435 } else { | 439 } else { |
| 436 EXPECT_FALSE(cert_stats.issuer_certificate_id.is_defined()); | 440 EXPECT_FALSE(cert_stats.issuer_certificate_id.is_defined()); |
| 437 } | 441 } |
| 438 } | 442 } |
| 439 } | 443 } |
| 440 | 444 |
| 445 void ExpectReportContainsDataChannel( |
| 446 const rtc::scoped_refptr<const RTCStatsReport>& report, |
| 447 const DataChannel& data_channel) { |
| 448 const RTCStats* stats = report->Get("RTCDataChannel_" + |
| 449 rtc::ToString<>(data_channel.id())); |
| 450 EXPECT_TRUE(stats); |
| 451 const RTCDataChannelStats& data_channel_stats = |
| 452 stats->cast_to<const RTCDataChannelStats>(); |
| 453 EXPECT_EQ(*data_channel_stats.label, data_channel.label()); |
| 454 EXPECT_EQ(*data_channel_stats.protocol, data_channel.protocol()); |
| 455 EXPECT_EQ(*data_channel_stats.datachannelid, data_channel.id()); |
| 456 EXPECT_EQ(*data_channel_stats.state, |
| 457 DataStateToRTCDataChannelStateForTesting(data_channel.state())); |
| 458 EXPECT_EQ(*data_channel_stats.messages_sent, data_channel.messages_sent()); |
| 459 EXPECT_EQ(*data_channel_stats.bytes_sent, data_channel.bytes_sent()); |
| 460 EXPECT_EQ(*data_channel_stats.messages_received, |
| 461 data_channel.messages_received()); |
| 462 EXPECT_EQ(*data_channel_stats.bytes_received, |
| 463 data_channel.bytes_received()); |
| 464 } |
| 465 |
| 441 protected: | 466 protected: |
| 442 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; | 467 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; |
| 443 rtc::scoped_refptr<RTCStatsCollector> collector_; | 468 rtc::scoped_refptr<RTCStatsCollector> collector_; |
| 444 }; | 469 }; |
| 445 | 470 |
| 446 TEST_F(RTCStatsCollectorTest, SingleCallback) { | 471 TEST_F(RTCStatsCollectorTest, SingleCallback) { |
| 447 rtc::scoped_refptr<const RTCStatsReport> result; | 472 rtc::scoped_refptr<const RTCStatsReport> result; |
| 448 collector_->GetStatsReport(StatsCallback::Create(&result)); | 473 collector_->GetStatsReport(StatsCallback::Create(&result)); |
| 449 EXPECT_TRUE_WAIT(result, kGetStatsReportTimeoutMs); | 474 EXPECT_TRUE_WAIT(result, kGetStatsReportTimeoutMs); |
| 450 } | 475 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 if (transport_name == "transport") | 661 if (transport_name == "transport") |
| 637 return remote_certinfo->certificate->ssl_certificate().GetReference(); | 662 return remote_certinfo->certificate->ssl_certificate().GetReference(); |
| 638 return static_cast<rtc::SSLCertificate*>(nullptr); | 663 return static_cast<rtc::SSLCertificate*>(nullptr); |
| 639 })); | 664 })); |
| 640 | 665 |
| 641 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 666 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 642 ExpectReportContainsCertificateInfo(report, *local_certinfo.get()); | 667 ExpectReportContainsCertificateInfo(report, *local_certinfo.get()); |
| 643 ExpectReportContainsCertificateInfo(report, *remote_certinfo.get()); | 668 ExpectReportContainsCertificateInfo(report, *remote_certinfo.get()); |
| 644 } | 669 } |
| 645 | 670 |
| 671 TEST_F(RTCStatsCollectorTest, CollectRTCDataChannelStats) { |
| 672 test_->data_channels().push_back( |
| 673 new MockDataChannel(0, DataChannelInterface::kConnecting)); |
| 674 test_->data_channels().push_back( |
| 675 new MockDataChannel(1, DataChannelInterface::kOpen)); |
| 676 test_->data_channels().push_back( |
| 677 new MockDataChannel(2, DataChannelInterface::kClosing)); |
| 678 test_->data_channels().push_back( |
| 679 new MockDataChannel(3, DataChannelInterface::kClosed)); |
| 680 |
| 681 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 682 ExpectReportContainsDataChannel(report, *test_->data_channels()[0]); |
| 683 ExpectReportContainsDataChannel(report, *test_->data_channels()[1]); |
| 684 ExpectReportContainsDataChannel(report, *test_->data_channels()[2]); |
| 685 ExpectReportContainsDataChannel(report, *test_->data_channels()[3]); |
| 686 |
| 687 test_->data_channels().clear(); |
| 688 test_->data_channels().push_back( |
| 689 new MockDataChannel(0, DataChannelInterface::kConnecting, |
| 690 1, 2, 3, 4)); |
| 691 test_->data_channels().push_back( |
| 692 new MockDataChannel(1, DataChannelInterface::kOpen, |
| 693 5, 6, 7, 8)); |
| 694 test_->data_channels().push_back( |
| 695 new MockDataChannel(2, DataChannelInterface::kClosing, |
| 696 9, 10, 11, 12)); |
| 697 test_->data_channels().push_back( |
| 698 new MockDataChannel(3, DataChannelInterface::kClosed, |
| 699 13, 14, 15, 16)); |
| 700 |
| 701 collector_->ClearCachedStatsReport(); |
| 702 report = GetStatsReport(); |
| 703 ExpectReportContainsDataChannel(report, *test_->data_channels()[0]); |
| 704 ExpectReportContainsDataChannel(report, *test_->data_channels()[1]); |
| 705 ExpectReportContainsDataChannel(report, *test_->data_channels()[2]); |
| 706 ExpectReportContainsDataChannel(report, *test_->data_channels()[3]); |
| 707 } |
| 708 |
| 646 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) { | 709 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) { |
| 647 // Candidates in the first transport stats. | 710 // Candidates in the first transport stats. |
| 648 std::unique_ptr<cricket::Candidate> a_local_host = CreateFakeCandidate( | 711 std::unique_ptr<cricket::Candidate> a_local_host = CreateFakeCandidate( |
| 649 "1.2.3.4", 5, | 712 "1.2.3.4", 5, |
| 650 "a_local_host's protocol", | 713 "a_local_host's protocol", |
| 651 cricket::LOCAL_PORT_TYPE, | 714 cricket::LOCAL_PORT_TYPE, |
| 652 0); | 715 0); |
| 653 std::unique_ptr<cricket::Candidate> a_remote_srflx = CreateFakeCandidate( | 716 std::unique_ptr<cricket::Candidate> a_remote_srflx = CreateFakeCandidate( |
| 654 "6.7.8.9", 10, | 717 "6.7.8.9", 10, |
| 655 "remote_srflx's protocol", | 718 "remote_srflx's protocol", |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 *stats = session_stats; | 815 *stats = session_stats; |
| 753 return true; | 816 return true; |
| 754 })); | 817 })); |
| 755 | 818 |
| 756 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 819 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 757 ExpectReportContainsCandidatePair( | 820 ExpectReportContainsCandidatePair( |
| 758 report, session_stats.transport_stats["transport"]); | 821 report, session_stats.transport_stats["transport"]); |
| 759 } | 822 } |
| 760 | 823 |
| 761 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { | 824 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { |
| 762 int64_t before = rtc::TimeUTCMicros(); | |
| 763 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 825 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 764 int64_t after = rtc::TimeUTCMicros(); | |
| 765 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), | 826 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), |
| 766 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; | 827 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; |
| 767 const RTCStats* stats = report->Get("RTCPeerConnection"); | 828 const RTCStats* stats = report->Get("RTCPeerConnection"); |
| 768 EXPECT_TRUE(stats); | 829 EXPECT_TRUE(stats); |
| 769 EXPECT_LE(before, stats->timestamp_us()); | |
| 770 EXPECT_LE(stats->timestamp_us(), after); | |
| 771 { | 830 { |
| 772 // Expected stats with no data channels | 831 // Expected stats with no data channels |
| 773 const RTCPeerConnectionStats& pcstats = | 832 const RTCPeerConnectionStats& pcstats = |
| 774 stats->cast_to<RTCPeerConnectionStats>(); | 833 stats->cast_to<RTCPeerConnectionStats>(); |
| 775 EXPECT_EQ(*pcstats.data_channels_opened, static_cast<uint32_t>(0)); | 834 EXPECT_EQ(*pcstats.data_channels_opened, static_cast<uint32_t>(0)); |
| 776 EXPECT_EQ(*pcstats.data_channels_closed, static_cast<uint32_t>(0)); | 835 EXPECT_EQ(*pcstats.data_channels_closed, static_cast<uint32_t>(0)); |
| 777 } | 836 } |
| 778 | 837 |
| 779 test_->data_channels().push_back( | 838 test_->data_channels().push_back( |
| 780 new MockDataChannel(DataChannelInterface::kConnecting)); | 839 new MockDataChannel(0, DataChannelInterface::kConnecting)); |
| 781 test_->data_channels().push_back( | 840 test_->data_channels().push_back( |
| 782 new MockDataChannel(DataChannelInterface::kOpen)); | 841 new MockDataChannel(1, DataChannelInterface::kOpen)); |
| 783 test_->data_channels().push_back( | 842 test_->data_channels().push_back( |
| 784 new MockDataChannel(DataChannelInterface::kClosing)); | 843 new MockDataChannel(2, DataChannelInterface::kClosing)); |
| 785 test_->data_channels().push_back( | 844 test_->data_channels().push_back( |
| 786 new MockDataChannel(DataChannelInterface::kClosed)); | 845 new MockDataChannel(3, DataChannelInterface::kClosed)); |
| 787 | 846 |
| 788 collector_->ClearCachedStatsReport(); | 847 collector_->ClearCachedStatsReport(); |
| 789 report = GetStatsReport(); | 848 report = GetStatsReport(); |
| 790 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), | 849 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), |
| 791 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; | 850 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; |
| 792 stats = report->Get("RTCPeerConnection"); | 851 stats = report->Get("RTCPeerConnection"); |
| 793 EXPECT_TRUE(stats); | 852 EXPECT_TRUE(stats); |
| 794 { | 853 { |
| 795 // Expected stats with the above four data channels | 854 // Expected stats with the above four data channels |
| 796 // TODO(hbos): When the |RTCPeerConnectionStats| is the number of data | 855 // TODO(hbos): When the |RTCPeerConnectionStats| is the number of data |
| (...skipping 20 matching lines...) Expand all Loading... |
| 817 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | 876 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
| 818 }; | 877 }; |
| 819 | 878 |
| 820 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 879 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
| 821 collector_->VerifyThreadUsageAndResultsMerging(); | 880 collector_->VerifyThreadUsageAndResultsMerging(); |
| 822 } | 881 } |
| 823 | 882 |
| 824 } // namespace | 883 } // namespace |
| 825 | 884 |
| 826 } // namespace webrtc | 885 } // namespace webrtc |
| OLD | NEW |