Chromium Code Reviews| Index: webrtc/api/rtcstatscollector_unittest.cc |
| diff --git a/webrtc/api/rtcstatscollector_unittest.cc b/webrtc/api/rtcstatscollector_unittest.cc |
| index 0da772fb97d3767682f5493442da9b41b6fa61c3..fa368bfbe5b2751080041444f3849464f665fdae 100644 |
| --- a/webrtc/api/rtcstatscollector_unittest.cc |
| +++ b/webrtc/api/rtcstatscollector_unittest.cc |
| @@ -331,12 +331,11 @@ class RTCStatsCollectorTest : public testing::Test { |
| return callback->report(); |
| } |
| - void ExpectReportContainsCandidate( |
| + const RTCIceCandidateStats* ExpectReportContainsCandidate( |
| const rtc::scoped_refptr<const RTCStatsReport>& report, |
| const cricket::Candidate& candidate, |
| bool is_local) { |
| - const RTCStats* stats = |
| - report->Get("RTCIceCandidate_" + candidate.id()); |
| + const RTCStats* stats = report->Get("RTCIceCandidate_" + candidate.id()); |
| EXPECT_TRUE(stats); |
| const RTCIceCandidateStats* candidate_stats; |
| if (is_local) |
| @@ -353,6 +352,68 @@ class RTCStatsCollectorTest : public testing::Test { |
| static_cast<int32_t>(candidate.priority())); |
| // TODO(hbos): Define candidate_stats->url. crbug.com/632723 |
| EXPECT_FALSE(candidate_stats->url.is_defined()); |
| + return candidate_stats; |
| + } |
| + |
| + void ExpectReportContainsCandidatePair( |
| + const rtc::scoped_refptr<const RTCStatsReport>& report, |
| + const cricket::TransportStats& transport_stats) { |
| + for (const auto& channel_stats : transport_stats.channel_stats) { |
| + int connection_id = 0; |
| + for (const cricket::ConnectionInfo& info : |
| + channel_stats.connection_infos) { |
| + const std::string& id = "RTCTransportChannel_" + |
| + transport_stats.transport_name + "_" + |
| + rtc::ToString<>(channel_stats.component) + "_Connection_" + |
| + 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
|
| + const RTCStats* stats = report->Get(id); |
| + EXPECT_TRUE(stats); |
| + const RTCIceCandidatePairStats& candidate_pair_stats = |
| + stats->cast_to<RTCIceCandidatePairStats>(); |
| + |
| + // TODO(hbos): Define all the undefined |candidate_pair_stats| stats. |
| + // crbug.com/633550 |
| + EXPECT_FALSE(candidate_pair_stats.transport_id.is_defined()); |
| + const RTCIceCandidateStats* local_candidate = |
| + ExpectReportContainsCandidate(report, info.local_candidate, true); |
| + EXPECT_EQ(*candidate_pair_stats.local_candidate_id, |
| + local_candidate->id()); |
| + const RTCIceCandidateStats* remote_candidate = |
| + ExpectReportContainsCandidate(report, info.remote_candidate, false); |
| + EXPECT_EQ(*candidate_pair_stats.remote_candidate_id, |
| + remote_candidate->id()); |
| + |
| + EXPECT_FALSE(candidate_pair_stats.state.is_defined()); |
| + EXPECT_FALSE(candidate_pair_stats.priority.is_defined()); |
| + EXPECT_FALSE(candidate_pair_stats.nominated.is_defined()); |
| + EXPECT_EQ(*candidate_pair_stats.writable, info.writable); |
| + EXPECT_FALSE(candidate_pair_stats.readable.is_defined()); |
| + EXPECT_EQ(*candidate_pair_stats.bytes_sent, |
| + static_cast<uint64_t>(info.sent_total_bytes)); |
| + EXPECT_EQ(*candidate_pair_stats.bytes_received, |
| + static_cast<uint64_t>(info.recv_total_bytes)); |
| + EXPECT_FALSE(candidate_pair_stats.total_rtt.is_defined()); |
| + EXPECT_EQ(*candidate_pair_stats.current_rtt, |
| + static_cast<double>(info.rtt) / 1000.0); |
| + EXPECT_FALSE( |
| + candidate_pair_stats.available_outgoing_bitrate.is_defined()); |
| + EXPECT_FALSE( |
| + candidate_pair_stats.available_incoming_bitrate.is_defined()); |
| + EXPECT_FALSE(candidate_pair_stats.requests_received.is_defined()); |
| + EXPECT_FALSE(candidate_pair_stats.requests_sent.is_defined()); |
| + EXPECT_FALSE(candidate_pair_stats.responses_received.is_defined()); |
| + EXPECT_FALSE(candidate_pair_stats.responses_sent.is_defined()); |
| + EXPECT_FALSE( |
| + candidate_pair_stats.retransmissions_received.is_defined()); |
| + EXPECT_FALSE(candidate_pair_stats.retransmissions_sent.is_defined()); |
| + EXPECT_FALSE( |
| + candidate_pair_stats.consent_requests_received.is_defined()); |
| + EXPECT_FALSE(candidate_pair_stats.consent_requests_sent.is_defined()); |
| + EXPECT_FALSE( |
| + candidate_pair_stats.consent_responses_received.is_defined()); |
| + EXPECT_FALSE(candidate_pair_stats.consent_responses_sent.is_defined()); |
| + } |
| + } |
| } |
| void ExpectReportContainsCertificateInfo( |
| @@ -659,6 +720,37 @@ TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) { |
| ExpectReportContainsCandidate(report, *b_remote.get(), false); |
| } |
| +TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { |
| + std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( |
| + "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
| + std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( |
| + "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
| + |
| + SessionStats session_stats; |
| + |
| + cricket::TransportChannelStats transport_channel_stats; |
| + transport_channel_stats.connection_infos.push_back( |
| + cricket::ConnectionInfo()); |
| + transport_channel_stats.connection_infos[0].local_candidate = |
| + *local_candidate.get(); |
| + transport_channel_stats.connection_infos[0].remote_candidate = |
| + *remote_candidate.get(); |
| + session_stats.transport_stats["transport"].transport_name = "transport"; |
| + session_stats.transport_stats["transport"].channel_stats.push_back( |
| + 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; |
| + })); |
| + |
| + rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| + ExpectReportContainsCandidatePair( |
| + report, session_stats.transport_stats["transport"]); |
| +} |
| + |
| TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { |
| int64_t before = rtc::TimeUTCMicros(); |
| rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |