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

Unified Diff: content/browser/memory/memory_coordinator_impl_unittest.cc

Issue 2685263002: Add PurgeMemory() method for ChildMemoryCoordinator.mojom (Closed)
Patch Set: comment 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
« no previous file with comments | « no previous file | content/child/memory/child_memory_coordinator_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/memory/memory_coordinator_impl_unittest.cc
diff --git a/content/browser/memory/memory_coordinator_impl_unittest.cc b/content/browser/memory/memory_coordinator_impl_unittest.cc
index 9c3c992990175f6da043a631c5ceeb744b6932f1..3e83a1264047c7248e2e8203cdd4ccda78d3d6dd 100644
--- a/content/browser/memory/memory_coordinator_impl_unittest.cc
+++ b/content/browser/memory/memory_coordinator_impl_unittest.cc
@@ -35,7 +35,8 @@ class MockChildMemoryCoordinator : public mojom::ChildMemoryCoordinator {
public:
MockChildMemoryCoordinator()
: state_(mojom::MemoryState::NORMAL),
- on_state_change_calls_(0) {}
+ on_state_change_calls_(0),
+ purge_memory_calls_(0) {}
~MockChildMemoryCoordinator() override {}
@@ -44,12 +45,16 @@ class MockChildMemoryCoordinator : public mojom::ChildMemoryCoordinator {
++on_state_change_calls_;
}
+ void PurgeMemory() override { ++purge_memory_calls_; }
+
mojom::MemoryState state() const { return state_; }
int on_state_change_calls() const { return on_state_change_calls_; }
+ int purge_memory_calls() const { return purge_memory_calls_; }
private:
mojom::MemoryState state_;
int on_state_change_calls_;
+ int purge_memory_calls_;
};
// A mock MemoryCoordinatorClient, for testing interaction between MC and
@@ -57,15 +62,15 @@ class MockChildMemoryCoordinator : public mojom::ChildMemoryCoordinator {
class MockMemoryCoordinatorClient : public base::MemoryCoordinatorClient {
public:
void OnMemoryStateChange(base::MemoryState state) override {
- is_called_ = true;
+ did_state_changed_ = true;
state_ = state;
}
- bool is_called() { return is_called_; }
- base::MemoryState state() { return state_; }
+ bool did_state_changed() const { return did_state_changed_; }
+ base::MemoryState state() const { return state_; }
private:
- bool is_called_ = false;
+ bool did_state_changed_ = false;
base::MemoryState state_ = base::MemoryState::NORMAL;
};
@@ -243,6 +248,14 @@ TEST_F(MemoryCoordinatorImplTest, SetMemoryStateDelivered) {
EXPECT_EQ(mojom::MemoryState::THROTTLED, cmc2->state());
}
+TEST_F(MemoryCoordinatorImplTest, PurgeMemoryChild) {
+ auto* child = coordinator_->CreateChildMemoryCoordinator(1);
+ EXPECT_EQ(0, child->purge_memory_calls());
+ child->PurgeMemory();
+ RunUntilIdle();
+ EXPECT_EQ(1, child->purge_memory_calls());
+}
+
TEST_F(MemoryCoordinatorImplTest, SetChildMemoryState) {
auto cmc = coordinator_->CreateChildMemoryCoordinator(1);
auto iter = coordinator_->children().find(1);
@@ -368,7 +381,7 @@ TEST_F(MemoryCoordinatorImplTest, UpdateState) {
GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40);
state_updater->UpdateState();
RunUntilIdle();
- EXPECT_TRUE(client.is_called());
+ EXPECT_TRUE(client.did_state_changed());
EXPECT_EQ(base::MemoryState::THROTTLED, client.state());
base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client);
}
@@ -381,7 +394,7 @@ TEST_F(MemoryCoordinatorImplTest, UpdateState) {
GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50);
state_updater->UpdateState();
RunUntilIdle();
- EXPECT_FALSE(client.is_called());
+ EXPECT_FALSE(client.did_state_changed());
EXPECT_EQ(base::MemoryState::NORMAL, client.state());
base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client);
}
@@ -422,7 +435,7 @@ TEST_F(MemoryCoordinatorImplTest, SetMemoryStateForTesting) {
base::MemoryCoordinatorProxy::GetInstance()->
GetCurrentMemoryState());
RunUntilIdle();
- EXPECT_TRUE(client.is_called());
+ EXPECT_TRUE(client.did_state_changed());
EXPECT_EQ(base::MemoryState::THROTTLED, client.state());
base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client);
}
« no previous file with comments | « no previous file | content/child/memory/child_memory_coordinator_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698