| 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::debug::TraceLog::RefCountedString>& | 18 const scoped_refptr<base::RefCountedString>& json_events_str); |
| 19 json_events_str); | |
| 20 void BeginTracing(); | 19 void BeginTracing(); |
| 21 void EndTracing(); | 20 void EndTracing(); |
| 22 | 21 |
| 23 base::debug::TraceResultBuffer::SimpleOutput output_; | 22 base::debug::TraceResultBuffer::SimpleOutput output_; |
| 24 base::debug::TraceResultBuffer buffer_; | 23 base::debug::TraceResultBuffer buffer_; |
| 25 }; | 24 }; |
| 26 | 25 |
| 27 void TraceEventAnalyzerTest::ManualSetUp() { | 26 void TraceEventAnalyzerTest::ManualSetUp() { |
| 28 base::debug::TraceLog::Resurrect(); | 27 base::debug::TraceLog::Resurrect(); |
| 29 base::debug::TraceLog* tracelog = base::debug::TraceLog::GetInstance(); | 28 base::debug::TraceLog* tracelog = base::debug::TraceLog::GetInstance(); |
| 30 ASSERT_TRUE(tracelog); | 29 ASSERT_TRUE(tracelog); |
| 31 tracelog->SetOutputCallback( | 30 tracelog->SetOutputCallback( |
| 32 base::Bind(&TraceEventAnalyzerTest::OnTraceDataCollected, | 31 base::Bind(&TraceEventAnalyzerTest::OnTraceDataCollected, |
| 33 base::Unretained(this))); | 32 base::Unretained(this))); |
| 34 buffer_.SetOutputCallback(output_.GetCallback()); | 33 buffer_.SetOutputCallback(output_.GetCallback()); |
| 35 output_.json_output.clear(); | 34 output_.json_output.clear(); |
| 36 } | 35 } |
| 37 | 36 |
| 38 void TraceEventAnalyzerTest::OnTraceDataCollected( | 37 void TraceEventAnalyzerTest::OnTraceDataCollected( |
| 39 const scoped_refptr<base::debug::TraceLog::RefCountedString>& | 38 const scoped_refptr<base::RefCountedString>& json_events_str) { |
| 40 json_events_str) { | 39 buffer_.AddFragment(json_events_str->data()); |
| 41 buffer_.AddFragment(json_events_str->data); | |
| 42 } | 40 } |
| 43 | 41 |
| 44 void TraceEventAnalyzerTest::BeginTracing() { | 42 void TraceEventAnalyzerTest::BeginTracing() { |
| 45 output_.json_output.clear(); | 43 output_.json_output.clear(); |
| 46 buffer_.Start(); | 44 buffer_.Start(); |
| 47 base::debug::TraceLog::GetInstance()->SetEnabled(true); | 45 base::debug::TraceLog::GetInstance()->SetEnabled(true); |
| 48 } | 46 } |
| 49 | 47 |
| 50 void TraceEventAnalyzerTest::EndTracing() { | 48 void TraceEventAnalyzerTest::EndTracing() { |
| 51 base::debug::TraceLog::GetInstance()->SetEnabled(false); | 49 base::debug::TraceLog::GetInstance()->SetEnabled(false); |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); | 733 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); |
| 736 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), | 734 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), |
| 737 1, num_events)); | 735 1, num_events)); |
| 738 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); | 736 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); |
| 739 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); | 737 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); |
| 740 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); | 738 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); |
| 741 } | 739 } |
| 742 | 740 |
| 743 | 741 |
| 744 } // namespace trace_analyzer | 742 } // namespace trace_analyzer |
| OLD | NEW |