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 using testing::Invoke; |
13 using testing::Return; | 14 using testing::Return; |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 namespace trace_event { | 17 namespace trace_event { |
17 | 18 |
18 class MemoryDumpManagerTest : public testing::Test { | 19 class MemoryDumpManagerTest : public testing::Test { |
19 public: | 20 public: |
20 void SetUp() override { | 21 void SetUp() override { |
21 mdm_.reset(new MemoryDumpManager()); | 22 mdm_.reset(new MemoryDumpManager()); |
22 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); | 23 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); |
(...skipping 21 matching lines...) Expand all Loading... |
44 | 45 |
45 private: | 46 private: |
46 // We want our singleton torn down after each test. | 47 // We want our singleton torn down after each test. |
47 ShadowingAtExitManager at_exit_manager_; | 48 ShadowingAtExitManager at_exit_manager_; |
48 }; | 49 }; |
49 | 50 |
50 class MockDumpProvider : public MemoryDumpProvider { | 51 class MockDumpProvider : public MemoryDumpProvider { |
51 public: | 52 public: |
52 MOCK_METHOD1(DumpInto, bool(ProcessMemoryDump* pmd)); | 53 MOCK_METHOD1(DumpInto, bool(ProcessMemoryDump* pmd)); |
53 | 54 |
| 55 // DumpInto() override for the ActiveDumpProviderConsistency test, |
| 56 bool DumpIntoAndCheckDumpProviderCurrentlyActive(ProcessMemoryDump* pmd) { |
| 57 EXPECT_EQ( |
| 58 this, |
| 59 MemoryDumpManager::GetInstance()->dump_provider_currently_active()); |
| 60 return true; |
| 61 } |
| 62 |
54 const char* GetFriendlyName() const override { return "MockDumpProvider"; } | 63 const char* GetFriendlyName() const override { return "MockDumpProvider"; } |
55 }; | 64 }; |
56 | 65 |
57 TEST_F(MemoryDumpManagerTest, SingleDumper) { | 66 TEST_F(MemoryDumpManagerTest, SingleDumper) { |
58 MockDumpProvider mdp; | 67 MockDumpProvider mdp; |
59 mdm_->RegisterDumpProvider(&mdp); | 68 mdm_->RegisterDumpProvider(&mdp); |
60 | 69 |
61 // Check that the dumper is not called if the memory category is not enabled. | 70 // Check that the dumper is not called if the memory category is not enabled. |
62 EnableTracing("foo-and-bar-but-not-memory"); | 71 EnableTracing("foo-and-bar-but-not-memory"); |
63 EXPECT_CALL(mdp, DumpInto(_)).Times(0); | 72 EXPECT_CALL(mdp, DumpInto(_)).Times(0); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 EXPECT_CALL(mdp2, DumpInto(_)).Times(1).WillRepeatedly(Return(true)); | 150 EXPECT_CALL(mdp2, DumpInto(_)).Times(1).WillRepeatedly(Return(true)); |
142 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED); | 151 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED); |
143 | 152 |
144 EXPECT_CALL(mdp1, DumpInto(_)).Times(0); | 153 EXPECT_CALL(mdp1, DumpInto(_)).Times(0); |
145 EXPECT_CALL(mdp2, DumpInto(_)).Times(1).WillRepeatedly(Return(false)); | 154 EXPECT_CALL(mdp2, DumpInto(_)).Times(1).WillRepeatedly(Return(false)); |
146 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED); | 155 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED); |
147 | 156 |
148 DisableTracing(); | 157 DisableTracing(); |
149 } | 158 } |
150 | 159 |
| 160 // TODO(primiano): remove once crbug.com/466121 gets fixed. |
| 161 // Ascertains that calls to MDM::dump_provider_currently_active() actually |
| 162 // returns the MemoryDumpProvider currently active during the DumpInto() call. |
| 163 TEST_F(MemoryDumpManagerTest, ActiveDumpProviderConsistency) { |
| 164 MockDumpProvider mdp1; |
| 165 MockDumpProvider mdp2; |
| 166 |
| 167 mdm_->RegisterDumpProvider(&mdp1); |
| 168 mdm_->RegisterDumpProvider(&mdp2); |
| 169 EnableTracing(kTraceCategory); |
| 170 EXPECT_CALL(mdp1, DumpInto(_)) |
| 171 .Times(2) |
| 172 .WillRepeatedly(Invoke( |
| 173 &mdp1, |
| 174 &MockDumpProvider::DumpIntoAndCheckDumpProviderCurrentlyActive)); |
| 175 EXPECT_CALL(mdp2, DumpInto(_)) |
| 176 .Times(2) |
| 177 .WillRepeatedly(Invoke( |
| 178 &mdp2, |
| 179 &MockDumpProvider::DumpIntoAndCheckDumpProviderCurrentlyActive)); |
| 180 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED); |
| 181 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED); |
| 182 DisableTracing(); |
| 183 } |
| 184 |
151 } // namespace trace_event | 185 } // namespace trace_event |
152 } // namespace base | 186 } // namespace base |
OLD | NEW |