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/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 const scoped_refptr<base::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 const scoped_refptr<base::RefCountedString>& json_events_str) { | 39 const scoped_refptr<base::debug::TraceLog::RefCountedString>& |
39 buffer_.AddFragment(json_events_str->data()); | 40 json_events_str) { |
| 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() { |
49 base::debug::TraceLog::GetInstance()->SetEnabled(false); | 51 base::debug::TraceLog::GetInstance()->SetEnabled(false); |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); | 735 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); |
734 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), | 736 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), |
735 1, num_events)); | 737 1, num_events)); |
736 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); | 738 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); |
737 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); | 739 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); |
738 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); | 740 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); |
739 } | 741 } |
740 | 742 |
741 | 743 |
742 } // namespace trace_analyzer | 744 } // namespace trace_analyzer |
OLD | NEW |