blob: e4c311836776be9b633a0ef663901cc6110e2d20 [file] [log] [blame]
hbosd565b732016-08-30 14:04:35 -07001/*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
hbos74e1a4f2016-09-15 23:33:01 -070011#include "webrtc/api/rtcstatscollector.h"
hbosd565b732016-08-30 14:04:35 -070012
13#include <memory>
hbosda389e32016-10-25 10:55:08 -070014#include <ostream>
hbosd565b732016-08-30 14:04:35 -070015#include <string>
16#include <vector>
17
hbos0adb8282016-11-23 02:32:06 -080018#include "webrtc/api/jsepsessiondescription.h"
hbos09bc1282016-11-08 06:29:22 -080019#include "webrtc/api/mediastream.h"
20#include "webrtc/api/mediastreamtrack.h"
hbos0adb8282016-11-23 02:32:06 -080021#include "webrtc/api/rtpparameters.h"
hbos74e1a4f2016-09-15 23:33:01 -070022#include "webrtc/api/stats/rtcstats_objects.h"
23#include "webrtc/api/stats/rtcstatsreport.h"
hbosd565b732016-08-30 14:04:35 -070024#include "webrtc/api/test/mock_datachannel.h"
25#include "webrtc/api/test/mock_peerconnection.h"
26#include "webrtc/api/test/mock_webrtcsession.h"
hbosdb346a72016-11-29 01:57:01 -080027#include "webrtc/api/test/rtcstatsobtainer.h"
hbosd565b732016-08-30 14:04:35 -070028#include "webrtc/base/checks.h"
hbos0e6758d2016-08-31 07:57:36 -070029#include "webrtc/base/fakeclock.h"
hbos6ab97ce2016-10-03 14:16:56 -070030#include "webrtc/base/fakesslidentity.h"
hbosd565b732016-08-30 14:04:35 -070031#include "webrtc/base/gunit.h"
32#include "webrtc/base/logging.h"
hbosab9f6e42016-10-07 02:18:47 -070033#include "webrtc/base/socketaddress.h"
hbosc82f2e12016-09-05 01:36:50 -070034#include "webrtc/base/thread_checker.h"
hbos0e6758d2016-08-31 07:57:36 -070035#include "webrtc/base/timedelta.h"
36#include "webrtc/base/timeutils.h"
skvlad11a9cbf2016-10-07 11:53:05 -070037#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
hbosd565b732016-08-30 14:04:35 -070038#include "webrtc/media/base/fakemediaengine.h"
hbos6ded1902016-11-01 01:50:46 -070039#include "webrtc/media/base/test/mock_mediachannel.h"
hbos2fa7c672016-10-24 04:00:05 -070040#include "webrtc/p2p/base/p2pconstants.h"
hbosab9f6e42016-10-07 02:18:47 -070041#include "webrtc/p2p/base/port.h"
hbosd565b732016-08-30 14:04:35 -070042
hbos6ab97ce2016-10-03 14:16:56 -070043using testing::_;
44using testing::Invoke;
hbosd565b732016-08-30 14:04:35 -070045using testing::Return;
hbos6ded1902016-11-01 01:50:46 -070046using testing::ReturnNull;
hbosd565b732016-08-30 14:04:35 -070047using testing::ReturnRef;
hbos6ded1902016-11-01 01:50:46 -070048using testing::SetArgPointee;
hbosd565b732016-08-30 14:04:35 -070049
50namespace webrtc {
51
hbosda389e32016-10-25 10:55:08 -070052// These are used by gtest code, such as if |EXPECT_EQ| fails.
53void PrintTo(const RTCCertificateStats& stats, ::std::ostream* os) {
54 *os << stats.ToString();
55}
56
hbos0adb8282016-11-23 02:32:06 -080057void PrintTo(const RTCCodecStats& stats, ::std::ostream* os) {
58 *os << stats.ToString();
59}
60
hbosda389e32016-10-25 10:55:08 -070061void PrintTo(const RTCDataChannelStats& stats, ::std::ostream* os) {
62 *os << stats.ToString();
63}
64
65void PrintTo(const RTCIceCandidatePairStats& stats, ::std::ostream* os) {
66 *os << stats.ToString();
67}
68
69void PrintTo(const RTCLocalIceCandidateStats& stats, ::std::ostream* os) {
70 *os << stats.ToString();
71}
72
73void PrintTo(const RTCRemoteIceCandidateStats& stats, ::std::ostream* os) {
74 *os << stats.ToString();
75}
76
77void PrintTo(const RTCPeerConnectionStats& stats, ::std::ostream* os) {
78 *os << stats.ToString();
79}
80
hbos09bc1282016-11-08 06:29:22 -080081void PrintTo(const RTCMediaStreamStats& stats, ::std::ostream* os) {
82 *os << stats.ToString();
83}
84
85void PrintTo(const RTCMediaStreamTrackStats& stats, ::std::ostream* os) {
86 *os << stats.ToString();
87}
88
hboseeafe942016-11-01 03:00:17 -070089void PrintTo(const RTCInboundRTPStreamStats& stats, ::std::ostream* os) {
90 *os << stats.ToString();
91}
92
hbos6ded1902016-11-01 01:50:46 -070093void PrintTo(const RTCOutboundRTPStreamStats& stats, ::std::ostream* os) {
94 *os << stats.ToString();
95}
96
hbosda389e32016-10-25 10:55:08 -070097void PrintTo(const RTCTransportStats& stats, ::std::ostream* os) {
98 *os << stats.ToString();
99}
100
hbosc82f2e12016-09-05 01:36:50 -0700101namespace {
102
103const int64_t kGetStatsReportTimeoutMs = 1000;
104
hbos6ab97ce2016-10-03 14:16:56 -0700105struct CertificateInfo {
106 rtc::scoped_refptr<rtc::RTCCertificate> certificate;
107 std::vector<std::string> ders;
108 std::vector<std::string> pems;
109 std::vector<std::string> fingerprints;
110};
111
112std::unique_ptr<CertificateInfo> CreateFakeCertificateAndInfoFromDers(
113 const std::vector<std::string>& ders) {
114 RTC_CHECK(!ders.empty());
115 std::unique_ptr<CertificateInfo> info(new CertificateInfo());
116 info->ders = ders;
117 for (const std::string& der : ders) {
118 info->pems.push_back(rtc::SSLIdentity::DerToPem(
119 "CERTIFICATE",
120 reinterpret_cast<const unsigned char*>(der.c_str()),
121 der.length()));
122 }
123 info->certificate =
124 rtc::RTCCertificate::Create(std::unique_ptr<rtc::FakeSSLIdentity>(
125 new rtc::FakeSSLIdentity(rtc::FakeSSLCertificate(info->pems))));
126 // Strip header/footer and newline characters of PEM strings.
127 for (size_t i = 0; i < info->pems.size(); ++i) {
128 rtc::replace_substrs("-----BEGIN CERTIFICATE-----", 27,
129 "", 0, &info->pems[i]);
130 rtc::replace_substrs("-----END CERTIFICATE-----", 25,
131 "", 0, &info->pems[i]);
132 rtc::replace_substrs("\n", 1,
133 "", 0, &info->pems[i]);
134 }
135 // Fingerprint of leaf certificate.
136 std::unique_ptr<rtc::SSLFingerprint> fp(
137 rtc::SSLFingerprint::Create("sha-1",
138 &info->certificate->ssl_certificate()));
139 EXPECT_TRUE(fp);
140 info->fingerprints.push_back(fp->GetRfc4572Fingerprint());
141 // Fingerprints of the rest of the chain.
142 std::unique_ptr<rtc::SSLCertChain> chain =
143 info->certificate->ssl_certificate().GetChain();
144 if (chain) {
145 for (size_t i = 0; i < chain->GetSize(); i++) {
146 fp.reset(rtc::SSLFingerprint::Create("sha-1", &chain->Get(i)));
147 EXPECT_TRUE(fp);
148 info->fingerprints.push_back(fp->GetRfc4572Fingerprint());
149 }
150 }
151 EXPECT_EQ(info->ders.size(), info->fingerprints.size());
152 return info;
153}
154
hbosab9f6e42016-10-07 02:18:47 -0700155std::unique_ptr<cricket::Candidate> CreateFakeCandidate(
156 const std::string& hostname,
157 int port,
158 const std::string& protocol,
159 const std::string& candidate_type,
160 uint32_t priority) {
161 std::unique_ptr<cricket::Candidate> candidate(new cricket::Candidate());
162 candidate->set_address(rtc::SocketAddress(hostname, port));
163 candidate->set_protocol(protocol);
164 candidate->set_type(candidate_type);
165 candidate->set_priority(priority);
166 return candidate;
167}
168
hbos09bc1282016-11-08 06:29:22 -0800169class FakeAudioProcessorForStats
170 : public rtc::RefCountedObject<AudioProcessorInterface> {
171 public:
172 FakeAudioProcessorForStats(
173 AudioProcessorInterface::AudioProcessorStats stats)
174 : stats_(stats) {
175 }
176
177 void GetStats(AudioProcessorInterface::AudioProcessorStats* stats) override {
178 *stats = stats_;
179 }
180
181 private:
182 AudioProcessorInterface::AudioProcessorStats stats_;
183};
184
185class FakeAudioTrackForStats
186 : public MediaStreamTrack<AudioTrackInterface> {
187 public:
188 static rtc::scoped_refptr<FakeAudioTrackForStats> Create(
189 const std::string& id,
190 MediaStreamTrackInterface::TrackState state,
191 int signal_level,
192 rtc::scoped_refptr<FakeAudioProcessorForStats> processor) {
193 rtc::scoped_refptr<FakeAudioTrackForStats> audio_track_stats(
194 new rtc::RefCountedObject<FakeAudioTrackForStats>(
195 id, signal_level, processor));
196 audio_track_stats->set_state(state);
197 return audio_track_stats;
198 }
199
200 FakeAudioTrackForStats(
201 const std::string& id,
202 int signal_level,
203 rtc::scoped_refptr<FakeAudioProcessorForStats> processor)
204 : MediaStreamTrack<AudioTrackInterface>(id),
205 signal_level_(signal_level),
206 processor_(processor) {
207 }
208
209 std::string kind() const override {
210 return MediaStreamTrackInterface::kAudioKind;
211 }
212 webrtc::AudioSourceInterface* GetSource() const override { return nullptr; }
213 void AddSink(webrtc::AudioTrackSinkInterface* sink) override {}
214 void RemoveSink(webrtc::AudioTrackSinkInterface* sink) override {}
215 bool GetSignalLevel(int* level) override {
216 *level = signal_level_;
217 return true;
218 }
219 rtc::scoped_refptr<AudioProcessorInterface> GetAudioProcessor() override {
220 return processor_;
221 }
222
223 private:
224 int signal_level_;
225 rtc::scoped_refptr<FakeAudioProcessorForStats> processor_;
226};
227
228class FakeVideoTrackSourceForStats
229 : public rtc::RefCountedObject<VideoTrackSourceInterface> {
230 public:
231 FakeVideoTrackSourceForStats(VideoTrackSourceInterface::Stats stats)
232 : stats_(stats) {
233 }
234
235 MediaSourceInterface::SourceState state() const override {
236 return MediaSourceInterface::kLive;
237 }
238 bool remote() const override { return false; }
239 void RegisterObserver(ObserverInterface* observer) override {}
240 void UnregisterObserver(ObserverInterface* observer) override {}
nisseacd935b2016-11-11 03:55:13 -0800241 void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
hbos09bc1282016-11-08 06:29:22 -0800242 const rtc::VideoSinkWants& wants) override {}
nisseacd935b2016-11-11 03:55:13 -0800243 void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override {
hbos09bc1282016-11-08 06:29:22 -0800244 }
245 bool is_screencast() const override { return false; }
246 rtc::Optional<bool> needs_denoising() const override {
247 return rtc::Optional<bool>();
248 }
249 bool GetStats(VideoTrackSourceInterface::Stats* stats) override {
250 *stats = stats_;
251 return true;
252 }
253
254 private:
255 VideoTrackSourceInterface::Stats stats_;
256};
257
258class FakeVideoTrackForStats
259 : public MediaStreamTrack<VideoTrackInterface> {
260 public:
261 static rtc::scoped_refptr<FakeVideoTrackForStats> Create(
262 const std::string& id,
263 MediaStreamTrackInterface::TrackState state,
264 rtc::scoped_refptr<VideoTrackSourceInterface> source) {
265 rtc::scoped_refptr<FakeVideoTrackForStats> video_track(
266 new rtc::RefCountedObject<FakeVideoTrackForStats>(id, source));
267 video_track->set_state(state);
268 return video_track;
269 }
270
271 FakeVideoTrackForStats(
272 const std::string& id,
273 rtc::scoped_refptr<VideoTrackSourceInterface> source)
274 : MediaStreamTrack<VideoTrackInterface>(id),
275 source_(source) {
276 }
277
278 std::string kind() const override {
279 return MediaStreamTrackInterface::kVideoKind;
280 }
281 VideoTrackSourceInterface* GetSource() const override {
282 return source_;
283 }
284
285 private:
286 rtc::scoped_refptr<VideoTrackSourceInterface> source_;
287};
288
hbosc82f2e12016-09-05 01:36:50 -0700289class RTCStatsCollectorTestHelper : public SetSessionDescriptionObserver {
hbosd565b732016-08-30 14:04:35 -0700290 public:
hbosc82f2e12016-09-05 01:36:50 -0700291 RTCStatsCollectorTestHelper()
hbosd565b732016-08-30 14:04:35 -0700292 : worker_thread_(rtc::Thread::Current()),
293 network_thread_(rtc::Thread::Current()),
hbos6ded1902016-11-01 01:50:46 -0700294 media_engine_(new cricket::FakeMediaEngine()),
skvlad11a9cbf2016-10-07 11:53:05 -0700295 channel_manager_(
hbos6ded1902016-11-01 01:50:46 -0700296 new cricket::ChannelManager(media_engine_,
skvlad11a9cbf2016-10-07 11:53:05 -0700297 worker_thread_,
298 network_thread_)),
hbosd565b732016-08-30 14:04:35 -0700299 media_controller_(
300 MediaControllerInterface::Create(cricket::MediaConfig(),
301 worker_thread_,
skvlad11a9cbf2016-10-07 11:53:05 -0700302 channel_manager_.get(),
303 &event_log_)),
hbosd565b732016-08-30 14:04:35 -0700304 session_(media_controller_.get()),
305 pc_() {
hbos6ab97ce2016-10-03 14:16:56 -0700306 // Default return values for mocks.
hbos09bc1282016-11-08 06:29:22 -0800307 EXPECT_CALL(pc_, local_streams()).WillRepeatedly(Return(nullptr));
308 EXPECT_CALL(pc_, remote_streams()).WillRepeatedly(Return(nullptr));
hbosd565b732016-08-30 14:04:35 -0700309 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_));
310 EXPECT_CALL(pc_, sctp_data_channels()).WillRepeatedly(
311 ReturnRef(data_channels_));
hbos6ded1902016-11-01 01:50:46 -0700312 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
313 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
hbos6ab97ce2016-10-03 14:16:56 -0700314 EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false));
hbosab9f6e42016-10-07 02:18:47 -0700315 EXPECT_CALL(session_, GetLocalCertificate(_, _)).WillRepeatedly(
316 Return(false));
317 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
318 .WillRepeatedly(Return(nullptr));
hbosd565b732016-08-30 14:04:35 -0700319 }
320
hbosfdafab82016-09-14 06:02:13 -0700321 rtc::ScopedFakeClock& fake_clock() { return fake_clock_; }
hbos6ded1902016-11-01 01:50:46 -0700322 rtc::Thread* worker_thread() { return worker_thread_; }
323 rtc::Thread* network_thread() { return network_thread_; }
324 cricket::FakeMediaEngine* media_engine() { return media_engine_; }
hbosd565b732016-08-30 14:04:35 -0700325 MockWebRtcSession& session() { return session_; }
326 MockPeerConnection& pc() { return pc_; }
327 std::vector<rtc::scoped_refptr<DataChannel>>& data_channels() {
328 return data_channels_;
329 }
330
331 // SetSessionDescriptionObserver overrides.
332 void OnSuccess() override {}
333 void OnFailure(const std::string& error) override {
334 RTC_NOTREACHED() << error;
335 }
336
337 private:
hbosfdafab82016-09-14 06:02:13 -0700338 rtc::ScopedFakeClock fake_clock_;
hbos09bc1282016-11-08 06:29:22 -0800339 RtcEventLogNullImpl event_log_;
hbosd565b732016-08-30 14:04:35 -0700340 rtc::Thread* const worker_thread_;
341 rtc::Thread* const network_thread_;
hbos6ded1902016-11-01 01:50:46 -0700342 cricket::FakeMediaEngine* media_engine_;
hbosd565b732016-08-30 14:04:35 -0700343 std::unique_ptr<cricket::ChannelManager> channel_manager_;
hbos09bc1282016-11-08 06:29:22 -0800344 std::unique_ptr<MediaControllerInterface> media_controller_;
hbosd565b732016-08-30 14:04:35 -0700345 MockWebRtcSession session_;
346 MockPeerConnection pc_;
347
348 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_;
349};
350
hbosc82f2e12016-09-05 01:36:50 -0700351class RTCTestStats : public RTCStats {
hbosd565b732016-08-30 14:04:35 -0700352 public:
hbosfc5e0502016-10-06 02:06:10 -0700353 WEBRTC_RTCSTATS_DECL();
354
hbosc82f2e12016-09-05 01:36:50 -0700355 RTCTestStats(const std::string& id, int64_t timestamp_us)
356 : RTCStats(id, timestamp_us),
357 dummy_stat("dummyStat") {}
358
hbosc82f2e12016-09-05 01:36:50 -0700359 RTCStatsMember<int32_t> dummy_stat;
360};
361
hbosfc5e0502016-10-06 02:06:10 -0700362WEBRTC_RTCSTATS_IMPL(RTCTestStats, RTCStats, "test-stats",
363 &dummy_stat);
hbosc82f2e12016-09-05 01:36:50 -0700364
365// Overrides the stats collection to verify thread usage and that the resulting
366// partial reports are merged.
367class FakeRTCStatsCollector : public RTCStatsCollector,
368 public RTCStatsCollectorCallback {
369 public:
370 static rtc::scoped_refptr<FakeRTCStatsCollector> Create(
371 PeerConnection* pc,
372 int64_t cache_lifetime_us) {
373 return rtc::scoped_refptr<FakeRTCStatsCollector>(
374 new rtc::RefCountedObject<FakeRTCStatsCollector>(
375 pc, cache_lifetime_us));
376 }
377
378 // RTCStatsCollectorCallback implementation.
379 void OnStatsDelivered(
380 const rtc::scoped_refptr<const RTCStatsReport>& report) override {
381 EXPECT_TRUE(signaling_thread_->IsCurrent());
382 rtc::CritScope cs(&lock_);
383 delivered_report_ = report;
384 }
385
386 void VerifyThreadUsageAndResultsMerging() {
387 GetStatsReport(rtc::scoped_refptr<RTCStatsCollectorCallback>(this));
388 EXPECT_TRUE_WAIT(HasVerifiedResults(), kGetStatsReportTimeoutMs);
389 }
390
391 bool HasVerifiedResults() {
392 EXPECT_TRUE(signaling_thread_->IsCurrent());
393 rtc::CritScope cs(&lock_);
394 if (!delivered_report_)
395 return false;
396 EXPECT_EQ(produced_on_signaling_thread_, 1);
397 EXPECT_EQ(produced_on_worker_thread_, 1);
398 EXPECT_EQ(produced_on_network_thread_, 1);
399
400 EXPECT_TRUE(delivered_report_->Get("SignalingThreadStats"));
401 EXPECT_TRUE(delivered_report_->Get("WorkerThreadStats"));
402 EXPECT_TRUE(delivered_report_->Get("NetworkThreadStats"));
403
404 produced_on_signaling_thread_ = 0;
405 produced_on_worker_thread_ = 0;
406 produced_on_network_thread_ = 0;
407 delivered_report_ = nullptr;
408 return true;
hbosd565b732016-08-30 14:04:35 -0700409 }
410
411 protected:
hbosc82f2e12016-09-05 01:36:50 -0700412 FakeRTCStatsCollector(
413 PeerConnection* pc,
414 int64_t cache_lifetime)
415 : RTCStatsCollector(pc, cache_lifetime),
416 signaling_thread_(pc->session()->signaling_thread()),
417 worker_thread_(pc->session()->worker_thread()),
418 network_thread_(pc->session()->network_thread()) {
419 }
420
421 void ProducePartialResultsOnSignalingThread(int64_t timestamp_us) override {
422 EXPECT_TRUE(signaling_thread_->IsCurrent());
423 {
424 rtc::CritScope cs(&lock_);
425 EXPECT_FALSE(delivered_report_);
426 ++produced_on_signaling_thread_;
427 }
428
429 rtc::scoped_refptr<RTCStatsReport> signaling_report =
hbos6ded1902016-11-01 01:50:46 -0700430 RTCStatsReport::Create(0);
hbosc82f2e12016-09-05 01:36:50 -0700431 signaling_report->AddStats(std::unique_ptr<const RTCStats>(
432 new RTCTestStats("SignalingThreadStats", timestamp_us)));
433 AddPartialResults(signaling_report);
434 }
435 void ProducePartialResultsOnWorkerThread(int64_t timestamp_us) override {
436 EXPECT_TRUE(worker_thread_->IsCurrent());
437 {
438 rtc::CritScope cs(&lock_);
439 EXPECT_FALSE(delivered_report_);
440 ++produced_on_worker_thread_;
441 }
442
hbos6ded1902016-11-01 01:50:46 -0700443 rtc::scoped_refptr<RTCStatsReport> worker_report =
444 RTCStatsReport::Create(0);
hbosc82f2e12016-09-05 01:36:50 -0700445 worker_report->AddStats(std::unique_ptr<const RTCStats>(
446 new RTCTestStats("WorkerThreadStats", timestamp_us)));
447 AddPartialResults(worker_report);
448 }
449 void ProducePartialResultsOnNetworkThread(int64_t timestamp_us) override {
450 EXPECT_TRUE(network_thread_->IsCurrent());
451 {
452 rtc::CritScope cs(&lock_);
453 EXPECT_FALSE(delivered_report_);
454 ++produced_on_network_thread_;
455 }
456
457 rtc::scoped_refptr<RTCStatsReport> network_report =
hbos6ded1902016-11-01 01:50:46 -0700458 RTCStatsReport::Create(0);
hbosc82f2e12016-09-05 01:36:50 -0700459 network_report->AddStats(std::unique_ptr<const RTCStats>(
460 new RTCTestStats("NetworkThreadStats", timestamp_us)));
461 AddPartialResults(network_report);
462 }
463
464 private:
465 rtc::Thread* const signaling_thread_;
466 rtc::Thread* const worker_thread_;
467 rtc::Thread* const network_thread_;
468
469 rtc::CriticalSection lock_;
470 rtc::scoped_refptr<const RTCStatsReport> delivered_report_;
471 int produced_on_signaling_thread_ = 0;
472 int produced_on_worker_thread_ = 0;
473 int produced_on_network_thread_ = 0;
hbosd565b732016-08-30 14:04:35 -0700474};
475
hbosc82f2e12016-09-05 01:36:50 -0700476class RTCStatsCollectorTest : public testing::Test {
477 public:
478 RTCStatsCollectorTest()
479 : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()),
480 collector_(RTCStatsCollector::Create(
481 &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) {
482 }
483
484 rtc::scoped_refptr<const RTCStatsReport> GetStatsReport() {
hbosdb346a72016-11-29 01:57:01 -0800485 rtc::scoped_refptr<RTCStatsObtainer> callback = RTCStatsObtainer::Create();
hbosc82f2e12016-09-05 01:36:50 -0700486 collector_->GetStatsReport(callback);
487 EXPECT_TRUE_WAIT(callback->report(), kGetStatsReportTimeoutMs);
hboscc555c52016-10-18 12:48:31 -0700488 int64_t after = rtc::TimeUTCMicros();
489 for (const RTCStats& stats : *callback->report()) {
490 EXPECT_LE(stats.timestamp_us(), after);
491 }
hbosc82f2e12016-09-05 01:36:50 -0700492 return callback->report();
493 }
494
hbosc47a0c32016-10-11 14:54:49 -0700495 const RTCIceCandidateStats* ExpectReportContainsCandidate(
hbosab9f6e42016-10-07 02:18:47 -0700496 const rtc::scoped_refptr<const RTCStatsReport>& report,
497 const cricket::Candidate& candidate,
498 bool is_local) {
hbosc47a0c32016-10-11 14:54:49 -0700499 const RTCStats* stats = report->Get("RTCIceCandidate_" + candidate.id());
hbosab9f6e42016-10-07 02:18:47 -0700500 EXPECT_TRUE(stats);
501 const RTCIceCandidateStats* candidate_stats;
502 if (is_local)
503 candidate_stats = &stats->cast_to<RTCLocalIceCandidateStats>();
504 else
505 candidate_stats = &stats->cast_to<RTCRemoteIceCandidateStats>();
506 EXPECT_EQ(*candidate_stats->ip, candidate.address().ipaddr().ToString());
507 EXPECT_EQ(*candidate_stats->port,
508 static_cast<int32_t>(candidate.address().port()));
509 EXPECT_EQ(*candidate_stats->protocol, candidate.protocol());
510 EXPECT_EQ(*candidate_stats->candidate_type,
hboscc555c52016-10-18 12:48:31 -0700511 CandidateTypeToRTCIceCandidateTypeForTesting(candidate.type()));
hbosab9f6e42016-10-07 02:18:47 -0700512 EXPECT_EQ(*candidate_stats->priority,
513 static_cast<int32_t>(candidate.priority()));
514 // TODO(hbos): Define candidate_stats->url. crbug.com/632723
515 EXPECT_FALSE(candidate_stats->url.is_defined());
hbosc47a0c32016-10-11 14:54:49 -0700516 return candidate_stats;
517 }
518
519 void ExpectReportContainsCandidatePair(
520 const rtc::scoped_refptr<const RTCStatsReport>& report,
521 const cricket::TransportStats& transport_stats) {
522 for (const auto& channel_stats : transport_stats.channel_stats) {
523 for (const cricket::ConnectionInfo& info :
524 channel_stats.connection_infos) {
525 const std::string& id = "RTCIceCandidatePair_" +
526 info.local_candidate.id() + "_" + info.remote_candidate.id();
527 const RTCStats* stats = report->Get(id);
hbos2fa7c672016-10-24 04:00:05 -0700528 ASSERT_TRUE(stats);
hbosc47a0c32016-10-11 14:54:49 -0700529 const RTCIceCandidatePairStats& candidate_pair_stats =
530 stats->cast_to<RTCIceCandidatePairStats>();
531
532 // TODO(hbos): Define all the undefined |candidate_pair_stats| stats.
533 // The EXPECT_FALSE are for the undefined stats, see also todos listed
hbos5d79a7c2016-10-24 09:27:10 -0700534 // in rtcstats_objects.h. crbug.com/633550
hbosc47a0c32016-10-11 14:54:49 -0700535 EXPECT_FALSE(candidate_pair_stats.transport_id.is_defined());
536 const RTCIceCandidateStats* local_candidate =
537 ExpectReportContainsCandidate(report, info.local_candidate, true);
538 EXPECT_EQ(*candidate_pair_stats.local_candidate_id,
539 local_candidate->id());
540 const RTCIceCandidateStats* remote_candidate =
541 ExpectReportContainsCandidate(report, info.remote_candidate, false);
542 EXPECT_EQ(*candidate_pair_stats.remote_candidate_id,
543 remote_candidate->id());
544
545 EXPECT_FALSE(candidate_pair_stats.state.is_defined());
546 EXPECT_FALSE(candidate_pair_stats.priority.is_defined());
547 EXPECT_FALSE(candidate_pair_stats.nominated.is_defined());
548 EXPECT_EQ(*candidate_pair_stats.writable, info.writable);
549 EXPECT_FALSE(candidate_pair_stats.readable.is_defined());
550 EXPECT_EQ(*candidate_pair_stats.bytes_sent,
551 static_cast<uint64_t>(info.sent_total_bytes));
552 EXPECT_EQ(*candidate_pair_stats.bytes_received,
553 static_cast<uint64_t>(info.recv_total_bytes));
554 EXPECT_FALSE(candidate_pair_stats.total_rtt.is_defined());
555 EXPECT_EQ(*candidate_pair_stats.current_rtt,
556 static_cast<double>(info.rtt) / 1000.0);
557 EXPECT_FALSE(
558 candidate_pair_stats.available_outgoing_bitrate.is_defined());
559 EXPECT_FALSE(
560 candidate_pair_stats.available_incoming_bitrate.is_defined());
561 EXPECT_FALSE(candidate_pair_stats.requests_received.is_defined());
562 EXPECT_EQ(*candidate_pair_stats.requests_sent,
563 static_cast<uint64_t>(info.sent_ping_requests_total));
564 EXPECT_EQ(*candidate_pair_stats.responses_received,
565 static_cast<uint64_t>(info.recv_ping_responses));
566 EXPECT_EQ(*candidate_pair_stats.responses_sent,
567 static_cast<uint64_t>(info.sent_ping_responses));
568 EXPECT_FALSE(
569 candidate_pair_stats.retransmissions_received.is_defined());
570 EXPECT_FALSE(candidate_pair_stats.retransmissions_sent.is_defined());
571 EXPECT_FALSE(
572 candidate_pair_stats.consent_requests_received.is_defined());
573 EXPECT_FALSE(candidate_pair_stats.consent_requests_sent.is_defined());
574 EXPECT_FALSE(
575 candidate_pair_stats.consent_responses_received.is_defined());
576 EXPECT_FALSE(candidate_pair_stats.consent_responses_sent.is_defined());
577 }
578 }
hbosab9f6e42016-10-07 02:18:47 -0700579 }
580
hbos6ab97ce2016-10-03 14:16:56 -0700581 void ExpectReportContainsCertificateInfo(
582 const rtc::scoped_refptr<const RTCStatsReport>& report,
583 const CertificateInfo& cert_info) {
584 for (size_t i = 0; i < cert_info.fingerprints.size(); ++i) {
585 const RTCStats* stats = report->Get(
586 "RTCCertificate_" + cert_info.fingerprints[i]);
hbos2fa7c672016-10-24 04:00:05 -0700587 ASSERT_TRUE(stats);
hbos6ab97ce2016-10-03 14:16:56 -0700588 const RTCCertificateStats& cert_stats =
589 stats->cast_to<const RTCCertificateStats>();
590 EXPECT_EQ(*cert_stats.fingerprint, cert_info.fingerprints[i]);
591 EXPECT_EQ(*cert_stats.fingerprint_algorithm, "sha-1");
592 EXPECT_EQ(*cert_stats.base64_certificate, cert_info.pems[i]);
593 if (i + 1 < cert_info.fingerprints.size()) {
594 EXPECT_EQ(*cert_stats.issuer_certificate_id,
595 "RTCCertificate_" + cert_info.fingerprints[i + 1]);
596 } else {
597 EXPECT_FALSE(cert_stats.issuer_certificate_id.is_defined());
598 }
599 }
600 }
601
hbos2fa7c672016-10-24 04:00:05 -0700602 void ExpectReportContainsTransportStats(
603 const rtc::scoped_refptr<const RTCStatsReport>& report,
604 const cricket::TransportStats& transport,
605 const CertificateInfo* local_certinfo,
606 const CertificateInfo* remote_certinfo) {
607 std::string rtcp_transport_stats_id;
608 for (const auto& channel_stats : transport.channel_stats) {
609 if (channel_stats.component == cricket::ICE_CANDIDATE_COMPONENT_RTCP) {
610 rtcp_transport_stats_id = "RTCTransport_" + transport.transport_name +
611 "_" + rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTCP);
612 }
613 }
614 for (const auto& channel_stats : transport.channel_stats) {
615 const cricket::ConnectionInfo* best_connection_info = nullptr;
616 const RTCStats* stats = report->Get(
617 "RTCTransport_" + transport.transport_name + "_" +
618 rtc::ToString<>(channel_stats.component));
619 ASSERT_TRUE(stats);
620 const RTCTransportStats& transport_stats =
621 stats->cast_to<const RTCTransportStats>();
622 uint64_t bytes_sent = 0;
623 uint64_t bytes_received = 0;
624 for (const cricket::ConnectionInfo& info :
625 channel_stats.connection_infos) {
626 bytes_sent += info.sent_total_bytes;
627 bytes_received += info.recv_total_bytes;
628 if (info.best_connection)
629 best_connection_info = &info;
630 }
631 EXPECT_EQ(*transport_stats.bytes_sent, bytes_sent);
632 EXPECT_EQ(*transport_stats.bytes_received, bytes_received);
633 if (best_connection_info) {
634 EXPECT_EQ(*transport_stats.active_connection, true);
635 // TODO(hbos): Instead of testing how the ID looks, test that the
636 // corresponding pair's IP addresses are equal to the IP addresses of
637 // the |best_connection_info| data. crbug.com/653873
638 EXPECT_EQ(*transport_stats.selected_candidate_pair_id,
639 "RTCIceCandidatePair_" +
640 best_connection_info->local_candidate.id() + "_" +
641 best_connection_info->remote_candidate.id());
642 EXPECT_TRUE(report->Get(*transport_stats.selected_candidate_pair_id));
643 } else {
644 EXPECT_EQ(*transport_stats.active_connection, false);
645 EXPECT_FALSE(transport_stats.selected_candidate_pair_id.is_defined());
646 }
647 if (channel_stats.component != cricket::ICE_CANDIDATE_COMPONENT_RTCP &&
648 !rtcp_transport_stats_id.empty()) {
649 EXPECT_EQ(*transport_stats.rtcp_transport_stats_id,
650 rtcp_transport_stats_id);
651 } else {
652 EXPECT_FALSE(transport_stats.rtcp_transport_stats_id.is_defined());
653 }
654 if (local_certinfo && remote_certinfo) {
655 EXPECT_EQ(*transport_stats.local_certificate_id,
656 "RTCCertificate_" + local_certinfo->fingerprints[0]);
657 EXPECT_EQ(*transport_stats.remote_certificate_id,
658 "RTCCertificate_" + remote_certinfo->fingerprints[0]);
659 EXPECT_TRUE(report->Get(*transport_stats.local_certificate_id));
660 EXPECT_TRUE(report->Get(*transport_stats.remote_certificate_id));
661 } else {
662 EXPECT_FALSE(transport_stats.local_certificate_id.is_defined());
663 EXPECT_FALSE(transport_stats.remote_certificate_id.is_defined());
664 }
665 }
666 }
667
hboscc555c52016-10-18 12:48:31 -0700668 void ExpectReportContainsDataChannel(
669 const rtc::scoped_refptr<const RTCStatsReport>& report,
670 const DataChannel& data_channel) {
671 const RTCStats* stats = report->Get("RTCDataChannel_" +
672 rtc::ToString<>(data_channel.id()));
673 EXPECT_TRUE(stats);
674 const RTCDataChannelStats& data_channel_stats =
675 stats->cast_to<const RTCDataChannelStats>();
676 EXPECT_EQ(*data_channel_stats.label, data_channel.label());
677 EXPECT_EQ(*data_channel_stats.protocol, data_channel.protocol());
678 EXPECT_EQ(*data_channel_stats.datachannelid, data_channel.id());
679 EXPECT_EQ(*data_channel_stats.state,
680 DataStateToRTCDataChannelStateForTesting(data_channel.state()));
681 EXPECT_EQ(*data_channel_stats.messages_sent, data_channel.messages_sent());
682 EXPECT_EQ(*data_channel_stats.bytes_sent, data_channel.bytes_sent());
683 EXPECT_EQ(*data_channel_stats.messages_received,
684 data_channel.messages_received());
685 EXPECT_EQ(*data_channel_stats.bytes_received,
686 data_channel.bytes_received());
687 }
688
hbosc82f2e12016-09-05 01:36:50 -0700689 protected:
690 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_;
691 rtc::scoped_refptr<RTCStatsCollector> collector_;
692};
693
694TEST_F(RTCStatsCollectorTest, SingleCallback) {
695 rtc::scoped_refptr<const RTCStatsReport> result;
hbosdb346a72016-11-29 01:57:01 -0800696 collector_->GetStatsReport(RTCStatsObtainer::Create(&result));
hbosc82f2e12016-09-05 01:36:50 -0700697 EXPECT_TRUE_WAIT(result, kGetStatsReportTimeoutMs);
698}
699
700TEST_F(RTCStatsCollectorTest, MultipleCallbacks) {
701 rtc::scoped_refptr<const RTCStatsReport> a;
702 rtc::scoped_refptr<const RTCStatsReport> b;
703 rtc::scoped_refptr<const RTCStatsReport> c;
hbosdb346a72016-11-29 01:57:01 -0800704 collector_->GetStatsReport(RTCStatsObtainer::Create(&a));
705 collector_->GetStatsReport(RTCStatsObtainer::Create(&b));
706 collector_->GetStatsReport(RTCStatsObtainer::Create(&c));
hbosc82f2e12016-09-05 01:36:50 -0700707 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs);
708 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs);
709 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs);
710 EXPECT_EQ(a.get(), b.get());
711 EXPECT_EQ(b.get(), c.get());
712}
713
714TEST_F(RTCStatsCollectorTest, CachedStatsReports) {
hbosd565b732016-08-30 14:04:35 -0700715 // Caching should ensure |a| and |b| are the same report.
hbosc82f2e12016-09-05 01:36:50 -0700716 rtc::scoped_refptr<const RTCStatsReport> a = GetStatsReport();
717 rtc::scoped_refptr<const RTCStatsReport> b = GetStatsReport();
hbosd565b732016-08-30 14:04:35 -0700718 EXPECT_EQ(a.get(), b.get());
719 // Invalidate cache by clearing it.
hbosc82f2e12016-09-05 01:36:50 -0700720 collector_->ClearCachedStatsReport();
721 rtc::scoped_refptr<const RTCStatsReport> c = GetStatsReport();
hbosd565b732016-08-30 14:04:35 -0700722 EXPECT_NE(b.get(), c.get());
723 // Invalidate cache by advancing time.
hbosfdafab82016-09-14 06:02:13 -0700724 test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51));
hbosc82f2e12016-09-05 01:36:50 -0700725 rtc::scoped_refptr<const RTCStatsReport> d = GetStatsReport();
hbosd565b732016-08-30 14:04:35 -0700726 EXPECT_TRUE(d);
727 EXPECT_NE(c.get(), d.get());
728}
729
hbosc82f2e12016-09-05 01:36:50 -0700730TEST_F(RTCStatsCollectorTest, MultipleCallbacksWithInvalidatedCacheInBetween) {
hbosc82f2e12016-09-05 01:36:50 -0700731 rtc::scoped_refptr<const RTCStatsReport> a;
732 rtc::scoped_refptr<const RTCStatsReport> b;
733 rtc::scoped_refptr<const RTCStatsReport> c;
hbosdb346a72016-11-29 01:57:01 -0800734 collector_->GetStatsReport(RTCStatsObtainer::Create(&a));
735 collector_->GetStatsReport(RTCStatsObtainer::Create(&b));
hbosc82f2e12016-09-05 01:36:50 -0700736 // Cache is invalidated after 50 ms.
hbosfdafab82016-09-14 06:02:13 -0700737 test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51));
hbosdb346a72016-11-29 01:57:01 -0800738 collector_->GetStatsReport(RTCStatsObtainer::Create(&c));
hbosc82f2e12016-09-05 01:36:50 -0700739 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs);
740 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs);
741 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs);
742 EXPECT_EQ(a.get(), b.get());
743 // The act of doing |AdvanceTime| processes all messages. If this was not the
744 // case we might not require |c| to be fresher than |b|.
745 EXPECT_NE(c.get(), b.get());
746}
747
hbos6ab97ce2016-10-03 14:16:56 -0700748TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsSingle) {
749 std::unique_ptr<CertificateInfo> local_certinfo =
750 CreateFakeCertificateAndInfoFromDers(
751 std::vector<std::string>({ "(local) single certificate" }));
752 std::unique_ptr<CertificateInfo> remote_certinfo =
753 CreateFakeCertificateAndInfoFromDers(
754 std::vector<std::string>({ "(remote) single certificate" }));
755
756 // Mock the session to return the local and remote certificates.
757 EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke(
758 [this](SessionStats* stats) {
759 stats->transport_stats["transport"].transport_name = "transport";
760 return true;
761 }));
762 EXPECT_CALL(test_->session(), GetLocalCertificate(_, _)).WillRepeatedly(
763 Invoke([this, &local_certinfo](const std::string& transport_name,
764 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) {
765 if (transport_name == "transport") {
766 *certificate = local_certinfo->certificate;
767 return true;
768 }
769 return false;
770 }));
771 EXPECT_CALL(test_->session(),
772 GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke(
773 [this, &remote_certinfo](const std::string& transport_name) {
774 if (transport_name == "transport")
775 return remote_certinfo->certificate->ssl_certificate().GetReference();
776 return static_cast<rtc::SSLCertificate*>(nullptr);
777 }));
778
779 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
780 ExpectReportContainsCertificateInfo(report, *local_certinfo.get());
781 ExpectReportContainsCertificateInfo(report, *remote_certinfo.get());
782}
783
hbos0adb8282016-11-23 02:32:06 -0800784TEST_F(RTCStatsCollectorTest, CollectRTCCodecStats) {
785 MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel();
786 cricket::VoiceChannel voice_channel(
787 test_->worker_thread(), test_->network_thread(), test_->media_engine(),
788 voice_media_channel, nullptr, "VoiceContentName", false);
789
790 MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel();
791 cricket::VideoChannel video_channel(
792 test_->worker_thread(), test_->network_thread(), video_media_channel,
793 nullptr, "VideoContentName", false);
794
795 // Audio
796 cricket::VoiceMediaInfo voice_media_info;
797
798 RtpCodecParameters inbound_audio_codec;
799 inbound_audio_codec.payload_type = 1;
800 inbound_audio_codec.mime_type = "opus";
801 inbound_audio_codec.clock_rate = 1337;
802 voice_media_info.receive_codecs.insert(
803 std::make_pair(inbound_audio_codec.payload_type, inbound_audio_codec));
804
805 RtpCodecParameters outbound_audio_codec;
806 outbound_audio_codec.payload_type = 2;
807 outbound_audio_codec.mime_type = "isac";
808 outbound_audio_codec.clock_rate = 1338;
809 voice_media_info.send_codecs.insert(
810 std::make_pair(outbound_audio_codec.payload_type, outbound_audio_codec));
811
812 EXPECT_CALL(*voice_media_channel, GetStats(_))
813 .WillOnce(DoAll(SetArgPointee<0>(voice_media_info), Return(true)));
814
815 // Video
816 cricket::VideoMediaInfo video_media_info;
817
818 RtpCodecParameters inbound_video_codec;
819 inbound_video_codec.payload_type = 3;
820 inbound_video_codec.mime_type = "H264";
821 inbound_video_codec.clock_rate = 1339;
822 video_media_info.receive_codecs.insert(
823 std::make_pair(inbound_video_codec.payload_type, inbound_video_codec));
824
825 RtpCodecParameters outbound_video_codec;
826 outbound_video_codec.payload_type = 4;
827 outbound_video_codec.mime_type = "VP8";
828 outbound_video_codec.clock_rate = 1340;
829 video_media_info.send_codecs.insert(
830 std::make_pair(outbound_video_codec.payload_type, outbound_video_codec));
831
832 EXPECT_CALL(*video_media_channel, GetStats(_))
833 .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true)));
834
835 SessionStats session_stats;
836 session_stats.proxy_to_transport["VoiceContentName"] = "TransportName";
837 session_stats.proxy_to_transport["VideoContentName"] = "TransportName";
838 session_stats.transport_stats["TransportName"].transport_name =
839 "TransportName";
840
841 EXPECT_CALL(test_->session(), GetTransportStats(_))
842 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats), Return(true)));
843 EXPECT_CALL(test_->session(), voice_channel())
844 .WillRepeatedly(Return(&voice_channel));
845 EXPECT_CALL(test_->session(), video_channel())
846 .WillRepeatedly(Return(&video_channel));
847
848 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
849
850 RTCCodecStats expected_inbound_audio_codec(
851 "RTCCodec_InboundAudio_1", report->timestamp_us());
852 expected_inbound_audio_codec.payload_type = 1;
853 expected_inbound_audio_codec.codec = "audio/opus";
854 expected_inbound_audio_codec.clock_rate = 1337;
855
856 RTCCodecStats expected_outbound_audio_codec(
857 "RTCCodec_OutboundAudio_2", report->timestamp_us());
858 expected_outbound_audio_codec.payload_type = 2;
859 expected_outbound_audio_codec.codec = "audio/isac";
860 expected_outbound_audio_codec.clock_rate = 1338;
861
862 RTCCodecStats expected_inbound_video_codec(
863 "RTCCodec_InboundVideo_3", report->timestamp_us());
864 expected_inbound_video_codec.payload_type = 3;
865 expected_inbound_video_codec.codec = "video/H264";
866 expected_inbound_video_codec.clock_rate = 1339;
867
868 RTCCodecStats expected_outbound_video_codec(
869 "RTCCodec_OutboundVideo_4", report->timestamp_us());
870 expected_outbound_video_codec.payload_type = 4;
871 expected_outbound_video_codec.codec = "video/VP8";
872 expected_outbound_video_codec.clock_rate = 1340;
873
874 ASSERT(report->Get(expected_inbound_audio_codec.id()));
875 EXPECT_EQ(expected_inbound_audio_codec,
876 report->Get(expected_inbound_audio_codec.id())->cast_to<
877 RTCCodecStats>());
878
879 ASSERT(report->Get(expected_outbound_audio_codec.id()));
880 EXPECT_EQ(expected_outbound_audio_codec,
881 report->Get(expected_outbound_audio_codec.id())->cast_to<
882 RTCCodecStats>());
883
884 ASSERT(report->Get(expected_inbound_video_codec.id()));
885 EXPECT_EQ(expected_inbound_video_codec,
886 report->Get(expected_inbound_video_codec.id())->cast_to<
887 RTCCodecStats>());
888
889 ASSERT(report->Get(expected_outbound_video_codec.id()));
890 EXPECT_EQ(expected_outbound_video_codec,
891 report->Get(expected_outbound_video_codec.id())->cast_to<
892 RTCCodecStats>());
893}
894
hbos6ab97ce2016-10-03 14:16:56 -0700895TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsMultiple) {
896 std::unique_ptr<CertificateInfo> audio_local_certinfo =
897 CreateFakeCertificateAndInfoFromDers(
898 std::vector<std::string>({ "(local) audio" }));
899 audio_local_certinfo = CreateFakeCertificateAndInfoFromDers(
900 audio_local_certinfo->ders);
901 std::unique_ptr<CertificateInfo> audio_remote_certinfo =
902 CreateFakeCertificateAndInfoFromDers(
903 std::vector<std::string>({ "(remote) audio" }));
904 audio_remote_certinfo = CreateFakeCertificateAndInfoFromDers(
905 audio_remote_certinfo->ders);
906
907 std::unique_ptr<CertificateInfo> video_local_certinfo =
908 CreateFakeCertificateAndInfoFromDers(
909 std::vector<std::string>({ "(local) video" }));
910 video_local_certinfo = CreateFakeCertificateAndInfoFromDers(
911 video_local_certinfo->ders);
912 std::unique_ptr<CertificateInfo> video_remote_certinfo =
913 CreateFakeCertificateAndInfoFromDers(
914 std::vector<std::string>({ "(remote) video" }));
915 video_remote_certinfo = CreateFakeCertificateAndInfoFromDers(
916 video_remote_certinfo->ders);
917
918 // Mock the session to return the local and remote certificates.
919 EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke(
920 [this](SessionStats* stats) {
921 stats->transport_stats["audio"].transport_name = "audio";
922 stats->transport_stats["video"].transport_name = "video";
923 return true;
924 }));
925 EXPECT_CALL(test_->session(), GetLocalCertificate(_, _)).WillRepeatedly(
926 Invoke([this, &audio_local_certinfo, &video_local_certinfo](
927 const std::string& transport_name,
928 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) {
929 if (transport_name == "audio") {
930 *certificate = audio_local_certinfo->certificate;
931 return true;
932 }
933 if (transport_name == "video") {
934 *certificate = video_local_certinfo->certificate;
935 return true;
936 }
937 return false;
938 }));
939 EXPECT_CALL(test_->session(),
940 GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke(
941 [this, &audio_remote_certinfo, &video_remote_certinfo](
942 const std::string& transport_name) {
943 if (transport_name == "audio") {
944 return audio_remote_certinfo->certificate->ssl_certificate()
945 .GetReference();
946 }
947 if (transport_name == "video") {
948 return video_remote_certinfo->certificate->ssl_certificate()
949 .GetReference();
950 }
951 return static_cast<rtc::SSLCertificate*>(nullptr);
952 }));
953
954 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
955 ExpectReportContainsCertificateInfo(report, *audio_local_certinfo.get());
956 ExpectReportContainsCertificateInfo(report, *audio_remote_certinfo.get());
957 ExpectReportContainsCertificateInfo(report, *video_local_certinfo.get());
958 ExpectReportContainsCertificateInfo(report, *video_remote_certinfo.get());
959}
960
961TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsChain) {
962 std::vector<std::string> local_ders;
963 local_ders.push_back("(local) this");
964 local_ders.push_back("(local) is");
965 local_ders.push_back("(local) a");
966 local_ders.push_back("(local) chain");
967 std::unique_ptr<CertificateInfo> local_certinfo =
968 CreateFakeCertificateAndInfoFromDers(local_ders);
969 std::vector<std::string> remote_ders;
970 remote_ders.push_back("(remote) this");
971 remote_ders.push_back("(remote) is");
972 remote_ders.push_back("(remote) another");
973 remote_ders.push_back("(remote) chain");
974 std::unique_ptr<CertificateInfo> remote_certinfo =
975 CreateFakeCertificateAndInfoFromDers(remote_ders);
976
977 // Mock the session to return the local and remote certificates.
978 EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke(
979 [this](SessionStats* stats) {
980 stats->transport_stats["transport"].transport_name = "transport";
981 return true;
982 }));
983 EXPECT_CALL(test_->session(), GetLocalCertificate(_, _)).WillRepeatedly(
984 Invoke([this, &local_certinfo](const std::string& transport_name,
985 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) {
986 if (transport_name == "transport") {
987 *certificate = local_certinfo->certificate;
988 return true;
989 }
990 return false;
991 }));
992 EXPECT_CALL(test_->session(),
993 GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke(
994 [this, &remote_certinfo](const std::string& transport_name) {
995 if (transport_name == "transport")
996 return remote_certinfo->certificate->ssl_certificate().GetReference();
997 return static_cast<rtc::SSLCertificate*>(nullptr);
998 }));
999
1000 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1001 ExpectReportContainsCertificateInfo(report, *local_certinfo.get());
1002 ExpectReportContainsCertificateInfo(report, *remote_certinfo.get());
1003}
1004
hboscc555c52016-10-18 12:48:31 -07001005TEST_F(RTCStatsCollectorTest, CollectRTCDataChannelStats) {
1006 test_->data_channels().push_back(
1007 new MockDataChannel(0, DataChannelInterface::kConnecting));
1008 test_->data_channels().push_back(
1009 new MockDataChannel(1, DataChannelInterface::kOpen));
1010 test_->data_channels().push_back(
1011 new MockDataChannel(2, DataChannelInterface::kClosing));
1012 test_->data_channels().push_back(
1013 new MockDataChannel(3, DataChannelInterface::kClosed));
1014
1015 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1016 ExpectReportContainsDataChannel(report, *test_->data_channels()[0]);
1017 ExpectReportContainsDataChannel(report, *test_->data_channels()[1]);
1018 ExpectReportContainsDataChannel(report, *test_->data_channels()[2]);
1019 ExpectReportContainsDataChannel(report, *test_->data_channels()[3]);
1020
1021 test_->data_channels().clear();
1022 test_->data_channels().push_back(
1023 new MockDataChannel(0, DataChannelInterface::kConnecting,
1024 1, 2, 3, 4));
1025 test_->data_channels().push_back(
1026 new MockDataChannel(1, DataChannelInterface::kOpen,
1027 5, 6, 7, 8));
1028 test_->data_channels().push_back(
1029 new MockDataChannel(2, DataChannelInterface::kClosing,
1030 9, 10, 11, 12));
1031 test_->data_channels().push_back(
1032 new MockDataChannel(3, DataChannelInterface::kClosed,
1033 13, 14, 15, 16));
1034
1035 collector_->ClearCachedStatsReport();
1036 report = GetStatsReport();
1037 ExpectReportContainsDataChannel(report, *test_->data_channels()[0]);
1038 ExpectReportContainsDataChannel(report, *test_->data_channels()[1]);
1039 ExpectReportContainsDataChannel(report, *test_->data_channels()[2]);
1040 ExpectReportContainsDataChannel(report, *test_->data_channels()[3]);
1041}
1042
hbosab9f6e42016-10-07 02:18:47 -07001043TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) {
1044 // Candidates in the first transport stats.
1045 std::unique_ptr<cricket::Candidate> a_local_host = CreateFakeCandidate(
1046 "1.2.3.4", 5,
1047 "a_local_host's protocol",
1048 cricket::LOCAL_PORT_TYPE,
1049 0);
1050 std::unique_ptr<cricket::Candidate> a_remote_srflx = CreateFakeCandidate(
1051 "6.7.8.9", 10,
1052 "remote_srflx's protocol",
1053 cricket::STUN_PORT_TYPE,
1054 1);
1055 std::unique_ptr<cricket::Candidate> a_local_prflx = CreateFakeCandidate(
1056 "11.12.13.14", 15,
1057 "a_local_prflx's protocol",
1058 cricket::PRFLX_PORT_TYPE,
1059 2);
1060 std::unique_ptr<cricket::Candidate> a_remote_relay = CreateFakeCandidate(
1061 "16.17.18.19", 20,
1062 "a_remote_relay's protocol",
1063 cricket::RELAY_PORT_TYPE,
1064 3);
1065 // Candidates in the second transport stats.
1066 std::unique_ptr<cricket::Candidate> b_local = CreateFakeCandidate(
1067 "42.42.42.42", 42,
1068 "b_local's protocol",
1069 cricket::LOCAL_PORT_TYPE,
1070 42);
1071 std::unique_ptr<cricket::Candidate> b_remote = CreateFakeCandidate(
1072 "42.42.42.42", 42,
1073 "b_remote's protocol",
1074 cricket::LOCAL_PORT_TYPE,
1075 42);
1076
1077 SessionStats session_stats;
1078
1079 cricket::TransportChannelStats a_transport_channel_stats;
1080 a_transport_channel_stats.connection_infos.push_back(
1081 cricket::ConnectionInfo());
1082 a_transport_channel_stats.connection_infos[0].local_candidate =
1083 *a_local_host.get();
1084 a_transport_channel_stats.connection_infos[0].remote_candidate =
1085 *a_remote_srflx.get();
1086 a_transport_channel_stats.connection_infos.push_back(
1087 cricket::ConnectionInfo());
1088 a_transport_channel_stats.connection_infos[1].local_candidate =
1089 *a_local_prflx.get();
1090 a_transport_channel_stats.connection_infos[1].remote_candidate =
1091 *a_remote_relay.get();
1092 session_stats.transport_stats["a"].channel_stats.push_back(
1093 a_transport_channel_stats);
1094
1095 cricket::TransportChannelStats b_transport_channel_stats;
1096 b_transport_channel_stats.connection_infos.push_back(
1097 cricket::ConnectionInfo());
1098 b_transport_channel_stats.connection_infos[0].local_candidate =
1099 *b_local.get();
1100 b_transport_channel_stats.connection_infos[0].remote_candidate =
1101 *b_remote.get();
1102 session_stats.transport_stats["b"].channel_stats.push_back(
1103 b_transport_channel_stats);
1104
1105 // Mock the session to return the desired candidates.
1106 EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke(
1107 [this, &session_stats](SessionStats* stats) {
1108 *stats = session_stats;
1109 return true;
1110 }));
1111
1112 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1113 ExpectReportContainsCandidate(report, *a_local_host.get(), true);
1114 ExpectReportContainsCandidate(report, *a_remote_srflx.get(), false);
1115 ExpectReportContainsCandidate(report, *a_local_prflx.get(), true);
1116 ExpectReportContainsCandidate(report, *a_remote_relay.get(), false);
1117 ExpectReportContainsCandidate(report, *b_local.get(), true);
1118 ExpectReportContainsCandidate(report, *b_remote.get(), false);
1119}
1120
hbosc47a0c32016-10-11 14:54:49 -07001121TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) {
1122 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate(
1123 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42);
1124 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate(
1125 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42);
1126
1127 SessionStats session_stats;
1128
1129 cricket::ConnectionInfo connection_info;
1130 connection_info.local_candidate = *local_candidate.get();
1131 connection_info.remote_candidate = *remote_candidate.get();
1132 connection_info.writable = true;
1133 connection_info.sent_total_bytes = 42;
1134 connection_info.recv_total_bytes = 1234;
1135 connection_info.rtt = 1337;
1136 connection_info.sent_ping_requests_total = 1010;
1137 connection_info.recv_ping_responses = 4321;
1138 connection_info.sent_ping_responses = 1000;
1139
1140 cricket::TransportChannelStats transport_channel_stats;
1141 transport_channel_stats.connection_infos.push_back(connection_info);
1142 session_stats.transport_stats["transport"].transport_name = "transport";
1143 session_stats.transport_stats["transport"].channel_stats.push_back(
1144 transport_channel_stats);
1145
1146 // Mock the session to return the desired candidates.
1147 EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke(
1148 [this, &session_stats](SessionStats* stats) {
1149 *stats = session_stats;
1150 return true;
1151 }));
1152
1153 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1154 ExpectReportContainsCandidatePair(
1155 report, session_stats.transport_stats["transport"]);
1156}
1157
hbosd565b732016-08-30 14:04:35 -07001158TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) {
hbosd565b732016-08-30 14:04:35 -07001159 {
hbos82ebe022016-11-14 01:41:09 -08001160 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1161 RTCPeerConnectionStats expected("RTCPeerConnection",
1162 report->timestamp_us());
1163 expected.data_channels_opened = 0;
1164 expected.data_channels_closed = 0;
1165 EXPECT_TRUE(report->Get("RTCPeerConnection"));
1166 EXPECT_EQ(expected,
1167 report->Get("RTCPeerConnection")->cast_to<
1168 RTCPeerConnectionStats>());
hbosd565b732016-08-30 14:04:35 -07001169 }
1170
hbos82ebe022016-11-14 01:41:09 -08001171 rtc::scoped_refptr<DataChannel> dummy_channel_a = DataChannel::Create(
1172 nullptr, cricket::DCT_NONE, "DummyChannelA", InternalDataChannelInit());
1173 test_->pc().SignalDataChannelCreated(dummy_channel_a.get());
1174 rtc::scoped_refptr<DataChannel> dummy_channel_b = DataChannel::Create(
1175 nullptr, cricket::DCT_NONE, "DummyChannelB", InternalDataChannelInit());
1176 test_->pc().SignalDataChannelCreated(dummy_channel_b.get());
hbosd565b732016-08-30 14:04:35 -07001177
hbos82ebe022016-11-14 01:41:09 -08001178 dummy_channel_a->SignalOpened(dummy_channel_a.get());
1179 // Closing a channel that is not opened should not affect the counts.
1180 dummy_channel_b->SignalClosed(dummy_channel_b.get());
1181
hbosd565b732016-08-30 14:04:35 -07001182 {
hbos82ebe022016-11-14 01:41:09 -08001183 collector_->ClearCachedStatsReport();
1184 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1185 RTCPeerConnectionStats expected("RTCPeerConnection",
1186 report->timestamp_us());
1187 expected.data_channels_opened = 1;
1188 expected.data_channels_closed = 0;
1189 EXPECT_TRUE(report->Get("RTCPeerConnection"));
1190 EXPECT_EQ(expected,
1191 report->Get("RTCPeerConnection")->cast_to<
1192 RTCPeerConnectionStats>());
1193 }
1194
1195 dummy_channel_b->SignalOpened(dummy_channel_b.get());
1196 dummy_channel_b->SignalClosed(dummy_channel_b.get());
1197
1198 {
1199 collector_->ClearCachedStatsReport();
1200 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1201 RTCPeerConnectionStats expected("RTCPeerConnection",
1202 report->timestamp_us());
1203 expected.data_channels_opened = 2;
1204 expected.data_channels_closed = 1;
1205 EXPECT_TRUE(report->Get("RTCPeerConnection"));
1206 EXPECT_EQ(expected,
1207 report->Get("RTCPeerConnection")->cast_to<
1208 RTCPeerConnectionStats>());
hbosd565b732016-08-30 14:04:35 -07001209 }
1210}
1211
hbos09bc1282016-11-08 06:29:22 -08001212TEST_F(RTCStatsCollectorTest,
1213 CollectRTCMediaStreamStatsAndRTCMediaStreamTrackStats_Audio) {
1214 rtc::scoped_refptr<StreamCollection> local_streams =
1215 StreamCollection::Create();
1216 rtc::scoped_refptr<StreamCollection> remote_streams =
1217 StreamCollection::Create();
1218 EXPECT_CALL(test_->pc(), local_streams())
1219 .WillRepeatedly(Return(local_streams));
1220 EXPECT_CALL(test_->pc(), remote_streams())
1221 .WillRepeatedly(Return(remote_streams));
1222
1223 rtc::scoped_refptr<MediaStream> local_stream =
1224 MediaStream::Create("LocalStreamLabel");
1225 local_streams->AddStream(local_stream);
1226 rtc::scoped_refptr<MediaStream> remote_stream =
1227 MediaStream::Create("RemoteStreamLabel");
1228 remote_streams->AddStream(remote_stream);
1229
1230 // Local audio track
1231 AudioProcessorInterface::AudioProcessorStats local_audio_processor_stats;
1232 local_audio_processor_stats.echo_return_loss = 42;
1233 local_audio_processor_stats.echo_return_loss_enhancement = 52;
1234 rtc::scoped_refptr<FakeAudioTrackForStats> local_audio_track =
1235 FakeAudioTrackForStats::Create(
1236 "LocalAudioTrackID",
1237 MediaStreamTrackInterface::TrackState::kEnded,
1238 32767,
1239 new FakeAudioProcessorForStats(local_audio_processor_stats));
1240 local_stream->AddTrack(local_audio_track);
1241
1242 // Remote audio track
1243 AudioProcessorInterface::AudioProcessorStats remote_audio_processor_stats;
1244 remote_audio_processor_stats.echo_return_loss = 13;
1245 remote_audio_processor_stats.echo_return_loss_enhancement = 37;
1246 rtc::scoped_refptr<FakeAudioTrackForStats> remote_audio_track =
1247 FakeAudioTrackForStats::Create(
1248 "RemoteAudioTrackID",
1249 MediaStreamTrackInterface::TrackState::kLive,
1250 0,
1251 new FakeAudioProcessorForStats(remote_audio_processor_stats));
1252 remote_stream->AddTrack(remote_audio_track);
1253
1254 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1255
1256 RTCMediaStreamStats expected_local_stream(
1257 "RTCMediaStream_LocalStreamLabel", report->timestamp_us());
1258 expected_local_stream.stream_identifier = local_stream->label();
1259 expected_local_stream.track_ids = std::vector<std::string>();
1260 expected_local_stream.track_ids->push_back(
1261 "RTCMediaStreamTrack_LocalAudioTrackID");
1262 EXPECT_TRUE(report->Get(expected_local_stream.id()));
1263 EXPECT_EQ(expected_local_stream,
1264 report->Get(expected_local_stream.id())->cast_to<
1265 RTCMediaStreamStats>());
1266
1267 RTCMediaStreamStats expected_remote_stream(
1268 "RTCMediaStream_RemoteStreamLabel", report->timestamp_us());
1269 expected_remote_stream.stream_identifier = remote_stream->label();
1270 expected_remote_stream.track_ids = std::vector<std::string>();
1271 expected_remote_stream.track_ids->push_back(
1272 "RTCMediaStreamTrack_RemoteAudioTrackID");
1273 EXPECT_TRUE(report->Get(expected_remote_stream.id()));
1274 EXPECT_EQ(expected_remote_stream,
1275 report->Get(expected_remote_stream.id())->cast_to<
1276 RTCMediaStreamStats>());
1277
1278 RTCMediaStreamTrackStats expected_local_audio_track(
1279 "RTCMediaStreamTrack_LocalAudioTrackID", report->timestamp_us());
1280 expected_local_audio_track.track_identifier = local_audio_track->id();
1281 expected_local_audio_track.remote_source = false;
1282 expected_local_audio_track.ended = true;
1283 expected_local_audio_track.detached = false;
1284 expected_local_audio_track.audio_level = 1.0;
1285 expected_local_audio_track.echo_return_loss = 42.0;
1286 expected_local_audio_track.echo_return_loss_enhancement = 52.0;
1287 EXPECT_TRUE(report->Get(expected_local_audio_track.id()));
1288 EXPECT_EQ(expected_local_audio_track,
1289 report->Get(expected_local_audio_track.id())->cast_to<
1290 RTCMediaStreamTrackStats>());
1291
1292 RTCMediaStreamTrackStats expected_remote_audio_track(
1293 "RTCMediaStreamTrack_RemoteAudioTrackID", report->timestamp_us());
1294 expected_remote_audio_track.track_identifier = remote_audio_track->id();
1295 expected_remote_audio_track.remote_source = true;
1296 expected_remote_audio_track.ended = false;
1297 expected_remote_audio_track.detached = false;
1298 expected_remote_audio_track.audio_level = 0.0;
1299 expected_remote_audio_track.echo_return_loss = 13.0;
1300 expected_remote_audio_track.echo_return_loss_enhancement = 37.0;
1301 EXPECT_TRUE(report->Get(expected_remote_audio_track.id()));
1302 EXPECT_EQ(expected_remote_audio_track,
1303 report->Get(expected_remote_audio_track.id())->cast_to<
1304 RTCMediaStreamTrackStats>());
1305}
1306
1307TEST_F(RTCStatsCollectorTest,
1308 CollectRTCMediaStreamStatsAndRTCMediaStreamTrackStats_Video) {
1309 rtc::scoped_refptr<StreamCollection> local_streams =
1310 StreamCollection::Create();
1311 rtc::scoped_refptr<StreamCollection> remote_streams =
1312 StreamCollection::Create();
1313 EXPECT_CALL(test_->pc(), local_streams())
1314 .WillRepeatedly(Return(local_streams));
1315 EXPECT_CALL(test_->pc(), remote_streams())
1316 .WillRepeatedly(Return(remote_streams));
1317
1318 rtc::scoped_refptr<MediaStream> local_stream =
1319 MediaStream::Create("LocalStreamLabel");
1320 local_streams->AddStream(local_stream);
1321 rtc::scoped_refptr<MediaStream> remote_stream =
1322 MediaStream::Create("RemoteStreamLabel");
1323 remote_streams->AddStream(remote_stream);
1324
1325 // Local video track
1326 VideoTrackSourceInterface::Stats local_video_track_source_stats;
1327 local_video_track_source_stats.input_width = 1234;
1328 local_video_track_source_stats.input_height = 4321;
1329 rtc::scoped_refptr<FakeVideoTrackSourceForStats> local_video_track_source =
1330 new FakeVideoTrackSourceForStats(local_video_track_source_stats);
1331 rtc::scoped_refptr<FakeVideoTrackForStats> local_video_track =
1332 FakeVideoTrackForStats::Create(
1333 "LocalVideoTrackID",
1334 MediaStreamTrackInterface::TrackState::kLive,
1335 local_video_track_source);
1336 local_stream->AddTrack(local_video_track);
1337
1338 // Remote video track
1339 VideoTrackSourceInterface::Stats remote_video_track_source_stats;
1340 remote_video_track_source_stats.input_width = 1234;
1341 remote_video_track_source_stats.input_height = 4321;
1342 rtc::scoped_refptr<FakeVideoTrackSourceForStats> remote_video_track_source =
1343 new FakeVideoTrackSourceForStats(remote_video_track_source_stats);
1344 rtc::scoped_refptr<FakeVideoTrackForStats> remote_video_track =
1345 FakeVideoTrackForStats::Create(
1346 "RemoteVideoTrackID",
1347 MediaStreamTrackInterface::TrackState::kEnded,
1348 remote_video_track_source);
1349 remote_stream->AddTrack(remote_video_track);
1350
1351 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1352
1353 RTCMediaStreamStats expected_local_stream(
1354 "RTCMediaStream_LocalStreamLabel", report->timestamp_us());
1355 expected_local_stream.stream_identifier = local_stream->label();
1356 expected_local_stream.track_ids = std::vector<std::string>();
1357 expected_local_stream.track_ids->push_back(
1358 "RTCMediaStreamTrack_LocalVideoTrackID");
1359 EXPECT_TRUE(report->Get(expected_local_stream.id()));
1360 EXPECT_EQ(expected_local_stream,
1361 report->Get(expected_local_stream.id())->cast_to<
1362 RTCMediaStreamStats>());
1363
1364 RTCMediaStreamStats expected_remote_stream(
1365 "RTCMediaStream_RemoteStreamLabel", report->timestamp_us());
1366 expected_remote_stream.stream_identifier = remote_stream->label();
1367 expected_remote_stream.track_ids = std::vector<std::string>();
1368 expected_remote_stream.track_ids->push_back(
1369 "RTCMediaStreamTrack_RemoteVideoTrackID");
1370 EXPECT_TRUE(report->Get(expected_remote_stream.id()));
1371 EXPECT_EQ(expected_remote_stream,
1372 report->Get(expected_remote_stream.id())->cast_to<
1373 RTCMediaStreamStats>());
1374
1375 RTCMediaStreamTrackStats expected_local_video_track(
1376 "RTCMediaStreamTrack_LocalVideoTrackID", report->timestamp_us());
1377 expected_local_video_track.track_identifier = local_video_track->id();
1378 expected_local_video_track.remote_source = false;
1379 expected_local_video_track.ended = false;
1380 expected_local_video_track.detached = false;
1381 expected_local_video_track.frame_width = 1234;
1382 expected_local_video_track.frame_height = 4321;
1383 EXPECT_TRUE(report->Get(expected_local_video_track.id()));
1384 EXPECT_EQ(expected_local_video_track,
1385 report->Get(expected_local_video_track.id())->cast_to<
1386 RTCMediaStreamTrackStats>());
1387
1388 RTCMediaStreamTrackStats expected_remote_video_track(
1389 "RTCMediaStreamTrack_RemoteVideoTrackID", report->timestamp_us());
1390 expected_remote_video_track.track_identifier = remote_video_track->id();
1391 expected_remote_video_track.remote_source = true;
1392 expected_remote_video_track.ended = true;
1393 expected_remote_video_track.detached = false;
1394 expected_remote_video_track.frame_width = 1234;
1395 expected_remote_video_track.frame_height = 4321;
1396 EXPECT_TRUE(report->Get(expected_remote_video_track.id()));
1397 EXPECT_EQ(expected_remote_video_track,
1398 report->Get(expected_remote_video_track.id())->cast_to<
1399 RTCMediaStreamTrackStats>());
1400}
1401
hboseeafe942016-11-01 03:00:17 -07001402TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Audio) {
1403 MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel();
1404 cricket::VoiceChannel voice_channel(
1405 test_->worker_thread(), test_->network_thread(), test_->media_engine(),
1406 voice_media_channel, nullptr, "VoiceContentName", false);
1407
1408 cricket::VoiceMediaInfo voice_media_info;
hbos0adb8282016-11-23 02:32:06 -08001409
hboseeafe942016-11-01 03:00:17 -07001410 voice_media_info.receivers.push_back(cricket::VoiceReceiverInfo());
1411 voice_media_info.receivers[0].local_stats.push_back(
1412 cricket::SsrcReceiverInfo());
1413 voice_media_info.receivers[0].local_stats[0].ssrc = 1;
1414 voice_media_info.receivers[0].packets_rcvd = 2;
1415 voice_media_info.receivers[0].bytes_rcvd = 3;
hbos0adb8282016-11-23 02:32:06 -08001416 voice_media_info.receivers[0].codec_payload_type = rtc::Optional<int>(42);
hboseeafe942016-11-01 03:00:17 -07001417 voice_media_info.receivers[0].jitter_ms = 4500;
1418 voice_media_info.receivers[0].fraction_lost = 5.5f;
hbos0adb8282016-11-23 02:32:06 -08001419
1420 RtpCodecParameters codec_parameters;
1421 codec_parameters.payload_type = 42;
1422 codec_parameters.mime_type = "dummy";
1423 codec_parameters.clock_rate = 0;
1424 voice_media_info.receive_codecs.insert(
1425 std::make_pair(codec_parameters.payload_type, codec_parameters));
1426
hboseeafe942016-11-01 03:00:17 -07001427 EXPECT_CALL(*voice_media_channel, GetStats(_))
1428 .WillOnce(DoAll(SetArgPointee<0>(voice_media_info), Return(true)));
1429
1430 SessionStats session_stats;
1431 session_stats.proxy_to_transport["VoiceContentName"] = "TransportName";
1432 session_stats.transport_stats["TransportName"].transport_name =
1433 "TransportName";
1434
1435 // Make sure the associated |RTCTransportStats| is created.
1436 cricket::TransportChannelStats channel_stats;
1437 channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP;
1438 session_stats.transport_stats["TransportName"].channel_stats.push_back(
1439 channel_stats);
1440
1441 EXPECT_CALL(test_->session(), GetTransportStats(_))
1442 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats), Return(true)));
1443 EXPECT_CALL(test_->session(), voice_channel())
1444 .WillRepeatedly(Return(&voice_channel));
1445
1446 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1447
1448 RTCInboundRTPStreamStats expected_audio(
1449 "RTCInboundRTPAudioStream_1", report->timestamp_us());
1450 expected_audio.ssrc = "1";
1451 expected_audio.is_remote = false;
1452 expected_audio.media_type = "audio";
1453 expected_audio.transport_id = "RTCTransport_TransportName_" +
1454 rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP);
hbos0adb8282016-11-23 02:32:06 -08001455 expected_audio.codec_id = "RTCCodec_InboundAudio_42";
hboseeafe942016-11-01 03:00:17 -07001456 expected_audio.packets_received = 2;
1457 expected_audio.bytes_received = 3;
1458 expected_audio.jitter = 4.5;
1459 expected_audio.fraction_lost = 5.5;
1460
1461 ASSERT(report->Get(expected_audio.id()));
1462 const RTCInboundRTPStreamStats& audio = report->Get(
1463 expected_audio.id())->cast_to<RTCInboundRTPStreamStats>();
1464 EXPECT_EQ(audio, expected_audio);
1465
1466 EXPECT_TRUE(report->Get(*expected_audio.transport_id));
hbos0adb8282016-11-23 02:32:06 -08001467 EXPECT_TRUE(report->Get(*expected_audio.codec_id));
hboseeafe942016-11-01 03:00:17 -07001468}
1469
1470TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Video) {
1471 MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel();
1472 cricket::VideoChannel video_channel(
1473 test_->worker_thread(), test_->network_thread(), video_media_channel,
1474 nullptr, "VideoContentName", false);
1475
1476 cricket::VideoMediaInfo video_media_info;
hbos0adb8282016-11-23 02:32:06 -08001477
hboseeafe942016-11-01 03:00:17 -07001478 video_media_info.receivers.push_back(cricket::VideoReceiverInfo());
1479 video_media_info.receivers[0].local_stats.push_back(
1480 cricket::SsrcReceiverInfo());
1481 video_media_info.receivers[0].local_stats[0].ssrc = 1;
1482 video_media_info.receivers[0].packets_rcvd = 2;
1483 video_media_info.receivers[0].bytes_rcvd = 3;
1484 video_media_info.receivers[0].fraction_lost = 4.5f;
hbos0adb8282016-11-23 02:32:06 -08001485 video_media_info.receivers[0].codec_payload_type = rtc::Optional<int>(42);
hbos820f5782016-11-22 03:16:50 -08001486 video_media_info.receivers[0].firs_sent = 5;
1487 video_media_info.receivers[0].plis_sent = 6;
1488 video_media_info.receivers[0].nacks_sent = 7;
hbos0adb8282016-11-23 02:32:06 -08001489
1490 RtpCodecParameters codec_parameters;
1491 codec_parameters.payload_type = 42;
1492 codec_parameters.mime_type = "dummy";
1493 codec_parameters.clock_rate = 0;
1494 video_media_info.receive_codecs.insert(
1495 std::make_pair(codec_parameters.payload_type, codec_parameters));
1496
hboseeafe942016-11-01 03:00:17 -07001497 EXPECT_CALL(*video_media_channel, GetStats(_))
1498 .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true)));
1499
1500 SessionStats session_stats;
1501 session_stats.proxy_to_transport["VideoContentName"] = "TransportName";
1502 session_stats.transport_stats["TransportName"].transport_name =
1503 "TransportName";
1504
1505 // Make sure the associated |RTCTransportStats| is created.
1506 cricket::TransportChannelStats channel_stats;
1507 channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP;
1508 session_stats.transport_stats["TransportName"].channel_stats.push_back(
1509 channel_stats);
1510
1511 EXPECT_CALL(test_->session(), GetTransportStats(_))
1512 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats), Return(true)));
1513 EXPECT_CALL(test_->session(), video_channel())
1514 .WillRepeatedly(Return(&video_channel));
1515
1516 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1517
hbos820f5782016-11-22 03:16:50 -08001518 RTCInboundRTPStreamStats expected_video(
hboseeafe942016-11-01 03:00:17 -07001519 "RTCInboundRTPVideoStream_1", report->timestamp_us());
hbos820f5782016-11-22 03:16:50 -08001520 expected_video.ssrc = "1";
1521 expected_video.is_remote = false;
1522 expected_video.media_type = "video";
1523 expected_video.transport_id = "RTCTransport_TransportName_" +
hboseeafe942016-11-01 03:00:17 -07001524 rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP);
hbos0adb8282016-11-23 02:32:06 -08001525 expected_video.codec_id = "RTCCodec_InboundVideo_42";
hbos820f5782016-11-22 03:16:50 -08001526 expected_video.fir_count = 5;
1527 expected_video.pli_count = 6;
1528 expected_video.nack_count = 7;
1529 expected_video.packets_received = 2;
1530 expected_video.bytes_received = 3;
1531 expected_video.fraction_lost = 4.5;
hboseeafe942016-11-01 03:00:17 -07001532
hbos820f5782016-11-22 03:16:50 -08001533 ASSERT(report->Get(expected_video.id()));
1534 const RTCInboundRTPStreamStats& video = report->Get(
1535 expected_video.id())->cast_to<RTCInboundRTPStreamStats>();
1536 EXPECT_EQ(video, expected_video);
hboseeafe942016-11-01 03:00:17 -07001537
hbos820f5782016-11-22 03:16:50 -08001538 EXPECT_TRUE(report->Get(*expected_video.transport_id));
hbos0adb8282016-11-23 02:32:06 -08001539 EXPECT_TRUE(report->Get(*video.codec_id));
hboseeafe942016-11-01 03:00:17 -07001540}
1541
hbos6ded1902016-11-01 01:50:46 -07001542TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Audio) {
1543 MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel();
1544 cricket::VoiceChannel voice_channel(
1545 test_->worker_thread(), test_->network_thread(), test_->media_engine(),
1546 voice_media_channel, nullptr, "VoiceContentName", false);
1547
1548 cricket::VoiceMediaInfo voice_media_info;
hbos0adb8282016-11-23 02:32:06 -08001549
hbos6ded1902016-11-01 01:50:46 -07001550 voice_media_info.senders.push_back(cricket::VoiceSenderInfo());
1551 voice_media_info.senders[0].local_stats.push_back(cricket::SsrcSenderInfo());
1552 voice_media_info.senders[0].local_stats[0].ssrc = 1;
1553 voice_media_info.senders[0].packets_sent = 2;
1554 voice_media_info.senders[0].bytes_sent = 3;
hboseeafe942016-11-01 03:00:17 -07001555 voice_media_info.senders[0].rtt_ms = 4500;
hbos0adb8282016-11-23 02:32:06 -08001556 voice_media_info.senders[0].codec_payload_type = rtc::Optional<int>(42);
1557
1558 RtpCodecParameters codec_parameters;
1559 codec_parameters.payload_type = 42;
1560 codec_parameters.mime_type = "dummy";
1561 codec_parameters.clock_rate = 0;
1562 voice_media_info.send_codecs.insert(
1563 std::make_pair(codec_parameters.payload_type, codec_parameters));
1564
hbos6ded1902016-11-01 01:50:46 -07001565 EXPECT_CALL(*voice_media_channel, GetStats(_))
1566 .WillOnce(DoAll(SetArgPointee<0>(voice_media_info), Return(true)));
1567
1568 SessionStats session_stats;
1569 session_stats.proxy_to_transport["VoiceContentName"] = "TransportName";
1570 session_stats.transport_stats["TransportName"].transport_name =
1571 "TransportName";
1572
1573 // Make sure the associated |RTCTransportStats| is created.
1574 cricket::TransportChannelStats channel_stats;
1575 channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP;
hbos6ded1902016-11-01 01:50:46 -07001576 session_stats.transport_stats["TransportName"].channel_stats.push_back(
1577 channel_stats);
1578
1579 EXPECT_CALL(test_->session(), GetTransportStats(_))
1580 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats), Return(true)));
1581 EXPECT_CALL(test_->session(), voice_channel())
1582 .WillRepeatedly(Return(&voice_channel));
1583
1584 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1585
1586 RTCOutboundRTPStreamStats expected_audio(
1587 "RTCOutboundRTPAudioStream_1", report->timestamp_us());
1588 expected_audio.ssrc = "1";
1589 expected_audio.is_remote = false;
1590 expected_audio.media_type = "audio";
1591 expected_audio.transport_id = "RTCTransport_TransportName_" +
1592 rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP);
hbos0adb8282016-11-23 02:32:06 -08001593 expected_audio.codec_id = "RTCCodec_OutboundAudio_42";
hbos6ded1902016-11-01 01:50:46 -07001594 expected_audio.packets_sent = 2;
1595 expected_audio.bytes_sent = 3;
1596 expected_audio.round_trip_time = 4.5;
1597
1598 ASSERT(report->Get(expected_audio.id()));
1599 const RTCOutboundRTPStreamStats& audio = report->Get(
1600 expected_audio.id())->cast_to<RTCOutboundRTPStreamStats>();
1601 EXPECT_EQ(audio, expected_audio);
1602
1603 EXPECT_TRUE(report->Get(*expected_audio.transport_id));
hbos0adb8282016-11-23 02:32:06 -08001604 EXPECT_TRUE(report->Get(*expected_audio.codec_id));
hbos6ded1902016-11-01 01:50:46 -07001605}
1606
1607TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Video) {
1608 MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel();
1609 cricket::VideoChannel video_channel(
1610 test_->worker_thread(), test_->network_thread(), video_media_channel,
1611 nullptr, "VideoContentName", false);
1612
1613 cricket::VideoMediaInfo video_media_info;
hbos0adb8282016-11-23 02:32:06 -08001614
hbos6ded1902016-11-01 01:50:46 -07001615 video_media_info.senders.push_back(cricket::VideoSenderInfo());
1616 video_media_info.senders[0].local_stats.push_back(cricket::SsrcSenderInfo());
1617 video_media_info.senders[0].local_stats[0].ssrc = 1;
1618 video_media_info.senders[0].firs_rcvd = 2;
1619 video_media_info.senders[0].plis_rcvd = 3;
1620 video_media_info.senders[0].nacks_rcvd = 4;
1621 video_media_info.senders[0].packets_sent = 5;
1622 video_media_info.senders[0].bytes_sent = 6;
hboseeafe942016-11-01 03:00:17 -07001623 video_media_info.senders[0].rtt_ms = 7500;
hbos0adb8282016-11-23 02:32:06 -08001624 video_media_info.senders[0].codec_payload_type = rtc::Optional<int>(42);
1625
1626 RtpCodecParameters codec_parameters;
1627 codec_parameters.payload_type = 42;
1628 codec_parameters.mime_type = "dummy";
1629 codec_parameters.clock_rate = 0;
1630 video_media_info.send_codecs.insert(
1631 std::make_pair(codec_parameters.payload_type, codec_parameters));
1632
hbos6ded1902016-11-01 01:50:46 -07001633 EXPECT_CALL(*video_media_channel, GetStats(_))
1634 .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true)));
1635
1636 SessionStats session_stats;
1637 session_stats.proxy_to_transport["VideoContentName"] = "TransportName";
1638 session_stats.transport_stats["TransportName"].transport_name =
1639 "TransportName";
1640
1641 // Make sure the associated |RTCTransportStats| is created.
1642 cricket::TransportChannelStats channel_stats;
1643 channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP;
hbos6ded1902016-11-01 01:50:46 -07001644 session_stats.transport_stats["TransportName"].channel_stats.push_back(
1645 channel_stats);
1646
1647 EXPECT_CALL(test_->session(), GetTransportStats(_))
1648 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats), Return(true)));
1649 EXPECT_CALL(test_->session(), video_channel())
1650 .WillRepeatedly(Return(&video_channel));
1651
1652 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1653
1654 RTCOutboundRTPStreamStats expected_video(
1655 "RTCOutboundRTPVideoStream_1", report->timestamp_us());
1656 expected_video.ssrc = "1";
1657 expected_video.is_remote = false;
1658 expected_video.media_type = "video";
1659 expected_video.transport_id = "RTCTransport_TransportName_" +
1660 rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP);
hbos0adb8282016-11-23 02:32:06 -08001661 expected_video.codec_id = "RTCCodec_OutboundVideo_42";
hbos6ded1902016-11-01 01:50:46 -07001662 expected_video.fir_count = 2;
1663 expected_video.pli_count = 3;
1664 expected_video.nack_count = 4;
1665 expected_video.packets_sent = 5;
1666 expected_video.bytes_sent = 6;
1667 expected_video.round_trip_time = 7.5;
1668
1669 ASSERT(report->Get(expected_video.id()));
1670 const RTCOutboundRTPStreamStats& video = report->Get(
1671 expected_video.id())->cast_to<RTCOutboundRTPStreamStats>();
1672 EXPECT_EQ(video, expected_video);
1673
1674 EXPECT_TRUE(report->Get(*expected_video.transport_id));
hbos0adb8282016-11-23 02:32:06 -08001675 EXPECT_TRUE(report->Get(*expected_video.codec_id));
hbos6ded1902016-11-01 01:50:46 -07001676}
1677
hbos2fa7c672016-10-24 04:00:05 -07001678TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) {
1679 std::unique_ptr<cricket::Candidate> rtp_local_candidate = CreateFakeCandidate(
1680 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42);
1681 std::unique_ptr<cricket::Candidate> rtp_remote_candidate =
1682 CreateFakeCandidate("42.42.42.42", 42, "protocol",
1683 cricket::LOCAL_PORT_TYPE, 42);
1684 std::unique_ptr<cricket::Candidate> rtcp_local_candidate =
1685 CreateFakeCandidate("42.42.42.42", 42, "protocol",
1686 cricket::LOCAL_PORT_TYPE, 42);
1687 std::unique_ptr<cricket::Candidate> rtcp_remote_candidate =
1688 CreateFakeCandidate("42.42.42.42", 42, "protocol",
1689 cricket::LOCAL_PORT_TYPE, 42);
1690
1691 SessionStats session_stats;
1692 session_stats.transport_stats["transport"].transport_name = "transport";
1693
1694 cricket::ConnectionInfo rtp_connection_info;
1695 rtp_connection_info.best_connection = false;
1696 rtp_connection_info.local_candidate = *rtp_local_candidate.get();
1697 rtp_connection_info.remote_candidate = *rtp_remote_candidate.get();
1698 rtp_connection_info.sent_total_bytes = 42;
1699 rtp_connection_info.recv_total_bytes = 1337;
1700 cricket::TransportChannelStats rtp_transport_channel_stats;
1701 rtp_transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP;
1702 rtp_transport_channel_stats.connection_infos.push_back(rtp_connection_info);
1703 session_stats.transport_stats["transport"].channel_stats.push_back(
1704 rtp_transport_channel_stats);
1705
1706
1707 // Mock the session to return the desired candidates.
1708 EXPECT_CALL(test_->session(), GetTransportStats(_)).WillRepeatedly(Invoke(
1709 [this, &session_stats](SessionStats* stats) {
1710 *stats = session_stats;
1711 return true;
1712 }));
1713
1714 // Get stats without RTCP, an active connection or certificates.
1715 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
1716 ExpectReportContainsTransportStats(
1717 report, session_stats.transport_stats["transport"], nullptr, nullptr);
1718
1719 cricket::ConnectionInfo rtcp_connection_info;
1720 rtcp_connection_info.best_connection = false;
1721 rtcp_connection_info.local_candidate = *rtcp_local_candidate.get();
1722 rtcp_connection_info.remote_candidate = *rtcp_remote_candidate.get();
1723 rtcp_connection_info.sent_total_bytes = 1337;
1724 rtcp_connection_info.recv_total_bytes = 42;
1725 cricket::TransportChannelStats rtcp_transport_channel_stats;
1726 rtcp_transport_channel_stats.component =
1727 cricket::ICE_CANDIDATE_COMPONENT_RTCP;
1728 rtcp_transport_channel_stats.connection_infos.push_back(rtcp_connection_info);
1729 session_stats.transport_stats["transport"].channel_stats.push_back(
1730 rtcp_transport_channel_stats);
1731
1732 collector_->ClearCachedStatsReport();
1733 // Get stats with RTCP and without an active connection or certificates.
1734 report = GetStatsReport();
1735 ExpectReportContainsTransportStats(
1736 report, session_stats.transport_stats["transport"], nullptr, nullptr);
1737
1738 // Get stats with an active connection.
1739 rtcp_connection_info.best_connection = true;
1740
1741 collector_->ClearCachedStatsReport();
1742 report = GetStatsReport();
1743 ExpectReportContainsTransportStats(
1744 report, session_stats.transport_stats["transport"], nullptr, nullptr);
1745
1746 // Get stats with certificates.
1747 std::unique_ptr<CertificateInfo> local_certinfo =
1748 CreateFakeCertificateAndInfoFromDers(
1749 std::vector<std::string>({ "(local) local", "(local) chain" }));
1750 std::unique_ptr<CertificateInfo> remote_certinfo =
1751 CreateFakeCertificateAndInfoFromDers(
1752 std::vector<std::string>({ "(remote) local", "(remote) chain" }));
1753 EXPECT_CALL(test_->session(), GetLocalCertificate(_, _)).WillRepeatedly(
1754 Invoke([this, &local_certinfo](const std::string& transport_name,
1755 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) {
1756 if (transport_name == "transport") {
1757 *certificate = local_certinfo->certificate;
1758 return true;
1759 }
1760 return false;
1761 }));
1762 EXPECT_CALL(test_->session(),
1763 GetRemoteSSLCertificate_ReturnsRawPointer(_)).WillRepeatedly(Invoke(
1764 [this, &remote_certinfo](const std::string& transport_name) {
1765 if (transport_name == "transport")
1766 return remote_certinfo->certificate->ssl_certificate().GetReference();
1767 return static_cast<rtc::SSLCertificate*>(nullptr);
1768 }));
1769
1770 collector_->ClearCachedStatsReport();
1771 report = GetStatsReport();
1772 ExpectReportContainsTransportStats(
1773 report, session_stats.transport_stats["transport"],
1774 local_certinfo.get(), remote_certinfo.get());
1775}
1776
hbosc82f2e12016-09-05 01:36:50 -07001777class RTCStatsCollectorTestWithFakeCollector : public testing::Test {
1778 public:
1779 RTCStatsCollectorTestWithFakeCollector()
1780 : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()),
1781 collector_(FakeRTCStatsCollector::Create(
1782 &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) {
1783 }
1784
1785 protected:
1786 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_;
1787 rtc::scoped_refptr<FakeRTCStatsCollector> collector_;
1788};
1789
1790TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) {
1791 collector_->VerifyThreadUsageAndResultsMerging();
1792}
1793
1794} // namespace
1795
hbosd565b732016-08-30 14:04:35 -07001796} // namespace webrtc