Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1977)

Unified Diff: base/trace_event/memory_dump_manager_unittest.cc

Issue 2694083005: memory-infra: Finish moving memory_infra from TracingController (Closed)
Patch Set: review Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 e8c33af3e06b935a80911bf049ff3d6e8c3c4b01..30607ee61499ecca35043df75f49e54740d36724 100644
--- a/base/trace_event/memory_dump_manager_unittest.cc
+++ b/base/trace_event/memory_dump_manager_unittest.cc
@@ -118,7 +118,8 @@ void PostTaskAndWait(const tracked_objects::Location& from_here,
// requests locally to the MemoryDumpManager instead of performing IPC dances.
class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate {
public:
- MemoryDumpManagerDelegateForTesting() {
+ MemoryDumpManagerDelegateForTesting(bool is_coordinator)
+ : is_coordinator_(is_coordinator) {
ON_CALL(*this, RequestGlobalMemoryDump(_, _))
.WillByDefault(Invoke(
this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump));
@@ -128,13 +129,13 @@ class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate {
void(const MemoryDumpRequestArgs& args,
const MemoryDumpCallback& callback));
- uint64_t GetTracingProcessId() const override {
- NOTREACHED();
- return MemoryDumpManager::kInvalidTracingProcessId;
- }
+ bool IsCoordinator() const override { return is_coordinator_; }
// Promote the CreateProcessDump to public so it can be used by test fixtures.
using MemoryDumpManagerDelegate::CreateProcessDump;
+
+ private:
+ bool is_coordinator_;
};
class MockMemoryDumpProvider : public MemoryDumpProvider {
@@ -219,13 +220,13 @@ class MemoryDumpManagerTest : public testing::Test {
mdm_.reset(new MemoryDumpManager());
MemoryDumpManager::SetInstanceForTesting(mdm_.get());
ASSERT_EQ(mdm_.get(), MemoryDumpManager::GetInstance());
- delegate_.reset(new MemoryDumpManagerDelegateForTesting);
}
void TearDown() override {
MemoryDumpManager::SetInstanceForTesting(nullptr);
+ delegate_for_mdm_.reset();
+ delegate_ = nullptr;
mdm_.reset();
- delegate_.reset();
message_loop_.reset();
TraceLog::DeleteForTesting();
}
@@ -247,7 +248,10 @@ class MemoryDumpManagerTest : public testing::Test {
protected:
void InitializeMemoryDumpManager(bool is_coordinator) {
mdm_->set_dumper_registrations_ignored_for_testing(true);
- mdm_->Initialize(delegate_.get(), is_coordinator);
+ delegate_for_mdm_.reset(
+ new MemoryDumpManagerDelegateForTesting(is_coordinator));
+ delegate_ = delegate_for_mdm_.get();
+ mdm_->Initialize(std::move(delegate_for_mdm_));
}
void RequestGlobalDumpAndWait(MemoryDumpType dump_type,
@@ -286,7 +290,10 @@ class MemoryDumpManagerTest : public testing::Test {
const MemoryDumpProvider::Options kDefaultOptions;
std::unique_ptr<MemoryDumpManager> mdm_;
- std::unique_ptr<MemoryDumpManagerDelegateForTesting> delegate_;
+ // The delegate that is going to be passed to MDM.
+ std::unique_ptr<MemoryDumpManagerDelegateForTesting> delegate_for_mdm_;
+ // A pointer to the delegate that is owned by MDM, after MD initialization.
+ MemoryDumpManagerDelegateForTesting* delegate_;
bool last_callback_success_;
private:
@@ -889,7 +896,6 @@ TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) {
// initialization gets NACK-ed cleanly.
{
EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
- EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0);
RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
MemoryDumpLevelOfDetail::DETAILED);
EXPECT_FALSE(last_callback_success_);
@@ -898,9 +904,9 @@ TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) {
// Now late-initialize the MemoryDumpManager and check that the
// RequestGlobalDump completes successfully.
{
+ InitializeMemoryDumpManager(false /* is_coordinator */);
EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1);
EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
- InitializeMemoryDumpManager(false /* is_coordinator */);
RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
MemoryDumpLevelOfDetail::DETAILED);
EXPECT_TRUE(last_callback_success_);

Powered by Google App Engine
This is Rietveld 408576698