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

Unified Diff: chrome/common/memory_pressure_monitor_chromeos_unittest.cc

Issue 1045433002: Migrate ChromeOS to base::MemoryPressureMonitor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup/fixes Created 5 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
Index: chrome/common/memory_pressure_monitor_chromeos_unittest.cc
diff --git a/base/chromeos/memory_pressure_observer_chromeos_unittest.cc b/chrome/common/memory_pressure_monitor_chromeos_unittest.cc
similarity index 76%
rename from base/chromeos/memory_pressure_observer_chromeos_unittest.cc
rename to chrome/common/memory_pressure_monitor_chromeos_unittest.cc
index a227f93dc0e79ad49814b3f43fff3bfbfdf04533..1258a712df50634ceec96c75cfaea38af91231e1 100644
--- a/base/chromeos/memory_pressure_observer_chromeos_unittest.cc
+++ b/chrome/common/memory_pressure_monitor_chromeos_unittest.cc
@@ -3,12 +3,12 @@
// found in the LICENSE file.
#include "base/basictypes.h"
-#include "base/chromeos/memory_pressure_observer_chromeos.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/message_loop/message_loop.h"
+#include "chrome/common/memory_pressure_monitor_chromeos.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace base {
+using base::MemoryPressureListener;
namespace {
@@ -40,17 +40,16 @@ bool WasOnMemoryPressureCalled() {
} // namespace
-class TestMemoryPressureObserver : public MemoryPressureObserverChromeOS {
+class TestMemoryPressureMonitor : public MemoryPressureMonitorChromeOS {
public:
- TestMemoryPressureObserver() :
- MemoryPressureObserverChromeOS(
- MemoryPressureObserverChromeOS::THRESHOLD_DEFAULT),
+ TestMemoryPressureMonitor() :
+ MemoryPressureMonitorChromeOS(chromeos::switches::THRESHOLD_DEFAULT),
memory_in_percent_override_(0) {
// Disable any timers which are going on and set a special memory reporting
// function.
StopObserving();
}
- ~TestMemoryPressureObserver() override {}
+ ~TestMemoryPressureMonitor() override {}
void SetMemoryInPercentOverride(int percent) {
memory_in_percent_override_ = percent;
@@ -66,45 +65,44 @@ class TestMemoryPressureObserver : public MemoryPressureObserverChromeOS {
}
int memory_in_percent_override_;
- DISALLOW_COPY_AND_ASSIGN(TestMemoryPressureObserver);
+ DISALLOW_COPY_AND_ASSIGN(TestMemoryPressureMonitor);
};
// This test tests the various transition states from memory pressure, looking
// for the correct behavior on event reposting as well as state updates.
-TEST(MemoryPressureObserverChromeOSTest, CheckMemoryPressure) {
+TEST(MemoryPressureMonitorChromeOSTest, CheckMemoryPressure) {
base::MessageLoopForUI message_loop;
- scoped_ptr<TestMemoryPressureObserver> observer(
- new TestMemoryPressureObserver);
+ scoped_ptr<TestMemoryPressureMonitor> monitor(new TestMemoryPressureMonitor);
scoped_ptr<MemoryPressureListener> listener(
new MemoryPressureListener(base::Bind(&OnMemoryPressure)));
// Checking the memory pressure while 0% are used should not produce any
// events.
- observer->SetMemoryInPercentOverride(0);
+ monitor->SetMemoryInPercentOverride(0);
ResetOnMemoryPressureCalled();
- observer->CheckMemoryPressureForTest();
+ monitor->CheckMemoryPressureForTest();
message_loop.RunUntilIdle();
EXPECT_FALSE(WasOnMemoryPressureCalled());
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE,
- observer->GetCurrentPressureLevel());
+ monitor->GetCurrentPressureLevel());
// Setting the memory level to 80% should produce a moderate pressure level.
- observer->SetMemoryInPercentOverride(80);
- observer->CheckMemoryPressureForTest();
+ monitor->SetMemoryInPercentOverride(80);
+ monitor->CheckMemoryPressureForTest();
message_loop.RunUntilIdle();
EXPECT_TRUE(WasOnMemoryPressureCalled());
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE,
- observer->GetCurrentPressureLevel());
+ monitor->GetCurrentPressureLevel());
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE,
on_memory_pressure_level);
// We need to check that the event gets reposted after a while.
int i = 0;
for (; i < 100; i++) {
- observer->CheckMemoryPressureForTest();
+ monitor->CheckMemoryPressureForTest();
message_loop.RunUntilIdle();
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE,
- observer->GetCurrentPressureLevel());
+ monitor->GetCurrentPressureLevel());
if (WasOnMemoryPressureCalled()) {
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE,
on_memory_pressure_level);
@@ -116,41 +114,41 @@ TEST(MemoryPressureObserverChromeOSTest, CheckMemoryPressure) {
EXPECT_GE(99, i);
// Setting the memory usage to 99% should produce critical levels.
- observer->SetMemoryInPercentOverride(99);
- observer->CheckMemoryPressureForTest();
+ monitor->SetMemoryInPercentOverride(99);
+ monitor->CheckMemoryPressureForTest();
message_loop.RunUntilIdle();
EXPECT_TRUE(WasOnMemoryPressureCalled());
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL,
on_memory_pressure_level);
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL,
- observer->GetCurrentPressureLevel());
+ monitor->GetCurrentPressureLevel());
// Calling it again should immediately produce a second call.
- observer->CheckMemoryPressureForTest();
+ monitor->CheckMemoryPressureForTest();
message_loop.RunUntilIdle();
EXPECT_TRUE(WasOnMemoryPressureCalled());
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL,
on_memory_pressure_level);
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL,
- observer->GetCurrentPressureLevel());
+ monitor->GetCurrentPressureLevel());
// When lowering the pressure again we should not get an event, but the
// pressure should go back to moderate.
- observer->SetMemoryInPercentOverride(80);
- observer->CheckMemoryPressureForTest();
+ monitor->SetMemoryInPercentOverride(80);
+ monitor->CheckMemoryPressureForTest();
message_loop.RunUntilIdle();
EXPECT_FALSE(WasOnMemoryPressureCalled());
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE,
- observer->GetCurrentPressureLevel());
+ monitor->GetCurrentPressureLevel());
// We should need exactly the same amount of calls as before, before the next
// call comes in.
int j = 0;
for (; j < 100; j++) {
- observer->CheckMemoryPressureForTest();
+ monitor->CheckMemoryPressureForTest();
message_loop.RunUntilIdle();
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE,
- observer->GetCurrentPressureLevel());
+ monitor->GetCurrentPressureLevel());
if (WasOnMemoryPressureCalled()) {
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE,
on_memory_pressure_level);
@@ -161,4 +159,3 @@ TEST(MemoryPressureObserverChromeOSTest, CheckMemoryPressure) {
EXPECT_EQ(j, i);
}
-} // namespace base

Powered by Google App Engine
This is Rietveld 408576698