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

Side by Side Diff: content/browser/tracing/tracing_ui_unittest.cc

Issue 2954603002: Extend unit test for json/begin_recording endpoint. (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/trace_event/memory_dump_manager.h"
10 #include "base/trace_event/trace_config.h" 11 #include "base/trace_event/trace_config.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "content/browser/tracing/tracing_ui.h" 13 #include "content/browser/tracing/tracing_ui.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 class TracingUITest : public testing::Test { 18 class TracingUITest : public testing::Test {
18 public: 19 public:
19 TracingUITest() {} 20 TracingUITest() {}
20 }; 21 };
21 22
22 std::string GetOldStyleConfig() { 23 std::string GetOldStyleConfig() {
23 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 24 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
24 dict->SetString("categoryFilter", "filter1,-filter2"); 25 dict->SetString("categoryFilter", "filter1,-filter2");
25 dict->SetString("tracingRecordMode", "record-continuously"); 26 dict->SetString("tracingRecordMode", "record-continuously");
26 dict->SetBoolean("useSystemTracing", true); 27 dict->SetBoolean("useSystemTracing", true);
27 28
28 std::string results; 29 std::string results;
29 if (!base::JSONWriter::Write(*dict.get(), &results)) 30 if (!base::JSONWriter::Write(*dict.get(), &results))
30 return ""; 31 return "";
31 32
32 std::string data; 33 std::string data;
33 base::Base64Encode(results, &data); 34 base::Base64Encode(results, &data);
34 return data; 35 return data;
35 } 36 }
36 37
37 std::string GetNewStyleConfig() { 38 std::string GetNewStyleConfig() {
38 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 39 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
39 std::unique_ptr<base::Value> filter1(new base::Value("filter1")); 40 std::unique_ptr<base::Value> filter1(
41 new base::Value(base::trace_event::MemoryDumpManager::kTraceCategory));
40 std::unique_ptr<base::Value> filter2(new base::Value("filter2")); 42 std::unique_ptr<base::Value> filter2(new base::Value("filter2"));
41 std::unique_ptr<base::ListValue> included(new base::ListValue); 43 std::unique_ptr<base::ListValue> included(new base::ListValue);
42 included->Append(std::move(filter1)); 44 included->Append(std::move(filter1));
43 std::unique_ptr<base::ListValue> excluded(new base::ListValue); 45 std::unique_ptr<base::ListValue> excluded(new base::ListValue);
44 excluded->Append(std::move(filter2)); 46 excluded->Append(std::move(filter2));
45 47
46 dict->SetList("included_categories", std::move(included)); 48 dict->SetList("included_categories", std::move(included));
47 dict->SetList("excluded_categories", std::move(excluded)); 49 dict->SetList("excluded_categories", std::move(excluded));
48 dict->SetString("record_mode", "record-continuously"); 50 dict->SetString("record_mode", "record-continuously");
49 dict->SetBoolean("enable_systrace", true); 51 dict->SetBoolean("enable_systrace", true);
50 52
53 std::unique_ptr<base::DictionaryValue> memory_config(
54 new base::DictionaryValue());
55 std::unique_ptr<base::DictionaryValue> trigger(new base::DictionaryValue());
56 trigger->SetString("mode", "detailed");
57 trigger->SetInteger("periodic_interval_ms", 10000);
58 std::unique_ptr<base::ListValue> triggers(new base::ListValue);
Primiano Tucci (use gerrit) 2017/06/23 09:43:42 /me pretends to not realize that new DictionaryVal
59 triggers->Append(std::move(trigger));
60 memory_config->SetList("triggers", std::move(triggers));
61 dict->SetDictionary("memory_dump_config", std::move(memory_config));
62
51 std::string results; 63 std::string results;
52 if (!base::JSONWriter::Write(*dict.get(), &results)) 64 if (!base::JSONWriter::Write(*dict.get(), &results))
53 return ""; 65 return "";
54 66
55 std::string data; 67 std::string data;
56 base::Base64Encode(results, &data); 68 base::Base64Encode(results, &data);
57 return data; 69 return data;
58 } 70 }
59 71
60 TEST_F(TracingUITest, OldStyleConfig) { 72 TEST_F(TracingUITest, OldStyleConfig) {
61 base::trace_event::TraceConfig config; 73 base::trace_event::TraceConfig config;
62 ASSERT_TRUE(TracingUI::GetTracingOptions(GetOldStyleConfig(), &config)); 74 ASSERT_TRUE(TracingUI::GetTracingOptions(GetOldStyleConfig(), &config));
63 EXPECT_EQ(config.GetTraceRecordMode(), 75 EXPECT_EQ(config.GetTraceRecordMode(),
64 base::trace_event::RECORD_CONTINUOUSLY); 76 base::trace_event::RECORD_CONTINUOUSLY);
65 EXPECT_EQ(config.ToCategoryFilterString(), "filter1,-filter2"); 77 EXPECT_EQ(config.ToCategoryFilterString(), "filter1,-filter2");
66 EXPECT_TRUE(config.IsSystraceEnabled()); 78 EXPECT_TRUE(config.IsSystraceEnabled());
67 } 79 }
68 80
69 TEST_F(TracingUITest, NewStyleConfig) { 81 TEST_F(TracingUITest, NewStyleConfig) {
70 base::trace_event::TraceConfig config; 82 base::trace_event::TraceConfig config;
71 ASSERT_TRUE(TracingUI::GetTracingOptions(GetNewStyleConfig(), &config)); 83 ASSERT_TRUE(TracingUI::GetTracingOptions(GetNewStyleConfig(), &config));
72 EXPECT_EQ(config.GetTraceRecordMode(), 84 EXPECT_EQ(config.GetTraceRecordMode(),
73 base::trace_event::RECORD_CONTINUOUSLY); 85 base::trace_event::RECORD_CONTINUOUSLY);
74 EXPECT_EQ(config.ToCategoryFilterString(), "filter1,-filter2"); 86 std::string expected(base::trace_event::MemoryDumpManager::kTraceCategory);
87 expected += ",-filter2";
88 EXPECT_EQ(config.ToCategoryFilterString(), expected);
75 EXPECT_TRUE(config.IsSystraceEnabled()); 89 EXPECT_TRUE(config.IsSystraceEnabled());
90
91 ASSERT_EQ(config.memory_dump_config().triggers.size(), 1u);
92 EXPECT_EQ(config.memory_dump_config().triggers[0].min_time_between_dumps_ms,
93 10000u);
94 EXPECT_EQ(config.memory_dump_config().triggers[0].level_of_detail,
95 base::trace_event::MemoryDumpLevelOfDetail::DETAILED);
76 } 96 }
77 97
78 } // namespace content 98 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698