Chromium Code Reviews| Index: webrtc/pc/rtcstats_integrationtest.cc |
| diff --git a/webrtc/pc/rtcstats_integrationtest.cc b/webrtc/pc/rtcstats_integrationtest.cc |
| index 56a4ef11edae0c74339569cd760b1cc530986a6c..7c2d0abe9a4e5f96fc927d4bf39c7059f3792e97 100644 |
| --- a/webrtc/pc/rtcstats_integrationtest.cc |
| +++ b/webrtc/pc/rtcstats_integrationtest.cc |
| @@ -24,6 +24,7 @@ |
| #include "webrtc/rtc_base/gunit.h" |
| #include "webrtc/rtc_base/refcountedobject.h" |
| #include "webrtc/rtc_base/scoped_ref_ptr.h" |
| +#include "webrtc/rtc_base/trace_event.h" |
| #include "webrtc/rtc_base/virtualsocketserver.h" |
| namespace webrtc { |
| @@ -33,27 +34,62 @@ namespace { |
| const int64_t kGetStatsTimeoutMs = 10000; |
| const unsigned char* GetCategoryEnabledHandler(const char* name) { |
| - return reinterpret_cast<const unsigned char*>("webrtc_stats"); |
| + if (strcmp("webrtc_stats", name) != 0) { |
| + return reinterpret_cast<const unsigned char*>(""); |
| + } |
| + return reinterpret_cast<const unsigned char*>(name); |
| } |
| -void AddTraceEventHandler(char phase, |
| - const unsigned char* category_enabled, |
| - const char* name, |
| - unsigned long long id, |
| - int num_args, |
| - const char** arg_names, |
| - const unsigned char* arg_types, |
| - const unsigned long long* arg_values, |
| - unsigned char flags) { |
| - // Do nothing |
| -} |
| +class RTCStatsTracedReport { |
|
hbos
2017/08/14 15:49:23
nit: Maybe RTCStatsReportTraceListener is a more s
ehmaldonado_webrtc
2017/08/14 16:14:07
Agree. Done.
|
| + public: |
| + static void SetUp() { |
| + if (!traced_report_) |
| + traced_report_ = new RTCStatsTracedReport(); |
| + traced_report_->last_trace_ = ""; |
| + SetupEventTracer(&GetCategoryEnabledHandler, |
| + &RTCStatsTracedReport::AddTraceEventHandler); |
| + } |
| + |
| + static std::string& GetTracedReport() { |
|
hbos
2017/08/14 15:49:23
nit: const std::string& last_trace()
ehmaldonado_webrtc
2017/08/14 16:14:07
Done.
|
| + RTC_DCHECK(traced_report_); |
| + return traced_report_->last_trace_; |
| + } |
| + |
| + private: |
| + static void AddTraceEventHandler(char phase, |
| + const unsigned char* category_enabled, |
| + const char* name, |
| + unsigned long long id, |
| + int num_args, |
| + const char** arg_names, |
| + const unsigned char* arg_types, |
| + const unsigned long long* arg_values, |
| + unsigned char flags) { |
| + RTC_DCHECK(traced_report_); |
| + EXPECT_EQ(traced_report_->last_trace_, ""); |
| + EXPECT_STREQ("webrtc_stats", |
| + reinterpret_cast<const char*>(category_enabled)); |
| + EXPECT_STREQ("webrtc_stats", name); |
| + EXPECT_EQ(1, num_args); |
| + EXPECT_STREQ("report", arg_names[0]); |
| + EXPECT_EQ(TRACE_VALUE_TYPE_COPY_STRING, arg_types[0]); |
| + |
| + traced_report_->last_trace_ = |
| + reinterpret_cast<const char*>(arg_values[0]); |
| + } |
| + |
| + std::string last_trace_; |
| + static RTCStatsTracedReport* traced_report_; |
|
hbos
2017/08/14 15:49:23
nit: Can't find anything in the style guide, but I
ehmaldonado_webrtc
2017/08/14 16:14:07
Done.
|
| +}; |
| + |
| +RTCStatsTracedReport* RTCStatsTracedReport::traced_report_ = nullptr; |
| class RTCStatsIntegrationTest : public testing::Test { |
| public: |
| RTCStatsIntegrationTest() |
| : network_thread_(new rtc::Thread(&virtual_socket_server_)), |
| worker_thread_(rtc::Thread::Create()) { |
| - SetupEventTracer(&GetCategoryEnabledHandler, &AddTraceEventHandler); |
| + RTCStatsTracedReport::SetUp(); |
| RTC_CHECK(network_thread_->Start()); |
| RTC_CHECK(worker_thread_->Start()); |
| @@ -650,6 +686,7 @@ TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) { |
| rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller(); |
| RTCStatsReportVerifier(report.get()).VerifyReport(); |
| + EXPECT_EQ(report->ToJson(), RTCStatsTracedReport::GetTracedReport()); |
| } |
| TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { |
| @@ -657,6 +694,7 @@ TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { |
| rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); |
| RTCStatsReportVerifier(report.get()).VerifyReport(); |
| + EXPECT_EQ(report->ToJson(), RTCStatsTracedReport::GetTracedReport()); |
| } |
| TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) { |
| @@ -670,6 +708,8 @@ TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) { |
| // Any pending stats requests should have completed in the act of destroying |
| // the peer connection. |
| EXPECT_TRUE(stats_obtainer->report()); |
| + EXPECT_EQ(stats_obtainer->report()->ToJson(), |
| + RTCStatsTracedReport::GetTracedReport()); |
| } |
| #endif // HAVE_SCTP |