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 6fb8c321e5bd978b50c6cf1468a684bd14e70ddd..c5913a8a660baeaccde6b2b9c534c7e622c696cd 100644 |
--- a/base/trace_event/memory_dump_manager_unittest.cc |
+++ b/base/trace_event/memory_dump_manager_unittest.cc |
@@ -52,8 +52,9 @@ class MemoryDumpManagerTest : public testing::Test { |
mdm_.reset(new MemoryDumpManager()); |
MemoryDumpManager::SetInstanceForTesting(mdm_.get()); |
ASSERT_EQ(mdm_, MemoryDumpManager::GetInstance()); |
- MemoryDumpManager::GetInstance()->Initialize(); |
- MemoryDumpManager::GetInstance()->SetDelegate(&delegate_); |
+ mdm_->set_ignore_registrations_for_testing(true); |
+ mdm_->Initialize(); |
+ mdm_->SetDelegate(&delegate_); |
} |
void TearDown() override { |
@@ -75,12 +76,23 @@ class MemoryDumpManagerTest : public testing::Test { |
const char* kTraceCategory = MemoryDumpManager::kTraceCategoryForTesting; |
void EnableTracing(const char* category) { |
+ bool registrations_ignored = mdm_->ignore_registrations_for_testing(); |
+ mdm_->set_ignore_registrations_for_testing(true); |
TraceLog::GetInstance()->SetEnabled( |
TraceConfig(category, ""), TraceLog::RECORDING_MODE); |
+ mdm_->set_ignore_registrations_for_testing(registrations_ignored); |
} |
void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } |
+ void EnableRegistrations() { |
Primiano Tucci (use gerrit)
2015/08/24 17:23:34
Nit: EnableMemoryDumpProviderRegistrations (Same b
Ruud van Asseldonk
2015/08/25 09:51:17
Done.
|
+ mdm_->set_ignore_registrations_for_testing(false); |
+ } |
+ |
+ void DisableRegistrations() { |
+ mdm_->set_ignore_registrations_for_testing(true); |
+ } |
+ |
scoped_ptr<MemoryDumpManager> mdm_; |
bool last_callback_success_; |
@@ -166,6 +178,7 @@ class MockDumpProvider : public MemoryDumpProvider { |
TEST_F(MemoryDumpManagerTest, SingleDumper) { |
MockDumpProvider mdp; |
+ EnableRegistrations(); |
mdm_->RegisterDumpProvider(&mdp); |
// Check that the dumper is not called if the memory category is not enabled. |
@@ -198,6 +211,7 @@ TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { |
// Check that requesting dumps with high level of detail actually propagates |
// to OnMemoryDump() call on dump providers. |
MockDumpProvider mdp_high_detail(MemoryDumpArgs::LevelOfDetail::HIGH); |
+ EnableRegistrations(); |
mdm_->RegisterDumpProvider(&mdp_high_detail); |
EnableTracing(kTraceCategory); |
@@ -231,6 +245,7 @@ TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { |
TEST_F(MemoryDumpManagerTest, SharedSessionState) { |
MockDumpProvider mdp1; |
MockDumpProvider mdp2; |
+ EnableRegistrations(); |
mdm_->RegisterDumpProvider(&mdp1); |
mdm_->RegisterDumpProvider(&mdp2); |
@@ -256,6 +271,7 @@ TEST_F(MemoryDumpManagerTest, MultipleDumpers) { |
MockDumpProvider mdp2; |
// Enable only mdp1. |
+ EnableRegistrations(); |
mdm_->RegisterDumpProvider(&mdp1); |
EnableTracing(kTraceCategory); |
EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
@@ -288,6 +304,7 @@ TEST_F(MemoryDumpManagerTest, MultipleDumpers) { |
// registration state and not on previous registrations and dumps. |
TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { |
MockDumpProvider mdp; |
+ EnableRegistrations(); |
mdm_->RegisterDumpProvider(&mdp); |
@@ -343,6 +360,8 @@ TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { |
ScopedVector<Thread> threads; |
ScopedVector<MockDumpProvider> mdps; |
+ EnableRegistrations(); |
+ |
// Create the threads and setup the expectations. Given that at each iteration |
// we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be |
// invoked a number of times equal to its index. |
@@ -360,6 +379,8 @@ TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { |
EnableTracing(kTraceCategory); |
+ DisableRegistrations(); |
+ |
while (!threads.empty()) { |
last_callback_success_ = false; |
{ |
@@ -401,6 +422,7 @@ TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { |
MockDumpProvider mdp1; |
MockDumpProvider mdp2; |
+ EnableRegistrations(); |
mdm_->RegisterDumpProvider(&mdp1); |
mdm_->RegisterDumpProvider(&mdp2); |
EnableTracing(kTraceCategory); |
@@ -428,6 +450,7 @@ TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { |
MockDumpProvider mdp1; |
MockDumpProvider mdp2; |
+ EnableRegistrations(); |
mdp1.dump_provider_to_register_or_unregister = &mdp2; |
mdm_->RegisterDumpProvider(&mdp1); |
EnableTracing(kTraceCategory); |
@@ -458,6 +481,7 @@ TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { |
MockDumpProvider mdp1; |
MockDumpProvider mdp2; |
+ EnableRegistrations(); |
mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); |
mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); |
mdp1.dump_provider_to_register_or_unregister = &mdp2; |
@@ -493,7 +517,9 @@ TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { |
for (int i = 0; i < 2; i++) { |
threads.push_back(new TestIOThread(TestIOThread::kAutoStart)); |
mdps.push_back(new MockDumpProvider(threads.back()->task_runner())); |
+ EnableRegistrations(); |
mdm_->RegisterDumpProvider(mdps.back(), threads.back()->task_runner()); |
+ DisableRegistrations(); |
} |
int on_memory_dump_call_count = 0; |
@@ -544,6 +570,7 @@ TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { |
TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { |
MockDumpProvider mdp1; |
+ EnableRegistrations(); |
mdm_->RegisterDumpProvider(&mdp1); |
EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |