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 for (const cricket::ConnectionInfo& info : | |
363 channel_stats.connection_infos) { | |
364 const std::string& id = "RTCIceCandidatePair_" + | |
365 info.local_candidate.id() + "_" + info.remote_candidate.id(); | |
366 const RTCStats* stats = report->Get(id); | |
367 EXPECT_TRUE(stats); | |
368 const RTCIceCandidatePairStats& candidate_pair_stats = | |
369 stats->cast_to<RTCIceCandidatePairStats>(); | |
370 | |
371 // TODO(hbos): Define all the undefined |candidate_pair_stats| stats. | |
372 // crbug.com/633550 | |
373 EXPECT_FALSE(candidate_pair_stats.transport_id.is_defined()); | |
374 const RTCIceCandidateStats* local_candidate = | |
375 ExpectReportContainsCandidate(report, info.local_candidate, true); | |
376 EXPECT_EQ(*candidate_pair_stats.local_candidate_id, | |
377 local_candidate->id()); | |
378 const RTCIceCandidateStats* remote_candidate = | |
379 ExpectReportContainsCandidate(report, info.remote_candidate, false); | |
380 EXPECT_EQ(*candidate_pair_stats.remote_candidate_id, | |
381 remote_candidate->id()); | |
382 | |
383 EXPECT_FALSE(candidate_pair_stats.state.is_defined()); | |
hta-webrtc
2016/10/11 20:40:26
Please add a comment saying that the EXPECT_FALSE(
hbos
2016/10/11 21:28:44
Done.
| |
384 EXPECT_FALSE(candidate_pair_stats.priority.is_defined()); | |
385 EXPECT_FALSE(candidate_pair_stats.nominated.is_defined()); | |
386 EXPECT_EQ(*candidate_pair_stats.writable, info.writable); | |
387 EXPECT_FALSE(candidate_pair_stats.readable.is_defined()); | |
388 EXPECT_EQ(*candidate_pair_stats.bytes_sent, | |
389 static_cast<uint64_t>(info.sent_total_bytes)); | |
390 EXPECT_EQ(*candidate_pair_stats.bytes_received, | |
391 static_cast<uint64_t>(info.recv_total_bytes)); | |
392 EXPECT_FALSE(candidate_pair_stats.total_rtt.is_defined()); | |
393 EXPECT_EQ(*candidate_pair_stats.current_rtt, | |
394 static_cast<double>(info.rtt) / 1000.0); | |
395 EXPECT_FALSE( | |
396 candidate_pair_stats.available_outgoing_bitrate.is_defined()); | |
397 EXPECT_FALSE( | |
398 candidate_pair_stats.available_incoming_bitrate.is_defined()); | |
399 EXPECT_FALSE(candidate_pair_stats.requests_received.is_defined()); | |
400 EXPECT_FALSE(candidate_pair_stats.requests_sent.is_defined()); | |
401 EXPECT_EQ(*candidate_pair_stats.responses_received, | |
402 static_cast<uint64_t>(info.recv_ping_responses)); | |
403 EXPECT_FALSE(candidate_pair_stats.responses_sent.is_defined()); | |
404 EXPECT_FALSE( | |
405 candidate_pair_stats.retransmissions_received.is_defined()); | |
406 EXPECT_FALSE(candidate_pair_stats.retransmissions_sent.is_defined()); | |
407 EXPECT_FALSE( | |
408 candidate_pair_stats.consent_requests_received.is_defined()); | |
409 EXPECT_FALSE(candidate_pair_stats.consent_requests_sent.is_defined()); | |
410 EXPECT_FALSE( | |
411 candidate_pair_stats.consent_responses_received.is_defined()); | |
412 EXPECT_FALSE(candidate_pair_stats.consent_responses_sent.is_defined()); | |
413 } | |
414 } | |
356 } | 415 } |
357 | 416 |
358 void ExpectReportContainsCertificateInfo( | 417 void ExpectReportContainsCertificateInfo( |
359 const rtc::scoped_refptr<const RTCStatsReport>& report, | 418 const rtc::scoped_refptr<const RTCStatsReport>& report, |
360 const CertificateInfo& cert_info) { | 419 const CertificateInfo& cert_info) { |
361 for (size_t i = 0; i < cert_info.fingerprints.size(); ++i) { | 420 for (size_t i = 0; i < cert_info.fingerprints.size(); ++i) { |
362 const RTCStats* stats = report->Get( | 421 const RTCStats* stats = report->Get( |
363 "RTCCertificate_" + cert_info.fingerprints[i]); | 422 "RTCCertificate_" + cert_info.fingerprints[i]); |
364 EXPECT_TRUE(stats); | 423 EXPECT_TRUE(stats); |
365 const RTCCertificateStats& cert_stats = | 424 const RTCCertificateStats& cert_stats = |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 | 711 |
653 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 712 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
654 ExpectReportContainsCandidate(report, *a_local_host.get(), true); | 713 ExpectReportContainsCandidate(report, *a_local_host.get(), true); |
655 ExpectReportContainsCandidate(report, *a_remote_srflx.get(), false); | 714 ExpectReportContainsCandidate(report, *a_remote_srflx.get(), false); |
656 ExpectReportContainsCandidate(report, *a_local_prflx.get(), true); | 715 ExpectReportContainsCandidate(report, *a_local_prflx.get(), true); |
657 ExpectReportContainsCandidate(report, *a_remote_relay.get(), false); | 716 ExpectReportContainsCandidate(report, *a_remote_relay.get(), false); |
658 ExpectReportContainsCandidate(report, *b_local.get(), true); | 717 ExpectReportContainsCandidate(report, *b_local.get(), true); |
659 ExpectReportContainsCandidate(report, *b_remote.get(), false); | 718 ExpectReportContainsCandidate(report, *b_remote.get(), false); |
660 } | 719 } |
661 | 720 |
721 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { | |
722 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( | |
723 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | |
724 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( | |
725 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | |
726 | |
727 SessionStats session_stats; | |
728 | |
729 cricket::ConnectionInfo connection_info; | |
730 connection_info.local_candidate = *local_candidate.get(); | |
731 connection_info.remote_candidate = *remote_candidate.get(); | |
732 connection_info.writable = true; | |
733 connection_info.sent_total_bytes = 42; | |
734 connection_info.recv_total_bytes = 1234; | |
735 connection_info.rtt = 1337; | |
736 connection_info.recv_ping_responses = 4321; | |
737 | |
738 cricket::TransportChannelStats transport_channel_stats; | |
739 transport_channel_stats.connection_infos.push_back(connection_info); | |
740 session_stats.transport_stats["transport"].transport_name = "transport"; | |
741 session_stats.transport_stats["transport"].channel_stats.push_back( | |
742 transport_channel_stats); | |
743 | |
744 // Mock the session to return the desired candidates. | |
745 EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke( | |
746 [this, &session_stats](SessionStats* stats) { | |
747 *stats = session_stats; | |
748 return true; | |
749 })); | |
750 | |
751 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | |
752 ExpectReportContainsCandidatePair( | |
753 report, session_stats.transport_stats["transport"]); | |
754 } | |
755 | |
662 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { | 756 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { |
663 int64_t before = rtc::TimeUTCMicros(); | 757 int64_t before = rtc::TimeUTCMicros(); |
664 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 758 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
665 int64_t after = rtc::TimeUTCMicros(); | 759 int64_t after = rtc::TimeUTCMicros(); |
666 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), | 760 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), |
667 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; | 761 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; |
668 const RTCStats* stats = report->Get("RTCPeerConnection"); | 762 const RTCStats* stats = report->Get("RTCPeerConnection"); |
669 EXPECT_TRUE(stats); | 763 EXPECT_TRUE(stats); |
670 EXPECT_LE(before, stats->timestamp_us()); | 764 EXPECT_LE(before, stats->timestamp_us()); |
671 EXPECT_LE(stats->timestamp_us(), after); | 765 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_; | 812 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
719 }; | 813 }; |
720 | 814 |
721 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 815 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
722 collector_->VerifyThreadUsageAndResultsMerging(); | 816 collector_->VerifyThreadUsageAndResultsMerging(); |
723 } | 817 } |
724 | 818 |
725 } // namespace | 819 } // namespace |
726 | 820 |
727 } // namespace webrtc | 821 } // namespace webrtc |
OLD | NEW |