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

Unified Diff: chrome/browser/media/webrtc/rtc_stats_dictionary_unittest.cc

Issue 2534633002: Preparation CL for WebRTC performance test using promise-based getStats (Closed)
Patch Set: Created 4 years 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
Index: chrome/browser/media/webrtc/rtc_stats_dictionary_unittest.cc
diff --git a/chrome/browser/media/webrtc/rtc_stats_dictionary_unittest.cc b/chrome/browser/media/webrtc/rtc_stats_dictionary_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f1bd05d8275808810783baa57c3991ca26dc2501
--- /dev/null
+++ b/chrome/browser/media/webrtc/rtc_stats_dictionary_unittest.cc
@@ -0,0 +1,132 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/webrtc/rtc_stats_dictionary.h"
+
+#include <memory>
+#include <vector>
+
+#include "base/json/json_reader.h"
+#include "base/logging.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/values.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+namespace {
+
+const char kTestStatsReportJson[] =
+ "{\n"
+ " \"GarbageA\": {\n"
+ " \"id\": \"GarbageA\",\n"
+ " \"timestamp\": 0.0,\n"
+ " \"type\": \"garbage\"\n"
+ " },\n"
+ " \"RTCTestStatsID\": {\n"
+ " \"id\": \"RTCTestStatsID\",\n"
+ " \"timestamp\": 13.37,\n"
+ " \"type\": \"test\",\n"
+ " \"boolean\": true,\n"
+ " \"number\": 42,\n"
+ " \"string\": \"text\",\n"
+ " \"sequenceBoolean\": [ true ],\n"
+ " \"sequenceNumber\": [ 42 ],\n"
+ " \"sequenceString\": [ \"text\" ]\n"
+ " },\n"
+ " \"GarbageB\": {\n"
+ " \"id\": \"GarbageB\",\n"
+ " \"timestamp\": 0.0,\n"
+ " \"type\": \"garbage\"\n"
+ " }\n"
+ "}";
+
+class RTCStatsDictionaryTest : public testing::Test {
+ public:
+ RTCStatsDictionaryTest() {
+ std::unique_ptr<base::Value> value =
+ base::JSONReader::Read(kTestStatsReportJson);
+ CHECK(value);
+ base::DictionaryValue* dictionary;
+ CHECK(value->GetAsDictionary(&dictionary));
+ ignore_result(value.release());
+ report_ = new RTCStatsReportDictionary(
+ std::unique_ptr<base::DictionaryValue>(dictionary));
+ }
+
+ protected:
+ scoped_refptr<RTCStatsReportDictionary> report_;
+};
+
+TEST_F(RTCStatsDictionaryTest, ReportGetStats) {
+ EXPECT_FALSE(report_->Get("InvalidID"));
+ EXPECT_TRUE(report_->Get("GarbageA"));
+ EXPECT_TRUE(report_->Get("RTCTestStatsID"));
+ EXPECT_TRUE(report_->Get("GarbageB"));
+}
+
+TEST_F(RTCStatsDictionaryTest, ReportFilterStats) {
+ std::vector<RTCStatsDictionary> filtered_stats = report_->Filter(
+ [](const RTCStatsDictionary& stats) -> bool {
+ return false;
+ });
+ EXPECT_EQ(filtered_stats.size(), 0u);
+
+ filtered_stats = report_->Filter(
+ [](const RTCStatsDictionary& stats) -> bool {
+ return true;
+ });
+ EXPECT_EQ(filtered_stats.size(), 3u);
+
+ filtered_stats = report_->Filter(
+ [](const RTCStatsDictionary& stats) -> bool {
+ return stats.GetString("id") == "RTCTestStatsID";
+ });
+ EXPECT_EQ(filtered_stats.size(), 1u);
+}
+
+TEST_F(RTCStatsDictionaryTest, StatsVerifyMembers) {
+ std::unique_ptr<RTCStatsDictionary> stats = report_->Get("RTCTestStatsID");
+ EXPECT_TRUE(stats);
+
+ EXPECT_FALSE(stats->IsBoolean("nonexistentMember"));
+ EXPECT_FALSE(stats->IsNumber("nonexistentMember"));
+ EXPECT_FALSE(stats->IsString("nonexistentMember"));
+ EXPECT_FALSE(stats->IsSequenceBoolean("nonexistentMember"));
+ EXPECT_FALSE(stats->IsSequenceNumber("nonexistentMember"));
+ EXPECT_FALSE(stats->IsSequenceString("nonexistentMember"));
+
+ ASSERT_TRUE(stats->IsBoolean("boolean"));
+ EXPECT_EQ(stats->GetBoolean("boolean"), true);
+
+ ASSERT_TRUE(stats->IsNumber("number"));
+ EXPECT_EQ(stats->GetNumber("number"), 42.0);
+
+ ASSERT_TRUE(stats->IsString("string"));
+ EXPECT_EQ(stats->GetString("string"), "text");
+
+ ASSERT_TRUE(stats->IsSequenceBoolean("sequenceBoolean"));
+ EXPECT_EQ(stats->GetSequenceBoolean("sequenceBoolean"),
+ std::vector<bool> { true });
+
+ ASSERT_TRUE(stats->IsSequenceNumber("sequenceNumber"));
+ EXPECT_EQ(stats->GetSequenceNumber("sequenceNumber"),
+ std::vector<double> { 42.0 });
+
+ ASSERT_TRUE(stats->IsSequenceString("sequenceString"));
+ EXPECT_EQ(stats->GetSequenceString("sequenceString"),
+ std::vector<std::string> { "text" });
+}
+
+TEST_F(RTCStatsDictionaryTest, RTCStatsDictionaryShouldKeepReportAlive) {
+ std::unique_ptr<RTCStatsDictionary> stats = report_->Get("RTCTestStatsID");
+ EXPECT_TRUE(stats);
+ report_ = nullptr;
+ EXPECT_EQ(stats->GetString("string"), "text");
+}
+
+} // namespace
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698