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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 RTCDataChannelStats>()); | 913 RTCDataChannelStats>()); |
938 } | 914 } |
939 | 915 |
940 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) { | 916 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) { |
941 // Candidates in the first transport stats. | 917 // Candidates in the first transport stats. |
942 std::unique_ptr<cricket::Candidate> a_local_host = CreateFakeCandidate( | 918 std::unique_ptr<cricket::Candidate> a_local_host = CreateFakeCandidate( |
943 "1.2.3.4", 5, | 919 "1.2.3.4", 5, |
944 "a_local_host's protocol", | 920 "a_local_host's protocol", |
945 cricket::LOCAL_PORT_TYPE, | 921 cricket::LOCAL_PORT_TYPE, |
946 0); | 922 0); |
| 923 RTCLocalIceCandidateStats expected_a_local_host( |
| 924 "RTCIceCandidate_" + a_local_host->id(), 0); |
| 925 expected_a_local_host.ip = "1.2.3.4"; |
| 926 expected_a_local_host.port = 5; |
| 927 expected_a_local_host.protocol = "a_local_host's protocol"; |
| 928 expected_a_local_host.candidate_type = "host"; |
| 929 expected_a_local_host.priority = 0; |
| 930 |
947 std::unique_ptr<cricket::Candidate> a_remote_srflx = CreateFakeCandidate( | 931 std::unique_ptr<cricket::Candidate> a_remote_srflx = CreateFakeCandidate( |
948 "6.7.8.9", 10, | 932 "6.7.8.9", 10, |
949 "remote_srflx's protocol", | 933 "remote_srflx's protocol", |
950 cricket::STUN_PORT_TYPE, | 934 cricket::STUN_PORT_TYPE, |
951 1); | 935 1); |
| 936 RTCRemoteIceCandidateStats expected_a_remote_srflx( |
| 937 "RTCIceCandidate_" + a_remote_srflx->id(), 0); |
| 938 expected_a_remote_srflx.ip = "6.7.8.9"; |
| 939 expected_a_remote_srflx.port = 10; |
| 940 expected_a_remote_srflx.protocol = "remote_srflx's protocol"; |
| 941 expected_a_remote_srflx.candidate_type = "srflx"; |
| 942 expected_a_remote_srflx.priority = 1; |
| 943 |
952 std::unique_ptr<cricket::Candidate> a_local_prflx = CreateFakeCandidate( | 944 std::unique_ptr<cricket::Candidate> a_local_prflx = CreateFakeCandidate( |
953 "11.12.13.14", 15, | 945 "11.12.13.14", 15, |
954 "a_local_prflx's protocol", | 946 "a_local_prflx's protocol", |
955 cricket::PRFLX_PORT_TYPE, | 947 cricket::PRFLX_PORT_TYPE, |
956 2); | 948 2); |
| 949 RTCLocalIceCandidateStats expected_a_local_prflx( |
| 950 "RTCIceCandidate_" + a_local_prflx->id(), 0); |
| 951 expected_a_local_prflx.ip = "11.12.13.14"; |
| 952 expected_a_local_prflx.port = 15; |
| 953 expected_a_local_prflx.protocol = "a_local_prflx's protocol"; |
| 954 expected_a_local_prflx.candidate_type = "prflx"; |
| 955 expected_a_local_prflx.priority = 2; |
| 956 |
957 std::unique_ptr<cricket::Candidate> a_remote_relay = CreateFakeCandidate( | 957 std::unique_ptr<cricket::Candidate> a_remote_relay = CreateFakeCandidate( |
958 "16.17.18.19", 20, | 958 "16.17.18.19", 20, |
959 "a_remote_relay's protocol", | 959 "a_remote_relay's protocol", |
960 cricket::RELAY_PORT_TYPE, | 960 cricket::RELAY_PORT_TYPE, |
961 3); | 961 3); |
| 962 RTCRemoteIceCandidateStats expected_a_remote_relay( |
| 963 "RTCIceCandidate_" + a_remote_relay->id(), 0); |
| 964 expected_a_remote_relay.ip = "16.17.18.19"; |
| 965 expected_a_remote_relay.port = 20; |
| 966 expected_a_remote_relay.protocol = "a_remote_relay's protocol"; |
| 967 expected_a_remote_relay.candidate_type = "relay"; |
| 968 expected_a_remote_relay.priority = 3; |
| 969 |
962 // Candidates in the second transport stats. | 970 // Candidates in the second transport stats. |
963 std::unique_ptr<cricket::Candidate> b_local = CreateFakeCandidate( | 971 std::unique_ptr<cricket::Candidate> b_local = CreateFakeCandidate( |
964 "42.42.42.42", 42, | 972 "42.42.42.42", 42, |
965 "b_local's protocol", | 973 "b_local's protocol", |
966 cricket::LOCAL_PORT_TYPE, | 974 cricket::LOCAL_PORT_TYPE, |
967 42); | 975 42); |
| 976 RTCLocalIceCandidateStats expected_b_local( |
| 977 "RTCIceCandidate_" + b_local->id(), 0); |
| 978 expected_b_local.ip = "42.42.42.42"; |
| 979 expected_b_local.port = 42; |
| 980 expected_b_local.protocol = "b_local's protocol"; |
| 981 expected_b_local.candidate_type = "host"; |
| 982 expected_b_local.priority = 42; |
| 983 |
968 std::unique_ptr<cricket::Candidate> b_remote = CreateFakeCandidate( | 984 std::unique_ptr<cricket::Candidate> b_remote = CreateFakeCandidate( |
969 "42.42.42.42", 42, | 985 "42.42.42.42", 42, |
970 "b_remote's protocol", | 986 "b_remote's protocol", |
971 cricket::LOCAL_PORT_TYPE, | 987 cricket::LOCAL_PORT_TYPE, |
972 42); | 988 42); |
| 989 RTCRemoteIceCandidateStats expected_b_remote( |
| 990 "RTCIceCandidate_" + b_remote->id(), 0); |
| 991 expected_b_remote.ip = "42.42.42.42"; |
| 992 expected_b_remote.port = 42; |
| 993 expected_b_remote.protocol = "b_remote's protocol"; |
| 994 expected_b_remote.candidate_type = "host"; |
| 995 expected_b_remote.priority = 42; |
973 | 996 |
974 SessionStats session_stats; | 997 SessionStats session_stats; |
975 | 998 |
976 cricket::TransportChannelStats a_transport_channel_stats; | 999 cricket::TransportChannelStats a_transport_channel_stats; |
977 a_transport_channel_stats.connection_infos.push_back( | 1000 a_transport_channel_stats.connection_infos.push_back( |
978 cricket::ConnectionInfo()); | 1001 cricket::ConnectionInfo()); |
979 a_transport_channel_stats.connection_infos[0].local_candidate = | 1002 a_transport_channel_stats.connection_infos[0].local_candidate = |
980 *a_local_host.get(); | 1003 *a_local_host.get(); |
981 a_transport_channel_stats.connection_infos[0].remote_candidate = | 1004 a_transport_channel_stats.connection_infos[0].remote_candidate = |
982 *a_remote_srflx.get(); | 1005 *a_remote_srflx.get(); |
(...skipping 18 matching lines...) Expand all Loading... |
1001 session_stats.transport_stats["b"].channel_stats.push_back( | 1024 session_stats.transport_stats["b"].channel_stats.push_back( |
1002 b_transport_channel_stats); | 1025 b_transport_channel_stats); |
1003 | 1026 |
1004 // Mock the session to return the desired candidates. | 1027 // Mock the session to return the desired candidates. |
1005 EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( | 1028 EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( |
1006 [&session_stats](const ChannelNamePairs&) { | 1029 [&session_stats](const ChannelNamePairs&) { |
1007 return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); | 1030 return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
1008 })); | 1031 })); |
1009 | 1032 |
1010 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 1033 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
1011 ExpectReportContainsCandidate(report, *a_local_host.get(), true); | 1034 |
1012 ExpectReportContainsCandidate(report, *a_remote_srflx.get(), false); | 1035 EXPECT_TRUE(report->Get(expected_a_local_host.id())); |
1013 ExpectReportContainsCandidate(report, *a_local_prflx.get(), true); | 1036 EXPECT_EQ(expected_a_local_host, |
1014 ExpectReportContainsCandidate(report, *a_remote_relay.get(), false); | 1037 report->Get(expected_a_local_host.id())->cast_to< |
1015 ExpectReportContainsCandidate(report, *b_local.get(), true); | 1038 RTCLocalIceCandidateStats>()); |
1016 ExpectReportContainsCandidate(report, *b_remote.get(), false); | 1039 EXPECT_TRUE(report->Get(expected_a_remote_srflx.id())); |
| 1040 EXPECT_EQ(expected_a_remote_srflx, |
| 1041 report->Get(expected_a_remote_srflx.id())->cast_to< |
| 1042 RTCRemoteIceCandidateStats>()); |
| 1043 EXPECT_TRUE(report->Get(expected_a_local_prflx.id())); |
| 1044 EXPECT_EQ(expected_a_local_prflx, |
| 1045 report->Get(expected_a_local_prflx.id())->cast_to< |
| 1046 RTCLocalIceCandidateStats>()); |
| 1047 EXPECT_TRUE(report->Get(expected_a_remote_relay.id())); |
| 1048 EXPECT_EQ(expected_a_remote_relay, |
| 1049 report->Get(expected_a_remote_relay.id())->cast_to< |
| 1050 RTCRemoteIceCandidateStats>()); |
| 1051 EXPECT_TRUE(report->Get(expected_b_local.id())); |
| 1052 EXPECT_EQ(expected_b_local, |
| 1053 report->Get(expected_b_local.id())->cast_to< |
| 1054 RTCLocalIceCandidateStats>()); |
| 1055 EXPECT_TRUE(report->Get(expected_b_remote.id())); |
| 1056 EXPECT_EQ(expected_b_remote, |
| 1057 report->Get(expected_b_remote.id())->cast_to< |
| 1058 RTCRemoteIceCandidateStats>()); |
1017 } | 1059 } |
1018 | 1060 |
1019 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { | 1061 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { |
1020 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( | 1062 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( |
1021 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | 1063 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
1022 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( | 1064 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( |
1023 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | 1065 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
1024 | 1066 |
1025 SessionStats session_stats; | 1067 SessionStats session_stats; |
1026 | 1068 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 expected_pair.requests_sent = 2000; | 1112 expected_pair.requests_sent = 2000; |
1071 expected_pair.responses_received = 4321; | 1113 expected_pair.responses_received = 4321; |
1072 expected_pair.responses_sent = 1000; | 1114 expected_pair.responses_sent = 1000; |
1073 expected_pair.consent_requests_sent = (2020 - 2000); | 1115 expected_pair.consent_requests_sent = (2020 - 2000); |
1074 | 1116 |
1075 ASSERT_TRUE(report->Get(expected_pair.id())); | 1117 ASSERT_TRUE(report->Get(expected_pair.id())); |
1076 EXPECT_EQ( | 1118 EXPECT_EQ( |
1077 expected_pair, | 1119 expected_pair, |
1078 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); | 1120 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
1079 | 1121 |
1080 ASSERT_TRUE(report->Get(*expected_pair.local_candidate_id)); | 1122 RTCLocalIceCandidateStats expected_local_candidate( |
1081 ExpectReportContainsCandidate(report, connection_info.local_candidate, true); | 1123 *expected_pair.local_candidate_id, report->timestamp_us()); |
1082 ASSERT_TRUE(report->Get(*expected_pair.remote_candidate_id)); | 1124 expected_local_candidate.ip = "42.42.42.42"; |
1083 ExpectReportContainsCandidate(report, connection_info.remote_candidate, | 1125 expected_local_candidate.port = 42; |
1084 false); | 1126 expected_local_candidate.protocol = "protocol"; |
| 1127 expected_local_candidate.candidate_type = "host"; |
| 1128 expected_local_candidate.priority = 42; |
| 1129 ASSERT_TRUE(report->Get(expected_local_candidate.id())); |
| 1130 EXPECT_EQ(expected_local_candidate, |
| 1131 report->Get(expected_local_candidate.id())->cast_to< |
| 1132 RTCLocalIceCandidateStats>()); |
| 1133 |
| 1134 RTCRemoteIceCandidateStats expected_remote_candidate( |
| 1135 *expected_pair.remote_candidate_id, report->timestamp_us()); |
| 1136 expected_remote_candidate.ip = "42.42.42.42"; |
| 1137 expected_remote_candidate.port = 42; |
| 1138 expected_remote_candidate.protocol = "protocol"; |
| 1139 expected_remote_candidate.candidate_type = "host"; |
| 1140 expected_remote_candidate.priority = 42; |
| 1141 ASSERT_TRUE(report->Get(expected_remote_candidate.id())); |
| 1142 EXPECT_EQ(expected_remote_candidate, |
| 1143 report->Get(expected_remote_candidate.id())->cast_to< |
| 1144 RTCRemoteIceCandidateStats>()); |
1085 } | 1145 } |
1086 | 1146 |
1087 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { | 1147 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { |
1088 { | 1148 { |
1089 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 1149 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
1090 RTCPeerConnectionStats expected("RTCPeerConnection", | 1150 RTCPeerConnectionStats expected("RTCPeerConnection", |
1091 report->timestamp_us()); | 1151 report->timestamp_us()); |
1092 expected.data_channels_opened = 0; | 1152 expected.data_channels_opened = 0; |
1093 expected.data_channels_closed = 0; | 1153 expected.data_channels_closed = 0; |
1094 ASSERT_TRUE(report->Get("RTCPeerConnection")); | 1154 ASSERT_TRUE(report->Get("RTCPeerConnection")); |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1926 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | 1986 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
1927 }; | 1987 }; |
1928 | 1988 |
1929 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 1989 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
1930 collector_->VerifyThreadUsageAndResultsMerging(); | 1990 collector_->VerifyThreadUsageAndResultsMerging(); |
1931 } | 1991 } |
1932 | 1992 |
1933 } // namespace | 1993 } // namespace |
1934 | 1994 |
1935 } // namespace webrtc | 1995 } // namespace webrtc |
OLD | NEW |