Chromium Code Reviews| 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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 rtc::scoped_refptr<RTCStatsObtainer> callback = RTCStatsObtainer::Create(); | 487 rtc::scoped_refptr<RTCStatsObtainer> callback = RTCStatsObtainer::Create(); |
| 488 collector_->GetStatsReport(callback); | 488 collector_->GetStatsReport(callback); |
| 489 EXPECT_TRUE_WAIT(callback->report(), kGetStatsReportTimeoutMs); | 489 EXPECT_TRUE_WAIT(callback->report(), kGetStatsReportTimeoutMs); |
| 490 int64_t after = rtc::TimeUTCMicros(); | 490 int64_t after = rtc::TimeUTCMicros(); |
| 491 for (const RTCStats& stats : *callback->report()) { | 491 for (const RTCStats& stats : *callback->report()) { |
| 492 EXPECT_LE(stats.timestamp_us(), after); | 492 EXPECT_LE(stats.timestamp_us(), after); |
| 493 } | 493 } |
| 494 return callback->report(); | 494 return callback->report(); |
| 495 } | 495 } |
| 496 | 496 |
| 497 const RTCIceCandidateStats* ExpectReportContainsCandidate( | |
| 498 const rtc::scoped_refptr<const RTCStatsReport>& report, | |
| 499 const cricket::Candidate& candidate, | |
| 500 bool is_local) { | |
| 501 const RTCStats* stats = report->Get("RTCIceCandidate_" + candidate.id()); | |
| 502 EXPECT_TRUE(stats); | |
| 503 const RTCIceCandidateStats* candidate_stats; | |
| 504 if (is_local) | |
| 505 candidate_stats = &stats->cast_to<RTCLocalIceCandidateStats>(); | |
| 506 else | |
| 507 candidate_stats = &stats->cast_to<RTCRemoteIceCandidateStats>(); | |
| 508 EXPECT_EQ(*candidate_stats->ip, candidate.address().ipaddr().ToString()); | |
| 509 EXPECT_EQ(*candidate_stats->port, | |
| 510 static_cast<int32_t>(candidate.address().port())); | |
| 511 EXPECT_EQ(*candidate_stats->protocol, candidate.protocol()); | |
| 512 EXPECT_EQ(*candidate_stats->candidate_type, | |
| 513 CandidateTypeToRTCIceCandidateTypeForTesting(candidate.type())); | |
| 514 EXPECT_EQ(*candidate_stats->priority, | |
| 515 static_cast<int32_t>(candidate.priority())); | |
| 516 // TODO(hbos): Define candidate_stats->url. crbug.com/632723 | |
| 517 EXPECT_FALSE(candidate_stats->url.is_defined()); | |
| 518 return candidate_stats; | |
| 519 } | |
| 520 | |
| 521 void ExpectReportContainsCertificateInfo( | 497 void ExpectReportContainsCertificateInfo( |
| 522 const rtc::scoped_refptr<const RTCStatsReport>& report, | 498 const rtc::scoped_refptr<const RTCStatsReport>& report, |
| 523 const CertificateInfo& cert_info) { | 499 const CertificateInfo& cert_info) { |
| 524 for (size_t i = 0; i < cert_info.fingerprints.size(); ++i) { | 500 for (size_t i = 0; i < cert_info.fingerprints.size(); ++i) { |
| 525 const RTCStats* stats = report->Get( | 501 const RTCStats* stats = report->Get( |
| 526 "RTCCertificate_" + cert_info.fingerprints[i]); | 502 "RTCCertificate_" + cert_info.fingerprints[i]); |
| 527 ASSERT_TRUE(stats); | 503 ASSERT_TRUE(stats); |
| 528 const RTCCertificateStats& cert_stats = | 504 const RTCCertificateStats& cert_stats = |
| 529 stats->cast_to<const RTCCertificateStats>(); | 505 stats->cast_to<const RTCCertificateStats>(); |
| 530 EXPECT_EQ(*cert_stats.fingerprint, cert_info.fingerprints[i]); | 506 EXPECT_EQ(*cert_stats.fingerprint, cert_info.fingerprints[i]); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 982 session_stats.transport_stats["b"].channel_stats.push_back( | 958 session_stats.transport_stats["b"].channel_stats.push_back( |
| 983 b_transport_channel_stats); | 959 b_transport_channel_stats); |
| 984 | 960 |
| 985 // Mock the session to return the desired candidates. | 961 // Mock the session to return the desired candidates. |
| 986 EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( | 962 EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( |
| 987 [&session_stats](const ChannelNamePairs&) { | 963 [&session_stats](const ChannelNamePairs&) { |
| 988 return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); | 964 return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
| 989 })); | 965 })); |
| 990 | 966 |
| 991 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 967 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 992 ExpectReportContainsCandidate(report, *a_local_host.get(), true); | 968 |
| 993 ExpectReportContainsCandidate(report, *a_remote_srflx.get(), false); | 969 RTCLocalIceCandidateStats expected_a_local_host( |
| 994 ExpectReportContainsCandidate(report, *a_local_prflx.get(), true); | 970 "RTCIceCandidate_" + a_local_host->id(), report->timestamp_us()); |
| 995 ExpectReportContainsCandidate(report, *a_remote_relay.get(), false); | 971 expected_a_local_host.ip = "1.2.3.4"; |
| 996 ExpectReportContainsCandidate(report, *b_local.get(), true); | 972 expected_a_local_host.port = 5; |
| 997 ExpectReportContainsCandidate(report, *b_remote.get(), false); | 973 expected_a_local_host.protocol = "a_local_host's protocol"; |
| 974 expected_a_local_host.candidate_type = "host"; | |
| 975 expected_a_local_host.priority = 0; | |
| 976 EXPECT_TRUE(report->Get(expected_a_local_host.id())); | |
| 977 EXPECT_EQ(expected_a_local_host, | |
| 978 report->Get(expected_a_local_host.id())->cast_to< | |
| 979 RTCLocalIceCandidateStats>()); | |
|
Taylor Brandstetter
2016/12/20 19:56:43
nit: It may make sense to create the "expected sta
hbos
2016/12/21 09:42:07
Done.
| |
| 980 | |
| 981 RTCRemoteIceCandidateStats expected_a_remote_srflx( | |
| 982 "RTCIceCandidate_" + a_remote_srflx->id(), report->timestamp_us()); | |
| 983 expected_a_remote_srflx.ip = "6.7.8.9"; | |
| 984 expected_a_remote_srflx.port = 10; | |
| 985 expected_a_remote_srflx.protocol = "remote_srflx's protocol"; | |
| 986 expected_a_remote_srflx.candidate_type = "srflx"; | |
| 987 expected_a_remote_srflx.priority = 1; | |
| 988 EXPECT_TRUE(report->Get(expected_a_remote_srflx.id())); | |
| 989 EXPECT_EQ(expected_a_remote_srflx, | |
| 990 report->Get(expected_a_remote_srflx.id())->cast_to< | |
| 991 RTCRemoteIceCandidateStats>()); | |
| 992 | |
| 993 RTCLocalIceCandidateStats expected_a_local_prflx( | |
| 994 "RTCIceCandidate_" + a_local_prflx->id(), report->timestamp_us()); | |
| 995 expected_a_local_prflx.ip = "11.12.13.14"; | |
| 996 expected_a_local_prflx.port = 15; | |
| 997 expected_a_local_prflx.protocol = "a_local_prflx's protocol"; | |
| 998 expected_a_local_prflx.candidate_type = "prflx"; | |
| 999 expected_a_local_prflx.priority = 2; | |
| 1000 EXPECT_TRUE(report->Get(expected_a_local_prflx.id())); | |
| 1001 EXPECT_EQ(expected_a_local_prflx, | |
| 1002 report->Get(expected_a_local_prflx.id())->cast_to< | |
| 1003 RTCLocalIceCandidateStats>()); | |
| 1004 | |
| 1005 RTCRemoteIceCandidateStats expected_a_remote_relay( | |
| 1006 "RTCIceCandidate_" + a_remote_relay->id(), report->timestamp_us()); | |
| 1007 expected_a_remote_relay.ip = "16.17.18.19"; | |
| 1008 expected_a_remote_relay.port = 20; | |
| 1009 expected_a_remote_relay.protocol = "a_remote_relay's protocol"; | |
| 1010 expected_a_remote_relay.candidate_type = "relay"; | |
| 1011 expected_a_remote_relay.priority = 3; | |
| 1012 EXPECT_TRUE(report->Get(expected_a_remote_relay.id())); | |
| 1013 EXPECT_EQ(expected_a_remote_relay, | |
| 1014 report->Get(expected_a_remote_relay.id())->cast_to< | |
| 1015 RTCRemoteIceCandidateStats>()); | |
| 1016 | |
| 1017 RTCLocalIceCandidateStats expected_b_local( | |
| 1018 "RTCIceCandidate_" + b_local->id(), report->timestamp_us()); | |
| 1019 expected_b_local.ip = "42.42.42.42"; | |
| 1020 expected_b_local.port = 42; | |
| 1021 expected_b_local.protocol = "b_local's protocol"; | |
| 1022 expected_b_local.candidate_type = "host"; | |
| 1023 expected_b_local.priority = 42; | |
| 1024 EXPECT_TRUE(report->Get(expected_b_local.id())); | |
| 1025 EXPECT_EQ(expected_b_local, | |
| 1026 report->Get(expected_b_local.id())->cast_to< | |
| 1027 RTCLocalIceCandidateStats>()); | |
| 1028 | |
| 1029 RTCRemoteIceCandidateStats expected_b_remote( | |
| 1030 "RTCIceCandidate_" + b_remote->id(), report->timestamp_us()); | |
| 1031 expected_b_remote.ip = "42.42.42.42"; | |
| 1032 expected_b_remote.port = 42; | |
| 1033 expected_b_remote.protocol = "b_remote's protocol"; | |
| 1034 expected_b_remote.candidate_type = "host"; | |
| 1035 expected_b_remote.priority = 42; | |
| 1036 EXPECT_TRUE(report->Get(expected_b_remote.id())); | |
| 1037 EXPECT_EQ(expected_b_remote, | |
| 1038 report->Get(expected_b_remote.id())->cast_to< | |
| 1039 RTCRemoteIceCandidateStats>()); | |
| 998 } | 1040 } |
| 999 | 1041 |
| 1000 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { | 1042 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { |
| 1001 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( | 1043 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( |
| 1002 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | 1044 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
| 1003 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( | 1045 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( |
| 1004 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | 1046 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
| 1005 | 1047 |
| 1006 SessionStats session_stats; | 1048 SessionStats session_stats; |
| 1007 | 1049 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1051 expected_pair.requests_sent = 2000; | 1093 expected_pair.requests_sent = 2000; |
| 1052 expected_pair.responses_received = 4321; | 1094 expected_pair.responses_received = 4321; |
| 1053 expected_pair.responses_sent = 1000; | 1095 expected_pair.responses_sent = 1000; |
| 1054 expected_pair.consent_requests_sent = (2020 - 2000); | 1096 expected_pair.consent_requests_sent = (2020 - 2000); |
| 1055 | 1097 |
| 1056 EXPECT_TRUE(report->Get(expected_pair.id())); | 1098 EXPECT_TRUE(report->Get(expected_pair.id())); |
| 1057 EXPECT_EQ( | 1099 EXPECT_EQ( |
| 1058 expected_pair, | 1100 expected_pair, |
| 1059 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); | 1101 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
| 1060 | 1102 |
| 1061 EXPECT_TRUE(report->Get(*expected_pair.local_candidate_id)); | 1103 RTCLocalIceCandidateStats expected_local_candidate( |
| 1062 ExpectReportContainsCandidate(report, connection_info.local_candidate, true); | 1104 *expected_pair.local_candidate_id, report->timestamp_us()); |
| 1063 EXPECT_TRUE(report->Get(*expected_pair.remote_candidate_id)); | 1105 expected_local_candidate.ip = "42.42.42.42"; |
| 1064 ExpectReportContainsCandidate(report, connection_info.remote_candidate, | 1106 expected_local_candidate.port = 42; |
| 1065 false); | 1107 expected_local_candidate.protocol = "protocol"; |
| 1108 expected_local_candidate.candidate_type = "host"; | |
| 1109 expected_local_candidate.priority = 42; | |
| 1110 ASSERT_TRUE(report->Get(expected_local_candidate.id())); | |
| 1111 EXPECT_EQ(expected_local_candidate, | |
| 1112 report->Get(expected_local_candidate.id())->cast_to< | |
| 1113 RTCLocalIceCandidateStats>()); | |
| 1114 | |
| 1115 RTCRemoteIceCandidateStats expected_remote_candidate( | |
| 1116 *expected_pair.remote_candidate_id, report->timestamp_us()); | |
| 1117 expected_remote_candidate.ip = "42.42.42.42"; | |
| 1118 expected_remote_candidate.port = 42; | |
| 1119 expected_remote_candidate.protocol = "protocol"; | |
| 1120 expected_remote_candidate.candidate_type = "host"; | |
| 1121 expected_remote_candidate.priority = 42; | |
| 1122 ASSERT_TRUE(report->Get(expected_remote_candidate.id())); | |
| 1123 EXPECT_EQ(expected_remote_candidate, | |
| 1124 report->Get(expected_remote_candidate.id())->cast_to< | |
| 1125 RTCRemoteIceCandidateStats>()); | |
| 1066 } | 1126 } |
| 1067 | 1127 |
| 1068 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { | 1128 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { |
| 1069 { | 1129 { |
| 1070 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 1130 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1071 RTCPeerConnectionStats expected("RTCPeerConnection", | 1131 RTCPeerConnectionStats expected("RTCPeerConnection", |
| 1072 report->timestamp_us()); | 1132 report->timestamp_us()); |
| 1073 expected.data_channels_opened = 0; | 1133 expected.data_channels_opened = 0; |
| 1074 expected.data_channels_closed = 0; | 1134 expected.data_channels_closed = 0; |
| 1075 EXPECT_TRUE(report->Get("RTCPeerConnection")); | 1135 EXPECT_TRUE(report->Get("RTCPeerConnection")); |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1907 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | 1967 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
| 1908 }; | 1968 }; |
| 1909 | 1969 |
| 1910 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 1970 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
| 1911 collector_->VerifyThreadUsageAndResultsMerging(); | 1971 collector_->VerifyThreadUsageAndResultsMerging(); |
| 1912 } | 1972 } |
| 1913 | 1973 |
| 1914 } // namespace | 1974 } // namespace |
| 1915 | 1975 |
| 1916 } // namespace webrtc | 1976 } // namespace webrtc |
| OLD | NEW |