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

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

Issue 2757653003: memory coordinator: Delay setting browsers memory state if needed (Closed)
Patch Set: comment Created 3 years, 9 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 | « content/browser/memory/memory_coordinator_impl.cc ('k') | no next file » | 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 8663ae207e68d610c3819ba0f76e15dccf4865d6..a2d1be92e067b210b1720ad1bd8084e9ebdc2bd6 100644
--- a/content/browser/memory/memory_coordinator_impl_unittest.cc
+++ b/content/browser/memory/memory_coordinator_impl_unittest.cc
@@ -130,6 +130,7 @@ class TestMemoryCoordinatorImpl : public MemoryCoordinatorImpl {
: MemoryCoordinatorImpl(task_runner,
base::MakeUnique<MockMemoryMonitor>()) {
SetDelegateForTesting(base::MakeUnique<TestMemoryCoordinatorDelegate>());
+ SetTickClockForTesting(task_runner->GetMockTickClock());
}
~TestMemoryCoordinatorImpl() override {}
@@ -447,6 +448,33 @@ TEST_F(MemoryCoordinatorImplTest, UpdateCondition) {
EXPECT_EQ(base::MemoryState::NORMAL, client.state());
base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client);
}
+
+ {
+ // Transition happends but browser state change is delayed
+ // (CRITICAL -> NORMAL).
+ base::TimeDelta transition_interval =
+ coordinator_->minimum_state_transition_period_ +
+ base::TimeDelta::FromSeconds(1);
+ coordinator_->memory_condition_ = MemoryCondition::NORMAL;
+ coordinator_->last_state_change_ = task_runner_->NowTicks();
+ GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20);
+ condition_observer->UpdateCondition();
+ EXPECT_EQ(base::MemoryState::THROTTLED,
+ coordinator_->GetCurrentMemoryState());
+
+ // Back to NORMAL condition before |minimum_state_transition_period_| is
+ // passed. At this point the browser's state shouldn't be changed.
+ GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50);
+ condition_observer->UpdateCondition();
+ task_runner_->FastForwardBy(transition_interval / 2);
+ EXPECT_EQ(MemoryCondition::NORMAL, coordinator_->GetMemoryCondition());
+ EXPECT_EQ(base::MemoryState::THROTTLED,
+ coordinator_->GetCurrentMemoryState());
+
+ // |minimum_state_transition_period_| is passed. State should be changed.
+ task_runner_->FastForwardBy(transition_interval / 2);
+ EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetCurrentMemoryState());
+ }
}
TEST_F(MemoryCoordinatorImplTest, ForceSetMemoryCondition) {
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698