Use fake PeerConnection for RTCStatsCollector tests
This removes use of the MockPeerConnection and replaces it with the FakePeerConnectionForStats testing class. Bug: webrtc:8764 Change-Id: I78553c5a4e4d68cb6666a83f443f72f7c25488dc Reviewed-on: https://webrtc-review.googlesource.com/46940 Commit-Queue: Steve Anton <steveanton@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21882}
This commit is contained in:
parent
8eca1ff510
commit
5b38731f0b
File diff suppressed because it is too large
Load Diff
@ -646,7 +646,7 @@ class StatsCollectorTest : public testing::Test {
|
||||
auto pc = CreatePeerConnection();
|
||||
auto stats = CreateStatsCollector(pc);
|
||||
|
||||
pc->AddVoiceChannel("audio", kTransportName, VoiceMediaInfo());
|
||||
pc->AddVoiceChannel("audio", kTransportName);
|
||||
|
||||
// Fake stats to process.
|
||||
TransportChannelStats channel_stats;
|
||||
@ -859,7 +859,9 @@ TEST_P(StatsCollectorTrackTest, BytesCounterHandles64Bits) {
|
||||
video_sender_info.bytes_sent = kBytesSent;
|
||||
VideoMediaInfo video_info;
|
||||
video_info.senders.push_back(video_sender_info);
|
||||
pc->AddVideoChannel("video", "transport", video_info);
|
||||
|
||||
auto* video_media_channel = pc->AddVideoChannel("video", "transport");
|
||||
video_media_channel->SetStats(video_info);
|
||||
|
||||
AddOutgoingVideoTrack(pc, stats.get());
|
||||
|
||||
@ -889,7 +891,9 @@ TEST_P(StatsCollectorTrackTest, AudioBandwidthEstimationInfoIsReported) {
|
||||
voice_sender_info.bytes_sent = kBytesSent;
|
||||
VoiceMediaInfo voice_info;
|
||||
voice_info.senders.push_back(voice_sender_info);
|
||||
pc->AddVoiceChannel("audio", "transport", voice_info);
|
||||
|
||||
auto* voice_media_channel = pc->AddVoiceChannel("audio", "transport");
|
||||
voice_media_channel->SetStats(voice_info);
|
||||
|
||||
AddOutgoingAudioTrack(pc, stats.get());
|
||||
|
||||
@ -935,7 +939,9 @@ TEST_P(StatsCollectorTrackTest, VideoBandwidthEstimationInfoIsReported) {
|
||||
video_sender_info.bytes_sent = kBytesSent;
|
||||
VideoMediaInfo video_info;
|
||||
video_info.senders.push_back(video_sender_info);
|
||||
pc->AddVideoChannel("video", "transport", video_info);
|
||||
|
||||
auto* video_media_channel = pc->AddVideoChannel("video", "transport");
|
||||
video_media_channel->SetStats(video_info);
|
||||
|
||||
AddOutgoingVideoTrack(pc, stats.get());
|
||||
|
||||
@ -1001,7 +1007,7 @@ TEST_P(StatsCollectorTrackTest, TrackObjectExistsWithoutUpdateStats) {
|
||||
auto pc = CreatePeerConnection();
|
||||
auto stats = CreateStatsCollector(pc);
|
||||
|
||||
pc->AddVideoChannel("video", "transport", VideoMediaInfo());
|
||||
pc->AddVideoChannel("video", "transport");
|
||||
AddOutgoingVideoTrack(pc, stats.get());
|
||||
|
||||
// Verfies the existence of the track report.
|
||||
@ -1031,7 +1037,9 @@ TEST_P(StatsCollectorTrackTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) {
|
||||
video_sender_info.bytes_sent = kBytesSent;
|
||||
VideoMediaInfo video_info;
|
||||
video_info.senders.push_back(video_sender_info);
|
||||
pc->AddVideoChannel("video", "transport", video_info);
|
||||
|
||||
auto* video_media_channel = pc->AddVideoChannel("video", "transport");
|
||||
video_media_channel->SetStats(video_info);
|
||||
|
||||
AddOutgoingVideoTrack(pc, stats.get());
|
||||
|
||||
@ -1083,7 +1091,9 @@ TEST_P(StatsCollectorTrackTest, TransportObjectLinkedFromSsrcObject) {
|
||||
video_sender_info.bytes_sent = kBytesSent;
|
||||
VideoMediaInfo video_info;
|
||||
video_info.senders.push_back(video_sender_info);
|
||||
pc->AddVideoChannel("video", "transport", video_info);
|
||||
|
||||
auto* video_media_channel = pc->AddVideoChannel("video", "transport");
|
||||
video_media_channel->SetStats(video_info);
|
||||
|
||||
AddOutgoingVideoTrack(pc, stats.get());
|
||||
|
||||
@ -1119,7 +1129,7 @@ TEST_P(StatsCollectorTrackTest, RemoteSsrcInfoIsAbsent) {
|
||||
auto pc = CreatePeerConnection();
|
||||
auto stats = CreateStatsCollector(pc);
|
||||
|
||||
pc->AddVideoChannel("video", "transport", VideoMediaInfo());
|
||||
pc->AddVideoChannel("video", "transport");
|
||||
AddOutgoingVideoTrack(pc, stats.get());
|
||||
|
||||
stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
|
||||
@ -1145,7 +1155,9 @@ TEST_P(StatsCollectorTrackTest, RemoteSsrcInfoIsPresent) {
|
||||
video_sender_info.remote_stats.push_back(remote_ssrc_stats);
|
||||
VideoMediaInfo video_info;
|
||||
video_info.senders.push_back(video_sender_info);
|
||||
pc->AddVideoChannel("video", "transport", video_info);
|
||||
|
||||
auto* video_media_channel = pc->AddVideoChannel("video", "transport");
|
||||
video_media_channel->SetStats(video_info);
|
||||
|
||||
AddOutgoingVideoTrack(pc, stats.get());
|
||||
|
||||
@ -1172,7 +1184,9 @@ TEST_P(StatsCollectorTrackTest, ReportsFromRemoteTrack) {
|
||||
video_receiver_info.packets_concealed = kNumOfPacketsConcealed;
|
||||
VideoMediaInfo video_info;
|
||||
video_info.receivers.push_back(video_receiver_info);
|
||||
pc->AddVideoChannel("video", "transport", video_info);
|
||||
|
||||
auto* video_media_info = pc->AddVideoChannel("video", "transport");
|
||||
video_media_info->SetStats(video_info);
|
||||
|
||||
AddIncomingVideoTrack(pc, stats.get());
|
||||
|
||||
@ -1237,7 +1251,7 @@ TEST_F(StatsCollectorTest, IceCandidateReport) {
|
||||
TransportChannelStats channel_stats;
|
||||
channel_stats.connection_infos.push_back(connection_info);
|
||||
|
||||
pc->AddVoiceChannel("audio", kTransportName, VoiceMediaInfo());
|
||||
pc->AddVoiceChannel("audio", kTransportName);
|
||||
pc->SetTransportStats(kTransportName, channel_stats);
|
||||
|
||||
stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
|
||||
@ -1355,7 +1369,7 @@ TEST_F(StatsCollectorTest, NoTransport) {
|
||||
|
||||
// This will cause the fake PeerConnection to generate a TransportStats entry
|
||||
// but with only a single dummy TransportChannelStats.
|
||||
pc->AddVoiceChannel("audio", "transport", VoiceMediaInfo());
|
||||
pc->AddVoiceChannel("audio", "transport");
|
||||
|
||||
stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
|
||||
StatsReports reports;
|
||||
@ -1459,7 +1473,8 @@ TEST_P(StatsCollectorTrackTest, FilterOutNegativeInitialValues) {
|
||||
voice_info.senders.push_back(voice_sender_info);
|
||||
voice_info.receivers.push_back(voice_receiver_info);
|
||||
|
||||
pc->AddVoiceChannel("voice", "transport", voice_info);
|
||||
auto* voice_media_channel = pc->AddVoiceChannel("voice", "transport");
|
||||
voice_media_channel->SetStats(voice_info);
|
||||
|
||||
stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
|
||||
|
||||
@ -1508,7 +1523,9 @@ TEST_P(StatsCollectorTrackTest, GetStatsFromLocalAudioTrack) {
|
||||
UpdateVoiceSenderInfoFromAudioTrack(audio_track_, &voice_sender_info, false);
|
||||
VoiceMediaInfo voice_info;
|
||||
voice_info.senders.push_back(voice_sender_info);
|
||||
pc->AddVoiceChannel("audio", "transport", voice_info);
|
||||
|
||||
auto* voice_media_channel = pc->AddVoiceChannel("audio", "transport");
|
||||
voice_media_channel->SetStats(voice_info);
|
||||
|
||||
StatsReports reports; // returned values.
|
||||
VerifyAudioTrackStats(audio_track_, stats.get(), voice_info, &reports);
|
||||
@ -1533,7 +1550,9 @@ TEST_P(StatsCollectorTrackTest, GetStatsFromRemoteStream) {
|
||||
voice_receiver_info.codec_name = "fake_codec";
|
||||
VoiceMediaInfo voice_info;
|
||||
voice_info.receivers.push_back(voice_receiver_info);
|
||||
pc->AddVoiceChannel("audio", "transport", voice_info);
|
||||
|
||||
auto* voice_media_channel = pc->AddVoiceChannel("audio", "transport");
|
||||
voice_media_channel->SetStats(voice_info);
|
||||
|
||||
StatsReports reports; // returned values.
|
||||
VerifyAudioTrackStats(audio_track_, stats.get(), voice_info, &reports);
|
||||
@ -1553,7 +1572,8 @@ TEST_P(StatsCollectorTrackTest, GetStatsAfterRemoveAudioStream) {
|
||||
VoiceMediaInfo voice_info;
|
||||
voice_info.senders.push_back(voice_sender_info);
|
||||
|
||||
pc->AddVoiceChannel("audio", "transport", voice_info);
|
||||
auto* voice_media_channel = pc->AddVoiceChannel("audio", "transport");
|
||||
voice_media_channel->SetStats(voice_info);
|
||||
|
||||
stats->RemoveLocalAudioTrack(audio_track_.get(), kSsrcOfTrack);
|
||||
|
||||
@ -1614,7 +1634,8 @@ TEST_P(StatsCollectorTrackTest, LocalAndRemoteTracksWithSameSsrc) {
|
||||
voice_info.receivers.push_back(voice_receiver_info);
|
||||
|
||||
// Instruct the session to return stats containing the transport channel.
|
||||
pc->AddVoiceChannel("audio", "transport", voice_info);
|
||||
auto* voice_media_channel = pc->AddVoiceChannel("audio", "transport");
|
||||
voice_media_channel->SetStats(voice_info);
|
||||
|
||||
stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
|
||||
|
||||
@ -1667,7 +1688,9 @@ TEST_P(StatsCollectorTrackTest, TwoLocalTracksWithSameSsrc) {
|
||||
voice_sender_info.add_ssrc(kSsrcOfTrack);
|
||||
VoiceMediaInfo voice_info;
|
||||
voice_info.senders.push_back(voice_sender_info);
|
||||
auto* media_channel = pc->AddVoiceChannel("voice", "transport", voice_info);
|
||||
|
||||
auto* voice_media_channel = pc->AddVoiceChannel("voice", "transport");
|
||||
voice_media_channel->SetStats(voice_info);
|
||||
|
||||
StatsReports reports; // returned values.
|
||||
VerifyAudioTrackStats(audio_track_, stats.get(), voice_info, &reports);
|
||||
@ -1692,7 +1715,7 @@ TEST_P(StatsCollectorTrackTest, TwoLocalTracksWithSameSsrc) {
|
||||
false);
|
||||
VoiceMediaInfo new_voice_info;
|
||||
new_voice_info.senders.push_back(new_voice_sender_info);
|
||||
media_channel->SetStats(new_voice_info);
|
||||
voice_media_channel->SetStats(new_voice_info);
|
||||
|
||||
reports.clear();
|
||||
VerifyAudioTrackStats(new_audio_track, stats.get(), new_voice_info, &reports);
|
||||
@ -1711,7 +1734,9 @@ TEST_P(StatsCollectorTrackTest, VerifyVideoSendSsrcStats) {
|
||||
video_sender_info.qp_sum = 11;
|
||||
VideoMediaInfo video_info;
|
||||
video_info.senders.push_back(video_sender_info);
|
||||
pc->AddVideoChannel("video", "transport", video_info);
|
||||
|
||||
auto* video_media_channel = pc->AddVideoChannel("video", "transport");
|
||||
video_media_channel->SetStats(video_info);
|
||||
|
||||
stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
|
||||
StatsReports reports;
|
||||
@ -1737,7 +1762,9 @@ TEST_P(StatsCollectorTrackTest, VerifyVideoReceiveSsrcStatsNew) {
|
||||
video_receiver_info.qp_sum = 11;
|
||||
VideoMediaInfo video_info;
|
||||
video_info.receivers.push_back(video_receiver_info);
|
||||
pc->AddVideoChannel("video", "transport", video_info);
|
||||
|
||||
auto* video_media_channel = pc->AddVideoChannel("video", "transport");
|
||||
video_media_channel->SetStats(video_info);
|
||||
|
||||
stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
|
||||
StatsReports reports;
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "media/base/fakemediaengine.h"
|
||||
#include "pc/streamcollection.h"
|
||||
#include "pc/test/fakedatachannelprovider.h"
|
||||
#include "pc/test/fakepeerconnectionbase.h"
|
||||
|
||||
@ -84,12 +85,29 @@ class FakePeerConnectionForStats : public FakePeerConnectionBase {
|
||||
FakePeerConnectionForStats()
|
||||
: network_thread_(rtc::Thread::Current()),
|
||||
worker_thread_(rtc::Thread::Current()),
|
||||
signaling_thread_(rtc::Thread::Current()) {}
|
||||
signaling_thread_(rtc::Thread::Current()),
|
||||
local_streams_(StreamCollection::Create()),
|
||||
remote_streams_(StreamCollection::Create()) {}
|
||||
|
||||
rtc::scoped_refptr<StreamCollection> mutable_local_streams() {
|
||||
return local_streams_;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<StreamCollection> mutable_remote_streams() {
|
||||
return remote_streams_;
|
||||
}
|
||||
|
||||
void AddSender(rtc::scoped_refptr<RtpSenderInterface> sender) {
|
||||
senders_.push_back(sender);
|
||||
}
|
||||
|
||||
void AddReceiver(rtc::scoped_refptr<RtpReceiverInterface> receiver) {
|
||||
receivers_.push_back(receiver);
|
||||
}
|
||||
|
||||
FakeVoiceMediaChannelForStats* AddVoiceChannel(
|
||||
const std::string& mid,
|
||||
const std::string& transport_name,
|
||||
const cricket::VoiceMediaInfo& voice_info) {
|
||||
const std::string& transport_name) {
|
||||
RTC_DCHECK(!voice_channel_);
|
||||
auto voice_media_channel = rtc::MakeUnique<FakeVoiceMediaChannelForStats>();
|
||||
auto* voice_media_channel_ptr = voice_media_channel.get();
|
||||
@ -98,14 +116,12 @@ class FakePeerConnectionForStats : public FakePeerConnectionBase {
|
||||
std::move(voice_media_channel), mid, kDefaultRtcpMuxRequired,
|
||||
kDefaultSrtpRequired);
|
||||
voice_channel_->set_transport_name_for_testing(transport_name);
|
||||
voice_media_channel_ptr->SetStats(voice_info);
|
||||
return voice_media_channel_ptr;
|
||||
}
|
||||
|
||||
FakeVideoMediaChannelForStats* AddVideoChannel(
|
||||
const std::string& mid,
|
||||
const std::string& transport_name,
|
||||
const cricket::VideoMediaInfo& video_stats) {
|
||||
const std::string& transport_name) {
|
||||
RTC_DCHECK(!video_channel_);
|
||||
auto video_media_channel = rtc::MakeUnique<FakeVideoMediaChannelForStats>();
|
||||
auto video_media_channel_ptr = video_media_channel.get();
|
||||
@ -114,7 +130,6 @@ class FakePeerConnectionForStats : public FakePeerConnectionBase {
|
||||
std::move(video_media_channel), mid, kDefaultRtcpMuxRequired,
|
||||
kDefaultSrtpRequired);
|
||||
video_channel_->set_transport_name_for_testing(transport_name);
|
||||
video_media_channel_ptr->SetStats(video_stats);
|
||||
return video_media_channel_ptr;
|
||||
}
|
||||
|
||||
@ -132,15 +147,27 @@ class FakePeerConnectionForStats : public FakePeerConnectionBase {
|
||||
|
||||
void AddSctpDataChannel(const std::string& label,
|
||||
const InternalDataChannelInit& init) {
|
||||
sctp_data_channels_.push_back(DataChannel::Create(
|
||||
&data_channel_provider_, cricket::DCT_SCTP, label, init));
|
||||
AddSctpDataChannel(DataChannel::Create(&data_channel_provider_,
|
||||
cricket::DCT_SCTP, label, init));
|
||||
}
|
||||
|
||||
void AddSctpDataChannel(rtc::scoped_refptr<DataChannel> data_channel) {
|
||||
sctp_data_channels_.push_back(data_channel);
|
||||
}
|
||||
|
||||
void SetTransportStats(const std::string& transport_name,
|
||||
const cricket::TransportChannelStats& channel_stats) {
|
||||
SetTransportStats(
|
||||
transport_name,
|
||||
std::vector<cricket::TransportChannelStats>{channel_stats});
|
||||
}
|
||||
|
||||
void SetTransportStats(
|
||||
const std::string& transport_name,
|
||||
const std::vector<cricket::TransportChannelStats>& channel_stats_list) {
|
||||
cricket::TransportStats transport_stats;
|
||||
transport_stats.transport_name = transport_name;
|
||||
transport_stats.channel_stats.push_back(channel_stats);
|
||||
transport_stats.channel_stats = channel_stats_list;
|
||||
transport_stats_by_name_[transport_name] = transport_stats;
|
||||
}
|
||||
|
||||
@ -157,6 +184,26 @@ class FakePeerConnectionForStats : public FakePeerConnectionBase {
|
||||
remote_certificates_by_transport_[transport_name] = std::move(certificate);
|
||||
}
|
||||
|
||||
// PeerConnectionInterface overrides.
|
||||
|
||||
rtc::scoped_refptr<StreamCollectionInterface> local_streams() override {
|
||||
return local_streams_;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override {
|
||||
return remote_streams_;
|
||||
}
|
||||
|
||||
std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
|
||||
const override {
|
||||
return senders_;
|
||||
}
|
||||
|
||||
std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
|
||||
const override {
|
||||
return receivers_;
|
||||
}
|
||||
|
||||
// PeerConnectionInternal overrides.
|
||||
|
||||
rtc::Thread* network_thread() const override { return network_thread_; }
|
||||
@ -268,7 +315,7 @@ class FakePeerConnectionForStats : public FakePeerConnectionBase {
|
||||
}
|
||||
// Otherwise, generate some dummy stats.
|
||||
cricket::TransportChannelStats channel_stats;
|
||||
channel_stats.component = 1;
|
||||
channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP;
|
||||
cricket::TransportStats transport_stats;
|
||||
transport_stats.transport_name = transport_name;
|
||||
transport_stats.channel_stats.push_back(channel_stats);
|
||||
@ -279,6 +326,12 @@ class FakePeerConnectionForStats : public FakePeerConnectionBase {
|
||||
rtc::Thread* const worker_thread_;
|
||||
rtc::Thread* const signaling_thread_;
|
||||
|
||||
rtc::scoped_refptr<StreamCollection> local_streams_;
|
||||
rtc::scoped_refptr<StreamCollection> remote_streams_;
|
||||
|
||||
std::vector<rtc::scoped_refptr<RtpSenderInterface>> senders_;
|
||||
std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers_;
|
||||
|
||||
FakeDataChannelProvider data_channel_provider_;
|
||||
|
||||
std::unique_ptr<cricket::VoiceChannel> voice_channel_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user