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

Unified Diff: base/memory/discardable_memory_manager_unittest.cc

Issue 448173002: Re-land: base: Introduce an explicit call for reducing emulated discardable memory usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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: base/memory/discardable_memory_manager_unittest.cc
diff --git a/base/memory/discardable_memory_manager_unittest.cc b/base/memory/discardable_memory_manager_unittest.cc
index ef5739a6526a5e03495d82c3b136c44f2b162e99..5cf8391197d1401055c58390644d9b0b2bead3aa 100644
--- a/base/memory/discardable_memory_manager_unittest.cc
+++ b/base/memory/discardable_memory_manager_unittest.cc
@@ -5,7 +5,6 @@
#include "base/memory/discardable_memory_manager.h"
#include "base/bind.h"
-#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -68,9 +67,7 @@ class TestDiscardableMemoryManagerImpl
class DiscardableMemoryManagerTestBase {
public:
- DiscardableMemoryManagerTestBase() {
- manager_.RegisterMemoryPressureListener();
- }
+ DiscardableMemoryManagerTestBase() {}
protected:
enum LockStatus {
@@ -127,10 +124,15 @@ class DiscardableMemoryManagerTestBase {
void SetNow(TimeTicks now) { manager_.SetNow(now); }
+ void PurgeAll() { return manager_.PurgeAll(); }
+
bool ReduceMemoryUsage() { return manager_.ReduceMemoryUsage(); }
+ void ReduceMemoryUsageUntilWithinModeratePressureLimit() {
+ manager_.ReduceMemoryUsageUntilWithinModeratePressureLimit();
+ }
+
private:
- MessageLoopForIO message_loop_;
TestDiscardableMemoryManagerImpl manager_;
};
@@ -192,11 +194,7 @@ TEST_F(DiscardableMemoryManagerTest, LockAfterPurge) {
EXPECT_TRUE(CanBePurged(&allocation));
// Force the system to purge.
- MemoryPressureListener::NotifyMemoryPressure(
- MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
-
- // Required because ObserverListThreadSafe notifies via PostTask.
- RunLoop().RunUntilIdle();
+ PurgeAll();
EXPECT_EQ(LOCK_STATUS_PURGED, Lock(&allocation));
EXPECT_FALSE(CanBePurged(&allocation));
@@ -301,17 +299,15 @@ class DiscardableMemoryManagerPermutationTest
TestAllocationImpl allocation_[3];
};
-// Verify that memory was discarded in the correct order after applying
-// memory pressure.
+// Verify that memory was discarded in the correct order after reducing usage to
+// moderate pressure limit.
TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscardedModeratePressure) {
RegisterAndUseAllocations();
SetBytesToKeepUnderModeratePressure(1024);
SetMemoryLimit(2048);
- MemoryPressureListener::NotifyMemoryPressure(
- MemoryPressureListener::MEMORY_PRESSURE_MODERATE);
- RunLoop().RunUntilIdle();
+ ReduceMemoryUsageUntilWithinModeratePressureLimit();
EXPECT_NE(LOCK_STATUS_FAILED, Lock(allocation(2)));
EXPECT_EQ(LOCK_STATUS_PURGED, Lock(allocation(1)));
@@ -358,9 +354,7 @@ TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscardedAmount) {
TEST_P(DiscardableMemoryManagerPermutationTest, PurgeFreesAllUnlocked) {
RegisterAndUseAllocations();
- MemoryPressureListener::NotifyMemoryPressure(
- MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
- RunLoop().RunUntilIdle();
+ PurgeAll();
for (int i = 0; i < 3; ++i) {
if (i == 0)

Powered by Google App Engine
This is Rietveld 408576698