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

Side by Side Diff: base/test/trace_event_analyzer_unittest.cc

Issue 10837082: implement SetWatchEvent and WaitForEvent for trace-based-tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleaned up and fixed a bug Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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::RefCountedString>& json_events_str);
19 void BeginTracing(); 19 void BeginTracing();
20 void EndTracing(); 20 void EndTracing();
21 21
22 base::debug::TraceResultBuffer::SimpleOutput output_; 22 base::debug::TraceResultBuffer::SimpleOutput output_;
23 base::debug::TraceResultBuffer buffer_; 23 base::debug::TraceResultBuffer buffer_;
24 }; 24 };
25 25
26 void TraceEventAnalyzerTest::ManualSetUp() { 26 void TraceEventAnalyzerTest::ManualSetUp() {
27 base::debug::TraceLog::Resurrect(); 27 base::debug::TraceLog::Resurrect();
28 base::debug::TraceLog* tracelog = base::debug::TraceLog::GetInstance(); 28 ASSERT_TRUE(base::debug::TraceLog::GetInstance());
29 ASSERT_TRUE(tracelog);
30 tracelog->SetOutputCallback(
31 base::Bind(&TraceEventAnalyzerTest::OnTraceDataCollected,
32 base::Unretained(this)));
33 buffer_.SetOutputCallback(output_.GetCallback()); 29 buffer_.SetOutputCallback(output_.GetCallback());
34 output_.json_output.clear(); 30 output_.json_output.clear();
35 } 31 }
36 32
37 void TraceEventAnalyzerTest::OnTraceDataCollected( 33 void TraceEventAnalyzerTest::OnTraceDataCollected(
38 const scoped_refptr<base::RefCountedString>& json_events_str) { 34 const scoped_refptr<base::RefCountedString>& json_events_str) {
39 buffer_.AddFragment(json_events_str->data()); 35 buffer_.AddFragment(json_events_str->data());
40 } 36 }
41 37
42 void TraceEventAnalyzerTest::BeginTracing() { 38 void TraceEventAnalyzerTest::BeginTracing() {
43 output_.json_output.clear(); 39 output_.json_output.clear();
44 buffer_.Start(); 40 buffer_.Start();
45 base::debug::TraceLog::GetInstance()->SetEnabled(true); 41 base::debug::TraceLog::GetInstance()->SetEnabled(true);
46 } 42 }
47 43
48 void TraceEventAnalyzerTest::EndTracing() { 44 void TraceEventAnalyzerTest::EndTracing() {
49 base::debug::TraceLog::GetInstance()->SetEnabled(false); 45 base::debug::TraceLog::GetInstance()->SetEnabled(false);
46 base::debug::TraceLog::GetInstance()->Flush(
47 base::Bind(&TraceEventAnalyzerTest::OnTraceDataCollected,
48 base::Unretained(this)));
50 buffer_.Finish(); 49 buffer_.Finish();
51 } 50 }
52 51
53 } // namespace 52 } // namespace
54 53
55 TEST_F(TraceEventAnalyzerTest, NoEvents) { 54 TEST_F(TraceEventAnalyzerTest, NoEvents) {
56 ManualSetUp(); 55 ManualSetUp();
57 56
58 // Create an empty JSON event string: 57 // Create an empty JSON event string:
59 buffer_.Start(); 58 buffer_.Start();
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); 817 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true)));
819 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), 818 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true),
820 1, num_events)); 819 1, num_events));
821 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); 820 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one));
822 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); 821 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one));
823 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); 822 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named));
824 } 823 }
825 824
826 825
827 } // namespace trace_analyzer 826 } // namespace trace_analyzer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698