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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: talk/app/webrtc/statscollector_unittest.cc
diff --git a/talk/app/webrtc/statscollector_unittest.cc b/talk/app/webrtc/statscollector_unittest.cc
index 7c055f6566862c7f8af5dc77df1a12df7d0f1c4f..fec63eed9681aafdf6af373614bd80ad7955bd8b 100644
--- a/talk/app/webrtc/statscollector_unittest.cc
+++ b/talk/app/webrtc/statscollector_unittest.cc
@@ -31,12 +31,13 @@
#include "talk/app/webrtc/statscollector.h"
+#include "talk/app/webrtc/peerconnection.h"
+#include "talk/app/webrtc/peerconnectionfactory.h"
#include "talk/app/webrtc/mediastream.h"
#include "talk/app/webrtc/mediastreaminterface.h"
#include "talk/app/webrtc/mediastreamsignaling.h"
#include "talk/app/webrtc/mediastreamtrack.h"
#include "talk/app/webrtc/test/fakedatachannelprovider.h"
-#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
#include "talk/app/webrtc/videotrack.h"
#include "talk/media/base/fakemediaengine.h"
#include "talk/session/media/channelmanager.h"
@@ -54,6 +55,7 @@ using testing::DoAll;
using testing::Field;
using testing::Return;
using testing::ReturnNull;
+using testing::ReturnRef;
using testing::SetArgPointee;
using webrtc::PeerConnectionInterface;
using webrtc::StatsReport;
@@ -78,12 +80,12 @@ const uint32 kSsrcOfTrack = 1234;
class MockWebRtcSession : public webrtc::WebRtcSession {
public:
explicit MockWebRtcSession(cricket::ChannelManager* channel_manager)
- : WebRtcSession(channel_manager, rtc::Thread::Current(),
- rtc::Thread::Current(), NULL, NULL) {
- }
+ : WebRtcSession(channel_manager,
+ rtc::Thread::Current(),
+ rtc::Thread::Current(),
+ nullptr) {}
MOCK_METHOD0(voice_channel, cricket::VoiceChannel*());
MOCK_METHOD0(video_channel, cricket::VideoChannel*());
- MOCK_CONST_METHOD0(mediastream_signaling, const MediaStreamSignaling*());
// Libjingle uses "local" for a outgoing track, and "remote" for a incoming
// track.
MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32, std::string*));
@@ -97,6 +99,20 @@ class MockWebRtcSession : public webrtc::WebRtcSession {
rtc::SSLCertificate** cert));
};
+// The factory isn't really used; it just satisfies the base PeerConnection.
+class FakePeerConnectionFactory
+ : public rtc::RefCountedObject<PeerConnectionFactory> {};
+
+class MockPeerConnection
+ : public rtc::RefCountedObject<webrtc::PeerConnection> {
+ public:
+ MockPeerConnection()
+ : rtc::RefCountedObject<webrtc::PeerConnection>(
+ new FakePeerConnectionFactory()) {}
+ MOCK_CONST_METHOD0(sctp_data_channels,
+ const std::vector<rtc::scoped_refptr<DataChannel>>&());
+};
+
class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel {
public:
MockVideoMediaChannel() :
@@ -467,9 +483,8 @@ void InitVoiceReceiverInfo(cricket::VoiceReceiverInfo* voice_receiver_info) {
class StatsCollectorForTest : public webrtc::StatsCollector {
public:
- explicit StatsCollectorForTest(WebRtcSession* session) :
- StatsCollector(session), time_now_(19477) {
- }
+ explicit StatsCollectorForTest(PeerConnection* pc, WebRtcSession* session)
+ : StatsCollector(pc, session), time_now_(19477) {}
double GetTimeNow() override {
return time_now_;
@@ -482,15 +497,17 @@ class StatsCollectorForTest : public webrtc::StatsCollector {
class StatsCollectorTest : public testing::Test {
protected:
StatsCollectorTest()
- : media_engine_(new cricket::FakeMediaEngine()),
- channel_manager_(
- new cricket::ChannelManager(media_engine_, rtc::Thread::Current())),
- session_(channel_manager_.get()),
- signaling_(channel_manager_.get()) {
+ : media_engine_(new cricket::FakeMediaEngine()),
+ channel_manager_(
+ new cricket::ChannelManager(media_engine_, rtc::Thread::Current())),
+ session_(channel_manager_.get()) {
// By default, we ignore session GetStats calls.
EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false));
- EXPECT_CALL(session_, mediastream_signaling()).WillRepeatedly(
- Return(&signaling_));
+ // Add default returns for mock classes.
+ EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
+ EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
+ EXPECT_CALL(pc_, sctp_data_channels())
+ .WillRepeatedly(ReturnRef(data_channels_));
Taylor Brandstetter 2015/10/07 00:26:19 WillRepeatedly(ReturnNull()) appears in so many pl
}
~StatsCollectorTest() {}
@@ -552,6 +569,16 @@ class StatsCollectorTest : public testing::Test {
.WillOnce(DoAll(SetArgPointee<1>(kRemoteTrackId), Return(true)));
}
+ void AddDataChannel(cricket::DataChannelType type,
+ const std::string& label,
+ int id) {
+ InternalDataChannelInit config;
+ config.id = id;
+
+ data_channels_.push_back(DataChannel::Create(
+ &data_channel_provider_, cricket::DCT_SCTP, label, config));
+ }
+
StatsReport* AddCandidateReport(StatsCollector* collector,
const cricket::Candidate& candidate,
bool local) {
@@ -639,7 +666,7 @@ class StatsCollectorTest : public testing::Test {
const std::vector<std::string>& local_ders,
const rtc::FakeSSLCertificate& remote_cert,
const std::vector<std::string>& remote_ders) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
StatsReports reports; // returned values.
@@ -674,8 +701,6 @@ class StatsCollectorTest : public testing::Test {
EXPECT_CALL(session_, GetTransportStats(_))
.WillOnce(DoAll(SetArgPointee<0>(session_stats),
Return(true)));
- EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
- EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
@@ -727,12 +752,13 @@ class StatsCollectorTest : public testing::Test {
cricket::FakeMediaEngine* media_engine_;
rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
MockWebRtcSession session_;
- FakeMediaStreamSignaling signaling_;
+ MockPeerConnection pc_;
FakeDataChannelProvider data_channel_provider_;
cricket::SessionStats session_stats_;
rtc::scoped_refptr<webrtc::MediaStream> stream_;
rtc::scoped_refptr<webrtc::VideoTrack> track_;
rtc::scoped_refptr<FakeAudioTrack> audio_track_;
+ std::vector<rtc::scoped_refptr<DataChannel>> data_channels_;
};
// Verify that ExtractDataInfo populates reports.
@@ -742,14 +768,8 @@ TEST_F(StatsCollectorTest, ExtractDataInfo) {
const std::string state = DataChannelInterface::DataStateString(
DataChannelInterface::DataState::kConnecting);
- EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
- EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
-
- InternalDataChannelInit config;
- config.id = id;
- signaling_.AddDataChannel(DataChannel::Create(
- &data_channel_provider_, cricket::DCT_SCTP, label, config));
- StatsCollectorForTest stats(&session_);
+ AddDataChannel(cricket::DCT_SCTP, label, id);
+ StatsCollectorForTest stats(&pc_, &session_);
stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
@@ -782,7 +802,7 @@ TEST_F(StatsCollectorTest, ExtractDataInfo) {
// This test verifies that 64-bit counters are passed successfully.
TEST_F(StatsCollectorTest, BytesCounterHandles64Bits) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -828,7 +848,7 @@ TEST_F(StatsCollectorTest, BytesCounterHandles64Bits) {
// Test that BWE information is reported via stats.
TEST_F(StatsCollectorTest, BandwidthEstimationInfoIsReported) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -885,11 +905,9 @@ TEST_F(StatsCollectorTest, BandwidthEstimationInfoIsReported) {
// This test verifies that an object of type "googSession" always
// exists in the returned stats.
TEST_F(StatsCollectorTest, SessionObjectExists) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
StatsReports reports; // returned values.
- EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
- EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
stats.GetStats(NULL, &reports);
const StatsReport* session_report = FindNthReportByType(
@@ -900,11 +918,9 @@ TEST_F(StatsCollectorTest, SessionObjectExists) {
// This test verifies that only one object of type "googSession" exists
// in the returned stats.
TEST_F(StatsCollectorTest, OnlyOneSessionObjectExists) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
StatsReports reports; // returned values.
- EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
- EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
stats.GetStats(NULL, &reports);
@@ -919,7 +935,7 @@ TEST_F(StatsCollectorTest, OnlyOneSessionObjectExists) {
// This test verifies that the empty track report exists in the returned stats
// without calling StatsCollector::UpdateStats.
TEST_F(StatsCollectorTest, TrackObjectExistsWithoutUpdateStats) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
cricket::VideoChannel video_channel(rtc::Thread::Current(),
@@ -944,7 +960,7 @@ TEST_F(StatsCollectorTest, TrackObjectExistsWithoutUpdateStats) {
// This test verifies that the empty track report exists in the returned stats
// when StatsCollector::UpdateStats is called with ssrc stats.
TEST_F(StatsCollectorTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -1012,7 +1028,7 @@ TEST_F(StatsCollectorTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) {
// This test verifies that an SSRC object has the identifier of a Transport
// stats object, and that this transport stats object exists in stats.
TEST_F(StatsCollectorTest, TransportObjectLinkedFromSsrcObject) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -1075,7 +1091,7 @@ TEST_F(StatsCollectorTest, TransportObjectLinkedFromSsrcObject) {
// This test verifies that a remote stats object will not be created for
// an outgoing SSRC where remote stats are not returned.
TEST_F(StatsCollectorTest, RemoteSsrcInfoIsAbsent) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
// The transport_name known by the video channel.
@@ -1085,9 +1101,6 @@ TEST_F(StatsCollectorTest, RemoteSsrcInfoIsAbsent) {
AddOutgoingVideoTrackStats();
stats.AddStream(stream_);
- EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
- EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
-
stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
StatsReports reports;
stats.GetStats(NULL, &reports);
@@ -1099,7 +1112,7 @@ TEST_F(StatsCollectorTest, RemoteSsrcInfoIsAbsent) {
// This test verifies that a remote stats object will be created for
// an outgoing SSRC where stats are returned.
TEST_F(StatsCollectorTest, RemoteSsrcInfoIsPresent) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -1150,7 +1163,7 @@ TEST_F(StatsCollectorTest, RemoteSsrcInfoIsPresent) {
// This test verifies that the empty track report exists in the returned stats
// when StatsCollector::UpdateStats is called with ssrc stats.
TEST_F(StatsCollectorTest, ReportsFromRemoteTrack) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -1208,7 +1221,7 @@ TEST_F(StatsCollectorTest, ReportsFromRemoteTrack) {
// This test verifies the Ice Candidate report should contain the correct
// information from local/remote candidates.
TEST_F(StatsCollectorTest, IceCandidateReport) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
StatsReports reports; // returned values.
@@ -1338,7 +1351,7 @@ TEST_F(StatsCollectorTest, ChainlessCertificateReportsCreated) {
// This test verifies that the stats are generated correctly when no
// transport is present.
TEST_F(StatsCollectorTest, NoTransport) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -1364,9 +1377,6 @@ TEST_F(StatsCollectorTest, NoTransport) {
.WillOnce(DoAll(SetArgPointee<0>(session_stats),
Return(true)));
- EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
- EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
-
stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
stats.GetStats(NULL, &reports);
@@ -1400,7 +1410,7 @@ TEST_F(StatsCollectorTest, NoTransport) {
// This test verifies that the stats are generated correctly when the transport
// does not have any certificates.
TEST_F(StatsCollectorTest, NoCertificates) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -1429,9 +1439,6 @@ TEST_F(StatsCollectorTest, NoCertificates) {
EXPECT_CALL(session_, GetTransportStats(_))
.WillOnce(DoAll(SetArgPointee<0>(session_stats),
Return(true)));
- EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
- EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
-
stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
stats.GetStats(NULL, &reports);
@@ -1469,7 +1476,7 @@ TEST_F(StatsCollectorTest, UnsupportedDigestIgnored) {
// This test verifies that a local stats object can get statistics via
// AudioTrackInterface::GetStats() method.
TEST_F(StatsCollectorTest, GetStatsFromLocalAudioTrack) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -1504,7 +1511,7 @@ TEST_F(StatsCollectorTest, GetStatsFromLocalAudioTrack) {
// This test verifies that audio receive streams populate stats reports
// correctly.
TEST_F(StatsCollectorTest, GetStatsFromRemoteStream) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -1533,7 +1540,7 @@ TEST_F(StatsCollectorTest, GetStatsFromRemoteStream) {
// This test verifies that a local stats object won't update its statistics
// after a RemoveLocalAudioTrack() call.
TEST_F(StatsCollectorTest, GetStatsAfterRemoveAudioStream) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -1594,7 +1601,7 @@ TEST_F(StatsCollectorTest, GetStatsAfterRemoveAudioStream) {
// This test verifies that when ongoing and incoming audio tracks are using
// the same ssrc, they populate stats reports correctly.
TEST_F(StatsCollectorTest, LocalAndRemoteTracksWithSameSsrc) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));
@@ -1681,7 +1688,7 @@ TEST_F(StatsCollectorTest, LocalAndRemoteTracksWithSameSsrc) {
// TODO(xians): Figure out if it is possible to encapsulate the setup and
// avoid duplication of code in test cases.
TEST_F(StatsCollectorTest, TwoLocalTracksWithSameSsrc) {
- StatsCollectorForTest stats(&session_);
+ StatsCollectorForTest stats(&pc_, &session_);
EXPECT_CALL(session_, GetLocalCertificate(_, _))
.WillRepeatedly(Return(false));

Powered by Google App Engine
This is Rietveld 408576698