Index: base/trace_event/memory_dump_manager_unittest.cc |
diff --git a/base/trace_event/memory_dump_manager_unittest.cc b/base/trace_event/memory_dump_manager_unittest.cc |
index c1295efac653e66ad9ee6c50c80183f792ed3dd6..4815f6835b969cbc7dad1687e2b030f330b28543 100644 |
--- a/base/trace_event/memory_dump_manager_unittest.cc |
+++ b/base/trace_event/memory_dump_manager_unittest.cc |
@@ -48,16 +48,24 @@ MATCHER(IsLightDump, "") { |
return arg.level_of_detail == MemoryDumpLevelOfDetail::LIGHT; |
} |
+MATCHER(IsBackgroundDump, "") { |
+ return arg.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND; |
+} |
+ |
namespace { |
+const char* kMDPName = "TestDumpProvider"; |
+const char* kWhitelistedMDPName = "WhitelistedTestDumpProvider"; |
+const char* const kTestMDPWhitelist[] = {kWhitelistedMDPName, nullptr}; |
+ |
void RegisterDumpProvider( |
MemoryDumpProvider* mdp, |
scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
- const MemoryDumpProvider::Options& options) { |
+ const MemoryDumpProvider::Options& options, |
+ const char* name = kMDPName) { |
MemoryDumpManager* mdm = MemoryDumpManager::GetInstance(); |
mdm->set_dumper_registrations_ignored_for_testing(false); |
- const char* kMDPName = "TestDumpProvider"; |
- mdm->RegisterDumpProvider(mdp, kMDPName, std::move(task_runner), options); |
+ mdm->RegisterDumpProvider(mdp, name, std::move(task_runner), options); |
mdm->set_dumper_registrations_ignored_for_testing(true); |
} |
@@ -71,7 +79,6 @@ void RegisterDumpProviderWithSequencedTaskRunner( |
const MemoryDumpProvider::Options& options) { |
MemoryDumpManager* mdm = MemoryDumpManager::GetInstance(); |
mdm->set_dumper_registrations_ignored_for_testing(false); |
- const char* kMDPName = "TestDumpProvider"; |
mdm->RegisterDumpProviderWithSequencedTaskRunner(mdp, kMDPName, task_runner, |
options); |
mdm->set_dumper_registrations_ignored_for_testing(true); |
@@ -1099,5 +1106,48 @@ TEST_F(MemoryDumpManagerTest, UnregisterAndDeleteDumpProviderSoonDuringDump) { |
DisableTracing(); |
} |
+TEST_F(MemoryDumpManagerTest, TestWhitelistingMDP) { |
+ InitializeMemoryDumpManager(false /* is_coordinator */); |
+ mdm_->set_dump_provider_whitelist_for_testing(kTestMDPWhitelist); |
+ std::unique_ptr<MockMemoryDumpProvider> mdp1(new MockMemoryDumpProvider); |
+ RegisterDumpProvider(mdp1.get()); |
+ std::unique_ptr<MockMemoryDumpProvider> mdp2(new MockMemoryDumpProvider); |
+ RegisterDumpProvider(mdp2.get(), nullptr, kDefaultOptions, |
+ kWhitelistedMDPName); |
+ |
+ EXPECT_CALL(*mdp1, OnMemoryDump(_, _)).Times(0); |
+ EXPECT_CALL(*mdp2, OnMemoryDump(_, _)).Times(1).WillOnce(Return(true)); |
+ EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
+ |
+ EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
+ EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
+ RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
+ MemoryDumpLevelOfDetail::BACKGROUND); |
+ DisableTracing(); |
+} |
+ |
+TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) { |
+ InitializeMemoryDumpManager(true /* is_coordinator */); |
+ |
+ RunLoop run_loop; |
+ auto quit_closure = run_loop.QuitClosure(); |
+ |
+ testing::InSequence sequence; |
+ EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _)) |
+ .Times(5); |
+ EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _)) |
+ .WillOnce(Invoke([quit_closure](const MemoryDumpRequestArgs& args, |
+ const MemoryDumpCallback& callback) { |
+ ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure); |
+ })); |
+ EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(AnyNumber()); |
+ |
+ EnableTracingWithTraceConfig( |
+ TraceConfigMemoryTestUtil::GetTraceConfig_BackgroundTrigger()); |
+ ASSERT_TRUE(IsPeriodicDumpingEnabled()); |
+ run_loop.Run(); |
+ DisableTracing(); |
+} |
+ |
} // namespace trace_event |
} // namespace base |