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

Unified Diff: base/debug/trace_event_unittest.cc

Issue 13590005: Add a ConvertableToTraceFormat type to the trace framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: base/debug/trace_event_unittest.cc
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index 8376660300d2d0bc2a9dc8bb0934e178021c93f7..9a7d93ec84538b85265e22a7e2a35643eae607e2 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -1590,6 +1590,46 @@ TEST_F(TraceEventTestFixture, TraceSampling) {
EXPECT_TRUE(FindNamePhase("Things", "P"));
}
+class MyData : public base::debug::ConvertableToJSON {
+ public:
+ MyData() {}
+ virtual ~MyData() {}
+
+ virtual void ToJSON(std::string& out) const OVERRIDE {
+ out.append("{\"foo\":1}");
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MyData);
+};
+
+TEST_F(TraceEventTestFixture, ConvertableTypes) {
+ ManualTestSetUp();
+ TraceLog::GetInstance()->SetEnabled(true, TraceLog::RECORD_UNTIL_FULL);
+
+ MyData* data(new MyData());
+
+ TRACE_EVENT1("foo", "bar", "data", static_cast<ConvertableToJSON*>(data));
+ EndTraceAndFlush();
+
+ DictionaryValue* dict = FindNamePhase("bar", "B");
+ ASSERT_TRUE(dict);
+
+ const DictionaryValue* args_dict = NULL;
+ dict->GetDictionary("args", &args_dict);
+ ASSERT_TRUE(args_dict);
+
+ const Value* value = NULL;
+ const DictionaryValue* convertable_dict = NULL;
+ EXPECT_TRUE(args_dict->Get("data", &value));
+ EXPECT_TRUE(value->GetAsDictionary(&convertable_dict));
+
+ int foo_val;
+ EXPECT_TRUE(convertable_dict->GetInteger("foo", &foo_val));
+ EXPECT_EQ(1, foo_val);
+}
+
+
class TraceEventCallbackTest : public TraceEventTestFixture {
public:
virtual void SetUp() OVERRIDE {

Powered by Google App Engine
This is Rietveld 408576698