Roll breakpad a513e85:7caf028 (svn 1384:1385)
[chromium-blink-merge.git] / base / debug / trace_event_argument_unittest.cc
blob06a7697f0828f2099844d96813e6cfa31d14c224
1 // Copyright (c) 2014 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.
5 #include "base/debug/trace_event_argument.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 namespace base {
9 namespace debug {
11 TEST(TraceEventArgumentTest, FlatDictionary) {
12 scoped_refptr<TracedValue> value = new TracedValue();
13 value->SetInteger("int", 2014);
14 value->SetDouble("double", 0.0);
15 value->SetBoolean("bool", true);
16 value->SetString("string", "string");
17 std::string json;
18 value->AppendAsTraceFormat(&json);
19 EXPECT_EQ("{\"bool\":true,\"double\":0.0,\"int\":2014,\"string\":\"string\"}",
20 json);
23 TEST(TraceEventArgumentTest, Hierarchy) {
24 scoped_refptr<TracedValue> value = new TracedValue();
25 value->SetInteger("i0", 2014);
26 value->BeginDictionary("dict1");
27 value->SetInteger("i1", 2014);
28 value->BeginDictionary("dict2");
29 value->SetBoolean("b2", false);
30 value->EndDictionary();
31 value->SetString("s1", "foo");
32 value->EndDictionary();
33 value->SetDouble("d0", 0.0);
34 value->SetBoolean("b0", true);
35 value->BeginArray("a1");
36 value->AppendInteger(1);
37 value->AppendBoolean(true);
38 value->BeginDictionary();
39 value->SetInteger("i2", 3);
40 value->EndDictionary();
41 value->EndArray();
42 value->SetString("s0", "foo");
43 std::string json;
44 value->AppendAsTraceFormat(&json);
45 EXPECT_EQ(
46 "{\"a1\":[1,true,{\"i2\":3}],\"b0\":true,\"d0\":0.0,\"dict1\":{\"dict2\":"
47 "{\"b2\":false},\"i1\":2014,\"s1\":\"foo\"},\"i0\":2014,\"s0\":"
48 "\"foo\"}",
49 json);
52 } // namespace debug
53 } // namespace base