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

Side by Side Diff: talk/app/webrtc/statscollector_unittest.cc

Issue 1403633005: Revert of Moving MediaStreamSignaling logic into PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 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 | « talk/app/webrtc/statscollector.cc ('k') | talk/app/webrtc/webrtcsession.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 * libjingle 2 * libjingle
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 13 matching lines...) Expand all
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include <stdio.h> 28 #include <stdio.h>
29 29
30 #include <algorithm> 30 #include <algorithm>
31 31
32 #include "talk/app/webrtc/statscollector.h" 32 #include "talk/app/webrtc/statscollector.h"
33 33
34 #include "talk/app/webrtc/peerconnection.h"
35 #include "talk/app/webrtc/peerconnectionfactory.h"
36 #include "talk/app/webrtc/mediastream.h" 34 #include "talk/app/webrtc/mediastream.h"
37 #include "talk/app/webrtc/mediastreaminterface.h" 35 #include "talk/app/webrtc/mediastreaminterface.h"
38 #include "talk/app/webrtc/mediastreamsignaling.h" 36 #include "talk/app/webrtc/mediastreamsignaling.h"
39 #include "talk/app/webrtc/mediastreamtrack.h" 37 #include "talk/app/webrtc/mediastreamtrack.h"
40 #include "talk/app/webrtc/test/fakedatachannelprovider.h" 38 #include "talk/app/webrtc/test/fakedatachannelprovider.h"
39 #include "talk/app/webrtc/test/fakemediastreamsignaling.h"
41 #include "talk/app/webrtc/videotrack.h" 40 #include "talk/app/webrtc/videotrack.h"
42 #include "talk/media/base/fakemediaengine.h" 41 #include "talk/media/base/fakemediaengine.h"
43 #include "talk/session/media/channelmanager.h" 42 #include "talk/session/media/channelmanager.h"
44 #include "testing/gmock/include/gmock/gmock.h" 43 #include "testing/gmock/include/gmock/gmock.h"
45 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
46 #include "webrtc/base/base64.h" 45 #include "webrtc/base/base64.h"
47 #include "webrtc/base/fakesslidentity.h" 46 #include "webrtc/base/fakesslidentity.h"
48 #include "webrtc/base/gunit.h" 47 #include "webrtc/base/gunit.h"
49 #include "webrtc/base/network.h" 48 #include "webrtc/base/network.h"
50 #include "webrtc/p2p/base/faketransportcontroller.h" 49 #include "webrtc/p2p/base/faketransportcontroller.h"
51 50
52 using rtc::scoped_ptr; 51 using rtc::scoped_ptr;
53 using testing::_; 52 using testing::_;
54 using testing::DoAll; 53 using testing::DoAll;
55 using testing::Field; 54 using testing::Field;
56 using testing::Return; 55 using testing::Return;
57 using testing::ReturnNull; 56 using testing::ReturnNull;
58 using testing::ReturnRef;
59 using testing::SetArgPointee; 57 using testing::SetArgPointee;
60 using webrtc::PeerConnectionInterface; 58 using webrtc::PeerConnectionInterface;
61 using webrtc::StatsReport; 59 using webrtc::StatsReport;
62 using webrtc::StatsReports; 60 using webrtc::StatsReports;
63 61
64 namespace { 62 namespace {
65 // This value comes from openssl/tls1.h 63 // This value comes from openssl/tls1.h
66 const int TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014; 64 const int TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014;
67 } // namespace 65 } // namespace
68 66
69 namespace cricket { 67 namespace cricket {
70 68
71 class ChannelManager; 69 class ChannelManager;
72 70
73 } // namespace cricket 71 } // namespace cricket
74 72
75 namespace webrtc { 73 namespace webrtc {
76 74
77 // Error return values 75 // Error return values
78 const char kNotFound[] = "NOT FOUND"; 76 const char kNotFound[] = "NOT FOUND";
79 77
80 // Constant names for track identification. 78 // Constant names for track identification.
81 const char kLocalTrackId[] = "local_track_id"; 79 const char kLocalTrackId[] = "local_track_id";
82 const char kRemoteTrackId[] = "remote_track_id"; 80 const char kRemoteTrackId[] = "remote_track_id";
83 const uint32_t kSsrcOfTrack = 1234; 81 const uint32_t kSsrcOfTrack = 1234;
84 82
85 class MockWebRtcSession : public webrtc::WebRtcSession { 83 class MockWebRtcSession : public webrtc::WebRtcSession {
86 public: 84 public:
87 explicit MockWebRtcSession(cricket::ChannelManager* channel_manager) 85 explicit MockWebRtcSession(cricket::ChannelManager* channel_manager)
88 : WebRtcSession(channel_manager, 86 : WebRtcSession(channel_manager, rtc::Thread::Current(),
89 rtc::Thread::Current(), 87 rtc::Thread::Current(), NULL, NULL) {
90 rtc::Thread::Current(), 88 }
91 nullptr) {}
92 MOCK_METHOD0(voice_channel, cricket::VoiceChannel*()); 89 MOCK_METHOD0(voice_channel, cricket::VoiceChannel*());
93 MOCK_METHOD0(video_channel, cricket::VideoChannel*()); 90 MOCK_METHOD0(video_channel, cricket::VideoChannel*());
91 MOCK_CONST_METHOD0(mediastream_signaling, const MediaStreamSignaling*());
94 // Libjingle uses "local" for a outgoing track, and "remote" for a incoming 92 // Libjingle uses "local" for a outgoing track, and "remote" for a incoming
95 // track. 93 // track.
96 MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32_t, std::string*)); 94 MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32_t, std::string*));
97 MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32_t, std::string*)); 95 MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32_t, std::string*));
98 MOCK_METHOD1(GetTransportStats, bool(cricket::SessionStats*)); 96 MOCK_METHOD1(GetTransportStats, bool(cricket::SessionStats*));
99 MOCK_METHOD2(GetLocalCertificate, 97 MOCK_METHOD2(GetLocalCertificate,
100 bool(const std::string& transport_name, 98 bool(const std::string& transport_name,
101 rtc::scoped_refptr<rtc::RTCCertificate>* certificate)); 99 rtc::scoped_refptr<rtc::RTCCertificate>* certificate));
102 MOCK_METHOD2(GetRemoteSSLCertificate, 100 MOCK_METHOD2(GetRemoteSSLCertificate,
103 bool(const std::string& transport_name, 101 bool(const std::string& transport_name,
104 rtc::SSLCertificate** cert)); 102 rtc::SSLCertificate** cert));
105 }; 103 };
106 104
107 // The factory isn't really used; it just satisfies the base PeerConnection.
108 class FakePeerConnectionFactory
109 : public rtc::RefCountedObject<PeerConnectionFactory> {};
110
111 class MockPeerConnection
112 : public rtc::RefCountedObject<webrtc::PeerConnection> {
113 public:
114 MockPeerConnection()
115 : rtc::RefCountedObject<webrtc::PeerConnection>(
116 new FakePeerConnectionFactory()) {}
117 MOCK_METHOD0(session, WebRtcSession*());
118 MOCK_CONST_METHOD0(sctp_data_channels,
119 const std::vector<rtc::scoped_refptr<DataChannel>>&());
120 };
121
122 class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel { 105 class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel {
123 public: 106 public:
124 MockVideoMediaChannel() : 107 MockVideoMediaChannel() :
125 cricket::FakeVideoMediaChannel(NULL, cricket::VideoOptions()) {} 108 cricket::FakeVideoMediaChannel(NULL, cricket::VideoOptions()) {}
126 MOCK_METHOD1(GetStats, bool(cricket::VideoMediaInfo*)); 109 MOCK_METHOD1(GetStats, bool(cricket::VideoMediaInfo*));
127 }; 110 };
128 111
129 class MockVoiceMediaChannel : public cricket::FakeVoiceMediaChannel { 112 class MockVoiceMediaChannel : public cricket::FakeVoiceMediaChannel {
130 public: 113 public:
131 MockVoiceMediaChannel() : 114 MockVoiceMediaChannel() :
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 voice_receiver_info->audio_level = 120; 465 voice_receiver_info->audio_level = 120;
483 voice_receiver_info->expand_rate = 121; 466 voice_receiver_info->expand_rate = 121;
484 voice_receiver_info->speech_expand_rate = 122; 467 voice_receiver_info->speech_expand_rate = 122;
485 voice_receiver_info->secondary_decoded_rate = 123; 468 voice_receiver_info->secondary_decoded_rate = 123;
486 voice_receiver_info->accelerate_rate = 124; 469 voice_receiver_info->accelerate_rate = 124;
487 voice_receiver_info->preemptive_expand_rate = 125; 470 voice_receiver_info->preemptive_expand_rate = 125;
488 } 471 }
489 472
490 class StatsCollectorForTest : public webrtc::StatsCollector { 473 class StatsCollectorForTest : public webrtc::StatsCollector {
491 public: 474 public:
492 explicit StatsCollectorForTest(PeerConnection* pc) 475 explicit StatsCollectorForTest(WebRtcSession* session) :
493 : StatsCollector(pc), time_now_(19477) {} 476 StatsCollector(session), time_now_(19477) {
477 }
494 478
495 double GetTimeNow() override { 479 double GetTimeNow() override {
496 return time_now_; 480 return time_now_;
497 } 481 }
498 482
499 private: 483 private:
500 double time_now_; 484 double time_now_;
501 }; 485 };
502 486
503 class StatsCollectorTest : public testing::Test { 487 class StatsCollectorTest : public testing::Test {
504 protected: 488 protected:
505 StatsCollectorTest() 489 StatsCollectorTest()
506 : media_engine_(new cricket::FakeMediaEngine()), 490 : media_engine_(new cricket::FakeMediaEngine()),
507 channel_manager_( 491 channel_manager_(
508 new cricket::ChannelManager(media_engine_, rtc::Thread::Current())), 492 new cricket::ChannelManager(media_engine_, rtc::Thread::Current())),
509 session_(channel_manager_.get()) { 493 session_(channel_manager_.get()),
494 signaling_(channel_manager_.get()) {
510 // By default, we ignore session GetStats calls. 495 // By default, we ignore session GetStats calls.
511 EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false)); 496 EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false));
512 // Add default returns for mock classes. 497 EXPECT_CALL(session_, mediastream_signaling()).WillRepeatedly(
513 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull()); 498 Return(&signaling_));
514 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
515 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_));
516 EXPECT_CALL(pc_, sctp_data_channels())
517 .WillRepeatedly(ReturnRef(data_channels_));
518 } 499 }
519 500
520 ~StatsCollectorTest() {} 501 ~StatsCollectorTest() {}
521 502
522 // This creates a standard setup with a transport called "trspname" 503 // This creates a standard setup with a transport called "trspname"
523 // having one transport channel 504 // having one transport channel
524 // and the specified virtual connection name. 505 // and the specified virtual connection name.
525 void InitSessionStats(const std::string& vc_name) { 506 void InitSessionStats(const std::string& vc_name) {
526 const std::string kTransportName("trspname"); 507 const std::string kTransportName("trspname");
527 cricket::TransportStats transport_stats; 508 cricket::TransportStats transport_stats;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 if (stream_ == NULL) 550 if (stream_ == NULL)
570 stream_ = webrtc::MediaStream::Create("streamlabel"); 551 stream_ = webrtc::MediaStream::Create("streamlabel");
571 552
572 audio_track_ = new rtc::RefCountedObject<FakeAudioTrack>( 553 audio_track_ = new rtc::RefCountedObject<FakeAudioTrack>(
573 kRemoteTrackId); 554 kRemoteTrackId);
574 stream_->AddTrack(audio_track_); 555 stream_->AddTrack(audio_track_);
575 EXPECT_CALL(session_, GetRemoteTrackIdBySsrc(kSsrcOfTrack, _)) 556 EXPECT_CALL(session_, GetRemoteTrackIdBySsrc(kSsrcOfTrack, _))
576 .WillOnce(DoAll(SetArgPointee<1>(kRemoteTrackId), Return(true))); 557 .WillOnce(DoAll(SetArgPointee<1>(kRemoteTrackId), Return(true)));
577 } 558 }
578 559
579 void AddDataChannel(cricket::DataChannelType type,
580 const std::string& label,
581 int id) {
582 InternalDataChannelInit config;
583 config.id = id;
584
585 data_channels_.push_back(DataChannel::Create(
586 &data_channel_provider_, cricket::DCT_SCTP, label, config));
587 }
588
589 StatsReport* AddCandidateReport(StatsCollector* collector, 560 StatsReport* AddCandidateReport(StatsCollector* collector,
590 const cricket::Candidate& candidate, 561 const cricket::Candidate& candidate,
591 bool local) { 562 bool local) {
592 return collector->AddCandidateReport(candidate, local); 563 return collector->AddCandidateReport(candidate, local);
593 } 564 }
594 565
595 void SetupAndVerifyAudioTrackStats( 566 void SetupAndVerifyAudioTrackStats(
596 FakeAudioTrack* audio_track, 567 FakeAudioTrack* audio_track,
597 webrtc::MediaStream* stream, 568 webrtc::MediaStream* stream,
598 webrtc::StatsCollector* stats, 569 webrtc::StatsCollector* stats,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 if (voice_sender_info) 637 if (voice_sender_info)
667 VerifyVoiceSenderInfoReport(track_report, *voice_sender_info); 638 VerifyVoiceSenderInfoReport(track_report, *voice_sender_info);
668 if (voice_receiver_info) 639 if (voice_receiver_info)
669 VerifyVoiceReceiverInfoReport(track_report, *voice_receiver_info); 640 VerifyVoiceReceiverInfoReport(track_report, *voice_receiver_info);
670 } 641 }
671 642
672 void TestCertificateReports(const rtc::FakeSSLCertificate& local_cert, 643 void TestCertificateReports(const rtc::FakeSSLCertificate& local_cert,
673 const std::vector<std::string>& local_ders, 644 const std::vector<std::string>& local_ders,
674 const rtc::FakeSSLCertificate& remote_cert, 645 const rtc::FakeSSLCertificate& remote_cert,
675 const std::vector<std::string>& remote_ders) { 646 const std::vector<std::string>& remote_ders) {
676 StatsCollectorForTest stats(&pc_); 647 StatsCollectorForTest stats(&session_);
677 648
678 StatsReports reports; // returned values. 649 StatsReports reports; // returned values.
679 650
680 // Fake stats to process. 651 // Fake stats to process.
681 cricket::TransportChannelStats channel_stats; 652 cricket::TransportChannelStats channel_stats;
682 channel_stats.component = 1; 653 channel_stats.component = 1;
683 channel_stats.srtp_cipher = "the-srtp-cipher"; 654 channel_stats.srtp_cipher = "the-srtp-cipher";
684 channel_stats.ssl_cipher = TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA; 655 channel_stats.ssl_cipher = TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA;
685 656
686 cricket::TransportStats transport_stats; 657 cricket::TransportStats transport_stats;
(...skipping 14 matching lines...) Expand all
701 EXPECT_CALL(session_, 672 EXPECT_CALL(session_,
702 GetLocalCertificate(transport_stats.transport_name, _)) 673 GetLocalCertificate(transport_stats.transport_name, _))
703 .WillOnce(DoAll(SetArgPointee<1>(local_certificate), Return(true))); 674 .WillOnce(DoAll(SetArgPointee<1>(local_certificate), Return(true)));
704 EXPECT_CALL(session_, 675 EXPECT_CALL(session_,
705 GetRemoteSSLCertificate(transport_stats.transport_name, _)) 676 GetRemoteSSLCertificate(transport_stats.transport_name, _))
706 .WillOnce( 677 .WillOnce(
707 DoAll(SetArgPointee<1>(remote_cert.GetReference()), Return(true))); 678 DoAll(SetArgPointee<1>(remote_cert.GetReference()), Return(true)));
708 EXPECT_CALL(session_, GetTransportStats(_)) 679 EXPECT_CALL(session_, GetTransportStats(_))
709 .WillOnce(DoAll(SetArgPointee<0>(session_stats), 680 .WillOnce(DoAll(SetArgPointee<0>(session_stats),
710 Return(true))); 681 Return(true)));
682 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
683 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
711 684
712 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 685 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
713 686
714 stats.GetStats(NULL, &reports); 687 stats.GetStats(NULL, &reports);
715 688
716 const StatsReport* channel_report = FindNthReportByType( 689 const StatsReport* channel_report = FindNthReportByType(
717 reports, StatsReport::kStatsReportTypeComponent, 1); 690 reports, StatsReport::kStatsReportTypeComponent, 1);
718 EXPECT_TRUE(channel_report != NULL); 691 EXPECT_TRUE(channel_report != NULL);
719 692
720 // Check local certificate chain. 693 // Check local certificate chain.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 std::string srtp_cipher = ExtractStatsValue( 727 std::string srtp_cipher = ExtractStatsValue(
755 StatsReport::kStatsReportTypeComponent, 728 StatsReport::kStatsReportTypeComponent,
756 reports, 729 reports,
757 StatsReport::kStatsValueNameSrtpCipher); 730 StatsReport::kStatsValueNameSrtpCipher);
758 EXPECT_EQ("the-srtp-cipher", srtp_cipher); 731 EXPECT_EQ("the-srtp-cipher", srtp_cipher);
759 } 732 }
760 733
761 cricket::FakeMediaEngine* media_engine_; 734 cricket::FakeMediaEngine* media_engine_;
762 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_; 735 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
763 MockWebRtcSession session_; 736 MockWebRtcSession session_;
764 MockPeerConnection pc_; 737 FakeMediaStreamSignaling signaling_;
765 FakeDataChannelProvider data_channel_provider_; 738 FakeDataChannelProvider data_channel_provider_;
766 cricket::SessionStats session_stats_; 739 cricket::SessionStats session_stats_;
767 rtc::scoped_refptr<webrtc::MediaStream> stream_; 740 rtc::scoped_refptr<webrtc::MediaStream> stream_;
768 rtc::scoped_refptr<webrtc::VideoTrack> track_; 741 rtc::scoped_refptr<webrtc::VideoTrack> track_;
769 rtc::scoped_refptr<FakeAudioTrack> audio_track_; 742 rtc::scoped_refptr<FakeAudioTrack> audio_track_;
770 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_;
771 }; 743 };
772 744
773 // Verify that ExtractDataInfo populates reports. 745 // Verify that ExtractDataInfo populates reports.
774 TEST_F(StatsCollectorTest, ExtractDataInfo) { 746 TEST_F(StatsCollectorTest, ExtractDataInfo) {
775 const std::string label = "hacks"; 747 const std::string label = "hacks";
776 const int id = 31337; 748 const int id = 31337;
777 const std::string state = DataChannelInterface::DataStateString( 749 const std::string state = DataChannelInterface::DataStateString(
778 DataChannelInterface::DataState::kConnecting); 750 DataChannelInterface::DataState::kConnecting);
779 751
780 AddDataChannel(cricket::DCT_SCTP, label, id); 752 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
781 StatsCollectorForTest stats(&pc_); 753 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
754
755 InternalDataChannelInit config;
756 config.id = id;
757 signaling_.AddDataChannel(DataChannel::Create(
758 &data_channel_provider_, cricket::DCT_SCTP, label, config));
759 StatsCollectorForTest stats(&session_);
782 760
783 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 761 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
784 762
785 StatsReports reports; 763 StatsReports reports;
786 stats.GetStats(NULL, &reports); 764 stats.GetStats(NULL, &reports);
787 765
788 const StatsReport* report = 766 const StatsReport* report =
789 FindNthReportByType(reports, StatsReport::kStatsReportTypeDataChannel, 1); 767 FindNthReportByType(reports, StatsReport::kStatsReportTypeDataChannel, 1);
790 768
791 StatsReport::Id reportId = StatsReport::NewTypedIntId( 769 StatsReport::Id reportId = StatsReport::NewTypedIntId(
(...skipping 11 matching lines...) Expand all
803 EXPECT_EQ(state, ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel, 781 EXPECT_EQ(state, ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel,
804 reports, 782 reports,
805 StatsReport::kStatsValueNameState)); 783 StatsReport::kStatsValueNameState));
806 EXPECT_EQ("", ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel, 784 EXPECT_EQ("", ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel,
807 reports, 785 reports,
808 StatsReport::kStatsValueNameProtocol)); 786 StatsReport::kStatsValueNameProtocol));
809 } 787 }
810 788
811 // This test verifies that 64-bit counters are passed successfully. 789 // This test verifies that 64-bit counters are passed successfully.
812 TEST_F(StatsCollectorTest, BytesCounterHandles64Bits) { 790 TEST_F(StatsCollectorTest, BytesCounterHandles64Bits) {
813 StatsCollectorForTest stats(&pc_); 791 StatsCollectorForTest stats(&session_);
814 792
815 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 793 EXPECT_CALL(session_, GetLocalCertificate(_, _))
816 .WillRepeatedly(Return(false)); 794 .WillRepeatedly(Return(false));
817 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 795 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
818 .WillRepeatedly(Return(false)); 796 .WillRepeatedly(Return(false));
819 797
820 const char kVideoChannelName[] = "video"; 798 const char kVideoChannelName[] = "video";
821 799
822 InitSessionStats(kVideoChannelName); 800 InitSessionStats(kVideoChannelName);
823 EXPECT_CALL(session_, GetTransportStats(_)) 801 EXPECT_CALL(session_, GetTransportStats(_))
(...skipping 25 matching lines...) Expand all
849 Return(true))); 827 Return(true)));
850 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 828 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
851 stats.GetStats(NULL, &reports); 829 stats.GetStats(NULL, &reports);
852 std::string result = ExtractSsrcStatsValue(reports, 830 std::string result = ExtractSsrcStatsValue(reports,
853 StatsReport::kStatsValueNameBytesSent); 831 StatsReport::kStatsValueNameBytesSent);
854 EXPECT_EQ(kBytesSentString, result); 832 EXPECT_EQ(kBytesSentString, result);
855 } 833 }
856 834
857 // Test that BWE information is reported via stats. 835 // Test that BWE information is reported via stats.
858 TEST_F(StatsCollectorTest, BandwidthEstimationInfoIsReported) { 836 TEST_F(StatsCollectorTest, BandwidthEstimationInfoIsReported) {
859 StatsCollectorForTest stats(&pc_); 837 StatsCollectorForTest stats(&session_);
860 838
861 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 839 EXPECT_CALL(session_, GetLocalCertificate(_, _))
862 .WillRepeatedly(Return(false)); 840 .WillRepeatedly(Return(false));
863 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 841 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
864 .WillRepeatedly(Return(false)); 842 .WillRepeatedly(Return(false));
865 843
866 const char kVideoChannelName[] = "video"; 844 const char kVideoChannelName[] = "video";
867 845
868 InitSessionStats(kVideoChannelName); 846 InitSessionStats(kVideoChannelName);
869 EXPECT_CALL(session_, GetTransportStats(_)) 847 EXPECT_CALL(session_, GetTransportStats(_))
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 StatsReport::kStatsValueNameBytesSent); 884 StatsReport::kStatsValueNameBytesSent);
907 EXPECT_EQ(kBytesSentString, result); 885 EXPECT_EQ(kBytesSentString, result);
908 result = ExtractBweStatsValue(reports, 886 result = ExtractBweStatsValue(reports,
909 StatsReport::kStatsValueNameTargetEncBitrate); 887 StatsReport::kStatsValueNameTargetEncBitrate);
910 EXPECT_EQ(kTargetEncBitrateString, result); 888 EXPECT_EQ(kTargetEncBitrateString, result);
911 } 889 }
912 890
913 // This test verifies that an object of type "googSession" always 891 // This test verifies that an object of type "googSession" always
914 // exists in the returned stats. 892 // exists in the returned stats.
915 TEST_F(StatsCollectorTest, SessionObjectExists) { 893 TEST_F(StatsCollectorTest, SessionObjectExists) {
916 StatsCollectorForTest stats(&pc_); 894 StatsCollectorForTest stats(&session_);
917 895
918 StatsReports reports; // returned values. 896 StatsReports reports; // returned values.
897 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
898 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
919 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 899 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
920 stats.GetStats(NULL, &reports); 900 stats.GetStats(NULL, &reports);
921 const StatsReport* session_report = FindNthReportByType( 901 const StatsReport* session_report = FindNthReportByType(
922 reports, StatsReport::kStatsReportTypeSession, 1); 902 reports, StatsReport::kStatsReportTypeSession, 1);
923 EXPECT_FALSE(session_report == NULL); 903 EXPECT_FALSE(session_report == NULL);
924 } 904 }
925 905
926 // This test verifies that only one object of type "googSession" exists 906 // This test verifies that only one object of type "googSession" exists
927 // in the returned stats. 907 // in the returned stats.
928 TEST_F(StatsCollectorTest, OnlyOneSessionObjectExists) { 908 TEST_F(StatsCollectorTest, OnlyOneSessionObjectExists) {
929 StatsCollectorForTest stats(&pc_); 909 StatsCollectorForTest stats(&session_);
930 910
931 StatsReports reports; // returned values. 911 StatsReports reports; // returned values.
912 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
913 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
932 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 914 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
933 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 915 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
934 stats.GetStats(NULL, &reports); 916 stats.GetStats(NULL, &reports);
935 const StatsReport* session_report = FindNthReportByType( 917 const StatsReport* session_report = FindNthReportByType(
936 reports, StatsReport::kStatsReportTypeSession, 1); 918 reports, StatsReport::kStatsReportTypeSession, 1);
937 EXPECT_FALSE(session_report == NULL); 919 EXPECT_FALSE(session_report == NULL);
938 session_report = FindNthReportByType( 920 session_report = FindNthReportByType(
939 reports, StatsReport::kStatsReportTypeSession, 2); 921 reports, StatsReport::kStatsReportTypeSession, 2);
940 EXPECT_EQ(NULL, session_report); 922 EXPECT_EQ(NULL, session_report);
941 } 923 }
942 924
943 // This test verifies that the empty track report exists in the returned stats 925 // This test verifies that the empty track report exists in the returned stats
944 // without calling StatsCollector::UpdateStats. 926 // without calling StatsCollector::UpdateStats.
945 TEST_F(StatsCollectorTest, TrackObjectExistsWithoutUpdateStats) { 927 TEST_F(StatsCollectorTest, TrackObjectExistsWithoutUpdateStats) {
946 StatsCollectorForTest stats(&pc_); 928 StatsCollectorForTest stats(&session_);
947 929
948 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 930 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
949 cricket::VideoChannel video_channel(rtc::Thread::Current(), 931 cricket::VideoChannel video_channel(rtc::Thread::Current(),
950 media_channel, NULL, "video", false); 932 media_channel, NULL, "video", false);
951 AddOutgoingVideoTrackStats(); 933 AddOutgoingVideoTrackStats();
952 stats.AddStream(stream_); 934 stats.AddStream(stream_);
953 935
954 // Verfies the existence of the track report. 936 // Verfies the existence of the track report.
955 StatsReports reports; 937 StatsReports reports;
956 stats.GetStats(NULL, &reports); 938 stats.GetStats(NULL, &reports);
957 EXPECT_EQ((size_t)1, reports.size()); 939 EXPECT_EQ((size_t)1, reports.size());
958 EXPECT_EQ(StatsReport::kStatsReportTypeTrack, reports[0]->type()); 940 EXPECT_EQ(StatsReport::kStatsReportTypeTrack, reports[0]->type());
959 EXPECT_EQ(0, reports[0]->timestamp()); 941 EXPECT_EQ(0, reports[0]->timestamp());
960 942
961 std::string trackValue = 943 std::string trackValue =
962 ExtractStatsValue(StatsReport::kStatsReportTypeTrack, 944 ExtractStatsValue(StatsReport::kStatsReportTypeTrack,
963 reports, 945 reports,
964 StatsReport::kStatsValueNameTrackId); 946 StatsReport::kStatsValueNameTrackId);
965 EXPECT_EQ(kLocalTrackId, trackValue); 947 EXPECT_EQ(kLocalTrackId, trackValue);
966 } 948 }
967 949
968 // This test verifies that the empty track report exists in the returned stats 950 // This test verifies that the empty track report exists in the returned stats
969 // when StatsCollector::UpdateStats is called with ssrc stats. 951 // when StatsCollector::UpdateStats is called with ssrc stats.
970 TEST_F(StatsCollectorTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) { 952 TEST_F(StatsCollectorTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) {
971 StatsCollectorForTest stats(&pc_); 953 StatsCollectorForTest stats(&session_);
972 954
973 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 955 EXPECT_CALL(session_, GetLocalCertificate(_, _))
974 .WillRepeatedly(Return(false)); 956 .WillRepeatedly(Return(false));
975 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 957 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
976 .WillRepeatedly(Return(false)); 958 .WillRepeatedly(Return(false));
977 959
978 const char kVideoChannelName[] = "video"; 960 const char kVideoChannelName[] = "video";
979 InitSessionStats(kVideoChannelName); 961 InitSessionStats(kVideoChannelName);
980 EXPECT_CALL(session_, GetTransportStats(_)) 962 EXPECT_CALL(session_, GetTransportStats(_))
981 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 963 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id); 1011 EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id);
1030 1012
1031 std::string track_id = ExtractSsrcStatsValue( 1013 std::string track_id = ExtractSsrcStatsValue(
1032 reports, StatsReport::kStatsValueNameTrackId); 1014 reports, StatsReport::kStatsValueNameTrackId);
1033 EXPECT_EQ(kLocalTrackId, track_id); 1015 EXPECT_EQ(kLocalTrackId, track_id);
1034 } 1016 }
1035 1017
1036 // This test verifies that an SSRC object has the identifier of a Transport 1018 // This test verifies that an SSRC object has the identifier of a Transport
1037 // stats object, and that this transport stats object exists in stats. 1019 // stats object, and that this transport stats object exists in stats.
1038 TEST_F(StatsCollectorTest, TransportObjectLinkedFromSsrcObject) { 1020 TEST_F(StatsCollectorTest, TransportObjectLinkedFromSsrcObject) {
1039 StatsCollectorForTest stats(&pc_); 1021 StatsCollectorForTest stats(&session_);
1040 1022
1041 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1023 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1042 .WillRepeatedly(Return(false)); 1024 .WillRepeatedly(Return(false));
1043 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1025 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1044 .WillRepeatedly(Return(false)); 1026 .WillRepeatedly(Return(false));
1045 1027
1046 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1028 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1047 // The transport_name known by the video channel. 1029 // The transport_name known by the video channel.
1048 const std::string kVcName("vcname"); 1030 const std::string kVcName("vcname");
1049 cricket::VideoChannel video_channel(rtc::Thread::Current(), 1031 cricket::VideoChannel video_channel(rtc::Thread::Current(),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 content = content.substr(0, index); 1074 content = content.substr(0, index);
1093 StatsReport::Id id(StatsReport::NewComponentId(content, 1)); 1075 StatsReport::Id id(StatsReport::NewComponentId(content, 1));
1094 ASSERT_EQ(transport_id, id->ToString()); 1076 ASSERT_EQ(transport_id, id->ToString());
1095 const StatsReport* transport_report = FindReportById(reports, id); 1077 const StatsReport* transport_report = FindReportById(reports, id);
1096 ASSERT_FALSE(transport_report == NULL); 1078 ASSERT_FALSE(transport_report == NULL);
1097 } 1079 }
1098 1080
1099 // This test verifies that a remote stats object will not be created for 1081 // This test verifies that a remote stats object will not be created for
1100 // an outgoing SSRC where remote stats are not returned. 1082 // an outgoing SSRC where remote stats are not returned.
1101 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsAbsent) { 1083 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsAbsent) {
1102 StatsCollectorForTest stats(&pc_); 1084 StatsCollectorForTest stats(&session_);
1103 1085
1104 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1086 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1105 // The transport_name known by the video channel. 1087 // The transport_name known by the video channel.
1106 const std::string kVcName("vcname"); 1088 const std::string kVcName("vcname");
1107 cricket::VideoChannel video_channel(rtc::Thread::Current(), 1089 cricket::VideoChannel video_channel(rtc::Thread::Current(),
1108 media_channel, NULL, kVcName, false); 1090 media_channel, NULL, kVcName, false);
1109 AddOutgoingVideoTrackStats(); 1091 AddOutgoingVideoTrackStats();
1110 stats.AddStream(stream_); 1092 stats.AddStream(stream_);
1111 1093
1094 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
1095 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
1096
1112 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1097 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1113 StatsReports reports; 1098 StatsReports reports;
1114 stats.GetStats(NULL, &reports); 1099 stats.GetStats(NULL, &reports);
1115 const StatsReport* remote_report = FindNthReportByType(reports, 1100 const StatsReport* remote_report = FindNthReportByType(reports,
1116 StatsReport::kStatsReportTypeRemoteSsrc, 1); 1101 StatsReport::kStatsReportTypeRemoteSsrc, 1);
1117 EXPECT_TRUE(remote_report == NULL); 1102 EXPECT_TRUE(remote_report == NULL);
1118 } 1103 }
1119 1104
1120 // This test verifies that a remote stats object will be created for 1105 // This test verifies that a remote stats object will be created for
1121 // an outgoing SSRC where stats are returned. 1106 // an outgoing SSRC where stats are returned.
1122 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsPresent) { 1107 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsPresent) {
1123 StatsCollectorForTest stats(&pc_); 1108 StatsCollectorForTest stats(&session_);
1124 1109
1125 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1110 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1126 .WillRepeatedly(Return(false)); 1111 .WillRepeatedly(Return(false));
1127 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1112 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1128 .WillRepeatedly(Return(false)); 1113 .WillRepeatedly(Return(false));
1129 1114
1130 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1115 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1131 // The transport_name known by the video channel. 1116 // The transport_name known by the video channel.
1132 const std::string kVcName("vcname"); 1117 const std::string kVcName("vcname");
1133 cricket::VideoChannel video_channel(rtc::Thread::Current(), 1118 cricket::VideoChannel video_channel(rtc::Thread::Current(),
(...skipping 30 matching lines...) Expand all
1164 1149
1165 const StatsReport* remote_report = FindNthReportByType(reports, 1150 const StatsReport* remote_report = FindNthReportByType(reports,
1166 StatsReport::kStatsReportTypeRemoteSsrc, 1); 1151 StatsReport::kStatsReportTypeRemoteSsrc, 1);
1167 EXPECT_FALSE(remote_report == NULL); 1152 EXPECT_FALSE(remote_report == NULL);
1168 EXPECT_EQ(12345.678, remote_report->timestamp()); 1153 EXPECT_EQ(12345.678, remote_report->timestamp());
1169 } 1154 }
1170 1155
1171 // This test verifies that the empty track report exists in the returned stats 1156 // This test verifies that the empty track report exists in the returned stats
1172 // when StatsCollector::UpdateStats is called with ssrc stats. 1157 // when StatsCollector::UpdateStats is called with ssrc stats.
1173 TEST_F(StatsCollectorTest, ReportsFromRemoteTrack) { 1158 TEST_F(StatsCollectorTest, ReportsFromRemoteTrack) {
1174 StatsCollectorForTest stats(&pc_); 1159 StatsCollectorForTest stats(&session_);
1175 1160
1176 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1161 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1177 .WillRepeatedly(Return(false)); 1162 .WillRepeatedly(Return(false));
1178 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1163 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1179 .WillRepeatedly(Return(false)); 1164 .WillRepeatedly(Return(false));
1180 1165
1181 const char kVideoChannelName[] = "video"; 1166 const char kVideoChannelName[] = "video";
1182 InitSessionStats(kVideoChannelName); 1167 InitSessionStats(kVideoChannelName);
1183 EXPECT_CALL(session_, GetTransportStats(_)) 1168 EXPECT_CALL(session_, GetTransportStats(_))
1184 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 1169 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id); 1207 EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id);
1223 1208
1224 std::string track_id = ExtractSsrcStatsValue( 1209 std::string track_id = ExtractSsrcStatsValue(
1225 reports, StatsReport::kStatsValueNameTrackId); 1210 reports, StatsReport::kStatsValueNameTrackId);
1226 EXPECT_EQ(kRemoteTrackId, track_id); 1211 EXPECT_EQ(kRemoteTrackId, track_id);
1227 } 1212 }
1228 1213
1229 // This test verifies the Ice Candidate report should contain the correct 1214 // This test verifies the Ice Candidate report should contain the correct
1230 // information from local/remote candidates. 1215 // information from local/remote candidates.
1231 TEST_F(StatsCollectorTest, IceCandidateReport) { 1216 TEST_F(StatsCollectorTest, IceCandidateReport) {
1232 StatsCollectorForTest stats(&pc_); 1217 StatsCollectorForTest stats(&session_);
1233 1218
1234 StatsReports reports; // returned values. 1219 StatsReports reports; // returned values.
1235 1220
1236 const int local_port = 2000; 1221 const int local_port = 2000;
1237 const char local_ip[] = "192.168.0.1"; 1222 const char local_ip[] = "192.168.0.1";
1238 const int remote_port = 2001; 1223 const int remote_port = 2001;
1239 const char remote_ip[] = "192.168.0.2"; 1224 const char remote_ip[] = "192.168.0.2";
1240 1225
1241 rtc::SocketAddress local_address(local_ip, local_port); 1226 rtc::SocketAddress local_address(local_ip, local_port);
1242 rtc::SocketAddress remote_address(remote_ip, remote_port); 1227 rtc::SocketAddress remote_address(remote_ip, remote_port);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 std::string remote_der = "This is somebody else's der."; 1337 std::string remote_der = "This is somebody else's der.";
1353 rtc::FakeSSLCertificate remote_cert(DerToPem(remote_der)); 1338 rtc::FakeSSLCertificate remote_cert(DerToPem(remote_der));
1354 1339
1355 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der), 1340 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der),
1356 remote_cert, std::vector<std::string>(1, remote_der)); 1341 remote_cert, std::vector<std::string>(1, remote_der));
1357 } 1342 }
1358 1343
1359 // This test verifies that the stats are generated correctly when no 1344 // This test verifies that the stats are generated correctly when no
1360 // transport is present. 1345 // transport is present.
1361 TEST_F(StatsCollectorTest, NoTransport) { 1346 TEST_F(StatsCollectorTest, NoTransport) {
1362 StatsCollectorForTest stats(&pc_); 1347 StatsCollectorForTest stats(&session_);
1363 1348
1364 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1349 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1365 .WillRepeatedly(Return(false)); 1350 .WillRepeatedly(Return(false));
1366 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1351 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1367 .WillRepeatedly(Return(false)); 1352 .WillRepeatedly(Return(false));
1368 1353
1369 StatsReports reports; // returned values. 1354 StatsReports reports; // returned values.
1370 1355
1371 // Fake stats to process. 1356 // Fake stats to process.
1372 cricket::TransportChannelStats channel_stats; 1357 cricket::TransportChannelStats channel_stats;
1373 channel_stats.component = 1; 1358 channel_stats.component = 1;
1374 1359
1375 cricket::TransportStats transport_stats; 1360 cricket::TransportStats transport_stats;
1376 transport_stats.transport_name = "audio"; 1361 transport_stats.transport_name = "audio";
1377 transport_stats.channel_stats.push_back(channel_stats); 1362 transport_stats.channel_stats.push_back(channel_stats);
1378 1363
1379 cricket::SessionStats session_stats; 1364 cricket::SessionStats session_stats;
1380 session_stats.transport_stats[transport_stats.transport_name] = 1365 session_stats.transport_stats[transport_stats.transport_name] =
1381 transport_stats; 1366 transport_stats;
1382 1367
1383 // Configure MockWebRtcSession 1368 // Configure MockWebRtcSession
1384 EXPECT_CALL(session_, GetTransportStats(_)) 1369 EXPECT_CALL(session_, GetTransportStats(_))
1385 .WillOnce(DoAll(SetArgPointee<0>(session_stats), 1370 .WillOnce(DoAll(SetArgPointee<0>(session_stats),
1386 Return(true))); 1371 Return(true)));
1387 1372
1373 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
1374 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
1375
1388 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1376 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1389 stats.GetStats(NULL, &reports); 1377 stats.GetStats(NULL, &reports);
1390 1378
1391 // Check that the local certificate is absent. 1379 // Check that the local certificate is absent.
1392 std::string local_certificate_id = ExtractStatsValue( 1380 std::string local_certificate_id = ExtractStatsValue(
1393 StatsReport::kStatsReportTypeComponent, 1381 StatsReport::kStatsReportTypeComponent,
1394 reports, 1382 reports,
1395 StatsReport::kStatsValueNameLocalCertificateId); 1383 StatsReport::kStatsValueNameLocalCertificateId);
1396 ASSERT_EQ(kNotFound, local_certificate_id); 1384 ASSERT_EQ(kNotFound, local_certificate_id);
1397 1385
(...skipping 13 matching lines...) Expand all
1411 std::string srtp_cipher = ExtractStatsValue( 1399 std::string srtp_cipher = ExtractStatsValue(
1412 StatsReport::kStatsReportTypeComponent, 1400 StatsReport::kStatsReportTypeComponent,
1413 reports, 1401 reports,
1414 StatsReport::kStatsValueNameSrtpCipher); 1402 StatsReport::kStatsValueNameSrtpCipher);
1415 ASSERT_EQ(kNotFound, srtp_cipher); 1403 ASSERT_EQ(kNotFound, srtp_cipher);
1416 } 1404 }
1417 1405
1418 // This test verifies that the stats are generated correctly when the transport 1406 // This test verifies that the stats are generated correctly when the transport
1419 // does not have any certificates. 1407 // does not have any certificates.
1420 TEST_F(StatsCollectorTest, NoCertificates) { 1408 TEST_F(StatsCollectorTest, NoCertificates) {
1421 StatsCollectorForTest stats(&pc_); 1409 StatsCollectorForTest stats(&session_);
1422 1410
1423 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1411 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1424 .WillRepeatedly(Return(false)); 1412 .WillRepeatedly(Return(false));
1425 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1413 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1426 .WillRepeatedly(Return(false)); 1414 .WillRepeatedly(Return(false));
1427 1415
1428 StatsReports reports; // returned values. 1416 StatsReports reports; // returned values.
1429 1417
1430 // Fake stats to process. 1418 // Fake stats to process.
1431 cricket::TransportChannelStats channel_stats; 1419 cricket::TransportChannelStats channel_stats;
1432 channel_stats.component = 1; 1420 channel_stats.component = 1;
1433 1421
1434 cricket::TransportStats transport_stats; 1422 cricket::TransportStats transport_stats;
1435 transport_stats.transport_name = "audio"; 1423 transport_stats.transport_name = "audio";
1436 transport_stats.channel_stats.push_back(channel_stats); 1424 transport_stats.channel_stats.push_back(channel_stats);
1437 1425
1438 cricket::SessionStats session_stats; 1426 cricket::SessionStats session_stats;
1439 session_stats.transport_stats[transport_stats.transport_name] = 1427 session_stats.transport_stats[transport_stats.transport_name] =
1440 transport_stats; 1428 transport_stats;
1441 1429
1442 // Fake transport object. 1430 // Fake transport object.
1443 rtc::scoped_ptr<cricket::FakeTransport> transport( 1431 rtc::scoped_ptr<cricket::FakeTransport> transport(
1444 new cricket::FakeTransport(transport_stats.transport_name)); 1432 new cricket::FakeTransport(transport_stats.transport_name));
1445 1433
1446 // Configure MockWebRtcSession 1434 // Configure MockWebRtcSession
1447 EXPECT_CALL(session_, GetTransportStats(_)) 1435 EXPECT_CALL(session_, GetTransportStats(_))
1448 .WillOnce(DoAll(SetArgPointee<0>(session_stats), 1436 .WillOnce(DoAll(SetArgPointee<0>(session_stats),
1449 Return(true))); 1437 Return(true)));
1438 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
1439 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
1440
1450 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1441 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1451 stats.GetStats(NULL, &reports); 1442 stats.GetStats(NULL, &reports);
1452 1443
1453 // Check that the local certificate is absent. 1444 // Check that the local certificate is absent.
1454 std::string local_certificate_id = ExtractStatsValue( 1445 std::string local_certificate_id = ExtractStatsValue(
1455 StatsReport::kStatsReportTypeComponent, 1446 StatsReport::kStatsReportTypeComponent,
1456 reports, 1447 reports,
1457 StatsReport::kStatsValueNameLocalCertificateId); 1448 StatsReport::kStatsValueNameLocalCertificateId);
1458 ASSERT_EQ(kNotFound, local_certificate_id); 1449 ASSERT_EQ(kNotFound, local_certificate_id);
1459 1450
(...skipping 17 matching lines...) Expand all
1477 rtc::FakeSSLCertificate remote_cert(DerToPem(remote_der)); 1468 rtc::FakeSSLCertificate remote_cert(DerToPem(remote_der));
1478 remote_cert.set_digest_algorithm("foobar"); 1469 remote_cert.set_digest_algorithm("foobar");
1479 1470
1480 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der), 1471 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der),
1481 remote_cert, std::vector<std::string>()); 1472 remote_cert, std::vector<std::string>());
1482 } 1473 }
1483 1474
1484 // This test verifies that a local stats object can get statistics via 1475 // This test verifies that a local stats object can get statistics via
1485 // AudioTrackInterface::GetStats() method. 1476 // AudioTrackInterface::GetStats() method.
1486 TEST_F(StatsCollectorTest, GetStatsFromLocalAudioTrack) { 1477 TEST_F(StatsCollectorTest, GetStatsFromLocalAudioTrack) {
1487 StatsCollectorForTest stats(&pc_); 1478 StatsCollectorForTest stats(&session_);
1488 1479
1489 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1480 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1490 .WillRepeatedly(Return(false)); 1481 .WillRepeatedly(Return(false));
1491 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1482 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1492 .WillRepeatedly(Return(false)); 1483 .WillRepeatedly(Return(false));
1493 1484
1494 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1485 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1495 // The transport_name known by the voice channel. 1486 // The transport_name known by the voice channel.
1496 const std::string kVcName("vcname"); 1487 const std::string kVcName("vcname");
1497 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), 1488 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
(...skipping 14 matching lines...) Expand all
1512 // Verify that there is no remote report for the local audio track because 1503 // Verify that there is no remote report for the local audio track because
1513 // we did not set it up. 1504 // we did not set it up.
1514 const StatsReport* remote_report = FindNthReportByType(reports, 1505 const StatsReport* remote_report = FindNthReportByType(reports,
1515 StatsReport::kStatsReportTypeRemoteSsrc, 1); 1506 StatsReport::kStatsReportTypeRemoteSsrc, 1);
1516 EXPECT_TRUE(remote_report == NULL); 1507 EXPECT_TRUE(remote_report == NULL);
1517 } 1508 }
1518 1509
1519 // This test verifies that audio receive streams populate stats reports 1510 // This test verifies that audio receive streams populate stats reports
1520 // correctly. 1511 // correctly.
1521 TEST_F(StatsCollectorTest, GetStatsFromRemoteStream) { 1512 TEST_F(StatsCollectorTest, GetStatsFromRemoteStream) {
1522 StatsCollectorForTest stats(&pc_); 1513 StatsCollectorForTest stats(&session_);
1523 1514
1524 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1515 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1525 .WillRepeatedly(Return(false)); 1516 .WillRepeatedly(Return(false));
1526 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1517 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1527 .WillRepeatedly(Return(false)); 1518 .WillRepeatedly(Return(false));
1528 1519
1529 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1520 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1530 // The transport_name known by the voice channel. 1521 // The transport_name known by the voice channel.
1531 const std::string kVcName("vcname"); 1522 const std::string kVcName("vcname");
1532 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), 1523 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
1533 media_engine_, media_channel, NULL, kVcName, false); 1524 media_engine_, media_channel, NULL, kVcName, false);
1534 AddIncomingAudioTrackStats(); 1525 AddIncomingAudioTrackStats();
1535 stats.AddStream(stream_); 1526 stats.AddStream(stream_);
1536 1527
1537 cricket::VoiceReceiverInfo voice_receiver_info; 1528 cricket::VoiceReceiverInfo voice_receiver_info;
1538 InitVoiceReceiverInfo(&voice_receiver_info); 1529 InitVoiceReceiverInfo(&voice_receiver_info);
1539 voice_receiver_info.codec_name = "fake_codec"; 1530 voice_receiver_info.codec_name = "fake_codec";
1540 1531
1541 cricket::VoiceMediaInfo stats_read; 1532 cricket::VoiceMediaInfo stats_read;
1542 StatsReports reports; // returned values. 1533 StatsReports reports; // returned values.
1543 SetupAndVerifyAudioTrackStats( 1534 SetupAndVerifyAudioTrackStats(
1544 audio_track_.get(), stream_.get(), &stats, &voice_channel, kVcName, 1535 audio_track_.get(), stream_.get(), &stats, &voice_channel, kVcName,
1545 media_channel, NULL, &voice_receiver_info, &stats_read, &reports); 1536 media_channel, NULL, &voice_receiver_info, &stats_read, &reports);
1546 } 1537 }
1547 1538
1548 // This test verifies that a local stats object won't update its statistics 1539 // This test verifies that a local stats object won't update its statistics
1549 // after a RemoveLocalAudioTrack() call. 1540 // after a RemoveLocalAudioTrack() call.
1550 TEST_F(StatsCollectorTest, GetStatsAfterRemoveAudioStream) { 1541 TEST_F(StatsCollectorTest, GetStatsAfterRemoveAudioStream) {
1551 StatsCollectorForTest stats(&pc_); 1542 StatsCollectorForTest stats(&session_);
1552 1543
1553 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1544 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1554 .WillRepeatedly(Return(false)); 1545 .WillRepeatedly(Return(false));
1555 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1546 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1556 .WillRepeatedly(Return(false)); 1547 .WillRepeatedly(Return(false));
1557 1548
1558 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1549 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1559 // The transport_name known by the voice channel. 1550 // The transport_name known by the voice channel.
1560 const std::string kVcName("vcname"); 1551 const std::string kVcName("vcname");
1561 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), 1552 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 1593
1603 // Verifies the values in the track report, no value will be changed by the 1594 // Verifies the values in the track report, no value will be changed by the
1604 // AudioTrackInterface::GetSignalValue() and 1595 // AudioTrackInterface::GetSignalValue() and
1605 // AudioProcessorInterface::AudioProcessorStats::GetStats(); 1596 // AudioProcessorInterface::AudioProcessorStats::GetStats();
1606 VerifyVoiceSenderInfoReport(report, voice_sender_info); 1597 VerifyVoiceSenderInfoReport(report, voice_sender_info);
1607 } 1598 }
1608 1599
1609 // This test verifies that when ongoing and incoming audio tracks are using 1600 // This test verifies that when ongoing and incoming audio tracks are using
1610 // the same ssrc, they populate stats reports correctly. 1601 // the same ssrc, they populate stats reports correctly.
1611 TEST_F(StatsCollectorTest, LocalAndRemoteTracksWithSameSsrc) { 1602 TEST_F(StatsCollectorTest, LocalAndRemoteTracksWithSameSsrc) {
1612 StatsCollectorForTest stats(&pc_); 1603 StatsCollectorForTest stats(&session_);
1613 1604
1614 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1605 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1615 .WillRepeatedly(Return(false)); 1606 .WillRepeatedly(Return(false));
1616 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1607 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1617 .WillRepeatedly(Return(false)); 1608 .WillRepeatedly(Return(false));
1618 1609
1619 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1610 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1620 // The transport_name known by the voice channel. 1611 // The transport_name known by the voice channel.
1621 const std::string kVcName("vcname"); 1612 const std::string kVcName("vcname");
1622 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), 1613 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 StatsReport::kStatsValueNameTrackId); 1680 StatsReport::kStatsValueNameTrackId);
1690 EXPECT_EQ(kRemoteTrackId, track_id); 1681 EXPECT_EQ(kRemoteTrackId, track_id);
1691 VerifyVoiceReceiverInfoReport(track_report, voice_receiver_info); 1682 VerifyVoiceReceiverInfoReport(track_report, voice_receiver_info);
1692 } 1683 }
1693 1684
1694 // This test verifies that when two outgoing audio tracks are using the same 1685 // This test verifies that when two outgoing audio tracks are using the same
1695 // ssrc at different times, they populate stats reports correctly. 1686 // ssrc at different times, they populate stats reports correctly.
1696 // TODO(xians): Figure out if it is possible to encapsulate the setup and 1687 // TODO(xians): Figure out if it is possible to encapsulate the setup and
1697 // avoid duplication of code in test cases. 1688 // avoid duplication of code in test cases.
1698 TEST_F(StatsCollectorTest, TwoLocalTracksWithSameSsrc) { 1689 TEST_F(StatsCollectorTest, TwoLocalTracksWithSameSsrc) {
1699 StatsCollectorForTest stats(&pc_); 1690 StatsCollectorForTest stats(&session_);
1700 1691
1701 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1692 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1702 .WillRepeatedly(Return(false)); 1693 .WillRepeatedly(Return(false));
1703 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1694 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1704 .WillRepeatedly(Return(false)); 1695 .WillRepeatedly(Return(false));
1705 1696
1706 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1697 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1707 // The transport_name known by the voice channel. 1698 // The transport_name known by the voice channel.
1708 const std::string kVcName("vcname"); 1699 const std::string kVcName("vcname");
1709 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), 1700 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
(...skipping 30 matching lines...) Expand all
1740 cricket::VoiceSenderInfo new_voice_sender_info; 1731 cricket::VoiceSenderInfo new_voice_sender_info;
1741 InitVoiceSenderInfo(&new_voice_sender_info); 1732 InitVoiceSenderInfo(&new_voice_sender_info);
1742 cricket::VoiceMediaInfo new_stats_read; 1733 cricket::VoiceMediaInfo new_stats_read;
1743 reports.clear(); 1734 reports.clear();
1744 SetupAndVerifyAudioTrackStats( 1735 SetupAndVerifyAudioTrackStats(
1745 new_audio_track.get(), stream_.get(), &stats, &voice_channel, kVcName, 1736 new_audio_track.get(), stream_.get(), &stats, &voice_channel, kVcName,
1746 media_channel, &new_voice_sender_info, NULL, &new_stats_read, &reports); 1737 media_channel, &new_voice_sender_info, NULL, &new_stats_read, &reports);
1747 } 1738 }
1748 1739
1749 } // namespace webrtc 1740 } // namespace webrtc
OLDNEW
« no previous file with comments | « talk/app/webrtc/statscollector.cc ('k') | talk/app/webrtc/webrtcsession.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698