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

Side by Side Diff: pc/statscollector_unittest.cc

Issue 3007973002: Mark template class RefCountedObject as final.
Patch Set: Rebased. Created 3 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2014 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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 protected: 565 protected:
566 StatsCollectorTest() 566 StatsCollectorTest()
567 : worker_thread_(rtc::Thread::Current()), 567 : worker_thread_(rtc::Thread::Current()),
568 network_thread_(rtc::Thread::Current()), 568 network_thread_(rtc::Thread::Current()),
569 media_engine_(new cricket::FakeMediaEngine()), 569 media_engine_(new cricket::FakeMediaEngine()),
570 channel_manager_(new cricket::ChannelManager( 570 channel_manager_(new cricket::ChannelManager(
571 std::unique_ptr<cricket::MediaEngineInterface>(media_engine_), 571 std::unique_ptr<cricket::MediaEngineInterface>(media_engine_),
572 worker_thread_, 572 worker_thread_,
573 network_thread_)), 573 network_thread_)),
574 574
575 session_(channel_manager_.get(), cricket::MediaConfig()) { 575 session_(channel_manager_.get(), cricket::MediaConfig()),
576 pc_(new rtc::RefCountedObject<MockPeerConnection>()) {
576 // By default, we ignore session GetStats calls. 577 // By default, we ignore session GetStats calls.
577 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(ReturnNull()); 578 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(ReturnNull());
578 // Add default returns for mock classes. 579 // Add default returns for mock classes.
579 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull()); 580 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
580 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull()); 581 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
581 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_)); 582 EXPECT_CALL(*pc_, session()).WillRepeatedly(Return(&session_));
582 EXPECT_CALL(pc_, sctp_data_channels()) 583 EXPECT_CALL(*pc_, sctp_data_channels())
583 .WillRepeatedly(ReturnRef(data_channels_)); 584 .WillRepeatedly(ReturnRef(data_channels_));
584 EXPECT_CALL(pc_, GetSenders()).WillRepeatedly(Return( 585 EXPECT_CALL(*pc_, GetSenders()).WillRepeatedly(Return(
585 std::vector<rtc::scoped_refptr<RtpSenderInterface>>())); 586 std::vector<rtc::scoped_refptr<RtpSenderInterface>>()));
586 EXPECT_CALL(pc_, GetReceivers()).WillRepeatedly(Return( 587 EXPECT_CALL(*pc_, GetReceivers()).WillRepeatedly(Return(
587 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>())); 588 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>()));
588 } 589 }
589 590
590 ~StatsCollectorTest() {} 591 ~StatsCollectorTest() {}
591 592
592 // This creates a standard setup with a transport called "trspname" 593 // This creates a standard setup with a transport called "trspname"
593 // having one transport channel 594 // having one transport channel
594 // and the specified virtual connection name. 595 // and the specified virtual connection name.
595 void InitSessionStats(const std::string& vc_name) { 596 void InitSessionStats(const std::string& vc_name) {
596 const std::string kTransportName("trspname"); 597 const std::string kTransportName("trspname");
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 VerifyVoiceSenderInfoReport(track_report, *voice_sender_info); 748 VerifyVoiceSenderInfoReport(track_report, *voice_sender_info);
748 if (voice_receiver_info) 749 if (voice_receiver_info)
749 VerifyVoiceReceiverInfoReport(track_report, *voice_receiver_info); 750 VerifyVoiceReceiverInfoReport(track_report, *voice_receiver_info);
750 } 751 }
751 752
752 void TestCertificateReports( 753 void TestCertificateReports(
753 const rtc::FakeSSLCertificate& local_cert, 754 const rtc::FakeSSLCertificate& local_cert,
754 const std::vector<std::string>& local_ders, 755 const std::vector<std::string>& local_ders,
755 std::unique_ptr<rtc::FakeSSLCertificate> remote_cert, 756 std::unique_ptr<rtc::FakeSSLCertificate> remote_cert,
756 const std::vector<std::string>& remote_ders) { 757 const std::vector<std::string>& remote_ders) {
757 StatsCollectorForTest stats(&pc_); 758 StatsCollectorForTest stats(pc_);
758 759
759 StatsReports reports; // returned values. 760 StatsReports reports; // returned values.
760 761
761 // Fake stats to process. 762 // Fake stats to process.
762 cricket::TransportChannelStats channel_stats; 763 cricket::TransportChannelStats channel_stats;
763 channel_stats.component = 1; 764 channel_stats.component = 1;
764 channel_stats.srtp_crypto_suite = rtc::SRTP_AES128_CM_SHA1_80; 765 channel_stats.srtp_crypto_suite = rtc::SRTP_AES128_CM_SHA1_80;
765 channel_stats.ssl_cipher_suite = 766 channel_stats.ssl_cipher_suite =
766 internal::TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA; 767 internal::TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA;
767 768
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 srtp_crypto_suite); 840 srtp_crypto_suite);
840 } 841 }
841 842
842 webrtc::RtcEventLogNullImpl event_log_; 843 webrtc::RtcEventLogNullImpl event_log_;
843 rtc::Thread* const worker_thread_; 844 rtc::Thread* const worker_thread_;
844 rtc::Thread* const network_thread_; 845 rtc::Thread* const network_thread_;
845 // |media_engine_| is actually owned by |channel_manager_|. 846 // |media_engine_| is actually owned by |channel_manager_|.
846 cricket::FakeMediaEngine* media_engine_; 847 cricket::FakeMediaEngine* media_engine_;
847 std::unique_ptr<cricket::ChannelManager> channel_manager_; 848 std::unique_ptr<cricket::ChannelManager> channel_manager_;
848 MockWebRtcSession session_; 849 MockWebRtcSession session_;
849 MockPeerConnection pc_; 850 rtc::scoped_refptr<MockPeerConnection> pc_;
850 FakeDataChannelProvider data_channel_provider_; 851 FakeDataChannelProvider data_channel_provider_;
851 SessionStats session_stats_; 852 SessionStats session_stats_;
852 rtc::scoped_refptr<webrtc::MediaStream> stream_; 853 rtc::scoped_refptr<webrtc::MediaStream> stream_;
853 rtc::scoped_refptr<webrtc::VideoTrack> track_; 854 rtc::scoped_refptr<webrtc::VideoTrack> track_;
854 rtc::scoped_refptr<FakeAudioTrack> audio_track_; 855 rtc::scoped_refptr<FakeAudioTrack> audio_track_;
855 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_; 856 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_;
856 }; 857 };
857 858
858 TEST_F(StatsCollectorTest, FilterOutNegativeDataChannelId) { 859 TEST_F(StatsCollectorTest, FilterOutNegativeDataChannelId) {
859 const std::string label = "hacks"; 860 const std::string label = "hacks";
860 // The data channel id is from the Config which is -1 initially. 861 // The data channel id is from the Config which is -1 initially.
861 const int id = -1; 862 const int id = -1;
862 const std::string state = DataChannelInterface::DataStateString( 863 const std::string state = DataChannelInterface::DataStateString(
863 DataChannelInterface::DataState::kConnecting); 864 DataChannelInterface::DataState::kConnecting);
864 865
865 AddDataChannel(cricket::DCT_SCTP, label, id); 866 AddDataChannel(cricket::DCT_SCTP, label, id);
866 StatsCollectorForTest stats(&pc_); 867 StatsCollectorForTest stats(pc_);
867 868
868 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 869 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
869 870
870 StatsReports reports; 871 StatsReports reports;
871 stats.GetStats(NULL, &reports); 872 stats.GetStats(NULL, &reports);
872 873
873 const StatsReport* report = 874 const StatsReport* report =
874 FindNthReportByType(reports, StatsReport::kStatsReportTypeDataChannel, 1); 875 FindNthReportByType(reports, StatsReport::kStatsReportTypeDataChannel, 1);
875 876
876 std::string value_in_report; 877 std::string value_in_report;
877 EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameDataChannelId, 878 EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameDataChannelId,
878 &value_in_report)); 879 &value_in_report));
879 } 880 }
880 881
881 // Verify that ExtractDataInfo populates reports. 882 // Verify that ExtractDataInfo populates reports.
882 TEST_F(StatsCollectorTest, ExtractDataInfo) { 883 TEST_F(StatsCollectorTest, ExtractDataInfo) {
883 const std::string label = "hacks"; 884 const std::string label = "hacks";
884 const int id = 31337; 885 const int id = 31337;
885 const std::string state = DataChannelInterface::DataStateString( 886 const std::string state = DataChannelInterface::DataStateString(
886 DataChannelInterface::DataState::kConnecting); 887 DataChannelInterface::DataState::kConnecting);
887 888
888 AddDataChannel(cricket::DCT_SCTP, label, id); 889 AddDataChannel(cricket::DCT_SCTP, label, id);
889 StatsCollectorForTest stats(&pc_); 890 StatsCollectorForTest stats(pc_);
890 891
891 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 892 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
892 893
893 StatsReports reports; 894 StatsReports reports;
894 stats.GetStats(NULL, &reports); 895 stats.GetStats(NULL, &reports);
895 896
896 const StatsReport* report = 897 const StatsReport* report =
897 FindNthReportByType(reports, StatsReport::kStatsReportTypeDataChannel, 1); 898 FindNthReportByType(reports, StatsReport::kStatsReportTypeDataChannel, 1);
898 899
899 StatsReport::Id reportId = StatsReport::NewTypedIntId( 900 StatsReport::Id reportId = StatsReport::NewTypedIntId(
(...skipping 11 matching lines...) Expand all
911 EXPECT_EQ(state, ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel, 912 EXPECT_EQ(state, ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel,
912 reports, 913 reports,
913 StatsReport::kStatsValueNameState)); 914 StatsReport::kStatsValueNameState));
914 EXPECT_EQ("", ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel, 915 EXPECT_EQ("", ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel,
915 reports, 916 reports,
916 StatsReport::kStatsValueNameProtocol)); 917 StatsReport::kStatsValueNameProtocol));
917 } 918 }
918 919
919 // This test verifies that 64-bit counters are passed successfully. 920 // This test verifies that 64-bit counters are passed successfully.
920 TEST_F(StatsCollectorTest, BytesCounterHandles64Bits) { 921 TEST_F(StatsCollectorTest, BytesCounterHandles64Bits) {
921 StatsCollectorForTest stats(&pc_); 922 StatsCollectorForTest stats(pc_);
922 923
923 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 924 EXPECT_CALL(session_, GetLocalCertificate(_, _))
924 .WillRepeatedly(Return(false)); 925 .WillRepeatedly(Return(false));
925 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 926 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
926 .WillRepeatedly(Return(nullptr)); 927 .WillRepeatedly(Return(nullptr));
927 928
928 const char kVideoChannelName[] = "video"; 929 const char kVideoChannelName[] = "video";
929 930
930 InitSessionStats(kVideoChannelName); 931 InitSessionStats(kVideoChannelName);
931 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke( 932 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
(...skipping 28 matching lines...) Expand all
960 Return(true))); 961 Return(true)));
961 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 962 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
962 stats.GetStats(NULL, &reports); 963 stats.GetStats(NULL, &reports);
963 std::string result = ExtractSsrcStatsValue(reports, 964 std::string result = ExtractSsrcStatsValue(reports,
964 StatsReport::kStatsValueNameBytesSent); 965 StatsReport::kStatsValueNameBytesSent);
965 EXPECT_EQ(kBytesSentString, result); 966 EXPECT_EQ(kBytesSentString, result);
966 } 967 }
967 968
968 // Test that audio BWE information is reported via stats. 969 // Test that audio BWE information is reported via stats.
969 TEST_F(StatsCollectorTest, AudioBandwidthEstimationInfoIsReported) { 970 TEST_F(StatsCollectorTest, AudioBandwidthEstimationInfoIsReported) {
970 StatsCollectorForTest stats(&pc_); 971 StatsCollectorForTest stats(pc_);
971 972
972 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 973 EXPECT_CALL(session_, GetLocalCertificate(_, _))
973 .WillRepeatedly(Return(false)); 974 .WillRepeatedly(Return(false));
974 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 975 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
975 .WillRepeatedly(Return(nullptr)); 976 .WillRepeatedly(Return(nullptr));
976 977
977 const char kAudioChannelName[] = "audio"; 978 const char kAudioChannelName[] = "audio";
978 979
979 InitSessionStats(kAudioChannelName); 980 InitSessionStats(kAudioChannelName);
980 EXPECT_CALL(session_, GetStats(_)) 981 EXPECT_CALL(session_, GetStats(_))
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 result = ExtractBweStatsValue( 1028 result = ExtractBweStatsValue(
1028 reports, StatsReport::kStatsValueNameAvailableReceiveBandwidth); 1029 reports, StatsReport::kStatsValueNameAvailableReceiveBandwidth);
1029 EXPECT_EQ(rtc::ToString(kRecvBandwidth), result); 1030 EXPECT_EQ(rtc::ToString(kRecvBandwidth), result);
1030 result = 1031 result =
1031 ExtractBweStatsValue(reports, StatsReport::kStatsValueNameBucketDelay); 1032 ExtractBweStatsValue(reports, StatsReport::kStatsValueNameBucketDelay);
1032 EXPECT_EQ(rtc::ToString(kPacerDelay), result); 1033 EXPECT_EQ(rtc::ToString(kPacerDelay), result);
1033 } 1034 }
1034 1035
1035 // Test that video BWE information is reported via stats. 1036 // Test that video BWE information is reported via stats.
1036 TEST_F(StatsCollectorTest, VideoBandwidthEstimationInfoIsReported) { 1037 TEST_F(StatsCollectorTest, VideoBandwidthEstimationInfoIsReported) {
1037 StatsCollectorForTest stats(&pc_); 1038 StatsCollectorForTest stats(pc_);
1038 1039
1039 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1040 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1040 .WillRepeatedly(Return(false)); 1041 .WillRepeatedly(Return(false));
1041 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1042 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1042 .WillRepeatedly(Return(nullptr)); 1043 .WillRepeatedly(Return(nullptr));
1043 1044
1044 const char kVideoChannelName[] = "video"; 1045 const char kVideoChannelName[] = "video";
1045 1046
1046 InitSessionStats(kVideoChannelName); 1047 InitSessionStats(kVideoChannelName);
1047 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke( 1048 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 reports, StatsReport::kStatsValueNameAvailableReceiveBandwidth); 1097 reports, StatsReport::kStatsValueNameAvailableReceiveBandwidth);
1097 EXPECT_EQ(rtc::ToString(kRecvBandwidth), result); 1098 EXPECT_EQ(rtc::ToString(kRecvBandwidth), result);
1098 result = 1099 result =
1099 ExtractBweStatsValue(reports, StatsReport::kStatsValueNameBucketDelay); 1100 ExtractBweStatsValue(reports, StatsReport::kStatsValueNameBucketDelay);
1100 EXPECT_EQ(rtc::ToString(kPacerDelay), result); 1101 EXPECT_EQ(rtc::ToString(kPacerDelay), result);
1101 } 1102 }
1102 1103
1103 // This test verifies that an object of type "googSession" always 1104 // This test verifies that an object of type "googSession" always
1104 // exists in the returned stats. 1105 // exists in the returned stats.
1105 TEST_F(StatsCollectorTest, SessionObjectExists) { 1106 TEST_F(StatsCollectorTest, SessionObjectExists) {
1106 StatsCollectorForTest stats(&pc_); 1107 StatsCollectorForTest stats(pc_);
1107 1108
1108 StatsReports reports; // returned values. 1109 StatsReports reports; // returned values.
1109 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1110 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1110 stats.GetStats(NULL, &reports); 1111 stats.GetStats(NULL, &reports);
1111 const StatsReport* session_report = FindNthReportByType( 1112 const StatsReport* session_report = FindNthReportByType(
1112 reports, StatsReport::kStatsReportTypeSession, 1); 1113 reports, StatsReport::kStatsReportTypeSession, 1);
1113 EXPECT_FALSE(session_report == NULL); 1114 EXPECT_FALSE(session_report == NULL);
1114 } 1115 }
1115 1116
1116 // This test verifies that only one object of type "googSession" exists 1117 // This test verifies that only one object of type "googSession" exists
1117 // in the returned stats. 1118 // in the returned stats.
1118 TEST_F(StatsCollectorTest, OnlyOneSessionObjectExists) { 1119 TEST_F(StatsCollectorTest, OnlyOneSessionObjectExists) {
1119 StatsCollectorForTest stats(&pc_); 1120 StatsCollectorForTest stats(pc_);
1120 1121
1121 StatsReports reports; // returned values. 1122 StatsReports reports; // returned values.
1122 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1123 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1123 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1124 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1124 stats.GetStats(NULL, &reports); 1125 stats.GetStats(NULL, &reports);
1125 const StatsReport* session_report = FindNthReportByType( 1126 const StatsReport* session_report = FindNthReportByType(
1126 reports, StatsReport::kStatsReportTypeSession, 1); 1127 reports, StatsReport::kStatsReportTypeSession, 1);
1127 EXPECT_FALSE(session_report == NULL); 1128 EXPECT_FALSE(session_report == NULL);
1128 session_report = FindNthReportByType( 1129 session_report = FindNthReportByType(
1129 reports, StatsReport::kStatsReportTypeSession, 2); 1130 reports, StatsReport::kStatsReportTypeSession, 2);
1130 EXPECT_EQ(NULL, session_report); 1131 EXPECT_EQ(NULL, session_report);
1131 } 1132 }
1132 1133
1133 // This test verifies that the empty track report exists in the returned stats 1134 // This test verifies that the empty track report exists in the returned stats
1134 // without calling StatsCollector::UpdateStats. 1135 // without calling StatsCollector::UpdateStats.
1135 TEST_F(StatsCollectorTest, TrackObjectExistsWithoutUpdateStats) { 1136 TEST_F(StatsCollectorTest, TrackObjectExistsWithoutUpdateStats) {
1136 StatsCollectorForTest stats(&pc_); 1137 StatsCollectorForTest stats(pc_);
1137 1138
1138 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1139 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1139 cricket::VideoChannel video_channel( 1140 cricket::VideoChannel video_channel(
1140 worker_thread_, network_thread_, nullptr, media_channel, "video", 1141 worker_thread_, network_thread_, nullptr, media_channel, "video",
1141 kDefaultRtcpMuxRequired, kDefaultSrtpRequired); 1142 kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
1142 AddOutgoingVideoTrackStats(); 1143 AddOutgoingVideoTrackStats();
1143 stats.AddStream(stream_); 1144 stats.AddStream(stream_);
1144 1145
1145 // Verfies the existence of the track report. 1146 // Verfies the existence of the track report.
1146 StatsReports reports; 1147 StatsReports reports;
1147 stats.GetStats(NULL, &reports); 1148 stats.GetStats(NULL, &reports);
1148 EXPECT_EQ((size_t)1, reports.size()); 1149 EXPECT_EQ((size_t)1, reports.size());
1149 EXPECT_EQ(StatsReport::kStatsReportTypeTrack, reports[0]->type()); 1150 EXPECT_EQ(StatsReport::kStatsReportTypeTrack, reports[0]->type());
1150 EXPECT_EQ(0, reports[0]->timestamp()); 1151 EXPECT_EQ(0, reports[0]->timestamp());
1151 1152
1152 std::string trackValue = 1153 std::string trackValue =
1153 ExtractStatsValue(StatsReport::kStatsReportTypeTrack, 1154 ExtractStatsValue(StatsReport::kStatsReportTypeTrack,
1154 reports, 1155 reports,
1155 StatsReport::kStatsValueNameTrackId); 1156 StatsReport::kStatsValueNameTrackId);
1156 EXPECT_EQ(kLocalTrackId, trackValue); 1157 EXPECT_EQ(kLocalTrackId, trackValue);
1157 } 1158 }
1158 1159
1159 // This test verifies that the empty track report exists in the returned stats 1160 // This test verifies that the empty track report exists in the returned stats
1160 // when StatsCollector::UpdateStats is called with ssrc stats. 1161 // when StatsCollector::UpdateStats is called with ssrc stats.
1161 TEST_F(StatsCollectorTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) { 1162 TEST_F(StatsCollectorTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) {
1162 StatsCollectorForTest stats(&pc_); 1163 StatsCollectorForTest stats(pc_);
1163 1164
1164 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1165 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1165 .WillRepeatedly(Return(false)); 1166 .WillRepeatedly(Return(false));
1166 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1167 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1167 .WillRepeatedly(Return(nullptr)); 1168 .WillRepeatedly(Return(nullptr));
1168 1169
1169 const char kVideoChannelName[] = "video"; 1170 const char kVideoChannelName[] = "video";
1170 InitSessionStats(kVideoChannelName); 1171 InitSessionStats(kVideoChannelName);
1171 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke( 1172 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1172 [this](const ChannelNamePairs&) { 1173 [this](const ChannelNamePairs&) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 EXPECT_EQ(kLocalTrackId, track_id); 1228 EXPECT_EQ(kLocalTrackId, track_id);
1228 1229
1229 std::string media_type = ExtractSsrcStatsValue(reports, 1230 std::string media_type = ExtractSsrcStatsValue(reports,
1230 StatsReport::kStatsValueNameMediaType); 1231 StatsReport::kStatsValueNameMediaType);
1231 EXPECT_EQ("video", media_type); 1232 EXPECT_EQ("video", media_type);
1232 } 1233 }
1233 1234
1234 // This test verifies that an SSRC object has the identifier of a Transport 1235 // This test verifies that an SSRC object has the identifier of a Transport
1235 // stats object, and that this transport stats object exists in stats. 1236 // stats object, and that this transport stats object exists in stats.
1236 TEST_F(StatsCollectorTest, TransportObjectLinkedFromSsrcObject) { 1237 TEST_F(StatsCollectorTest, TransportObjectLinkedFromSsrcObject) {
1237 StatsCollectorForTest stats(&pc_); 1238 StatsCollectorForTest stats(pc_);
1238 1239
1239 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1240 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1240 .WillRepeatedly(Return(false)); 1241 .WillRepeatedly(Return(false));
1241 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1242 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1242 .WillRepeatedly(Return(nullptr)); 1243 .WillRepeatedly(Return(nullptr));
1243 1244
1244 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1245 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1245 // The transport_name known by the video channel. 1246 // The transport_name known by the video channel.
1246 const std::string kVcName("vcname"); 1247 const std::string kVcName("vcname");
1247 cricket::VideoChannel video_channel( 1248 cricket::VideoChannel video_channel(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 content = content.substr(0, index); 1294 content = content.substr(0, index);
1294 StatsReport::Id id(StatsReport::NewComponentId(content, 1)); 1295 StatsReport::Id id(StatsReport::NewComponentId(content, 1));
1295 ASSERT_EQ(transport_id, id->ToString()); 1296 ASSERT_EQ(transport_id, id->ToString());
1296 const StatsReport* transport_report = FindReportById(reports, id); 1297 const StatsReport* transport_report = FindReportById(reports, id);
1297 ASSERT_FALSE(transport_report == NULL); 1298 ASSERT_FALSE(transport_report == NULL);
1298 } 1299 }
1299 1300
1300 // This test verifies that a remote stats object will not be created for 1301 // This test verifies that a remote stats object will not be created for
1301 // an outgoing SSRC where remote stats are not returned. 1302 // an outgoing SSRC where remote stats are not returned.
1302 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsAbsent) { 1303 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsAbsent) {
1303 StatsCollectorForTest stats(&pc_); 1304 StatsCollectorForTest stats(pc_);
1304 1305
1305 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1306 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1306 // The transport_name known by the video channel. 1307 // The transport_name known by the video channel.
1307 const std::string kVcName("vcname"); 1308 const std::string kVcName("vcname");
1308 cricket::VideoChannel video_channel( 1309 cricket::VideoChannel video_channel(
1309 worker_thread_, network_thread_, nullptr, media_channel, kVcName, 1310 worker_thread_, network_thread_, nullptr, media_channel, kVcName,
1310 kDefaultRtcpMuxRequired, kDefaultSrtpRequired); 1311 kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
1311 AddOutgoingVideoTrackStats(); 1312 AddOutgoingVideoTrackStats();
1312 stats.AddStream(stream_); 1313 stats.AddStream(stream_);
1313 1314
1314 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1315 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1315 StatsReports reports; 1316 StatsReports reports;
1316 stats.GetStats(NULL, &reports); 1317 stats.GetStats(NULL, &reports);
1317 const StatsReport* remote_report = FindNthReportByType(reports, 1318 const StatsReport* remote_report = FindNthReportByType(reports,
1318 StatsReport::kStatsReportTypeRemoteSsrc, 1); 1319 StatsReport::kStatsReportTypeRemoteSsrc, 1);
1319 EXPECT_TRUE(remote_report == NULL); 1320 EXPECT_TRUE(remote_report == NULL);
1320 } 1321 }
1321 1322
1322 // This test verifies that a remote stats object will be created for 1323 // This test verifies that a remote stats object will be created for
1323 // an outgoing SSRC where stats are returned. 1324 // an outgoing SSRC where stats are returned.
1324 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsPresent) { 1325 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsPresent) {
1325 StatsCollectorForTest stats(&pc_); 1326 StatsCollectorForTest stats(pc_);
1326 1327
1327 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1328 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1328 .WillRepeatedly(Return(false)); 1329 .WillRepeatedly(Return(false));
1329 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1330 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1330 .WillRepeatedly(Return(nullptr)); 1331 .WillRepeatedly(Return(nullptr));
1331 1332
1332 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1333 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1333 // The transport_name known by the video channel. 1334 // The transport_name known by the video channel.
1334 const std::string kVcName("vcname"); 1335 const std::string kVcName("vcname");
1335 cricket::VideoChannel video_channel( 1336 cricket::VideoChannel video_channel(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 1370
1370 const StatsReport* remote_report = FindNthReportByType(reports, 1371 const StatsReport* remote_report = FindNthReportByType(reports,
1371 StatsReport::kStatsReportTypeRemoteSsrc, 1); 1372 StatsReport::kStatsReportTypeRemoteSsrc, 1);
1372 EXPECT_FALSE(remote_report == NULL); 1373 EXPECT_FALSE(remote_report == NULL);
1373 EXPECT_EQ(12345.678, remote_report->timestamp()); 1374 EXPECT_EQ(12345.678, remote_report->timestamp());
1374 } 1375 }
1375 1376
1376 // This test verifies that the empty track report exists in the returned stats 1377 // This test verifies that the empty track report exists in the returned stats
1377 // when StatsCollector::UpdateStats is called with ssrc stats. 1378 // when StatsCollector::UpdateStats is called with ssrc stats.
1378 TEST_F(StatsCollectorTest, ReportsFromRemoteTrack) { 1379 TEST_F(StatsCollectorTest, ReportsFromRemoteTrack) {
1379 StatsCollectorForTest stats(&pc_); 1380 StatsCollectorForTest stats(pc_);
1380 1381
1381 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1382 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1382 .WillRepeatedly(Return(false)); 1383 .WillRepeatedly(Return(false));
1383 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1384 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1384 .WillRepeatedly(Return(nullptr)); 1385 .WillRepeatedly(Return(nullptr));
1385 1386
1386 const char kVideoChannelName[] = "video"; 1387 const char kVideoChannelName[] = "video";
1387 InitSessionStats(kVideoChannelName); 1388 InitSessionStats(kVideoChannelName);
1388 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke( 1389 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1389 [this](const ChannelNamePairs&) { 1390 [this](const ChannelNamePairs&) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id); 1431 EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id);
1431 1432
1432 std::string track_id = ExtractSsrcStatsValue( 1433 std::string track_id = ExtractSsrcStatsValue(
1433 reports, StatsReport::kStatsValueNameTrackId); 1434 reports, StatsReport::kStatsValueNameTrackId);
1434 EXPECT_EQ(kRemoteTrackId, track_id); 1435 EXPECT_EQ(kRemoteTrackId, track_id);
1435 } 1436 }
1436 1437
1437 // This test verifies the Ice Candidate report should contain the correct 1438 // This test verifies the Ice Candidate report should contain the correct
1438 // information from local/remote candidates. 1439 // information from local/remote candidates.
1439 TEST_F(StatsCollectorTest, IceCandidateReport) { 1440 TEST_F(StatsCollectorTest, IceCandidateReport) {
1440 StatsCollectorForTest stats(&pc_); 1441 StatsCollectorForTest stats(pc_);
1441 1442
1442 StatsReports reports; // returned values. 1443 StatsReports reports; // returned values.
1443 1444
1444 const int local_port = 2000; 1445 const int local_port = 2000;
1445 const char local_ip[] = "192.168.0.1"; 1446 const char local_ip[] = "192.168.0.1";
1446 const int remote_port = 2001; 1447 const int remote_port = 2001;
1447 const char remote_ip[] = "192.168.0.2"; 1448 const char remote_ip[] = "192.168.0.2";
1448 1449
1449 rtc::SocketAddress local_address(local_ip, local_port); 1450 rtc::SocketAddress local_address(local_ip, local_port);
1450 rtc::SocketAddress remote_address(remote_ip, remote_port); 1451 rtc::SocketAddress remote_address(remote_ip, remote_port);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 new rtc::FakeSSLCertificate(DerToPem(remote_der))); 1565 new rtc::FakeSSLCertificate(DerToPem(remote_der)));
1565 1566
1566 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der), 1567 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der),
1567 std::move(remote_cert), 1568 std::move(remote_cert),
1568 std::vector<std::string>(1, remote_der)); 1569 std::vector<std::string>(1, remote_der));
1569 } 1570 }
1570 1571
1571 // This test verifies that the stats are generated correctly when no 1572 // This test verifies that the stats are generated correctly when no
1572 // transport is present. 1573 // transport is present.
1573 TEST_F(StatsCollectorTest, NoTransport) { 1574 TEST_F(StatsCollectorTest, NoTransport) {
1574 StatsCollectorForTest stats(&pc_); 1575 StatsCollectorForTest stats(pc_);
1575 1576
1576 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1577 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1577 .WillRepeatedly(Return(false)); 1578 .WillRepeatedly(Return(false));
1578 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1579 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1579 .WillRepeatedly(Return(nullptr)); 1580 .WillRepeatedly(Return(nullptr));
1580 1581
1581 StatsReports reports; // returned values. 1582 StatsReports reports; // returned values.
1582 1583
1583 // Fake stats to process. 1584 // Fake stats to process.
1584 cricket::TransportChannelStats channel_stats; 1585 cricket::TransportChannelStats channel_stats;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 ASSERT_EQ(kNotFound, dtls_cipher_suite); 1624 ASSERT_EQ(kNotFound, dtls_cipher_suite);
1624 std::string srtp_crypto_suite = 1625 std::string srtp_crypto_suite =
1625 ExtractStatsValue(StatsReport::kStatsReportTypeComponent, reports, 1626 ExtractStatsValue(StatsReport::kStatsReportTypeComponent, reports,
1626 StatsReport::kStatsValueNameSrtpCipher); 1627 StatsReport::kStatsValueNameSrtpCipher);
1627 ASSERT_EQ(kNotFound, srtp_crypto_suite); 1628 ASSERT_EQ(kNotFound, srtp_crypto_suite);
1628 } 1629 }
1629 1630
1630 // This test verifies that the stats are generated correctly when the transport 1631 // This test verifies that the stats are generated correctly when the transport
1631 // does not have any certificates. 1632 // does not have any certificates.
1632 TEST_F(StatsCollectorTest, NoCertificates) { 1633 TEST_F(StatsCollectorTest, NoCertificates) {
1633 StatsCollectorForTest stats(&pc_); 1634 StatsCollectorForTest stats(pc_);
1634 1635
1635 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1636 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1636 .WillRepeatedly(Return(false)); 1637 .WillRepeatedly(Return(false));
1637 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1638 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1638 .WillRepeatedly(Return(nullptr)); 1639 .WillRepeatedly(Return(nullptr));
1639 1640
1640 StatsReports reports; // returned values. 1641 StatsReports reports; // returned values.
1641 1642
1642 // Fake stats to process. 1643 // Fake stats to process.
1643 cricket::TransportChannelStats channel_stats; 1644 cricket::TransportChannelStats channel_stats;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 new rtc::FakeSSLCertificate(DerToPem(remote_der))); 1689 new rtc::FakeSSLCertificate(DerToPem(remote_der)));
1689 remote_cert->set_digest_algorithm("foobar"); 1690 remote_cert->set_digest_algorithm("foobar");
1690 1691
1691 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der), 1692 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der),
1692 std::move(remote_cert), std::vector<std::string>()); 1693 std::move(remote_cert), std::vector<std::string>());
1693 } 1694 }
1694 1695
1695 // This test verifies that the audio/video related stats which are -1 initially 1696 // This test verifies that the audio/video related stats which are -1 initially
1696 // will be filtered out. 1697 // will be filtered out.
1697 TEST_F(StatsCollectorTest, FilterOutNegativeInitialValues) { 1698 TEST_F(StatsCollectorTest, FilterOutNegativeInitialValues) {
1698 StatsCollectorForTest stats(&pc_); 1699 StatsCollectorForTest stats(pc_);
1699 1700
1700 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1701 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1701 .WillRepeatedly(Return(false)); 1702 .WillRepeatedly(Return(false));
1702 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1703 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1703 .WillRepeatedly(Return(nullptr)); 1704 .WillRepeatedly(Return(nullptr));
1704 1705
1705 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1706 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1706 // The transport_name known by the voice channel. 1707 // The transport_name known by the voice channel.
1707 const std::string kVcName("vcname"); 1708 const std::string kVcName("vcname");
1708 cricket::VoiceChannel voice_channel( 1709 cricket::VoiceChannel voice_channel(
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 EXPECT_FALSE(GetValue(report, 1799 EXPECT_FALSE(GetValue(report,
1799 StatsReport::kStatsValueNameCaptureStartNtpTimeMs, 1800 StatsReport::kStatsValueNameCaptureStartNtpTimeMs,
1800 &value_in_report)); 1801 &value_in_report));
1801 EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameAudioInputLevel, 1802 EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameAudioInputLevel,
1802 &value_in_report)); 1803 &value_in_report));
1803 } 1804 }
1804 1805
1805 // This test verifies that a local stats object can get statistics via 1806 // This test verifies that a local stats object can get statistics via
1806 // AudioTrackInterface::GetStats() method. 1807 // AudioTrackInterface::GetStats() method.
1807 TEST_F(StatsCollectorTest, GetStatsFromLocalAudioTrack) { 1808 TEST_F(StatsCollectorTest, GetStatsFromLocalAudioTrack) {
1808 StatsCollectorForTest stats(&pc_); 1809 StatsCollectorForTest stats(pc_);
1809 1810
1810 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1811 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1811 .WillRepeatedly(Return(false)); 1812 .WillRepeatedly(Return(false));
1812 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1813 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1813 .WillRepeatedly(Return(nullptr)); 1814 .WillRepeatedly(Return(nullptr));
1814 1815
1815 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1816 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1816 // The transport_name known by the voice channel. 1817 // The transport_name known by the voice channel.
1817 const std::string kVcName("vcname"); 1818 const std::string kVcName("vcname");
1818 cricket::VoiceChannel voice_channel( 1819 cricket::VoiceChannel voice_channel(
(...skipping 15 matching lines...) Expand all
1834 // Verify that there is no remote report for the local audio track because 1835 // Verify that there is no remote report for the local audio track because
1835 // we did not set it up. 1836 // we did not set it up.
1836 const StatsReport* remote_report = FindNthReportByType(reports, 1837 const StatsReport* remote_report = FindNthReportByType(reports,
1837 StatsReport::kStatsReportTypeRemoteSsrc, 1); 1838 StatsReport::kStatsReportTypeRemoteSsrc, 1);
1838 EXPECT_TRUE(remote_report == NULL); 1839 EXPECT_TRUE(remote_report == NULL);
1839 } 1840 }
1840 1841
1841 // This test verifies that audio receive streams populate stats reports 1842 // This test verifies that audio receive streams populate stats reports
1842 // correctly. 1843 // correctly.
1843 TEST_F(StatsCollectorTest, GetStatsFromRemoteStream) { 1844 TEST_F(StatsCollectorTest, GetStatsFromRemoteStream) {
1844 StatsCollectorForTest stats(&pc_); 1845 StatsCollectorForTest stats(pc_);
1845 1846
1846 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1847 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1847 .WillRepeatedly(Return(false)); 1848 .WillRepeatedly(Return(false));
1848 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1849 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1849 .WillRepeatedly(Return(nullptr)); 1850 .WillRepeatedly(Return(nullptr));
1850 1851
1851 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1852 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1852 // The transport_name known by the voice channel. 1853 // The transport_name known by the voice channel.
1853 const std::string kVcName("vcname"); 1854 const std::string kVcName("vcname");
1854 cricket::VoiceChannel voice_channel( 1855 cricket::VoiceChannel voice_channel(
1855 worker_thread_, network_thread_, nullptr, media_engine_, media_channel, 1856 worker_thread_, network_thread_, nullptr, media_engine_, media_channel,
1856 kVcName, kDefaultRtcpMuxRequired, kDefaultSrtpRequired); 1857 kVcName, kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
1857 AddIncomingAudioTrackStats(); 1858 AddIncomingAudioTrackStats();
1858 stats.AddStream(stream_); 1859 stats.AddStream(stream_);
1859 1860
1860 cricket::VoiceReceiverInfo voice_receiver_info; 1861 cricket::VoiceReceiverInfo voice_receiver_info;
1861 InitVoiceReceiverInfo(&voice_receiver_info); 1862 InitVoiceReceiverInfo(&voice_receiver_info);
1862 voice_receiver_info.codec_name = "fake_codec"; 1863 voice_receiver_info.codec_name = "fake_codec";
1863 1864
1864 cricket::VoiceMediaInfo stats_read; 1865 cricket::VoiceMediaInfo stats_read;
1865 StatsReports reports; // returned values. 1866 StatsReports reports; // returned values.
1866 SetupAndVerifyAudioTrackStats( 1867 SetupAndVerifyAudioTrackStats(
1867 audio_track_.get(), stream_.get(), &stats, &voice_channel, kVcName, 1868 audio_track_.get(), stream_.get(), &stats, &voice_channel, kVcName,
1868 media_channel, NULL, &voice_receiver_info, &stats_read, &reports); 1869 media_channel, NULL, &voice_receiver_info, &stats_read, &reports);
1869 } 1870 }
1870 1871
1871 // This test verifies that a local stats object won't update its statistics 1872 // This test verifies that a local stats object won't update its statistics
1872 // after a RemoveLocalAudioTrack() call. 1873 // after a RemoveLocalAudioTrack() call.
1873 TEST_F(StatsCollectorTest, GetStatsAfterRemoveAudioStream) { 1874 TEST_F(StatsCollectorTest, GetStatsAfterRemoveAudioStream) {
1874 StatsCollectorForTest stats(&pc_); 1875 StatsCollectorForTest stats(pc_);
1875 1876
1876 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1877 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1877 .WillRepeatedly(Return(false)); 1878 .WillRepeatedly(Return(false));
1878 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1879 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1879 .WillRepeatedly(Return(nullptr)); 1880 .WillRepeatedly(Return(nullptr));
1880 1881
1881 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1882 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1882 // The transport_name known by the voice channel. 1883 // The transport_name known by the voice channel.
1883 const std::string kVcName("vcname"); 1884 const std::string kVcName("vcname");
1884 cricket::VoiceChannel voice_channel( 1885 cricket::VoiceChannel voice_channel(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1928 1929
1929 // Verifies the values in the track report, no value will be changed by the 1930 // Verifies the values in the track report, no value will be changed by the
1930 // AudioTrackInterface::GetSignalValue() and 1931 // AudioTrackInterface::GetSignalValue() and
1931 // AudioProcessorInterface::AudioProcessorStats::GetStats(); 1932 // AudioProcessorInterface::AudioProcessorStats::GetStats();
1932 VerifyVoiceSenderInfoReport(report, voice_sender_info); 1933 VerifyVoiceSenderInfoReport(report, voice_sender_info);
1933 } 1934 }
1934 1935
1935 // This test verifies that when ongoing and incoming audio tracks are using 1936 // This test verifies that when ongoing and incoming audio tracks are using
1936 // the same ssrc, they populate stats reports correctly. 1937 // the same ssrc, they populate stats reports correctly.
1937 TEST_F(StatsCollectorTest, LocalAndRemoteTracksWithSameSsrc) { 1938 TEST_F(StatsCollectorTest, LocalAndRemoteTracksWithSameSsrc) {
1938 StatsCollectorForTest stats(&pc_); 1939 StatsCollectorForTest stats(pc_);
1939 1940
1940 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1941 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1941 .WillRepeatedly(Return(false)); 1942 .WillRepeatedly(Return(false));
1942 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1943 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1943 .WillRepeatedly(Return(nullptr)); 1944 .WillRepeatedly(Return(nullptr));
1944 1945
1945 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1946 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1946 // The transport_name known by the voice channel. 1947 // The transport_name known by the voice channel.
1947 const std::string kVcName("vcname"); 1948 const std::string kVcName("vcname");
1948 cricket::VoiceChannel voice_channel( 1949 cricket::VoiceChannel voice_channel(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 StatsReport::kStatsValueNameTrackId); 2019 StatsReport::kStatsValueNameTrackId);
2019 EXPECT_EQ(kRemoteTrackId, track_id); 2020 EXPECT_EQ(kRemoteTrackId, track_id);
2020 VerifyVoiceReceiverInfoReport(track_report, voice_receiver_info); 2021 VerifyVoiceReceiverInfoReport(track_report, voice_receiver_info);
2021 } 2022 }
2022 2023
2023 // This test verifies that when two outgoing audio tracks are using the same 2024 // This test verifies that when two outgoing audio tracks are using the same
2024 // ssrc at different times, they populate stats reports correctly. 2025 // ssrc at different times, they populate stats reports correctly.
2025 // TODO(xians): Figure out if it is possible to encapsulate the setup and 2026 // TODO(xians): Figure out if it is possible to encapsulate the setup and
2026 // avoid duplication of code in test cases. 2027 // avoid duplication of code in test cases.
2027 TEST_F(StatsCollectorTest, TwoLocalTracksWithSameSsrc) { 2028 TEST_F(StatsCollectorTest, TwoLocalTracksWithSameSsrc) {
2028 StatsCollectorForTest stats(&pc_); 2029 StatsCollectorForTest stats(pc_);
2029 2030
2030 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 2031 EXPECT_CALL(session_, GetLocalCertificate(_, _))
2031 .WillRepeatedly(Return(false)); 2032 .WillRepeatedly(Return(false));
2032 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 2033 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
2033 .WillRepeatedly(Return(nullptr)); 2034 .WillRepeatedly(Return(nullptr));
2034 2035
2035 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 2036 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
2036 // The transport_name known by the voice channel. 2037 // The transport_name known by the voice channel.
2037 const std::string kVcName("vcname"); 2038 const std::string kVcName("vcname");
2038 cricket::VoiceChannel voice_channel( 2039 cricket::VoiceChannel voice_channel(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 InitVoiceSenderInfo(&new_voice_sender_info); 2073 InitVoiceSenderInfo(&new_voice_sender_info);
2073 cricket::VoiceMediaInfo new_stats_read; 2074 cricket::VoiceMediaInfo new_stats_read;
2074 reports.clear(); 2075 reports.clear();
2075 SetupAndVerifyAudioTrackStats( 2076 SetupAndVerifyAudioTrackStats(
2076 new_audio_track.get(), stream_.get(), &stats, &voice_channel, kVcName, 2077 new_audio_track.get(), stream_.get(), &stats, &voice_channel, kVcName,
2077 media_channel, &new_voice_sender_info, NULL, &new_stats_read, &reports); 2078 media_channel, &new_voice_sender_info, NULL, &new_stats_read, &reports);
2078 } 2079 }
2079 2080
2080 // This test verifies that stats are correctly set in video send ssrc stats. 2081 // This test verifies that stats are correctly set in video send ssrc stats.
2081 TEST_F(StatsCollectorTest, VerifyVideoSendSsrcStats) { 2082 TEST_F(StatsCollectorTest, VerifyVideoSendSsrcStats) {
2082 StatsCollectorForTest stats(&pc_); 2083 StatsCollectorForTest stats(pc_);
2083 2084
2084 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 2085 EXPECT_CALL(session_, GetLocalCertificate(_, _))
2085 .WillRepeatedly(Return(false)); 2086 .WillRepeatedly(Return(false));
2086 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 2087 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
2087 .WillRepeatedly(Return(nullptr)); 2088 .WillRepeatedly(Return(nullptr));
2088 2089
2089 const char kVideoChannelName[] = "video"; 2090 const char kVideoChannelName[] = "video";
2090 2091
2091 InitSessionStats(kVideoChannelName); 2092 InitSessionStats(kVideoChannelName);
2092 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke( 2093 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
(...skipping 27 matching lines...) Expand all
2120 stats.GetStats(NULL, &reports); 2121 stats.GetStats(NULL, &reports);
2121 EXPECT_EQ(rtc::ToString(video_sender_info.frames_encoded), 2122 EXPECT_EQ(rtc::ToString(video_sender_info.frames_encoded),
2122 ExtractSsrcStatsValue(reports, 2123 ExtractSsrcStatsValue(reports,
2123 StatsReport::kStatsValueNameFramesEncoded)); 2124 StatsReport::kStatsValueNameFramesEncoded));
2124 EXPECT_EQ(rtc::ToString(*video_sender_info.qp_sum), 2125 EXPECT_EQ(rtc::ToString(*video_sender_info.qp_sum),
2125 ExtractSsrcStatsValue(reports, StatsReport::kStatsValueNameQpSum)); 2126 ExtractSsrcStatsValue(reports, StatsReport::kStatsValueNameQpSum));
2126 } 2127 }
2127 2128
2128 // This test verifies that stats are correctly set in video receive ssrc stats. 2129 // This test verifies that stats are correctly set in video receive ssrc stats.
2129 TEST_F(StatsCollectorTest, VerifyVideoReceiveSsrcStats) { 2130 TEST_F(StatsCollectorTest, VerifyVideoReceiveSsrcStats) {
2130 StatsCollectorForTest stats(&pc_); 2131 StatsCollectorForTest stats(pc_);
2131 2132
2132 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 2133 EXPECT_CALL(session_, GetLocalCertificate(_, _))
2133 .WillRepeatedly(Return(false)); 2134 .WillRepeatedly(Return(false));
2134 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 2135 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
2135 .WillRepeatedly(Return(nullptr)); 2136 .WillRepeatedly(Return(nullptr));
2136 2137
2137 const char kVideoChannelName[] = "video"; 2138 const char kVideoChannelName[] = "video";
2138 2139
2139 InitSessionStats(kVideoChannelName); 2140 InitSessionStats(kVideoChannelName);
2140 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke( 2141 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
(...skipping 26 matching lines...) Expand all
2167 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 2168 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
2168 stats.GetStats(NULL, &reports); 2169 stats.GetStats(NULL, &reports);
2169 EXPECT_EQ(rtc::ToString(video_receiver_info.frames_decoded), 2170 EXPECT_EQ(rtc::ToString(video_receiver_info.frames_decoded),
2170 ExtractSsrcStatsValue(reports, 2171 ExtractSsrcStatsValue(reports,
2171 StatsReport::kStatsValueNameFramesDecoded)); 2172 StatsReport::kStatsValueNameFramesDecoded));
2172 EXPECT_EQ(rtc::ToString(*video_receiver_info.qp_sum), 2173 EXPECT_EQ(rtc::ToString(*video_receiver_info.qp_sum),
2173 ExtractSsrcStatsValue(reports, StatsReport::kStatsValueNameQpSum)); 2174 ExtractSsrcStatsValue(reports, StatsReport::kStatsValueNameQpSum));
2174 } 2175 }
2175 2176
2176 } // namespace webrtc 2177 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698