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

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

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