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 420 matching lines...) Loading... | |
431 EXPECT_EQ(*cert_stats.base64_certificate, cert_info.pems[i]); | 431 EXPECT_EQ(*cert_stats.base64_certificate, cert_info.pems[i]); |
432 if (i + 1 < cert_info.fingerprints.size()) { | 432 if (i + 1 < cert_info.fingerprints.size()) { |
433 EXPECT_EQ(*cert_stats.issuer_certificate_id, | 433 EXPECT_EQ(*cert_stats.issuer_certificate_id, |
434 "RTCCertificate_" + cert_info.fingerprints[i + 1]); | 434 "RTCCertificate_" + cert_info.fingerprints[i + 1]); |
435 } else { | 435 } else { |
436 EXPECT_FALSE(cert_stats.issuer_certificate_id.is_defined()); | 436 EXPECT_FALSE(cert_stats.issuer_certificate_id.is_defined()); |
437 } | 437 } |
438 } | 438 } |
439 } | 439 } |
440 | 440 |
441 void ExpectReportContainsTransportStats( | |
442 const rtc::scoped_refptr<const RTCStatsReport>& report, | |
443 const cricket::TransportStats& transport, | |
444 const CertificateInfo* local_certinfo, | |
445 const CertificateInfo* remote_certinfo) { | |
446 const RTCStats* stats = report->Get( | |
447 "RTCTransport_" + transport.transport_name); | |
448 EXPECT_TRUE(stats); | |
Taylor Brandstetter
2016/10/17 21:19:03
Won't the test crash if |stats| isn't found? Seems
hbos
2016/10/19 16:30:00
Done.
| |
449 const RTCTransportStats& transport_stats = | |
450 stats->cast_to<const RTCTransportStats>(); | |
451 uint64_t bytes_sent = 0; | |
452 uint64_t bytes_received = 0; | |
453 const cricket::ConnectionInfo* best_connection_info = nullptr; | |
454 for (const auto& channel_stats : transport.channel_stats) { | |
455 for (const cricket::ConnectionInfo& info : | |
456 channel_stats.connection_infos) { | |
457 bytes_sent += info.sent_total_bytes; | |
458 bytes_received += info.recv_total_bytes; | |
459 if (info.best_connection) | |
460 best_connection_info = &info; | |
461 } | |
462 } | |
Taylor Brandstetter
2016/10/17 21:19:03
I won't ask you to change everything, since it's s
hbos
2016/10/19 16:30:00
I think that is a good point.
There's no operator
Taylor Brandstetter
2016/10/19 19:03:06
Sounds good. Though if that seems like more effort
| |
463 EXPECT_EQ(*transport_stats.bytes_sent, bytes_sent); | |
464 EXPECT_EQ(*transport_stats.bytes_received, bytes_received); | |
465 if (best_connection_info) { | |
466 EXPECT_EQ(*transport_stats.active_connection, true); | |
467 EXPECT_EQ(*transport_stats.selected_candidate_pair_id, | |
468 "RTCIceCandidatePair_" + | |
469 best_connection_info->local_candidate.id() + "_" + | |
470 best_connection_info->remote_candidate.id()); | |
471 EXPECT_TRUE(report->Get(*transport_stats.selected_candidate_pair_id)); | |
472 } else { | |
473 EXPECT_EQ(*transport_stats.active_connection, false); | |
474 EXPECT_FALSE(transport_stats.selected_candidate_pair_id.is_defined()); | |
475 } | |
476 // TODO(hbos): Define transport_stats.rtcp_transport_stats_id. | |
477 // crbug.com/653873 | |
478 EXPECT_FALSE(transport_stats.rtcp_transport_stats_id.is_defined()); | |
479 if (local_certinfo && remote_certinfo) { | |
480 EXPECT_EQ(*transport_stats.local_certificate_id, | |
481 "RTCCertificate_" + local_certinfo->fingerprints[0]); | |
482 EXPECT_EQ(*transport_stats.remote_certificate_id, | |
483 "RTCCertificate_" + remote_certinfo->fingerprints[0]); | |
484 EXPECT_TRUE(report->Get(*transport_stats.local_certificate_id)); | |
485 EXPECT_TRUE(report->Get(*transport_stats.remote_certificate_id)); | |
486 } else { | |
487 EXPECT_FALSE(transport_stats.local_certificate_id.is_defined()); | |
488 EXPECT_FALSE(transport_stats.remote_certificate_id.is_defined()); | |
489 } | |
490 } | |
491 | |
441 protected: | 492 protected: |
442 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; | 493 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; |
443 rtc::scoped_refptr<RTCStatsCollector> collector_; | 494 rtc::scoped_refptr<RTCStatsCollector> collector_; |
444 }; | 495 }; |
445 | 496 |
446 TEST_F(RTCStatsCollectorTest, SingleCallback) { | 497 TEST_F(RTCStatsCollectorTest, SingleCallback) { |
447 rtc::scoped_refptr<const RTCStatsReport> result; | 498 rtc::scoped_refptr<const RTCStatsReport> result; |
448 collector_->GetStatsReport(StatsCallback::Create(&result)); | 499 collector_->GetStatsReport(StatsCallback::Create(&result)); |
449 EXPECT_TRUE_WAIT(result, kGetStatsReportTimeoutMs); | 500 EXPECT_TRUE_WAIT(result, kGetStatsReportTimeoutMs); |
450 } | 501 } |
(...skipping 346 matching lines...) Loading... | |
797 // channels that have been opened and closed, not the numbers currently | 848 // channels that have been opened and closed, not the numbers currently |
798 // open/closed, we would expect opened >= closed and (opened - closed) to be | 849 // open/closed, we would expect opened >= closed and (opened - closed) to be |
799 // the number currently open. crbug.com/636818. | 850 // the number currently open. crbug.com/636818. |
800 const RTCPeerConnectionStats& pcstats = | 851 const RTCPeerConnectionStats& pcstats = |
801 stats->cast_to<RTCPeerConnectionStats>(); | 852 stats->cast_to<RTCPeerConnectionStats>(); |
802 EXPECT_EQ(*pcstats.data_channels_opened, static_cast<uint32_t>(1)); | 853 EXPECT_EQ(*pcstats.data_channels_opened, static_cast<uint32_t>(1)); |
803 EXPECT_EQ(*pcstats.data_channels_closed, static_cast<uint32_t>(3)); | 854 EXPECT_EQ(*pcstats.data_channels_closed, static_cast<uint32_t>(3)); |
804 } | 855 } |
805 } | 856 } |
806 | 857 |
858 TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { | |
859 std::unique_ptr<cricket::Candidate> a_local_candidate = CreateFakeCandidate( | |
860 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | |
861 std::unique_ptr<cricket::Candidate> a_remote_candidate = CreateFakeCandidate( | |
862 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | |
863 std::unique_ptr<cricket::Candidate> b_local_candidate = CreateFakeCandidate( | |
864 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | |
865 std::unique_ptr<cricket::Candidate> b_remote_candidate = CreateFakeCandidate( | |
866 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | |
867 | |
868 SessionStats session_stats; | |
869 | |
870 cricket::ConnectionInfo a_connection_info; | |
871 a_connection_info.best_connection = false; | |
872 a_connection_info.local_candidate = *a_local_candidate.get(); | |
873 a_connection_info.remote_candidate = *a_remote_candidate.get(); | |
874 a_connection_info.sent_total_bytes = 42; | |
875 a_connection_info.recv_total_bytes = 1337; | |
876 cricket::TransportChannelStats a_transport_channel_stats; | |
877 a_transport_channel_stats.connection_infos.push_back(a_connection_info); | |
878 | |
879 cricket::ConnectionInfo b_connection_info; | |
880 b_connection_info.best_connection = false; | |
881 b_connection_info.local_candidate = *b_local_candidate.get(); | |
882 b_connection_info.remote_candidate = *b_remote_candidate.get(); | |
883 b_connection_info.sent_total_bytes = 1337; | |
884 b_connection_info.recv_total_bytes = 42; | |
885 cricket::TransportChannelStats b_transport_channel_stats; | |
886 b_transport_channel_stats.connection_infos.push_back(b_connection_info); | |
Taylor Brandstetter
2016/10/17 21:19:03
One of these channel stats should be component RTC
hbos
2016/10/19 16:30:00
Acknowledged.
| |
887 | |
888 session_stats.transport_stats["transport"].transport_name = "transport"; | |
889 session_stats.transport_stats["transport"].channel_stats.push_back( | |
890 a_transport_channel_stats); | |
891 session_stats.transport_stats["transport"].channel_stats.push_back( | |
892 b_transport_channel_stats); | |
893 | |
894 // Mock the session to return the desired candidates. | |
895 EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke( | |
896 [this, &session_stats](SessionStats* stats) { | |
897 *stats = session_stats; | |
898 return true; | |
899 })); | |
900 | |
901 // Get stats without an active connection or certificates. | |
902 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | |
903 ExpectReportContainsTransportStats( | |
904 report, session_stats.transport_stats["transport"], nullptr, nullptr); | |
905 | |
906 // Get stats with an active connection. | |
907 b_connection_info.best_connection = true; | |
908 | |
909 collector_->ClearCachedStatsReport(); | |
910 report = GetStatsReport(); | |
911 ExpectReportContainsTransportStats( | |
912 report, session_stats.transport_stats["transport"], nullptr, nullptr); | |
913 | |
914 // Get stats with certificates. | |
915 std::unique_ptr<CertificateInfo> local_certinfo = | |
916 CreateFakeCertificateAndInfoFromDers( | |
917 std::vector<std::string>({ "(local) local", "(local) chain" })); | |
918 std::unique_ptr<CertificateInfo> remote_certinfo = | |
919 CreateFakeCertificateAndInfoFromDers( | |
920 std::vector<std::string>({ "(remote) local", "(remote) chain" })); | |
921 EXPECT_CALL(test_->session(), GetLocalCertificate(_, _)).WillRepeatedly( | |
922 Invoke([this, &local_certinfo](const std::string& transport_name, | |
923 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { | |
924 if (transport_name == "transport") { | |
925 *certificate = local_certinfo->certificate; | |
926 return true; | |
927 } | |
928 return false; | |
929 })); | |
930 EXPECT_CALL(test_->session(), | |
931 GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke( | |
932 [this, &remote_certinfo](const std::string& transport_name) { | |
933 if (transport_name == "transport") | |
934 return remote_certinfo->certificate->ssl_certificate().GetReference(); | |
935 return static_cast<rtc::SSLCertificate*>(nullptr); | |
936 })); | |
937 | |
938 collector_->ClearCachedStatsReport(); | |
939 report = GetStatsReport(); | |
940 ExpectReportContainsTransportStats( | |
941 report, session_stats.transport_stats["transport"], | |
942 local_certinfo.get(), remote_certinfo.get()); | |
943 } | |
944 | |
807 class RTCStatsCollectorTestWithFakeCollector : public testing::Test { | 945 class RTCStatsCollectorTestWithFakeCollector : public testing::Test { |
808 public: | 946 public: |
809 RTCStatsCollectorTestWithFakeCollector() | 947 RTCStatsCollectorTestWithFakeCollector() |
810 : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()), | 948 : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()), |
811 collector_(FakeRTCStatsCollector::Create( | 949 collector_(FakeRTCStatsCollector::Create( |
812 &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) { | 950 &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) { |
813 } | 951 } |
814 | 952 |
815 protected: | 953 protected: |
816 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; | 954 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; |
817 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | 955 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
818 }; | 956 }; |
819 | 957 |
820 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 958 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
821 collector_->VerifyThreadUsageAndResultsMerging(); | 959 collector_->VerifyThreadUsageAndResultsMerging(); |
822 } | 960 } |
823 | 961 |
824 } // namespace | 962 } // namespace |
825 | 963 |
826 } // namespace webrtc | 964 } // namespace webrtc |
OLD | NEW |