Chromium Code Reviews| 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 d8c575d67a32da6a69997937f56be9f6512ef619..aa8023c3d11f53b63e83461e8e6bd3aa2451a0b4 100644 |
| --- a/content/browser/memory/memory_coordinator_impl_unittest.cc |
| +++ b/content/browser/memory/memory_coordinator_impl_unittest.cc |
| @@ -4,8 +4,11 @@ |
| #include "content/browser/memory/memory_coordinator_impl.h" |
| +#include "base/feature_list.h" |
| +#include "base/memory/memory_coordinator_proxy.h" |
| #include "base/run_loop.h" |
| #include "content/browser/memory/memory_monitor.h" |
| +#include "content/public/common/content_features.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace content { |
| @@ -50,8 +53,19 @@ class MockMemoryMonitor : public MemoryMonitor { |
| class MemoryCoordinatorImplTest : public testing::Test { |
| public: |
| void SetUp() override { |
| + std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
|
bashi
2016/10/24 00:10:25
nit: Can we move out EnableForTesting() in memory_
hajimehoshi
2016/10/24 06:51:06
Done.
|
| + feature_list->InitializeFromCommandLine(features::kMemoryCoordinator.name, |
| + ""); |
| + base::FeatureList::ClearInstanceForTesting(); |
| + base::FeatureList::SetInstance(std::move(feature_list)); |
| + |
| coordinator_.reset(new MemoryCoordinatorImpl( |
| message_loop_.task_runner(), base::WrapUnique(new MockMemoryMonitor))); |
| + |
| + base::MemoryCoordinatorProxy::GetInstance()-> |
| + SetGetCurrentMemoryStateCallback(base::Bind( |
| + &MemoryCoordinator::GetCurrentMemoryState, |
| + base::Unretained(coordinator_.get()))); |
| } |
| MockMemoryMonitor* GetMockMemoryMonitor() { |
| @@ -73,10 +87,17 @@ TEST_F(MemoryCoordinatorImplTest, CalculateNextState) { |
| // The default state is NORMAL. |
| EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetCurrentMemoryState()); |
| + EXPECT_EQ(base::MemoryState::NORMAL, |
| + base::MemoryCoordinatorProxy::GetInstance()-> |
| + GetCurrentMemoryState()); |
| // Transitions from NORMAL |
| coordinator_->current_state_ = base::MemoryState::NORMAL; |
| EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->GetCurrentMemoryState()); |
| + EXPECT_EQ(base::MemoryState::NORMAL, |
| + base::MemoryCoordinatorProxy::GetInstance()-> |
| + GetCurrentMemoryState()); |
| + |
| GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); |
| EXPECT_EQ(base::MemoryState::NORMAL, coordinator_->CalculateNextState()); |
| GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); |
| @@ -88,6 +109,10 @@ TEST_F(MemoryCoordinatorImplTest, CalculateNextState) { |
| coordinator_->current_state_ = base::MemoryState::THROTTLED; |
| EXPECT_EQ(base::MemoryState::THROTTLED, |
| coordinator_->GetCurrentMemoryState()); |
| + EXPECT_EQ(base::MemoryState::THROTTLED, |
| + base::MemoryCoordinatorProxy::GetInstance()-> |
| + GetCurrentMemoryState()); |
| + |
| GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(40); |
| EXPECT_EQ(base::MemoryState::THROTTLED, coordinator_->CalculateNextState()); |
| GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(50); |
| @@ -99,6 +124,10 @@ TEST_F(MemoryCoordinatorImplTest, CalculateNextState) { |
| coordinator_->current_state_ = base::MemoryState::SUSPENDED; |
| EXPECT_EQ(base::MemoryState::SUSPENDED, |
| coordinator_->GetCurrentMemoryState()); |
| + EXPECT_EQ(base::MemoryState::SUSPENDED, |
| + base::MemoryCoordinatorProxy::GetInstance()-> |
| + GetCurrentMemoryState()); |
| + |
| GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(20); |
| EXPECT_EQ(base::MemoryState::SUSPENDED, coordinator_->CalculateNextState()); |
| GetMockMemoryMonitor()->SetFreeMemoryUntilCriticalMB(30); |