Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
erikchen | 3e164f7 | 2017-06-22 21:15:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <memory> |
| 6 | |
| 7 | #include "base/base64.h" |
| 8 | #include "base/json/json_reader.h" |
| 9 | #include "base/json/json_writer.h" |
erikchen | 8401127 | 2017-06-23 16:12:59 | [diff] [blame] | 10 | #include "base/trace_event/memory_dump_manager.h" |
erikchen | 3e164f7 | 2017-06-22 21:15:44 | [diff] [blame] | 11 | #include "base/trace_event/trace_config.h" |
| 12 | #include "base/values.h" |
| 13 | #include "content/browser/tracing/tracing_ui.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
| 16 | namespace content { |
| 17 | |
| 18 | class TracingUITest : public testing::Test { |
| 19 | public: |
Sergii Bykov | 50e5b02 | 2023-10-10 13:46:47 | [diff] [blame] | 20 | TracingUITest() = default; |
erikchen | 3e164f7 | 2017-06-22 21:15:44 | [diff] [blame] | 21 | }; |
| 22 | |
Sami Kyostila | 9cb5c4ee2 | 2020-06-10 18:42:42 | [diff] [blame] | 23 | std::string GetConfig() { |
Sergii Bykov | 50e5b02 | 2023-10-10 13:46:47 | [diff] [blame] | 24 | auto dict = |
| 25 | base::Value::Dict() |
| 26 | .Set("included_categories", |
| 27 | base::Value::List().Append(base::Value( |
| 28 | base::trace_event::MemoryDumpManager::kTraceCategory))) |
| 29 | .Set("excluded_categories", |
| 30 | base::Value::List().Append(base::Value("filter2"))) |
| 31 | .Set("record_mode", "record-continuously") |
| 32 | .Set("enable_systrace", true) |
| 33 | .Set("stream_format", "protobuf") |
| 34 | .Set("memory_dump_config", |
| 35 | base::Value::Dict().Set( |
| 36 | "triggers", base::Value::List().Append( |
| 37 | base::Value::Dict() |
| 38 | .Set("mode", "detailed") |
| 39 | .Set("periodic_interval_ms", 10000)))); |
erikchen | 8401127 | 2017-06-23 16:12:59 | [diff] [blame] | 40 | |
erikchen | 3e164f7 | 2017-06-22 21:15:44 | [diff] [blame] | 41 | std::string results; |
Scott Haseley | 02ebe05 | 2021-09-16 01:43:00 | [diff] [blame] | 42 | if (!base::JSONWriter::Write(dict, &results)) |
erikchen | 3e164f7 | 2017-06-22 21:15:44 | [diff] [blame] | 43 | return ""; |
punithnayak | 80356b7 | 2024-01-29 15:28:50 | [diff] [blame] | 44 | return base::Base64Encode(results); |
erikchen | 3e164f7 | 2017-06-22 21:15:44 | [diff] [blame] | 45 | } |
| 46 | |
Sami Kyostila | 9cb5c4ee2 | 2020-06-10 18:42:42 | [diff] [blame] | 47 | TEST_F(TracingUITest, ConfigParsing) { |
erikchen | 3e164f7 | 2017-06-22 21:15:44 | [diff] [blame] | 48 | base::trace_event::TraceConfig config; |
Sami Kyostila | b3f9041 | 2020-07-09 11:47:54 | [diff] [blame] | 49 | std::string stream_format; |
| 50 | ASSERT_TRUE(TracingUI::GetTracingOptions(GetConfig(), config, stream_format)); |
erikchen | 3e164f7 | 2017-06-22 21:15:44 | [diff] [blame] | 51 | EXPECT_EQ(config.GetTraceRecordMode(), |
| 52 | base::trace_event::RECORD_CONTINUOUSLY); |
erikchen | 8401127 | 2017-06-23 16:12:59 | [diff] [blame] | 53 | std::string expected(base::trace_event::MemoryDumpManager::kTraceCategory); |
| 54 | expected += ",-filter2"; |
| 55 | EXPECT_EQ(config.ToCategoryFilterString(), expected); |
Sami Kyostila | b3f9041 | 2020-07-09 11:47:54 | [diff] [blame] | 56 | EXPECT_EQ(stream_format, "protobuf"); |
erikchen | 3e164f7 | 2017-06-22 21:15:44 | [diff] [blame] | 57 | EXPECT_TRUE(config.IsSystraceEnabled()); |
erikchen | 8401127 | 2017-06-23 16:12:59 | [diff] [blame] | 58 | |
| 59 | ASSERT_EQ(config.memory_dump_config().triggers.size(), 1u); |
| 60 | EXPECT_EQ(config.memory_dump_config().triggers[0].min_time_between_dumps_ms, |
| 61 | 10000u); |
| 62 | EXPECT_EQ(config.memory_dump_config().triggers[0].level_of_detail, |
Ho Cheung | adbf3fb | 2023-09-08 02:01:11 | [diff] [blame] | 63 | base::trace_event::MemoryDumpLevelOfDetail::kDetailed); |
erikchen | 3e164f7 | 2017-06-22 21:15:44 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } // namespace content |