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

Unified Diff: webrtc/pc/rtcstats_integrationtest.cc

Issue 2986453002: Trace the stats report as JSON instead of each stat separately. (Closed)
Patch Set: Nits. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/pc/rtcstatscollector.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/pc/rtcstats_integrationtest.cc
diff --git a/webrtc/pc/rtcstats_integrationtest.cc b/webrtc/pc/rtcstats_integrationtest.cc
index 56a4ef11edae0c74339569cd760b1cc530986a6c..d6326f6beaa4f8f7540a4b44f3701687cb3be4a9 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 RTCStatsReportTraceListener {
+ public:
+ static void SetUp() {
+ if (!traced_report_)
+ traced_report_ = new RTCStatsReportTraceListener();
+ traced_report_->last_trace_ = "";
+ SetupEventTracer(&GetCategoryEnabledHandler,
+ &RTCStatsReportTraceListener::AddTraceEventHandler);
+ }
+
+ static const std::string& last_trace() {
+ 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]);
+ }
+
+ static RTCStatsReportTraceListener* traced_report_;
+ std::string last_trace_;
+};
+
+RTCStatsReportTraceListener* RTCStatsReportTraceListener::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);
+ RTCStatsReportTraceListener::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(), RTCStatsReportTraceListener::last_trace());
}
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(), RTCStatsReportTraceListener::last_trace());
}
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(),
+ RTCStatsReportTraceListener::last_trace());
}
#endif // HAVE_SCTP
« no previous file with comments | « no previous file | webrtc/pc/rtcstatscollector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698