| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "base/trace_event/memory_dump_manager.h" | 9 #include "base/trace_event/memory_dump_manager.h" |
| 10 #include "base/trace_event/memory_dump_provider.h" | 10 #include "base/trace_event/memory_dump_provider.h" |
| 11 #include "base/trace_event/memory_dump_request_args.h" | 11 #include "base/trace_event/memory_dump_request_args.h" |
| 12 #include "base/trace_event/trace_config_memory_test_util.h" |
| 12 #include "content/public/browser/tracing_controller.h" | 13 #include "content/public/browser/tracing_controller.h" |
| 13 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 14 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
| 15 #include "content/public/test/content_browser_test.h" | 16 #include "content/public/test/content_browser_test.h" |
| 16 #include "content/public/test/content_browser_test_utils.h" | 17 #include "content/public/test/content_browser_test_utils.h" |
| 17 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 19 | 20 |
| 20 using base::trace_event::MemoryDumpArgs; | 21 using base::trace_event::MemoryDumpArgs; |
| 21 using base::trace_event::MemoryDumpManager; | 22 using base::trace_event::MemoryDumpManager; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 last_callback_success_ = success; | 63 last_callback_success_ = success; |
| 63 closure.Run(); | 64 closure.Run(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 protected: | 67 protected: |
| 67 void SetUp() override { | 68 void SetUp() override { |
| 68 callback_call_count_ = 0; | 69 callback_call_count_ = 0; |
| 69 last_callback_dump_guid_ = 0; | 70 last_callback_dump_guid_ = 0; |
| 70 last_callback_success_ = false; | 71 last_callback_success_ = false; |
| 71 | 72 |
| 72 // TODO(primiano): This should be done via TraceConfig. | |
| 73 // See https://goo.gl/5Hj3o0. | |
| 74 MemoryDumpManager::GetInstance()->DisablePeriodicDumpsForTesting(); | |
| 75 | |
| 76 mock_dump_provider_.reset(new MockDumpProvider()); | 73 mock_dump_provider_.reset(new MockDumpProvider()); |
| 77 MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 74 MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 78 mock_dump_provider_.get()); | 75 mock_dump_provider_.get()); |
| 79 ContentBrowserTest::SetUp(); | 76 ContentBrowserTest::SetUp(); |
| 80 } | 77 } |
| 81 | 78 |
| 82 void TearDown() override { | 79 void TearDown() override { |
| 83 MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 80 MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 84 mock_dump_provider_.get()); | 81 mock_dump_provider_.get()); |
| 85 mock_dump_provider_.reset(); | 82 mock_dump_provider_.reset(); |
| 86 ContentBrowserTest::TearDown(); | 83 ContentBrowserTest::TearDown(); |
| 87 } | 84 } |
| 88 | 85 |
| 89 void EnableMemoryTracing() { | 86 void EnableMemoryTracing() { |
| 87 // Enable tracing without periodic dumps. |
| 88 base::trace_event::TraceConfig trace_config( |
| 89 base::trace_event::TraceConfigMemoryTestUtil:: |
| 90 GetTraceConfig_EmptyTriggers()); |
| 91 |
| 90 base::RunLoop run_loop; | 92 base::RunLoop run_loop; |
| 91 std::string category_filter = MemoryDumpManager::kTraceCategory; | |
| 92 base::trace_event::TraceConfig trace_config(category_filter, ""); | |
| 93 bool success = TracingController::GetInstance()->EnableRecording( | 93 bool success = TracingController::GetInstance()->EnableRecording( |
| 94 trace_config, run_loop.QuitClosure()); | 94 trace_config, run_loop.QuitClosure()); |
| 95 EXPECT_TRUE(success); | 95 EXPECT_TRUE(success); |
| 96 run_loop.Run(); | 96 run_loop.Run(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void DisableTracing() { | 99 void DisableTracing() { |
| 100 bool success = TracingController::GetInstance()->DisableRecording(NULL); | 100 bool success = TracingController::GetInstance()->DisableRecording(NULL); |
| 101 EXPECT_TRUE(success); | 101 EXPECT_TRUE(success); |
| 102 base::RunLoop().RunUntilIdle(); | 102 base::RunLoop().RunUntilIdle(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 EnableMemoryTracing(); | 214 EnableMemoryTracing(); |
| 215 RequestGlobalDumpAndWait(false /* from_renderer_thread */); | 215 RequestGlobalDumpAndWait(false /* from_renderer_thread */); |
| 216 EXPECT_EQ(1u, callback_call_count_); | 216 EXPECT_EQ(1u, callback_call_count_); |
| 217 EXPECT_NE(0u, last_callback_dump_guid_); | 217 EXPECT_NE(0u, last_callback_dump_guid_); |
| 218 EXPECT_TRUE(last_callback_success_); | 218 EXPECT_TRUE(last_callback_success_); |
| 219 DisableTracing(); | 219 DisableTracing(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 } // namespace content | 222 } // namespace content |
| OLD | NEW |