Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(855)

Side by Side Diff: webrtc/api/rtcstatscollector_unittest.cc

Issue 2390693003: RTCIceCandidatePairStats added. (Closed)
Patch Set: Addressed comments (added requests_sent/responses_sent) Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/rtcstatscollector.cc ('k') | webrtc/api/stats/rtcstats_objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // The EXPECT_FALSE are for the undefined stats, see also todos listed
373 // in rtcstatscollector.cc. crbug.com/633550
374 EXPECT_FALSE(candidate_pair_stats.transport_id.is_defined());
375 const RTCIceCandidateStats* local_candidate =
376 ExpectReportContainsCandidate(report, info.local_candidate, true);
377 EXPECT_EQ(*candidate_pair_stats.local_candidate_id,
378 local_candidate->id());
379 const RTCIceCandidateStats* remote_candidate =
380 ExpectReportContainsCandidate(report, info.remote_candidate, false);
381 EXPECT_EQ(*candidate_pair_stats.remote_candidate_id,
382 remote_candidate->id());
383
384 EXPECT_FALSE(candidate_pair_stats.state.is_defined());
385 EXPECT_FALSE(candidate_pair_stats.priority.is_defined());
386 EXPECT_FALSE(candidate_pair_stats.nominated.is_defined());
387 EXPECT_EQ(*candidate_pair_stats.writable, info.writable);
388 EXPECT_FALSE(candidate_pair_stats.readable.is_defined());
389 EXPECT_EQ(*candidate_pair_stats.bytes_sent,
390 static_cast<uint64_t>(info.sent_total_bytes));
391 EXPECT_EQ(*candidate_pair_stats.bytes_received,
392 static_cast<uint64_t>(info.recv_total_bytes));
393 EXPECT_FALSE(candidate_pair_stats.total_rtt.is_defined());
394 EXPECT_EQ(*candidate_pair_stats.current_rtt,
395 static_cast<double>(info.rtt) / 1000.0);
396 EXPECT_FALSE(
397 candidate_pair_stats.available_outgoing_bitrate.is_defined());
398 EXPECT_FALSE(
399 candidate_pair_stats.available_incoming_bitrate.is_defined());
400 EXPECT_FALSE(candidate_pair_stats.requests_received.is_defined());
401 EXPECT_EQ(*candidate_pair_stats.requests_sent,
402 static_cast<uint64_t>(info.sent_ping_requests_total));
403 EXPECT_EQ(*candidate_pair_stats.responses_received,
404 static_cast<uint64_t>(info.recv_ping_responses));
405 EXPECT_EQ(*candidate_pair_stats.responses_sent,
406 static_cast<uint64_t>(info.sent_ping_responses));
407 EXPECT_FALSE(
408 candidate_pair_stats.retransmissions_received.is_defined());
409 EXPECT_FALSE(candidate_pair_stats.retransmissions_sent.is_defined());
410 EXPECT_FALSE(
411 candidate_pair_stats.consent_requests_received.is_defined());
412 EXPECT_FALSE(candidate_pair_stats.consent_requests_sent.is_defined());
413 EXPECT_FALSE(
414 candidate_pair_stats.consent_responses_received.is_defined());
415 EXPECT_FALSE(candidate_pair_stats.consent_responses_sent.is_defined());
416 }
417 }
356 } 418 }
357 419
358 void ExpectReportContainsCertificateInfo( 420 void ExpectReportContainsCertificateInfo(
359 const rtc::scoped_refptr<const RTCStatsReport>& report, 421 const rtc::scoped_refptr<const RTCStatsReport>& report,
360 const CertificateInfo& cert_info) { 422 const CertificateInfo& cert_info) {
361 for (size_t i = 0; i < cert_info.fingerprints.size(); ++i) { 423 for (size_t i = 0; i < cert_info.fingerprints.size(); ++i) {
362 const RTCStats* stats = report->Get( 424 const RTCStats* stats = report->Get(
363 "RTCCertificate_" + cert_info.fingerprints[i]); 425 "RTCCertificate_" + cert_info.fingerprints[i]);
364 EXPECT_TRUE(stats); 426 EXPECT_TRUE(stats);
365 const RTCCertificateStats& cert_stats = 427 const RTCCertificateStats& cert_stats =
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 714
653 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); 715 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
654 ExpectReportContainsCandidate(report, *a_local_host.get(), true); 716 ExpectReportContainsCandidate(report, *a_local_host.get(), true);
655 ExpectReportContainsCandidate(report, *a_remote_srflx.get(), false); 717 ExpectReportContainsCandidate(report, *a_remote_srflx.get(), false);
656 ExpectReportContainsCandidate(report, *a_local_prflx.get(), true); 718 ExpectReportContainsCandidate(report, *a_local_prflx.get(), true);
657 ExpectReportContainsCandidate(report, *a_remote_relay.get(), false); 719 ExpectReportContainsCandidate(report, *a_remote_relay.get(), false);
658 ExpectReportContainsCandidate(report, *b_local.get(), true); 720 ExpectReportContainsCandidate(report, *b_local.get(), true);
659 ExpectReportContainsCandidate(report, *b_remote.get(), false); 721 ExpectReportContainsCandidate(report, *b_remote.get(), false);
660 } 722 }
661 723
724 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) {
725 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate(
726 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42);
727 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate(
728 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42);
729
730 SessionStats session_stats;
731
732 cricket::ConnectionInfo connection_info;
733 connection_info.local_candidate = *local_candidate.get();
734 connection_info.remote_candidate = *remote_candidate.get();
735 connection_info.writable = true;
736 connection_info.sent_total_bytes = 42;
737 connection_info.recv_total_bytes = 1234;
738 connection_info.rtt = 1337;
739 connection_info.sent_ping_requests_total = 1010;
740 connection_info.recv_ping_responses = 4321;
741 connection_info.sent_ping_responses = 1000;
742
743 cricket::TransportChannelStats transport_channel_stats;
744 transport_channel_stats.connection_infos.push_back(connection_info);
745 session_stats.transport_stats["transport"].transport_name = "transport";
746 session_stats.transport_stats["transport"].channel_stats.push_back(
747 transport_channel_stats);
748
749 // Mock the session to return the desired candidates.
750 EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke(
751 [this, &session_stats](SessionStats* stats) {
752 *stats = session_stats;
753 return true;
754 }));
755
756 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
757 ExpectReportContainsCandidatePair(
758 report, session_stats.transport_stats["transport"]);
759 }
760
662 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { 761 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) {
663 int64_t before = rtc::TimeUTCMicros(); 762 int64_t before = rtc::TimeUTCMicros();
664 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); 763 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
665 int64_t after = rtc::TimeUTCMicros(); 764 int64_t after = rtc::TimeUTCMicros();
666 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(), 765 EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(),
667 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats."; 766 static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats.";
668 const RTCStats* stats = report->Get("RTCPeerConnection"); 767 const RTCStats* stats = report->Get("RTCPeerConnection");
669 EXPECT_TRUE(stats); 768 EXPECT_TRUE(stats);
670 EXPECT_LE(before, stats->timestamp_us()); 769 EXPECT_LE(before, stats->timestamp_us());
671 EXPECT_LE(stats->timestamp_us(), after); 770 EXPECT_LE(stats->timestamp_us(), after);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; 817 rtc::scoped_refptr<FakeRTCStatsCollector> collector_;
719 }; 818 };
720 819
721 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { 820 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) {
722 collector_->VerifyThreadUsageAndResultsMerging(); 821 collector_->VerifyThreadUsageAndResultsMerging();
723 } 822 }
724 823
725 } // namespace 824 } // namespace
726 825
727 } // namespace webrtc 826 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/rtcstatscollector.cc ('k') | webrtc/api/stats/rtcstats_objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698