| 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_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 21 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 using base::trace_event::MemoryDumpManager; | 27 using base::trace_event::MemoryDumpManager; |
| 27 using base::trace_event::MemoryDumpType; | 28 using base::trace_event::MemoryDumpType; |
| 29 using tracing::BeginTracing; |
| 28 using tracing::BeginTracingWithWatch; | 30 using tracing::BeginTracingWithWatch; |
| 29 using tracing::WaitForWatchEvent; | 31 using tracing::WaitForWatchEvent; |
| 30 using tracing::EndTracing; | 32 using tracing::EndTracing; |
| 31 | 33 |
| 32 const char g_category[] = "test_tracing"; | 34 const char g_category[] = "test_tracing"; |
| 33 const char g_event[] = "TheEvent"; | 35 const char g_event[] = "TheEvent"; |
| 34 | 36 |
| 35 class TracingBrowserTest : public InProcessBrowserTest { | 37 class TracingBrowserTest : public InProcessBrowserTest { |
| 36 protected: | 38 protected: |
| 37 // Execute some no-op javascript on the current tab - this triggers a trace | 39 // Execute some no-op javascript on the current tab - this triggers a trace |
| 38 // event in RenderFrameImpl::OnJavaScriptExecuteRequestForTests (from the | 40 // event in RenderFrameImpl::OnJavaScriptExecuteRequestForTests (from the |
| 39 // renderer process). | 41 // renderer process). |
| 40 void ExecuteJavascriptOnCurrentTab() { | 42 void ExecuteJavascriptOnCurrentTab() { |
| 41 content::RenderViewHost* rvh = browser()->tab_strip_model()-> | 43 content::RenderViewHost* rvh = browser()->tab_strip_model()-> |
| 42 GetActiveWebContents()->GetRenderViewHost(); | 44 GetActiveWebContents()->GetRenderViewHost(); |
| 43 ASSERT_TRUE(rvh); | 45 ASSERT_TRUE(rvh); |
| 44 ASSERT_TRUE(content::ExecuteScript(rvh, ";")); | 46 ASSERT_TRUE(content::ExecuteScript(rvh, ";")); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void PerformDumpMemoryTestActions() { | 49 void PerformDumpMemoryTestActions( |
| 50 const base::trace_event::TraceConfig& trace_config) { |
| 48 std::string json_events; | 51 std::string json_events; |
| 49 base::TimeDelta no_timeout; | 52 base::TimeDelta no_timeout; |
| 50 | 53 |
| 51 GURL url1("about:blank"); | 54 GURL url1("about:blank"); |
| 52 ui_test_utils::NavigateToURLWithDisposition( | 55 ui_test_utils::NavigateToURLWithDisposition( |
| 53 browser(), url1, NEW_FOREGROUND_TAB, | 56 browser(), url1, NEW_FOREGROUND_TAB, |
| 54 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 57 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 55 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); | 58 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); |
| 56 | 59 |
| 57 // Begin tracing and watch for multiple periodic dump trace events. | 60 // Begin tracing and watch for multiple periodic dump trace events. |
| 58 std::string event_name = base::trace_event::MemoryDumpTypeToString( | 61 std::string event_name = base::trace_event::MemoryDumpTypeToString( |
| 59 MemoryDumpType::PERIODIC_INTERVAL); | 62 MemoryDumpType::PERIODIC_INTERVAL); |
| 60 ASSERT_TRUE(BeginTracingWithWatch(MemoryDumpManager::kTraceCategory, | 63 ASSERT_TRUE(BeginTracing(trace_config)); |
| 61 MemoryDumpManager::kTraceCategory, | |
| 62 event_name, 10)); | |
| 63 | 64 |
| 64 // Create and destroy renderers while tracing is enabled. | 65 // Create and destroy renderers while tracing is enabled. |
| 65 GURL url2("chrome://credits"); | 66 GURL url2("chrome://credits"); |
| 66 ui_test_utils::NavigateToURLWithDisposition( | 67 ui_test_utils::NavigateToURLWithDisposition( |
| 67 browser(), url2, NEW_FOREGROUND_TAB, | 68 browser(), url2, NEW_FOREGROUND_TAB, |
| 68 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 69 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 69 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); | 70 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); |
| 70 | 71 |
| 71 // Close the current tab. | 72 // Close the current tab. |
| 72 browser()->tab_strip_model()->CloseSelectedTabs(); | 73 browser()->tab_strip_model()->CloseSelectedTabs(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); | 159 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); |
| 159 ui_test_utils::NavigateToURLWithDisposition(browser(), url2, | 160 ui_test_utils::NavigateToURLWithDisposition(browser(), url2, |
| 160 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 161 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 161 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); | 162 ASSERT_NO_FATAL_FAILURE(ExecuteJavascriptOnCurrentTab()); |
| 162 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); | 163 EXPECT_TRUE(WaitForWatchEvent(no_timeout)); |
| 163 ASSERT_TRUE(EndTracing(&json_events)); | 164 ASSERT_TRUE(EndTracing(&json_events)); |
| 164 } | 165 } |
| 165 | 166 |
| 166 // Multi-process mode. | 167 // Multi-process mode. |
| 167 IN_PROC_BROWSER_TEST_F(TracingBrowserTest, TestMemoryInfra) { | 168 IN_PROC_BROWSER_TEST_F(TracingBrowserTest, TestMemoryInfra) { |
| 168 PerformDumpMemoryTestActions(); | 169 PerformDumpMemoryTestActions(base::trace_event::TraceConfig( |
| 170 base::trace_event::TraceConfigMemoryTestUtil:: |
| 171 GetTraceConfig_PeriodicTriggers(250, 2000))); |
| 169 } | 172 } |
| 170 | 173 |
| 171 // Single-process mode. | 174 // Single-process mode. |
| 172 // Linux ASan: https://crbug.com/585026. | 175 // Linux ASan: https://crbug.com/585026. |
| 173 #if defined(ADDRESS_SANITIZER) | 176 #if defined(ADDRESS_SANITIZER) |
| 174 #define MAYBE_TestMemoryInfra DISABLED_TestMemoryInfra | 177 #define MAYBE_TestMemoryInfra DISABLED_TestMemoryInfra |
| 175 #else | 178 #else |
| 176 #define MAYBE_TestMemoryInfra TestMemoryInfra | 179 #define MAYBE_TestMemoryInfra TestMemoryInfra |
| 177 #endif | 180 #endif |
| 178 IN_PROC_BROWSER_TEST_F(SingleProcessTracingBrowserTest, MAYBE_TestMemoryInfra) { | 181 IN_PROC_BROWSER_TEST_F(SingleProcessTracingBrowserTest, MAYBE_TestMemoryInfra) { |
| 179 PerformDumpMemoryTestActions(); | 182 PerformDumpMemoryTestActions(base::trace_event::TraceConfig( |
| 183 base::trace_event::TraceConfigMemoryTestUtil:: |
| 184 GetTraceConfig_PeriodicTriggers(250, 2000))); |
| 185 } |
| 186 |
| 187 IN_PROC_BROWSER_TEST_F(TracingBrowserTest, TestBackgroundMemoryInfra) { |
| 188 PerformDumpMemoryTestActions(base::trace_event::TraceConfig( |
| 189 base::trace_event::TraceConfigMemoryTestUtil:: |
| 190 GetTraceConfig_BackgroundTrigger(200))); |
| 191 } |
| 192 |
| 193 IN_PROC_BROWSER_TEST_F(SingleProcessTracingBrowserTest, |
| 194 TestBackgroundMemoryInfra) { |
| 195 PerformDumpMemoryTestActions(base::trace_event::TraceConfig( |
| 196 base::trace_event::TraceConfigMemoryTestUtil:: |
| 197 GetTraceConfig_BackgroundTrigger(200))); |
| 180 } | 198 } |
| 181 | 199 |
| 182 } // namespace | 200 } // namespace |
| OLD | NEW |