OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/debug/trace_event_unittest.h" | 6 #include "base/debug/trace_event_unittest.h" |
7 #include "base/test/trace_event_analyzer.h" | 7 #include "base/test/trace_event_analyzer.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace trace_analyzer { | 11 namespace trace_analyzer { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 class TraceEventAnalyzerTest : public testing::Test { | 15 class TraceEventAnalyzerTest : public testing::Test { |
16 public: | 16 public: |
17 void ManualSetUp(); | 17 void ManualSetUp(); |
18 void OnTraceDataCollected( | 18 void OnTraceDataCollected( |
19 const scoped_refptr<base::RefCountedString>& json_events_str); | 19 const scoped_refptr<base::RefCountedString>& json_events_str); |
20 void BeginTracing(); | 20 void BeginTracing(); |
21 void EndTracing(); | 21 void EndTracing(); |
22 | 22 |
23 base::debug::TraceResultBuffer::SimpleOutput output_; | 23 base::debug::TraceResultBuffer::SimpleOutput output_; |
24 base::debug::TraceResultBuffer buffer_; | 24 base::debug::TraceResultBuffer buffer_; |
25 }; | 25 }; |
26 | 26 |
27 void TraceEventAnalyzerTest::ManualSetUp() { | 27 void TraceEventAnalyzerTest::ManualSetUp() { |
28 base::debug::TraceLog::Resurrect(); | 28 base::debug::TraceLog::Resurrect(); |
29 base::debug::TraceLog* tracelog = base::debug::TraceLog::GetInstance(); | 29 ASSERT_TRUE(base::debug::TraceLog::GetInstance()); |
30 ASSERT_TRUE(tracelog); | |
31 tracelog->SetOutputCallback( | |
32 base::Bind(&TraceEventAnalyzerTest::OnTraceDataCollected, | |
33 base::Unretained(this))); | |
34 buffer_.SetOutputCallback(output_.GetCallback()); | 30 buffer_.SetOutputCallback(output_.GetCallback()); |
35 output_.json_output.clear(); | 31 output_.json_output.clear(); |
36 } | 32 } |
37 | 33 |
38 void TraceEventAnalyzerTest::OnTraceDataCollected( | 34 void TraceEventAnalyzerTest::OnTraceDataCollected( |
39 const scoped_refptr<base::RefCountedString>& json_events_str) { | 35 const scoped_refptr<base::RefCountedString>& json_events_str) { |
40 buffer_.AddFragment(json_events_str->data()); | 36 buffer_.AddFragment(json_events_str->data()); |
41 } | 37 } |
42 | 38 |
43 void TraceEventAnalyzerTest::BeginTracing() { | 39 void TraceEventAnalyzerTest::BeginTracing() { |
44 output_.json_output.clear(); | 40 output_.json_output.clear(); |
45 buffer_.Start(); | 41 buffer_.Start(); |
46 base::debug::TraceLog::GetInstance()->SetEnabled(true); | 42 base::debug::TraceLog::GetInstance()->SetEnabled(true); |
47 } | 43 } |
48 | 44 |
49 void TraceEventAnalyzerTest::EndTracing() { | 45 void TraceEventAnalyzerTest::EndTracing() { |
50 base::debug::TraceLog::GetInstance()->SetEnabled(false); | 46 base::debug::TraceLog::GetInstance()->SetEnabled(false); |
| 47 base::debug::TraceLog::GetInstance()->Flush( |
| 48 base::Bind(&TraceEventAnalyzerTest::OnTraceDataCollected, |
| 49 base::Unretained(this))); |
51 buffer_.Finish(); | 50 buffer_.Finish(); |
52 } | 51 } |
53 | 52 |
54 } // namespace | 53 } // namespace |
55 | 54 |
56 TEST_F(TraceEventAnalyzerTest, NoEvents) { | 55 TEST_F(TraceEventAnalyzerTest, NoEvents) { |
57 ManualSetUp(); | 56 ManualSetUp(); |
58 | 57 |
59 // Create an empty JSON event string: | 58 // Create an empty JSON event string: |
60 buffer_.Start(); | 59 buffer_.Start(); |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); | 818 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); |
820 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), | 819 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), |
821 1, num_events)); | 820 1, num_events)); |
822 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); | 821 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); |
823 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); | 822 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); |
824 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); | 823 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); |
825 } | 824 } |
826 | 825 |
827 | 826 |
828 } // namespace trace_analyzer | 827 } // namespace trace_analyzer |
OLD | NEW |