OLD | NEW |
(Empty) | |
| 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 |
| 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" |
| 10 #include "base/trace_event/trace_config.h" |
| 11 #include "base/values.h" |
| 12 #include "content/browser/tracing/tracing_ui.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 class TracingUITest : public testing::Test { |
| 18 public: |
| 19 TracingUITest() {} |
| 20 }; |
| 21 |
| 22 std::string GetOldStyleConfig() { |
| 23 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 24 dict->SetString("categoryFilter", "filter1,-filter2"); |
| 25 dict->SetString("tracingRecordMode", "record-continuously"); |
| 26 dict->SetBoolean("useSystemTracing", true); |
| 27 |
| 28 std::string results; |
| 29 if (!base::JSONWriter::Write(*dict.get(), &results)) |
| 30 return ""; |
| 31 |
| 32 std::string data; |
| 33 base::Base64Encode(results, &data); |
| 34 return data; |
| 35 } |
| 36 |
| 37 std::string GetNewStyleConfig() { |
| 38 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> filter2(new base::Value("filter2")); |
| 41 std::unique_ptr<base::ListValue> included(new base::ListValue); |
| 42 included->Append(std::move(filter1)); |
| 43 std::unique_ptr<base::ListValue> excluded(new base::ListValue); |
| 44 excluded->Append(std::move(filter2)); |
| 45 |
| 46 dict->SetList("included_categories", std::move(included)); |
| 47 dict->SetList("excluded_categories", std::move(excluded)); |
| 48 dict->SetString("record_mode", "record-continuously"); |
| 49 dict->SetBoolean("enable_systrace", true); |
| 50 |
| 51 std::string results; |
| 52 if (!base::JSONWriter::Write(*dict.get(), &results)) |
| 53 return ""; |
| 54 |
| 55 std::string data; |
| 56 base::Base64Encode(results, &data); |
| 57 return data; |
| 58 } |
| 59 |
| 60 TEST_F(TracingUITest, OldStyleConfig) { |
| 61 base::trace_event::TraceConfig config; |
| 62 ASSERT_TRUE(TracingUI::GetTracingOptions(GetOldStyleConfig(), &config)); |
| 63 EXPECT_EQ(config.GetTraceRecordMode(), |
| 64 base::trace_event::RECORD_CONTINUOUSLY); |
| 65 EXPECT_EQ(config.ToCategoryFilterString(), "filter1,-filter2"); |
| 66 EXPECT_TRUE(config.IsSystraceEnabled()); |
| 67 } |
| 68 |
| 69 TEST_F(TracingUITest, NewStyleConfig) { |
| 70 base::trace_event::TraceConfig config; |
| 71 ASSERT_TRUE(TracingUI::GetTracingOptions(GetNewStyleConfig(), &config)); |
| 72 EXPECT_EQ(config.GetTraceRecordMode(), |
| 73 base::trace_event::RECORD_CONTINUOUSLY); |
| 74 EXPECT_EQ(config.ToCategoryFilterString(), "filter1,-filter2"); |
| 75 EXPECT_TRUE(config.IsSystraceEnabled()); |
| 76 } |
| 77 |
| 78 } // namespace content |
OLD | NEW |