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

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

Issue 2434353003: Introduce MemoryCoordinatorProxy in base (Closed)
Patch Set: Address on reviews Created 4 years, 2 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: 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..a0d1e925a31bc9cd86495ef3298a05c65d068a26 100644
--- a/content/browser/memory/memory_coordinator_impl_unittest.cc
+++ b/content/browser/memory/memory_coordinator_impl_unittest.cc
@@ -4,6 +4,7 @@
#include "content/browser/memory/memory_coordinator_impl.h"
+#include "base/memory/memory_coordinator_proxy.h"
#include "base/run_loop.h"
#include "content/browser/memory/memory_monitor.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -50,8 +51,15 @@ class MockMemoryMonitor : public MemoryMonitor {
class MemoryCoordinatorImplTest : public testing::Test {
public:
void SetUp() override {
+ MemoryCoordinator::EnableFeaturesForTesting();
+
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 +81,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 +103,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 +118,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);

Powered by Google App Engine
This is Rietveld 408576698