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

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

Issue 1393563002: Moving MediaStreamSignaling logic into PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Cleaning up comments, fixing naming, etc. 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
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 cricket { 64 namespace cricket {
63 65
64 class ChannelManager; 66 class ChannelManager;
65 67
66 } // namespace cricket 68 } // namespace cricket
67 69
68 namespace webrtc { 70 namespace webrtc {
69 71
70 // Error return values 72 // Error return values
71 const char kNotFound[] = "NOT FOUND"; 73 const char kNotFound[] = "NOT FOUND";
72 74
73 // Constant names for track identification. 75 // Constant names for track identification.
74 const char kLocalTrackId[] = "local_track_id"; 76 const char kLocalTrackId[] = "local_track_id";
75 const char kRemoteTrackId[] = "remote_track_id"; 77 const char kRemoteTrackId[] = "remote_track_id";
76 const uint32 kSsrcOfTrack = 1234; 78 const uint32 kSsrcOfTrack = 1234;
77 79
78 class MockWebRtcSession : public webrtc::WebRtcSession { 80 class MockWebRtcSession : public webrtc::WebRtcSession {
79 public: 81 public:
80 explicit MockWebRtcSession(cricket::ChannelManager* channel_manager) 82 explicit MockWebRtcSession(cricket::ChannelManager* channel_manager)
81 : WebRtcSession(channel_manager, rtc::Thread::Current(), 83 : WebRtcSession(channel_manager,
82 rtc::Thread::Current(), NULL, NULL) { 84 rtc::Thread::Current(),
83 } 85 rtc::Thread::Current(),
86 nullptr) {}
84 MOCK_METHOD0(voice_channel, cricket::VoiceChannel*()); 87 MOCK_METHOD0(voice_channel, cricket::VoiceChannel*());
85 MOCK_METHOD0(video_channel, cricket::VideoChannel*()); 88 MOCK_METHOD0(video_channel, cricket::VideoChannel*());
86 MOCK_CONST_METHOD0(mediastream_signaling, const MediaStreamSignaling*());
87 // Libjingle uses "local" for a outgoing track, and "remote" for a incoming 89 // Libjingle uses "local" for a outgoing track, and "remote" for a incoming
88 // track. 90 // track.
89 MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32, std::string*)); 91 MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32, std::string*));
90 MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32, std::string*)); 92 MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32, std::string*));
91 MOCK_METHOD1(GetTransportStats, bool(cricket::SessionStats*)); 93 MOCK_METHOD1(GetTransportStats, bool(cricket::SessionStats*));
92 MOCK_METHOD2(GetLocalCertificate, 94 MOCK_METHOD2(GetLocalCertificate,
93 bool(const std::string& transport_name, 95 bool(const std::string& transport_name,
94 rtc::scoped_refptr<rtc::RTCCertificate>* certificate)); 96 rtc::scoped_refptr<rtc::RTCCertificate>* certificate));
95 MOCK_METHOD2(GetRemoteSSLCertificate, 97 MOCK_METHOD2(GetRemoteSSLCertificate,
96 bool(const std::string& transport_name, 98 bool(const std::string& transport_name,
97 rtc::SSLCertificate** cert)); 99 rtc::SSLCertificate** cert));
98 }; 100 };
99 101
102 // The factory isn't really used; it just satisfies the base PeerConnection.
103 class FakePeerConnectionFactory
104 : public rtc::RefCountedObject<PeerConnectionFactory> {};
105
106 class MockPeerConnection
107 : public rtc::RefCountedObject<webrtc::PeerConnection> {
108 public:
109 MockPeerConnection()
110 : rtc::RefCountedObject<webrtc::PeerConnection>(
111 new FakePeerConnectionFactory()) {}
112 MOCK_CONST_METHOD0(sctp_data_channels,
113 const std::vector<rtc::scoped_refptr<DataChannel>>&());
114 };
115
100 class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel { 116 class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel {
101 public: 117 public:
102 MockVideoMediaChannel() : 118 MockVideoMediaChannel() :
103 cricket::FakeVideoMediaChannel(NULL, cricket::VideoOptions()) {} 119 cricket::FakeVideoMediaChannel(NULL, cricket::VideoOptions()) {}
104 MOCK_METHOD1(GetStats, bool(cricket::VideoMediaInfo*)); 120 MOCK_METHOD1(GetStats, bool(cricket::VideoMediaInfo*));
105 }; 121 };
106 122
107 class MockVoiceMediaChannel : public cricket::FakeVoiceMediaChannel { 123 class MockVoiceMediaChannel : public cricket::FakeVoiceMediaChannel {
108 public: 124 public:
109 MockVoiceMediaChannel() : 125 MockVoiceMediaChannel() :
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 voice_receiver_info->audio_level = 120; 476 voice_receiver_info->audio_level = 120;
461 voice_receiver_info->expand_rate = 121; 477 voice_receiver_info->expand_rate = 121;
462 voice_receiver_info->speech_expand_rate = 122; 478 voice_receiver_info->speech_expand_rate = 122;
463 voice_receiver_info->secondary_decoded_rate = 123; 479 voice_receiver_info->secondary_decoded_rate = 123;
464 voice_receiver_info->accelerate_rate = 124; 480 voice_receiver_info->accelerate_rate = 124;
465 voice_receiver_info->preemptive_expand_rate = 125; 481 voice_receiver_info->preemptive_expand_rate = 125;
466 } 482 }
467 483
468 class StatsCollectorForTest : public webrtc::StatsCollector { 484 class StatsCollectorForTest : public webrtc::StatsCollector {
469 public: 485 public:
470 explicit StatsCollectorForTest(WebRtcSession* session) : 486 explicit StatsCollectorForTest(PeerConnection* pc, WebRtcSession* session)
471 StatsCollector(session), time_now_(19477) { 487 : StatsCollector(pc, session), time_now_(19477) {}
472 }
473 488
474 double GetTimeNow() override { 489 double GetTimeNow() override {
475 return time_now_; 490 return time_now_;
476 } 491 }
477 492
478 private: 493 private:
479 double time_now_; 494 double time_now_;
480 }; 495 };
481 496
482 class StatsCollectorTest : public testing::Test { 497 class StatsCollectorTest : public testing::Test {
483 protected: 498 protected:
484 StatsCollectorTest() 499 StatsCollectorTest()
485 : media_engine_(new cricket::FakeMediaEngine()), 500 : media_engine_(new cricket::FakeMediaEngine()),
486 channel_manager_( 501 channel_manager_(
487 new cricket::ChannelManager(media_engine_, rtc::Thread::Current())), 502 new cricket::ChannelManager(media_engine_, rtc::Thread::Current())),
488 session_(channel_manager_.get()), 503 session_(channel_manager_.get()) {
489 signaling_(channel_manager_.get()) {
490 // By default, we ignore session GetStats calls. 504 // By default, we ignore session GetStats calls.
491 EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false)); 505 EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false));
492 EXPECT_CALL(session_, mediastream_signaling()).WillRepeatedly( 506 // Add default returns for mock classes.
493 Return(&signaling_)); 507 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
508 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
509 EXPECT_CALL(pc_, sctp_data_channels())
510 .WillRepeatedly(ReturnRef(data_channels_));
Taylor Brandstetter 2015/10/07 00:26:19 WillRepeatedly(ReturnNull()) appears in so many pl
494 } 511 }
495 512
496 ~StatsCollectorTest() {} 513 ~StatsCollectorTest() {}
497 514
498 // This creates a standard setup with a transport called "trspname" 515 // This creates a standard setup with a transport called "trspname"
499 // having one transport channel 516 // having one transport channel
500 // and the specified virtual connection name. 517 // and the specified virtual connection name.
501 void InitSessionStats(const std::string& vc_name) { 518 void InitSessionStats(const std::string& vc_name) {
502 const std::string kTransportName("trspname"); 519 const std::string kTransportName("trspname");
503 cricket::TransportStats transport_stats; 520 cricket::TransportStats transport_stats;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 if (stream_ == NULL) 562 if (stream_ == NULL)
546 stream_ = webrtc::MediaStream::Create("streamlabel"); 563 stream_ = webrtc::MediaStream::Create("streamlabel");
547 564
548 audio_track_ = new rtc::RefCountedObject<FakeAudioTrack>( 565 audio_track_ = new rtc::RefCountedObject<FakeAudioTrack>(
549 kRemoteTrackId); 566 kRemoteTrackId);
550 stream_->AddTrack(audio_track_); 567 stream_->AddTrack(audio_track_);
551 EXPECT_CALL(session_, GetRemoteTrackIdBySsrc(kSsrcOfTrack, _)) 568 EXPECT_CALL(session_, GetRemoteTrackIdBySsrc(kSsrcOfTrack, _))
552 .WillOnce(DoAll(SetArgPointee<1>(kRemoteTrackId), Return(true))); 569 .WillOnce(DoAll(SetArgPointee<1>(kRemoteTrackId), Return(true)));
553 } 570 }
554 571
572 void AddDataChannel(cricket::DataChannelType type,
573 const std::string& label,
574 int id) {
575 InternalDataChannelInit config;
576 config.id = id;
577
578 data_channels_.push_back(DataChannel::Create(
579 &data_channel_provider_, cricket::DCT_SCTP, label, config));
580 }
581
555 StatsReport* AddCandidateReport(StatsCollector* collector, 582 StatsReport* AddCandidateReport(StatsCollector* collector,
556 const cricket::Candidate& candidate, 583 const cricket::Candidate& candidate,
557 bool local) { 584 bool local) {
558 return collector->AddCandidateReport(candidate, local); 585 return collector->AddCandidateReport(candidate, local);
559 } 586 }
560 587
561 void SetupAndVerifyAudioTrackStats( 588 void SetupAndVerifyAudioTrackStats(
562 FakeAudioTrack* audio_track, 589 FakeAudioTrack* audio_track,
563 webrtc::MediaStream* stream, 590 webrtc::MediaStream* stream,
564 webrtc::StatsCollector* stats, 591 webrtc::StatsCollector* stats,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 if (voice_sender_info) 659 if (voice_sender_info)
633 VerifyVoiceSenderInfoReport(track_report, *voice_sender_info); 660 VerifyVoiceSenderInfoReport(track_report, *voice_sender_info);
634 if (voice_receiver_info) 661 if (voice_receiver_info)
635 VerifyVoiceReceiverInfoReport(track_report, *voice_receiver_info); 662 VerifyVoiceReceiverInfoReport(track_report, *voice_receiver_info);
636 } 663 }
637 664
638 void TestCertificateReports(const rtc::FakeSSLCertificate& local_cert, 665 void TestCertificateReports(const rtc::FakeSSLCertificate& local_cert,
639 const std::vector<std::string>& local_ders, 666 const std::vector<std::string>& local_ders,
640 const rtc::FakeSSLCertificate& remote_cert, 667 const rtc::FakeSSLCertificate& remote_cert,
641 const std::vector<std::string>& remote_ders) { 668 const std::vector<std::string>& remote_ders) {
642 StatsCollectorForTest stats(&session_); 669 StatsCollectorForTest stats(&pc_, &session_);
643 670
644 StatsReports reports; // returned values. 671 StatsReports reports; // returned values.
645 672
646 // Fake stats to process. 673 // Fake stats to process.
647 cricket::TransportChannelStats channel_stats; 674 cricket::TransportChannelStats channel_stats;
648 channel_stats.component = 1; 675 channel_stats.component = 1;
649 channel_stats.srtp_cipher = "the-srtp-cipher"; 676 channel_stats.srtp_cipher = "the-srtp-cipher";
650 channel_stats.ssl_cipher = "the-ssl-cipher"; 677 channel_stats.ssl_cipher = "the-ssl-cipher";
651 678
652 cricket::TransportStats transport_stats; 679 cricket::TransportStats transport_stats;
(...skipping 14 matching lines...) Expand all
667 EXPECT_CALL(session_, 694 EXPECT_CALL(session_,
668 GetLocalCertificate(transport_stats.transport_name, _)) 695 GetLocalCertificate(transport_stats.transport_name, _))
669 .WillOnce(DoAll(SetArgPointee<1>(local_certificate), Return(true))); 696 .WillOnce(DoAll(SetArgPointee<1>(local_certificate), Return(true)));
670 EXPECT_CALL(session_, 697 EXPECT_CALL(session_,
671 GetRemoteSSLCertificate(transport_stats.transport_name, _)) 698 GetRemoteSSLCertificate(transport_stats.transport_name, _))
672 .WillOnce( 699 .WillOnce(
673 DoAll(SetArgPointee<1>(remote_cert.GetReference()), Return(true))); 700 DoAll(SetArgPointee<1>(remote_cert.GetReference()), Return(true)));
674 EXPECT_CALL(session_, GetTransportStats(_)) 701 EXPECT_CALL(session_, GetTransportStats(_))
675 .WillOnce(DoAll(SetArgPointee<0>(session_stats), 702 .WillOnce(DoAll(SetArgPointee<0>(session_stats),
676 Return(true))); 703 Return(true)));
677 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
678 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
679 704
680 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 705 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
681 706
682 stats.GetStats(NULL, &reports); 707 stats.GetStats(NULL, &reports);
683 708
684 const StatsReport* channel_report = FindNthReportByType( 709 const StatsReport* channel_report = FindNthReportByType(
685 reports, StatsReport::kStatsReportTypeComponent, 1); 710 reports, StatsReport::kStatsReportTypeComponent, 1);
686 EXPECT_TRUE(channel_report != NULL); 711 EXPECT_TRUE(channel_report != NULL);
687 712
688 // Check local certificate chain. 713 // Check local certificate chain.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 std::string srtp_cipher = ExtractStatsValue( 745 std::string srtp_cipher = ExtractStatsValue(
721 StatsReport::kStatsReportTypeComponent, 746 StatsReport::kStatsReportTypeComponent,
722 reports, 747 reports,
723 StatsReport::kStatsValueNameSrtpCipher); 748 StatsReport::kStatsValueNameSrtpCipher);
724 EXPECT_EQ("the-srtp-cipher", srtp_cipher); 749 EXPECT_EQ("the-srtp-cipher", srtp_cipher);
725 } 750 }
726 751
727 cricket::FakeMediaEngine* media_engine_; 752 cricket::FakeMediaEngine* media_engine_;
728 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_; 753 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
729 MockWebRtcSession session_; 754 MockWebRtcSession session_;
730 FakeMediaStreamSignaling signaling_; 755 MockPeerConnection pc_;
731 FakeDataChannelProvider data_channel_provider_; 756 FakeDataChannelProvider data_channel_provider_;
732 cricket::SessionStats session_stats_; 757 cricket::SessionStats session_stats_;
733 rtc::scoped_refptr<webrtc::MediaStream> stream_; 758 rtc::scoped_refptr<webrtc::MediaStream> stream_;
734 rtc::scoped_refptr<webrtc::VideoTrack> track_; 759 rtc::scoped_refptr<webrtc::VideoTrack> track_;
735 rtc::scoped_refptr<FakeAudioTrack> audio_track_; 760 rtc::scoped_refptr<FakeAudioTrack> audio_track_;
761 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_;
736 }; 762 };
737 763
738 // Verify that ExtractDataInfo populates reports. 764 // Verify that ExtractDataInfo populates reports.
739 TEST_F(StatsCollectorTest, ExtractDataInfo) { 765 TEST_F(StatsCollectorTest, ExtractDataInfo) {
740 const std::string label = "hacks"; 766 const std::string label = "hacks";
741 const int id = 31337; 767 const int id = 31337;
742 const std::string state = DataChannelInterface::DataStateString( 768 const std::string state = DataChannelInterface::DataStateString(
743 DataChannelInterface::DataState::kConnecting); 769 DataChannelInterface::DataState::kConnecting);
744 770
745 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull()); 771 AddDataChannel(cricket::DCT_SCTP, label, id);
746 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull()); 772 StatsCollectorForTest stats(&pc_, &session_);
747
748 InternalDataChannelInit config;
749 config.id = id;
750 signaling_.AddDataChannel(DataChannel::Create(
751 &data_channel_provider_, cricket::DCT_SCTP, label, config));
752 StatsCollectorForTest stats(&session_);
753 773
754 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 774 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
755 775
756 StatsReports reports; 776 StatsReports reports;
757 stats.GetStats(NULL, &reports); 777 stats.GetStats(NULL, &reports);
758 778
759 const StatsReport* report = 779 const StatsReport* report =
760 FindNthReportByType(reports, StatsReport::kStatsReportTypeDataChannel, 1); 780 FindNthReportByType(reports, StatsReport::kStatsReportTypeDataChannel, 1);
761 781
762 StatsReport::Id reportId = StatsReport::NewTypedIntId( 782 StatsReport::Id reportId = StatsReport::NewTypedIntId(
(...skipping 12 matching lines...) Expand all
775 EXPECT_EQ(state, ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel, 795 EXPECT_EQ(state, ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel,
776 reports, 796 reports,
777 StatsReport::kStatsValueNameState)); 797 StatsReport::kStatsValueNameState));
778 EXPECT_EQ("", ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel, 798 EXPECT_EQ("", ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel,
779 reports, 799 reports,
780 StatsReport::kStatsValueNameProtocol)); 800 StatsReport::kStatsValueNameProtocol));
781 } 801 }
782 802
783 // This test verifies that 64-bit counters are passed successfully. 803 // This test verifies that 64-bit counters are passed successfully.
784 TEST_F(StatsCollectorTest, BytesCounterHandles64Bits) { 804 TEST_F(StatsCollectorTest, BytesCounterHandles64Bits) {
785 StatsCollectorForTest stats(&session_); 805 StatsCollectorForTest stats(&pc_, &session_);
786 806
787 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 807 EXPECT_CALL(session_, GetLocalCertificate(_, _))
788 .WillRepeatedly(Return(false)); 808 .WillRepeatedly(Return(false));
789 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 809 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
790 .WillRepeatedly(Return(false)); 810 .WillRepeatedly(Return(false));
791 811
792 const char kVideoChannelName[] = "video"; 812 const char kVideoChannelName[] = "video";
793 813
794 InitSessionStats(kVideoChannelName); 814 InitSessionStats(kVideoChannelName);
795 EXPECT_CALL(session_, GetTransportStats(_)) 815 EXPECT_CALL(session_, GetTransportStats(_))
(...skipping 25 matching lines...) Expand all
821 Return(true))); 841 Return(true)));
822 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 842 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
823 stats.GetStats(NULL, &reports); 843 stats.GetStats(NULL, &reports);
824 std::string result = ExtractSsrcStatsValue(reports, 844 std::string result = ExtractSsrcStatsValue(reports,
825 StatsReport::kStatsValueNameBytesSent); 845 StatsReport::kStatsValueNameBytesSent);
826 EXPECT_EQ(kBytesSentString, result); 846 EXPECT_EQ(kBytesSentString, result);
827 } 847 }
828 848
829 // Test that BWE information is reported via stats. 849 // Test that BWE information is reported via stats.
830 TEST_F(StatsCollectorTest, BandwidthEstimationInfoIsReported) { 850 TEST_F(StatsCollectorTest, BandwidthEstimationInfoIsReported) {
831 StatsCollectorForTest stats(&session_); 851 StatsCollectorForTest stats(&pc_, &session_);
832 852
833 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 853 EXPECT_CALL(session_, GetLocalCertificate(_, _))
834 .WillRepeatedly(Return(false)); 854 .WillRepeatedly(Return(false));
835 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 855 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
836 .WillRepeatedly(Return(false)); 856 .WillRepeatedly(Return(false));
837 857
838 const char kVideoChannelName[] = "video"; 858 const char kVideoChannelName[] = "video";
839 859
840 InitSessionStats(kVideoChannelName); 860 InitSessionStats(kVideoChannelName);
841 EXPECT_CALL(session_, GetTransportStats(_)) 861 EXPECT_CALL(session_, GetTransportStats(_))
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 StatsReport::kStatsValueNameBytesSent); 898 StatsReport::kStatsValueNameBytesSent);
879 EXPECT_EQ(kBytesSentString, result); 899 EXPECT_EQ(kBytesSentString, result);
880 result = ExtractBweStatsValue(reports, 900 result = ExtractBweStatsValue(reports,
881 StatsReport::kStatsValueNameTargetEncBitrate); 901 StatsReport::kStatsValueNameTargetEncBitrate);
882 EXPECT_EQ(kTargetEncBitrateString, result); 902 EXPECT_EQ(kTargetEncBitrateString, result);
883 } 903 }
884 904
885 // This test verifies that an object of type "googSession" always 905 // This test verifies that an object of type "googSession" always
886 // exists in the returned stats. 906 // exists in the returned stats.
887 TEST_F(StatsCollectorTest, SessionObjectExists) { 907 TEST_F(StatsCollectorTest, SessionObjectExists) {
888 StatsCollectorForTest stats(&session_); 908 StatsCollectorForTest stats(&pc_, &session_);
889 909
890 StatsReports reports; // returned values. 910 StatsReports reports; // returned values.
891 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
892 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
893 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 911 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
894 stats.GetStats(NULL, &reports); 912 stats.GetStats(NULL, &reports);
895 const StatsReport* session_report = FindNthReportByType( 913 const StatsReport* session_report = FindNthReportByType(
896 reports, StatsReport::kStatsReportTypeSession, 1); 914 reports, StatsReport::kStatsReportTypeSession, 1);
897 EXPECT_FALSE(session_report == NULL); 915 EXPECT_FALSE(session_report == NULL);
898 } 916 }
899 917
900 // This test verifies that only one object of type "googSession" exists 918 // This test verifies that only one object of type "googSession" exists
901 // in the returned stats. 919 // in the returned stats.
902 TEST_F(StatsCollectorTest, OnlyOneSessionObjectExists) { 920 TEST_F(StatsCollectorTest, OnlyOneSessionObjectExists) {
903 StatsCollectorForTest stats(&session_); 921 StatsCollectorForTest stats(&pc_, &session_);
904 922
905 StatsReports reports; // returned values. 923 StatsReports reports; // returned values.
906 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
907 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
908 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 924 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
909 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 925 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
910 stats.GetStats(NULL, &reports); 926 stats.GetStats(NULL, &reports);
911 const StatsReport* session_report = FindNthReportByType( 927 const StatsReport* session_report = FindNthReportByType(
912 reports, StatsReport::kStatsReportTypeSession, 1); 928 reports, StatsReport::kStatsReportTypeSession, 1);
913 EXPECT_FALSE(session_report == NULL); 929 EXPECT_FALSE(session_report == NULL);
914 session_report = FindNthReportByType( 930 session_report = FindNthReportByType(
915 reports, StatsReport::kStatsReportTypeSession, 2); 931 reports, StatsReport::kStatsReportTypeSession, 2);
916 EXPECT_EQ(NULL, session_report); 932 EXPECT_EQ(NULL, session_report);
917 } 933 }
918 934
919 // This test verifies that the empty track report exists in the returned stats 935 // This test verifies that the empty track report exists in the returned stats
920 // without calling StatsCollector::UpdateStats. 936 // without calling StatsCollector::UpdateStats.
921 TEST_F(StatsCollectorTest, TrackObjectExistsWithoutUpdateStats) { 937 TEST_F(StatsCollectorTest, TrackObjectExistsWithoutUpdateStats) {
922 StatsCollectorForTest stats(&session_); 938 StatsCollectorForTest stats(&pc_, &session_);
923 939
924 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 940 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
925 cricket::VideoChannel video_channel(rtc::Thread::Current(), 941 cricket::VideoChannel video_channel(rtc::Thread::Current(),
926 media_channel, NULL, "video", false); 942 media_channel, NULL, "video", false);
927 AddOutgoingVideoTrackStats(); 943 AddOutgoingVideoTrackStats();
928 stats.AddStream(stream_); 944 stats.AddStream(stream_);
929 945
930 // Verfies the existence of the track report. 946 // Verfies the existence of the track report.
931 StatsReports reports; 947 StatsReports reports;
932 stats.GetStats(NULL, &reports); 948 stats.GetStats(NULL, &reports);
933 EXPECT_EQ((size_t)1, reports.size()); 949 EXPECT_EQ((size_t)1, reports.size());
934 EXPECT_EQ(StatsReport::kStatsReportTypeTrack, reports[0]->type()); 950 EXPECT_EQ(StatsReport::kStatsReportTypeTrack, reports[0]->type());
935 EXPECT_EQ(0, reports[0]->timestamp()); 951 EXPECT_EQ(0, reports[0]->timestamp());
936 952
937 std::string trackValue = 953 std::string trackValue =
938 ExtractStatsValue(StatsReport::kStatsReportTypeTrack, 954 ExtractStatsValue(StatsReport::kStatsReportTypeTrack,
939 reports, 955 reports,
940 StatsReport::kStatsValueNameTrackId); 956 StatsReport::kStatsValueNameTrackId);
941 EXPECT_EQ(kLocalTrackId, trackValue); 957 EXPECT_EQ(kLocalTrackId, trackValue);
942 } 958 }
943 959
944 // This test verifies that the empty track report exists in the returned stats 960 // This test verifies that the empty track report exists in the returned stats
945 // when StatsCollector::UpdateStats is called with ssrc stats. 961 // when StatsCollector::UpdateStats is called with ssrc stats.
946 TEST_F(StatsCollectorTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) { 962 TEST_F(StatsCollectorTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) {
947 StatsCollectorForTest stats(&session_); 963 StatsCollectorForTest stats(&pc_, &session_);
948 964
949 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 965 EXPECT_CALL(session_, GetLocalCertificate(_, _))
950 .WillRepeatedly(Return(false)); 966 .WillRepeatedly(Return(false));
951 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 967 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
952 .WillRepeatedly(Return(false)); 968 .WillRepeatedly(Return(false));
953 969
954 const char kVideoChannelName[] = "video"; 970 const char kVideoChannelName[] = "video";
955 InitSessionStats(kVideoChannelName); 971 InitSessionStats(kVideoChannelName);
956 EXPECT_CALL(session_, GetTransportStats(_)) 972 EXPECT_CALL(session_, GetTransportStats(_))
957 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 973 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 EXPECT_EQ(rtc::ToString<uint32>(kSsrcOfTrack), ssrc_id); 1021 EXPECT_EQ(rtc::ToString<uint32>(kSsrcOfTrack), ssrc_id);
1006 1022
1007 std::string track_id = ExtractSsrcStatsValue( 1023 std::string track_id = ExtractSsrcStatsValue(
1008 reports, StatsReport::kStatsValueNameTrackId); 1024 reports, StatsReport::kStatsValueNameTrackId);
1009 EXPECT_EQ(kLocalTrackId, track_id); 1025 EXPECT_EQ(kLocalTrackId, track_id);
1010 } 1026 }
1011 1027
1012 // This test verifies that an SSRC object has the identifier of a Transport 1028 // This test verifies that an SSRC object has the identifier of a Transport
1013 // stats object, and that this transport stats object exists in stats. 1029 // stats object, and that this transport stats object exists in stats.
1014 TEST_F(StatsCollectorTest, TransportObjectLinkedFromSsrcObject) { 1030 TEST_F(StatsCollectorTest, TransportObjectLinkedFromSsrcObject) {
1015 StatsCollectorForTest stats(&session_); 1031 StatsCollectorForTest stats(&pc_, &session_);
1016 1032
1017 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1033 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1018 .WillRepeatedly(Return(false)); 1034 .WillRepeatedly(Return(false));
1019 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1035 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1020 .WillRepeatedly(Return(false)); 1036 .WillRepeatedly(Return(false));
1021 1037
1022 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1038 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1023 // The transport_name known by the video channel. 1039 // The transport_name known by the video channel.
1024 const std::string kVcName("vcname"); 1040 const std::string kVcName("vcname");
1025 cricket::VideoChannel video_channel(rtc::Thread::Current(), 1041 cricket::VideoChannel video_channel(rtc::Thread::Current(),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 content = content.substr(0, index); 1084 content = content.substr(0, index);
1069 StatsReport::Id id(StatsReport::NewComponentId(content, 1)); 1085 StatsReport::Id id(StatsReport::NewComponentId(content, 1));
1070 ASSERT_EQ(transport_id, id->ToString()); 1086 ASSERT_EQ(transport_id, id->ToString());
1071 const StatsReport* transport_report = FindReportById(reports, id); 1087 const StatsReport* transport_report = FindReportById(reports, id);
1072 ASSERT_FALSE(transport_report == NULL); 1088 ASSERT_FALSE(transport_report == NULL);
1073 } 1089 }
1074 1090
1075 // This test verifies that a remote stats object will not be created for 1091 // This test verifies that a remote stats object will not be created for
1076 // an outgoing SSRC where remote stats are not returned. 1092 // an outgoing SSRC where remote stats are not returned.
1077 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsAbsent) { 1093 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsAbsent) {
1078 StatsCollectorForTest stats(&session_); 1094 StatsCollectorForTest stats(&pc_, &session_);
1079 1095
1080 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1096 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1081 // The transport_name known by the video channel. 1097 // The transport_name known by the video channel.
1082 const std::string kVcName("vcname"); 1098 const std::string kVcName("vcname");
1083 cricket::VideoChannel video_channel(rtc::Thread::Current(), 1099 cricket::VideoChannel video_channel(rtc::Thread::Current(),
1084 media_channel, NULL, kVcName, false); 1100 media_channel, NULL, kVcName, false);
1085 AddOutgoingVideoTrackStats(); 1101 AddOutgoingVideoTrackStats();
1086 stats.AddStream(stream_); 1102 stats.AddStream(stream_);
1087 1103
1088 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
1089 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
1090
1091 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1104 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1092 StatsReports reports; 1105 StatsReports reports;
1093 stats.GetStats(NULL, &reports); 1106 stats.GetStats(NULL, &reports);
1094 const StatsReport* remote_report = FindNthReportByType(reports, 1107 const StatsReport* remote_report = FindNthReportByType(reports,
1095 StatsReport::kStatsReportTypeRemoteSsrc, 1); 1108 StatsReport::kStatsReportTypeRemoteSsrc, 1);
1096 EXPECT_TRUE(remote_report == NULL); 1109 EXPECT_TRUE(remote_report == NULL);
1097 } 1110 }
1098 1111
1099 // This test verifies that a remote stats object will be created for 1112 // This test verifies that a remote stats object will be created for
1100 // an outgoing SSRC where stats are returned. 1113 // an outgoing SSRC where stats are returned.
1101 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsPresent) { 1114 TEST_F(StatsCollectorTest, RemoteSsrcInfoIsPresent) {
1102 StatsCollectorForTest stats(&session_); 1115 StatsCollectorForTest stats(&pc_, &session_);
1103 1116
1104 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1117 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1105 .WillRepeatedly(Return(false)); 1118 .WillRepeatedly(Return(false));
1106 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1119 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1107 .WillRepeatedly(Return(false)); 1120 .WillRepeatedly(Return(false));
1108 1121
1109 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1122 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1110 // The transport_name known by the video channel. 1123 // The transport_name known by the video channel.
1111 const std::string kVcName("vcname"); 1124 const std::string kVcName("vcname");
1112 cricket::VideoChannel video_channel(rtc::Thread::Current(), 1125 cricket::VideoChannel video_channel(rtc::Thread::Current(),
(...skipping 30 matching lines...) Expand all
1143 1156
1144 const StatsReport* remote_report = FindNthReportByType(reports, 1157 const StatsReport* remote_report = FindNthReportByType(reports,
1145 StatsReport::kStatsReportTypeRemoteSsrc, 1); 1158 StatsReport::kStatsReportTypeRemoteSsrc, 1);
1146 EXPECT_FALSE(remote_report == NULL); 1159 EXPECT_FALSE(remote_report == NULL);
1147 EXPECT_EQ(12345.678, remote_report->timestamp()); 1160 EXPECT_EQ(12345.678, remote_report->timestamp());
1148 } 1161 }
1149 1162
1150 // This test verifies that the empty track report exists in the returned stats 1163 // This test verifies that the empty track report exists in the returned stats
1151 // when StatsCollector::UpdateStats is called with ssrc stats. 1164 // when StatsCollector::UpdateStats is called with ssrc stats.
1152 TEST_F(StatsCollectorTest, ReportsFromRemoteTrack) { 1165 TEST_F(StatsCollectorTest, ReportsFromRemoteTrack) {
1153 StatsCollectorForTest stats(&session_); 1166 StatsCollectorForTest stats(&pc_, &session_);
1154 1167
1155 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1168 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1156 .WillRepeatedly(Return(false)); 1169 .WillRepeatedly(Return(false));
1157 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1170 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1158 .WillRepeatedly(Return(false)); 1171 .WillRepeatedly(Return(false));
1159 1172
1160 const char kVideoChannelName[] = "video"; 1173 const char kVideoChannelName[] = "video";
1161 InitSessionStats(kVideoChannelName); 1174 InitSessionStats(kVideoChannelName);
1162 EXPECT_CALL(session_, GetTransportStats(_)) 1175 EXPECT_CALL(session_, GetTransportStats(_))
1163 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 1176 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 EXPECT_EQ(rtc::ToString<uint32>(kSsrcOfTrack), ssrc_id); 1214 EXPECT_EQ(rtc::ToString<uint32>(kSsrcOfTrack), ssrc_id);
1202 1215
1203 std::string track_id = ExtractSsrcStatsValue( 1216 std::string track_id = ExtractSsrcStatsValue(
1204 reports, StatsReport::kStatsValueNameTrackId); 1217 reports, StatsReport::kStatsValueNameTrackId);
1205 EXPECT_EQ(kRemoteTrackId, track_id); 1218 EXPECT_EQ(kRemoteTrackId, track_id);
1206 } 1219 }
1207 1220
1208 // This test verifies the Ice Candidate report should contain the correct 1221 // This test verifies the Ice Candidate report should contain the correct
1209 // information from local/remote candidates. 1222 // information from local/remote candidates.
1210 TEST_F(StatsCollectorTest, IceCandidateReport) { 1223 TEST_F(StatsCollectorTest, IceCandidateReport) {
1211 StatsCollectorForTest stats(&session_); 1224 StatsCollectorForTest stats(&pc_, &session_);
1212 1225
1213 StatsReports reports; // returned values. 1226 StatsReports reports; // returned values.
1214 1227
1215 const int local_port = 2000; 1228 const int local_port = 2000;
1216 const char local_ip[] = "192.168.0.1"; 1229 const char local_ip[] = "192.168.0.1";
1217 const int remote_port = 2001; 1230 const int remote_port = 2001;
1218 const char remote_ip[] = "192.168.0.2"; 1231 const char remote_ip[] = "192.168.0.2";
1219 1232
1220 rtc::SocketAddress local_address(local_ip, local_port); 1233 rtc::SocketAddress local_address(local_ip, local_port);
1221 rtc::SocketAddress remote_address(remote_ip, remote_port); 1234 rtc::SocketAddress remote_address(remote_ip, remote_port);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 std::string remote_der = "This is somebody else's der."; 1344 std::string remote_der = "This is somebody else's der.";
1332 rtc::FakeSSLCertificate remote_cert(DerToPem(remote_der)); 1345 rtc::FakeSSLCertificate remote_cert(DerToPem(remote_der));
1333 1346
1334 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der), 1347 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der),
1335 remote_cert, std::vector<std::string>(1, remote_der)); 1348 remote_cert, std::vector<std::string>(1, remote_der));
1336 } 1349 }
1337 1350
1338 // This test verifies that the stats are generated correctly when no 1351 // This test verifies that the stats are generated correctly when no
1339 // transport is present. 1352 // transport is present.
1340 TEST_F(StatsCollectorTest, NoTransport) { 1353 TEST_F(StatsCollectorTest, NoTransport) {
1341 StatsCollectorForTest stats(&session_); 1354 StatsCollectorForTest stats(&pc_, &session_);
1342 1355
1343 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1356 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1344 .WillRepeatedly(Return(false)); 1357 .WillRepeatedly(Return(false));
1345 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1358 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1346 .WillRepeatedly(Return(false)); 1359 .WillRepeatedly(Return(false));
1347 1360
1348 StatsReports reports; // returned values. 1361 StatsReports reports; // returned values.
1349 1362
1350 // Fake stats to process. 1363 // Fake stats to process.
1351 cricket::TransportChannelStats channel_stats; 1364 cricket::TransportChannelStats channel_stats;
1352 channel_stats.component = 1; 1365 channel_stats.component = 1;
1353 1366
1354 cricket::TransportStats transport_stats; 1367 cricket::TransportStats transport_stats;
1355 transport_stats.transport_name = "audio"; 1368 transport_stats.transport_name = "audio";
1356 transport_stats.channel_stats.push_back(channel_stats); 1369 transport_stats.channel_stats.push_back(channel_stats);
1357 1370
1358 cricket::SessionStats session_stats; 1371 cricket::SessionStats session_stats;
1359 session_stats.transport_stats[transport_stats.transport_name] = 1372 session_stats.transport_stats[transport_stats.transport_name] =
1360 transport_stats; 1373 transport_stats;
1361 1374
1362 // Configure MockWebRtcSession 1375 // Configure MockWebRtcSession
1363 EXPECT_CALL(session_, GetTransportStats(_)) 1376 EXPECT_CALL(session_, GetTransportStats(_))
1364 .WillOnce(DoAll(SetArgPointee<0>(session_stats), 1377 .WillOnce(DoAll(SetArgPointee<0>(session_stats),
1365 Return(true))); 1378 Return(true)));
1366 1379
1367 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
1368 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
1369
1370 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1380 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1371 stats.GetStats(NULL, &reports); 1381 stats.GetStats(NULL, &reports);
1372 1382
1373 // Check that the local certificate is absent. 1383 // Check that the local certificate is absent.
1374 std::string local_certificate_id = ExtractStatsValue( 1384 std::string local_certificate_id = ExtractStatsValue(
1375 StatsReport::kStatsReportTypeComponent, 1385 StatsReport::kStatsReportTypeComponent,
1376 reports, 1386 reports,
1377 StatsReport::kStatsValueNameLocalCertificateId); 1387 StatsReport::kStatsValueNameLocalCertificateId);
1378 ASSERT_EQ(kNotFound, local_certificate_id); 1388 ASSERT_EQ(kNotFound, local_certificate_id);
1379 1389
(...skipping 13 matching lines...) Expand all
1393 std::string srtp_cipher = ExtractStatsValue( 1403 std::string srtp_cipher = ExtractStatsValue(
1394 StatsReport::kStatsReportTypeComponent, 1404 StatsReport::kStatsReportTypeComponent,
1395 reports, 1405 reports,
1396 StatsReport::kStatsValueNameSrtpCipher); 1406 StatsReport::kStatsValueNameSrtpCipher);
1397 ASSERT_EQ(kNotFound, srtp_cipher); 1407 ASSERT_EQ(kNotFound, srtp_cipher);
1398 } 1408 }
1399 1409
1400 // This test verifies that the stats are generated correctly when the transport 1410 // This test verifies that the stats are generated correctly when the transport
1401 // does not have any certificates. 1411 // does not have any certificates.
1402 TEST_F(StatsCollectorTest, NoCertificates) { 1412 TEST_F(StatsCollectorTest, NoCertificates) {
1403 StatsCollectorForTest stats(&session_); 1413 StatsCollectorForTest stats(&pc_, &session_);
1404 1414
1405 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1415 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1406 .WillRepeatedly(Return(false)); 1416 .WillRepeatedly(Return(false));
1407 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1417 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1408 .WillRepeatedly(Return(false)); 1418 .WillRepeatedly(Return(false));
1409 1419
1410 StatsReports reports; // returned values. 1420 StatsReports reports; // returned values.
1411 1421
1412 // Fake stats to process. 1422 // Fake stats to process.
1413 cricket::TransportChannelStats channel_stats; 1423 cricket::TransportChannelStats channel_stats;
1414 channel_stats.component = 1; 1424 channel_stats.component = 1;
1415 1425
1416 cricket::TransportStats transport_stats; 1426 cricket::TransportStats transport_stats;
1417 transport_stats.transport_name = "audio"; 1427 transport_stats.transport_name = "audio";
1418 transport_stats.channel_stats.push_back(channel_stats); 1428 transport_stats.channel_stats.push_back(channel_stats);
1419 1429
1420 cricket::SessionStats session_stats; 1430 cricket::SessionStats session_stats;
1421 session_stats.transport_stats[transport_stats.transport_name] = 1431 session_stats.transport_stats[transport_stats.transport_name] =
1422 transport_stats; 1432 transport_stats;
1423 1433
1424 // Fake transport object. 1434 // Fake transport object.
1425 rtc::scoped_ptr<cricket::FakeTransport> transport( 1435 rtc::scoped_ptr<cricket::FakeTransport> transport(
1426 new cricket::FakeTransport(transport_stats.transport_name)); 1436 new cricket::FakeTransport(transport_stats.transport_name));
1427 1437
1428 // Configure MockWebRtcSession 1438 // Configure MockWebRtcSession
1429 EXPECT_CALL(session_, GetTransportStats(_)) 1439 EXPECT_CALL(session_, GetTransportStats(_))
1430 .WillOnce(DoAll(SetArgPointee<0>(session_stats), 1440 .WillOnce(DoAll(SetArgPointee<0>(session_stats),
1431 Return(true))); 1441 Return(true)));
1432 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
1433 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
1434
1435 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1442 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1436 stats.GetStats(NULL, &reports); 1443 stats.GetStats(NULL, &reports);
1437 1444
1438 // Check that the local certificate is absent. 1445 // Check that the local certificate is absent.
1439 std::string local_certificate_id = ExtractStatsValue( 1446 std::string local_certificate_id = ExtractStatsValue(
1440 StatsReport::kStatsReportTypeComponent, 1447 StatsReport::kStatsReportTypeComponent,
1441 reports, 1448 reports,
1442 StatsReport::kStatsValueNameLocalCertificateId); 1449 StatsReport::kStatsValueNameLocalCertificateId);
1443 ASSERT_EQ(kNotFound, local_certificate_id); 1450 ASSERT_EQ(kNotFound, local_certificate_id);
1444 1451
(...skipping 17 matching lines...) Expand all
1462 rtc::FakeSSLCertificate remote_cert(DerToPem(remote_der)); 1469 rtc::FakeSSLCertificate remote_cert(DerToPem(remote_der));
1463 remote_cert.set_digest_algorithm("foobar"); 1470 remote_cert.set_digest_algorithm("foobar");
1464 1471
1465 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der), 1472 TestCertificateReports(local_cert, std::vector<std::string>(1, local_der),
1466 remote_cert, std::vector<std::string>()); 1473 remote_cert, std::vector<std::string>());
1467 } 1474 }
1468 1475
1469 // This test verifies that a local stats object can get statistics via 1476 // This test verifies that a local stats object can get statistics via
1470 // AudioTrackInterface::GetStats() method. 1477 // AudioTrackInterface::GetStats() method.
1471 TEST_F(StatsCollectorTest, GetStatsFromLocalAudioTrack) { 1478 TEST_F(StatsCollectorTest, GetStatsFromLocalAudioTrack) {
1472 StatsCollectorForTest stats(&session_); 1479 StatsCollectorForTest stats(&pc_, &session_);
1473 1480
1474 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1481 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1475 .WillRepeatedly(Return(false)); 1482 .WillRepeatedly(Return(false));
1476 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1483 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1477 .WillRepeatedly(Return(false)); 1484 .WillRepeatedly(Return(false));
1478 1485
1479 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1486 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1480 // The transport_name known by the voice channel. 1487 // The transport_name known by the voice channel.
1481 const std::string kVcName("vcname"); 1488 const std::string kVcName("vcname");
1482 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), 1489 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
(...skipping 14 matching lines...) Expand all
1497 // Verify that there is no remote report for the local audio track because 1504 // Verify that there is no remote report for the local audio track because
1498 // we did not set it up. 1505 // we did not set it up.
1499 const StatsReport* remote_report = FindNthReportByType(reports, 1506 const StatsReport* remote_report = FindNthReportByType(reports,
1500 StatsReport::kStatsReportTypeRemoteSsrc, 1); 1507 StatsReport::kStatsReportTypeRemoteSsrc, 1);
1501 EXPECT_TRUE(remote_report == NULL); 1508 EXPECT_TRUE(remote_report == NULL);
1502 } 1509 }
1503 1510
1504 // This test verifies that audio receive streams populate stats reports 1511 // This test verifies that audio receive streams populate stats reports
1505 // correctly. 1512 // correctly.
1506 TEST_F(StatsCollectorTest, GetStatsFromRemoteStream) { 1513 TEST_F(StatsCollectorTest, GetStatsFromRemoteStream) {
1507 StatsCollectorForTest stats(&session_); 1514 StatsCollectorForTest stats(&pc_, &session_);
1508 1515
1509 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1516 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1510 .WillRepeatedly(Return(false)); 1517 .WillRepeatedly(Return(false));
1511 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1518 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1512 .WillRepeatedly(Return(false)); 1519 .WillRepeatedly(Return(false));
1513 1520
1514 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1521 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1515 // The transport_name known by the voice channel. 1522 // The transport_name known by the voice channel.
1516 const std::string kVcName("vcname"); 1523 const std::string kVcName("vcname");
1517 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), 1524 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
1518 media_engine_, media_channel, NULL, kVcName, false); 1525 media_engine_, media_channel, NULL, kVcName, false);
1519 AddIncomingAudioTrackStats(); 1526 AddIncomingAudioTrackStats();
1520 stats.AddStream(stream_); 1527 stats.AddStream(stream_);
1521 1528
1522 cricket::VoiceReceiverInfo voice_receiver_info; 1529 cricket::VoiceReceiverInfo voice_receiver_info;
1523 InitVoiceReceiverInfo(&voice_receiver_info); 1530 InitVoiceReceiverInfo(&voice_receiver_info);
1524 voice_receiver_info.codec_name = "fake_codec"; 1531 voice_receiver_info.codec_name = "fake_codec";
1525 1532
1526 cricket::VoiceMediaInfo stats_read; 1533 cricket::VoiceMediaInfo stats_read;
1527 StatsReports reports; // returned values. 1534 StatsReports reports; // returned values.
1528 SetupAndVerifyAudioTrackStats( 1535 SetupAndVerifyAudioTrackStats(
1529 audio_track_.get(), stream_.get(), &stats, &voice_channel, kVcName, 1536 audio_track_.get(), stream_.get(), &stats, &voice_channel, kVcName,
1530 media_channel, NULL, &voice_receiver_info, &stats_read, &reports); 1537 media_channel, NULL, &voice_receiver_info, &stats_read, &reports);
1531 } 1538 }
1532 1539
1533 // This test verifies that a local stats object won't update its statistics 1540 // This test verifies that a local stats object won't update its statistics
1534 // after a RemoveLocalAudioTrack() call. 1541 // after a RemoveLocalAudioTrack() call.
1535 TEST_F(StatsCollectorTest, GetStatsAfterRemoveAudioStream) { 1542 TEST_F(StatsCollectorTest, GetStatsAfterRemoveAudioStream) {
1536 StatsCollectorForTest stats(&session_); 1543 StatsCollectorForTest stats(&pc_, &session_);
1537 1544
1538 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1545 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1539 .WillRepeatedly(Return(false)); 1546 .WillRepeatedly(Return(false));
1540 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1547 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1541 .WillRepeatedly(Return(false)); 1548 .WillRepeatedly(Return(false));
1542 1549
1543 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1550 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1544 // The transport_name known by the voice channel. 1551 // The transport_name known by the voice channel.
1545 const std::string kVcName("vcname"); 1552 const std::string kVcName("vcname");
1546 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), 1553 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 1594
1588 // Verifies the values in the track report, no value will be changed by the 1595 // Verifies the values in the track report, no value will be changed by the
1589 // AudioTrackInterface::GetSignalValue() and 1596 // AudioTrackInterface::GetSignalValue() and
1590 // AudioProcessorInterface::AudioProcessorStats::GetStats(); 1597 // AudioProcessorInterface::AudioProcessorStats::GetStats();
1591 VerifyVoiceSenderInfoReport(report, voice_sender_info); 1598 VerifyVoiceSenderInfoReport(report, voice_sender_info);
1592 } 1599 }
1593 1600
1594 // This test verifies that when ongoing and incoming audio tracks are using 1601 // This test verifies that when ongoing and incoming audio tracks are using
1595 // the same ssrc, they populate stats reports correctly. 1602 // the same ssrc, they populate stats reports correctly.
1596 TEST_F(StatsCollectorTest, LocalAndRemoteTracksWithSameSsrc) { 1603 TEST_F(StatsCollectorTest, LocalAndRemoteTracksWithSameSsrc) {
1597 StatsCollectorForTest stats(&session_); 1604 StatsCollectorForTest stats(&pc_, &session_);
1598 1605
1599 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1606 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1600 .WillRepeatedly(Return(false)); 1607 .WillRepeatedly(Return(false));
1601 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1608 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1602 .WillRepeatedly(Return(false)); 1609 .WillRepeatedly(Return(false));
1603 1610
1604 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1611 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1605 // The transport_name known by the voice channel. 1612 // The transport_name known by the voice channel.
1606 const std::string kVcName("vcname"); 1613 const std::string kVcName("vcname");
1607 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), 1614 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 StatsReport::kStatsValueNameTrackId); 1681 StatsReport::kStatsValueNameTrackId);
1675 EXPECT_EQ(kRemoteTrackId, track_id); 1682 EXPECT_EQ(kRemoteTrackId, track_id);
1676 VerifyVoiceReceiverInfoReport(track_report, voice_receiver_info); 1683 VerifyVoiceReceiverInfoReport(track_report, voice_receiver_info);
1677 } 1684 }
1678 1685
1679 // This test verifies that when two outgoing audio tracks are using the same 1686 // This test verifies that when two outgoing audio tracks are using the same
1680 // ssrc at different times, they populate stats reports correctly. 1687 // ssrc at different times, they populate stats reports correctly.
1681 // TODO(xians): Figure out if it is possible to encapsulate the setup and 1688 // TODO(xians): Figure out if it is possible to encapsulate the setup and
1682 // avoid duplication of code in test cases. 1689 // avoid duplication of code in test cases.
1683 TEST_F(StatsCollectorTest, TwoLocalTracksWithSameSsrc) { 1690 TEST_F(StatsCollectorTest, TwoLocalTracksWithSameSsrc) {
1684 StatsCollectorForTest stats(&session_); 1691 StatsCollectorForTest stats(&pc_, &session_);
1685 1692
1686 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1693 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1687 .WillRepeatedly(Return(false)); 1694 .WillRepeatedly(Return(false));
1688 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1695 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1689 .WillRepeatedly(Return(false)); 1696 .WillRepeatedly(Return(false));
1690 1697
1691 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1698 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1692 // The transport_name known by the voice channel. 1699 // The transport_name known by the voice channel.
1693 const std::string kVcName("vcname"); 1700 const std::string kVcName("vcname");
1694 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), 1701 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
(...skipping 30 matching lines...) Expand all
1725 cricket::VoiceSenderInfo new_voice_sender_info; 1732 cricket::VoiceSenderInfo new_voice_sender_info;
1726 InitVoiceSenderInfo(&new_voice_sender_info); 1733 InitVoiceSenderInfo(&new_voice_sender_info);
1727 cricket::VoiceMediaInfo new_stats_read; 1734 cricket::VoiceMediaInfo new_stats_read;
1728 reports.clear(); 1735 reports.clear();
1729 SetupAndVerifyAudioTrackStats( 1736 SetupAndVerifyAudioTrackStats(
1730 new_audio_track.get(), stream_.get(), &stats, &voice_channel, kVcName, 1737 new_audio_track.get(), stream_.get(), &stats, &voice_channel, kVcName,
1731 media_channel, &new_voice_sender_info, NULL, &new_stats_read, &reports); 1738 media_channel, &new_voice_sender_info, NULL, &new_stats_read, &reports);
1732 } 1739 }
1733 1740
1734 } // namespace webrtc 1741 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698