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 "chrome/test/base/tracing.h" | 5 #include "chrome/test/base/tracing.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "base/trace_event/memory_dump_manager.h" | 12 #include "base/trace_event/memory_dump_manager.h" |
13 #include "base/trace_event/trace_config_memory_test_util.h" | 13 #include "base/trace_event/trace_config_memory_test_util.h" |
14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
22 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 using base::trace_event::MemoryDumpManager; | 27 using base::trace_event::MemoryDumpManager; |
28 using base::trace_event::MemoryDumpType; | 28 using base::trace_event::MemoryDumpType; |
29 using tracing::BeginTracingWithTraceConfig; | 29 using tracing::BeginTracingWithTraceConfig; |
30 using tracing::BeginTracingWithWatch; | |
31 using tracing::WaitForWatchEvent; | |
32 using tracing::EndTracing; | 30 using tracing::EndTracing; |
33 | 31 |
34 const char g_category[] = "test_tracing"; | 32 const char g_category[] = "test_tracing"; |
35 const char g_event[] = "TheEvent"; | 33 const char g_event[] = "TheEvent"; |
36 | 34 |
37 class TracingBrowserTest : public InProcessBrowserTest { | 35 class TracingBrowserTest : public InProcessBrowserTest { |
38 protected: | 36 protected: |
39 // Execute some no-op javascript on the current tab - this triggers a trace | 37 // Execute some no-op javascript on the current tab - this triggers a trace |
40 // event in RenderFrameImpl::OnJavaScriptExecuteRequestForTests (from the | 38 // event in RenderFrameImpl::OnJavaScriptExecuteRequestForTests (from the |
41 // renderer process). | 39 // renderer process). |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 EXPECT_NE(std::string::npos, json_events.find("v8")); | 81 EXPECT_NE(std::string::npos, json_events.find("v8")); |
84 EXPECT_NE(std::string::npos, json_events.find("blink_gc")); | 82 EXPECT_NE(std::string::npos, json_events.find("blink_gc")); |
85 } | 83 } |
86 }; | 84 }; |
87 | 85 |
88 void AddEvents(int num) { | 86 void AddEvents(int num) { |
89 for (int i = 0; i < num; ++i) | 87 for (int i = 0; i < num; ++i) |
90 TRACE_EVENT_INSTANT0(g_category, g_event, TRACE_EVENT_SCOPE_THREAD); | 88 TRACE_EVENT_INSTANT0(g_category, g_event, TRACE_EVENT_SCOPE_THREAD); |
91 } | 89 } |
92 | 90 |
93 IN_PROC_BROWSER_TEST_F(TracingBrowserTest, BeginTracingWithWatch) { | |
94 base::TimeDelta no_timeout; | |
95 base::TimeDelta short_timeout = base::TimeDelta::FromMilliseconds(5); | |
96 std::string json_events; | |
97 | |
98 // One event before wait. | |
99 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 1)); | |
100 AddEvents(1); | |
101 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); | |
102 ASSERT_TRUE(EndTracing(&json_events)); | |
103 | |
104 // One event after wait. | |
105 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 1)); | |
106 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | |
107 base::Bind(&AddEvents, 1)); | |
108 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); | |
109 ASSERT_TRUE(EndTracing(&json_events)); | |
110 | |
111 // Not enough events timeout. | |
112 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 2)); | |
113 AddEvents(1); | |
114 EXPECT_FALSE(WaitForWatchEvent(short_timeout)); | |
115 ASSERT_TRUE(EndTracing(&json_events)); | |
116 | |
117 // Multi event before wait. | |
118 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 5)); | |
119 AddEvents(5); | |
120 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); | |
121 ASSERT_TRUE(EndTracing(&json_events)); | |
122 | |
123 // Multi event after wait. | |
124 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, g_event, 5)); | |
125 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | |
126 base::Bind(&AddEvents, 5)); | |
127 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); | |
128 ASSERT_TRUE(EndTracing(&json_events)); | |
129 | |
130 // Child process events from same process. | |
131 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, | |
132 "OnJavaScriptExecuteRequestForTests", 2)); | |
133 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); | |
134 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); | |
135 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); | |
136 ASSERT_TRUE(EndTracing(&json_events)); | |
137 | |
138 // Child process events from different processes. | |
139 GURL url1("chrome://tracing/"); | |
140 GURL url2("chrome://credits/"); | |
141 ASSERT_TRUE(BeginTracingWithWatch(g_category, g_category, | |
142 "OnJavaScriptExecuteRequestForTests", 2)); | |
143 // Open two tabs to different URLs to encourage two separate renderer | |
144 // processes. Each will fire an event that will be counted towards the total. | |
145 ui_test_utils::NavigateToURLWithDisposition( | |
146 browser(), url1, WindowOpenDisposition::NEW_FOREGROUND_TAB, | |
147 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
148 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); | |
149 ui_test_utils::NavigateToURLWithDisposition( | |
150 browser(), url2, WindowOpenDisposition::NEW_FOREGROUND_TAB, | |
151 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
152 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); | |
153 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); | |
154 ASSERT_TRUE(EndTracing(&json_events)); | |
155 } | |
156 | |
157 IN_PROC_BROWSER_TEST_F(TracingBrowserTest, TestMemoryInfra) { | 91 IN_PROC_BROWSER_TEST_F(TracingBrowserTest, TestMemoryInfra) { |
158 PerformDumpMemoryTestActions(base::trace_event::TraceConfig( | 92 PerformDumpMemoryTestActions(base::trace_event::TraceConfig( |
159 base::trace_event::TraceConfigMemoryTestUtil:: | 93 base::trace_event::TraceConfigMemoryTestUtil:: |
160 GetTraceConfig_PeriodicTriggers(250, 2000))); | 94 GetTraceConfig_PeriodicTriggers(250, 2000))); |
161 } | 95 } |
162 | 96 |
163 IN_PROC_BROWSER_TEST_F(TracingBrowserTest, TestBackgroundMemoryInfra) { | 97 IN_PROC_BROWSER_TEST_F(TracingBrowserTest, TestBackgroundMemoryInfra) { |
164 PerformDumpMemoryTestActions(base::trace_event::TraceConfig( | 98 PerformDumpMemoryTestActions(base::trace_event::TraceConfig( |
165 base::trace_event::TraceConfigMemoryTestUtil:: | 99 base::trace_event::TraceConfigMemoryTestUtil:: |
166 GetTraceConfig_BackgroundTrigger(200))); | 100 GetTraceConfig_BackgroundTrigger(200))); |
167 } | 101 } |
168 | 102 |
169 } // namespace | 103 } // namespace |
OLD | NEW |