OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/test/trace_event_analyzer.h" | 6 #include "base/test/trace_event_analyzer.h" |
7 #include "testing/gmock/include/gmock/gmock.h" | 7 #include "testing/gmock/include/gmock/gmock.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace trace_analyzer { | 10 namespace trace_analyzer { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 class TraceEventAnalyzerTest : public testing::Test { | 14 class TraceEventAnalyzerTest : public testing::Test { |
15 public: | 15 public: |
16 void ManualSetUp(); | 16 void ManualSetUp(); |
17 void OnTraceDataCollected( | 17 void OnTraceDataCollected( |
18 scoped_refptr<base::debug::TraceLog::RefCountedString> json_events_str); | 18 const scoped_refptr<base::debug::TraceLog::RefCountedString>& |
| 19 json_events_str); |
19 void BeginTracing(); | 20 void BeginTracing(); |
20 void EndTracing(); | 21 void EndTracing(); |
21 | 22 |
22 base::debug::TraceResultBuffer::SimpleOutput output_; | 23 base::debug::TraceResultBuffer::SimpleOutput output_; |
23 base::debug::TraceResultBuffer buffer_; | 24 base::debug::TraceResultBuffer buffer_; |
24 }; | 25 }; |
25 | 26 |
26 void TraceEventAnalyzerTest::ManualSetUp() { | 27 void TraceEventAnalyzerTest::ManualSetUp() { |
27 base::debug::TraceLog::Resurrect(); | 28 base::debug::TraceLog::Resurrect(); |
28 base::debug::TraceLog* tracelog = base::debug::TraceLog::GetInstance(); | 29 base::debug::TraceLog* tracelog = base::debug::TraceLog::GetInstance(); |
29 ASSERT_TRUE(tracelog); | 30 ASSERT_TRUE(tracelog); |
30 tracelog->SetOutputCallback( | 31 tracelog->SetOutputCallback( |
31 base::Bind(&TraceEventAnalyzerTest::OnTraceDataCollected, | 32 base::Bind(&TraceEventAnalyzerTest::OnTraceDataCollected, |
32 base::Unretained(this))); | 33 base::Unretained(this))); |
33 buffer_.SetOutputCallback(output_.GetCallback()); | 34 buffer_.SetOutputCallback(output_.GetCallback()); |
34 output_.json_output.clear(); | 35 output_.json_output.clear(); |
35 } | 36 } |
36 | 37 |
37 void TraceEventAnalyzerTest::OnTraceDataCollected( | 38 void TraceEventAnalyzerTest::OnTraceDataCollected( |
38 scoped_refptr<base::debug::TraceLog::RefCountedString> json_events_str) { | 39 const scoped_refptr<base::debug::TraceLog::RefCountedString>& |
| 40 json_events_str) { |
39 buffer_.AddFragment(json_events_str->data); | 41 buffer_.AddFragment(json_events_str->data); |
40 } | 42 } |
41 | 43 |
42 void TraceEventAnalyzerTest::BeginTracing() { | 44 void TraceEventAnalyzerTest::BeginTracing() { |
43 output_.json_output.clear(); | 45 output_.json_output.clear(); |
44 buffer_.Start(); | 46 buffer_.Start(); |
45 base::debug::TraceLog::GetInstance()->SetEnabled(true); | 47 base::debug::TraceLog::GetInstance()->SetEnabled(true); |
46 } | 48 } |
47 | 49 |
48 void TraceEventAnalyzerTest::EndTracing() { | 50 void TraceEventAnalyzerTest::EndTracing() { |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); | 753 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); |
752 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), | 754 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), |
753 1, num_events)); | 755 1, num_events)); |
754 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); | 756 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); |
755 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); | 757 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); |
756 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); | 758 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); |
757 } | 759 } |
758 | 760 |
759 | 761 |
760 } // namespace trace_analyzer | 762 } // namespace trace_analyzer |
761 | |
OLD | NEW |