Chromium Code Reviews| Index: webrtc/api/rtcstatscollector_unittest.cc |
| diff --git a/webrtc/api/rtcstatscollector_unittest.cc b/webrtc/api/rtcstatscollector_unittest.cc |
| index c8eed9febbaed7c84e9411dabfb1173488b6d468..6033de4f5bbbfa9befe8727683cd61e9c3a22824 100644 |
| --- a/webrtc/api/rtcstatscollector_unittest.cc |
| +++ b/webrtc/api/rtcstatscollector_unittest.cc |
| @@ -438,6 +438,57 @@ class RTCStatsCollectorTest : public testing::Test { |
| } |
| } |
| + void ExpectReportContainsTransportStats( |
| + const rtc::scoped_refptr<const RTCStatsReport>& report, |
| + const cricket::TransportStats& transport, |
| + const CertificateInfo* local_certinfo, |
| + const CertificateInfo* remote_certinfo) { |
| + const RTCStats* stats = report->Get( |
| + "RTCTransport_" + transport.transport_name); |
| + EXPECT_TRUE(stats); |
| + const RTCTransportStats& transport_stats = |
| + stats->cast_to<const RTCTransportStats>(); |
| + uint64_t bytes_sent = 0; |
| + uint64_t bytes_received = 0; |
| + const cricket::ConnectionInfo* best_connection_info = nullptr; |
| + for (const auto& channel_stats : transport.channel_stats) { |
| + for (const cricket::ConnectionInfo& info : |
| + channel_stats.connection_infos) { |
| + bytes_sent += info.sent_total_bytes; |
| + bytes_received += info.recv_total_bytes; |
| + if (info.best_connection) |
| + best_connection_info = &info; |
| + } |
| + } |
| + EXPECT_EQ(*transport_stats.bytes_sent, bytes_sent); |
| + EXPECT_EQ(*transport_stats.bytes_received, bytes_received); |
| + if (best_connection_info) { |
| + EXPECT_EQ(*transport_stats.active_connection, true); |
| + EXPECT_EQ(*transport_stats.selected_candidate_pair_id, |
| + "RTCIceCandidatePair_" + |
| + best_connection_info->local_candidate.id() + "_" + |
| + best_connection_info->remote_candidate.id()); |
| + EXPECT_TRUE(report->Get(*transport_stats.selected_candidate_pair_id)); |
| + } else { |
| + EXPECT_EQ(*transport_stats.active_connection, false); |
| + EXPECT_FALSE(transport_stats.selected_candidate_pair_id.is_defined()); |
| + } |
| + // TODO(hbos): Define transport_stats.rtcp_transport_stats_id. |
| + // crbug.com/653873 |
| + EXPECT_FALSE(transport_stats.rtcp_transport_stats_id.is_defined()); |
| + if (local_certinfo && remote_certinfo) { |
| + EXPECT_EQ(*transport_stats.local_certificate_id, |
| + "RTCCertificate_" + local_certinfo->fingerprints[0]); |
| + EXPECT_EQ(*transport_stats.remote_certificate_id, |
| + "RTCCertificate_" + remote_certinfo->fingerprints[0]); |
| + EXPECT_TRUE(report->Get(*transport_stats.local_certificate_id)); |
| + EXPECT_TRUE(report->Get(*transport_stats.remote_certificate_id)); |
| + } else { |
| + EXPECT_FALSE(transport_stats.local_certificate_id.is_defined()); |
| + EXPECT_FALSE(transport_stats.remote_certificate_id.is_defined()); |
| + } |
| + } |
| + |
| protected: |
| rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; |
| rtc::scoped_refptr<RTCStatsCollector> collector_; |
| @@ -804,6 +855,93 @@ TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { |
| } |
| } |
| +TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { |
| + std::unique_ptr<cricket::Candidate> a_local_candidate = CreateFakeCandidate( |
| + "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
| + std::unique_ptr<cricket::Candidate> a_remote_candidate = CreateFakeCandidate( |
| + "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
|
hta-webrtc
2016/10/12 22:52:35
Curious: Can a remote cnadidate really have cricke
hbos
2016/10/17 19:33:13
Good question. There plenty of TODOs in our codeba
Taylor Brandstetter
2016/10/17 21:19:03
Yes, LOCAL_PORT_TYPE means "host" candidate. So it
|
| + std::unique_ptr<cricket::Candidate> b_local_candidate = CreateFakeCandidate( |
| + "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
| + std::unique_ptr<cricket::Candidate> b_remote_candidate = CreateFakeCandidate( |
| + "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
| + |
| + SessionStats session_stats; |
| + |
| + cricket::ConnectionInfo a_connection_info; |
| + a_connection_info.best_connection = false; |
| + a_connection_info.local_candidate = *a_local_candidate.get(); |
| + a_connection_info.remote_candidate = *a_remote_candidate.get(); |
| + a_connection_info.sent_total_bytes = 42; |
| + a_connection_info.recv_total_bytes = 1337; |
| + cricket::TransportChannelStats a_transport_channel_stats; |
| + a_transport_channel_stats.connection_infos.push_back(a_connection_info); |
| + |
| + cricket::ConnectionInfo b_connection_info; |
| + b_connection_info.best_connection = false; |
| + b_connection_info.local_candidate = *b_local_candidate.get(); |
| + b_connection_info.remote_candidate = *b_remote_candidate.get(); |
| + b_connection_info.sent_total_bytes = 1337; |
| + b_connection_info.recv_total_bytes = 42; |
| + cricket::TransportChannelStats b_transport_channel_stats; |
| + b_transport_channel_stats.connection_infos.push_back(b_connection_info); |
| + |
| + session_stats.transport_stats["transport"].transport_name = "transport"; |
| + session_stats.transport_stats["transport"].channel_stats.push_back( |
| + a_transport_channel_stats); |
| + session_stats.transport_stats["transport"].channel_stats.push_back( |
| + b_transport_channel_stats); |
| + |
| + // Mock the session to return the desired candidates. |
| + EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke( |
| + [this, &session_stats](SessionStats* stats) { |
| + *stats = session_stats; |
| + return true; |
| + })); |
| + |
| + // Get stats without an active connection or certificates. |
| + rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| + ExpectReportContainsTransportStats( |
| + report, session_stats.transport_stats["transport"], nullptr, nullptr); |
| + |
| + // Get stats with an active connection. |
| + b_connection_info.best_connection = true; |
| + |
| + collector_->ClearCachedStatsReport(); |
| + report = GetStatsReport(); |
| + ExpectReportContainsTransportStats( |
| + report, session_stats.transport_stats["transport"], nullptr, nullptr); |
| + |
| + // Get stats with certificates. |
| + std::unique_ptr<CertificateInfo> local_certinfo = |
| + CreateFakeCertificateAndInfoFromDers( |
| + std::vector<std::string>({ "(local) local", "(local) chain" })); |
| + std::unique_ptr<CertificateInfo> remote_certinfo = |
| + CreateFakeCertificateAndInfoFromDers( |
| + std::vector<std::string>({ "(remote) local", "(remote) chain" })); |
| + EXPECT_CALL(test_->session(), GetLocalCertificate(_, _)).WillRepeatedly( |
| + Invoke([this, &local_certinfo](const std::string& transport_name, |
| + rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
| + if (transport_name == "transport") { |
| + *certificate = local_certinfo->certificate; |
| + return true; |
| + } |
| + return false; |
| + })); |
| + EXPECT_CALL(test_->session(), |
| + GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke( |
| + [this, &remote_certinfo](const std::string& transport_name) { |
| + if (transport_name == "transport") |
| + return remote_certinfo->certificate->ssl_certificate().GetReference(); |
| + return static_cast<rtc::SSLCertificate*>(nullptr); |
| + })); |
| + |
| + collector_->ClearCachedStatsReport(); |
| + report = GetStatsReport(); |
| + ExpectReportContainsTransportStats( |
| + report, session_stats.transport_stats["transport"], |
| + local_certinfo.get(), remote_certinfo.get()); |
| +} |
| + |
| class RTCStatsCollectorTestWithFakeCollector : public testing::Test { |
| public: |
| RTCStatsCollectorTestWithFakeCollector() |