RTCStatsIntegrationTest added.
This is an integration test using peerconnectiontestwrapper.h to set up
and end to end test using a real PeerConnection implementation. These
tests will complement rtcstatscollector_unittest.cc which collects all
stats using mocks.
The integration test is set up so that all stats types are returned by
GetStats and verifies that expected dictionary members are defined. The
test could in the future be updated to include sanity checks for the
values of members. There is a sanity check that references to other
stats dictionaries yield existing stats of the appropriate type, but
other than that members are only tested for if they are defined not.
StatsCallback of rtcstatscollector_unittest.cc is moved so that it can
be reused and renamed to RTCStatsObtainer.
TODO: Audio stream track stats members are missing in the test. Find out
if this is because of a real problem or because of testing without real
devices. Do this before closing crbug.com/627816.
BUG=chromium:627816
Review-Url: https://codereview.webrtc.org/2521663002
Cr-Commit-Position: refs/heads/master@{#15287}
diff --git a/webrtc/api/rtcstatscollector_unittest.cc b/webrtc/api/rtcstatscollector_unittest.cc
index f27eb32..e4c3118 100644
--- a/webrtc/api/rtcstatscollector_unittest.cc
+++ b/webrtc/api/rtcstatscollector_unittest.cc
@@ -24,6 +24,7 @@
#include "webrtc/api/test/mock_datachannel.h"
#include "webrtc/api/test/mock_peerconnection.h"
#include "webrtc/api/test/mock_webrtcsession.h"
+#include "webrtc/api/test/rtcstatsobtainer.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/fakeclock.h"
#include "webrtc/base/fakesslidentity.h"
@@ -472,37 +473,6 @@
int produced_on_network_thread_ = 0;
};
-class StatsCallback : public RTCStatsCollectorCallback {
- public:
- static rtc::scoped_refptr<StatsCallback> Create(
- rtc::scoped_refptr<const RTCStatsReport>* report_ptr = nullptr) {
- return rtc::scoped_refptr<StatsCallback>(
- new rtc::RefCountedObject<StatsCallback>(report_ptr));
- }
-
- void OnStatsDelivered(
- const rtc::scoped_refptr<const RTCStatsReport>& report) override {
- EXPECT_TRUE(thread_checker_.CalledOnValidThread());
- report_ = report;
- if (report_ptr_)
- *report_ptr_ = report_;
- }
-
- rtc::scoped_refptr<const RTCStatsReport> report() const {
- EXPECT_TRUE(thread_checker_.CalledOnValidThread());
- return report_;
- }
-
- protected:
- explicit StatsCallback(rtc::scoped_refptr<const RTCStatsReport>* report_ptr)
- : report_ptr_(report_ptr) {}
-
- private:
- rtc::ThreadChecker thread_checker_;
- rtc::scoped_refptr<const RTCStatsReport> report_;
- rtc::scoped_refptr<const RTCStatsReport>* report_ptr_;
-};
-
class RTCStatsCollectorTest : public testing::Test {
public:
RTCStatsCollectorTest()
@@ -512,7 +482,7 @@
}
rtc::scoped_refptr<const RTCStatsReport> GetStatsReport() {
- rtc::scoped_refptr<StatsCallback> callback = StatsCallback::Create();
+ rtc::scoped_refptr<RTCStatsObtainer> callback = RTCStatsObtainer::Create();
collector_->GetStatsReport(callback);
EXPECT_TRUE_WAIT(callback->report(), kGetStatsReportTimeoutMs);
int64_t after = rtc::TimeUTCMicros();
@@ -723,7 +693,7 @@
TEST_F(RTCStatsCollectorTest, SingleCallback) {
rtc::scoped_refptr<const RTCStatsReport> result;
- collector_->GetStatsReport(StatsCallback::Create(&result));
+ collector_->GetStatsReport(RTCStatsObtainer::Create(&result));
EXPECT_TRUE_WAIT(result, kGetStatsReportTimeoutMs);
}
@@ -731,9 +701,9 @@
rtc::scoped_refptr<const RTCStatsReport> a;
rtc::scoped_refptr<const RTCStatsReport> b;
rtc::scoped_refptr<const RTCStatsReport> c;
- collector_->GetStatsReport(StatsCallback::Create(&a));
- collector_->GetStatsReport(StatsCallback::Create(&b));
- collector_->GetStatsReport(StatsCallback::Create(&c));
+ collector_->GetStatsReport(RTCStatsObtainer::Create(&a));
+ collector_->GetStatsReport(RTCStatsObtainer::Create(&b));
+ collector_->GetStatsReport(RTCStatsObtainer::Create(&c));
EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs);
EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs);
EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs);
@@ -761,11 +731,11 @@
rtc::scoped_refptr<const RTCStatsReport> a;
rtc::scoped_refptr<const RTCStatsReport> b;
rtc::scoped_refptr<const RTCStatsReport> c;
- collector_->GetStatsReport(StatsCallback::Create(&a));
- collector_->GetStatsReport(StatsCallback::Create(&b));
+ collector_->GetStatsReport(RTCStatsObtainer::Create(&a));
+ collector_->GetStatsReport(RTCStatsObtainer::Create(&b));
// Cache is invalidated after 50 ms.
test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51));
- collector_->GetStatsReport(StatsCallback::Create(&c));
+ collector_->GetStatsReport(RTCStatsObtainer::Create(&c));
EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs);
EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs);
EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs);