| 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/trace_event/memory_dump_manager.h" | 5 #include "base/trace_event/memory_dump_manager.h" |
| 6 | 6 |
| 7 #include "base/trace_event/memory_dump_provider.h" | 7 #include "base/trace_event/memory_dump_provider.h" |
| 8 #include "base/trace_event/process_memory_dump.h" | 8 #include "base/trace_event/process_memory_dump.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 using testing::_; | 12 using testing::_; |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 namespace trace_event { | 15 namespace trace_event { |
| 16 | 16 |
| 17 class MemoryDumpManagerTest : public testing::Test { | 17 class MemoryDumpManagerTest : public testing::Test { |
| 18 public: | 18 public: |
| 19 void SetUp() override { | 19 void SetUp() override { |
| 20 mdm_.reset(new MemoryDumpManager()); | |
| 21 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); | |
| 22 ASSERT_EQ(mdm_, MemoryDumpManager::GetInstance()); | |
| 23 MemoryDumpManager::GetInstance()->Initialize(); | 20 MemoryDumpManager::GetInstance()->Initialize(); |
| 21 mdm_ = MemoryDumpManager::GetInstance(); |
| 24 } | 22 } |
| 25 | 23 |
| 26 void TearDown() override { | 24 void TearDown() override { |
| 27 MemoryDumpManager::SetInstanceForTesting(nullptr); | 25 MemoryDumpManager::DeleteForTesting(); |
| 28 mdm_.reset(); | |
| 29 TraceLog::DeleteForTesting(); | 26 TraceLog::DeleteForTesting(); |
| 27 mdm_ = NULL; |
| 30 } | 28 } |
| 31 | 29 |
| 32 protected: | 30 protected: |
| 33 const char* const kTraceCategory = MemoryDumpManager::kTraceCategory; | 31 const char* const kTraceCategory = MemoryDumpManager::kTraceCategory; |
| 34 | 32 |
| 35 void EnableTracing(const char* category) { | 33 void EnableTracing(const char* category) { |
| 36 TraceLog::GetInstance()->SetEnabled( | 34 TraceLog::GetInstance()->SetEnabled( |
| 37 CategoryFilter(category), TraceLog::RECORDING_MODE, TraceOptions()); | 35 CategoryFilter(category), TraceLog::RECORDING_MODE, TraceOptions()); |
| 38 } | 36 } |
| 39 | 37 |
| 40 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } | 38 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } |
| 41 | 39 |
| 42 scoped_ptr<MemoryDumpManager> mdm_; | 40 MemoryDumpManager* mdm_; |
| 43 | 41 |
| 44 private: | 42 private: |
| 45 // We want our singleton torn down after each test. | 43 // We want our singleton torn down after each test. |
| 46 ShadowingAtExitManager at_exit_manager_; | 44 ShadowingAtExitManager at_exit_manager_; |
| 47 }; | 45 }; |
| 48 | 46 |
| 49 class MockDumpProvider : public MemoryDumpProvider { | 47 class MockDumpProvider : public MemoryDumpProvider { |
| 50 public: | 48 public: |
| 51 MOCK_METHOD1(DumpInto, void(ProcessMemoryDump* pmd)); | 49 MOCK_METHOD1(DumpInto, void(ProcessMemoryDump* pmd)); |
| 52 }; | 50 }; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 mdm_->RegisterDumpProvider(&mdp1); | 116 mdm_->RegisterDumpProvider(&mdp1); |
| 119 EnableTracing(kTraceCategory); | 117 EnableTracing(kTraceCategory); |
| 120 EXPECT_CALL(mdp1, DumpInto(_)).Times(1); | 118 EXPECT_CALL(mdp1, DumpInto(_)).Times(1); |
| 121 EXPECT_CALL(mdp2, DumpInto(_)).Times(1); | 119 EXPECT_CALL(mdp2, DumpInto(_)).Times(1); |
| 122 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED); | 120 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED); |
| 123 DisableTracing(); | 121 DisableTracing(); |
| 124 } | 122 } |
| 125 | 123 |
| 126 } // namespace trace_Event | 124 } // namespace trace_Event |
| 127 } // namespace base | 125 } // namespace base |
| OLD | NEW |