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..674499fe0ea0bd98bf6618fbc47dbe4137b6019c 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" |
@@ -46,7 +45,6 @@ class TestAllocationImpl : public internal::DiscardableMemoryManagerAllocation { |
// something else needs to explicit set the limit. |
const size_t kDefaultMemoryLimit = 1024; |
const size_t kDefaultSoftMemoryLimit = kDefaultMemoryLimit; |
-const size_t kDefaultBytesToKeepUnderModeratePressure = kDefaultMemoryLimit; |
class TestDiscardableMemoryManagerImpl |
: public internal::DiscardableMemoryManager { |
@@ -54,7 +52,6 @@ class TestDiscardableMemoryManagerImpl |
TestDiscardableMemoryManagerImpl() |
: DiscardableMemoryManager(kDefaultMemoryLimit, |
kDefaultSoftMemoryLimit, |
- kDefaultBytesToKeepUnderModeratePressure, |
TimeDelta::Max()) {} |
void SetNow(TimeTicks now) { now_ = now; } |
@@ -68,9 +65,7 @@ class TestDiscardableMemoryManagerImpl |
class DiscardableMemoryManagerTestBase { |
public: |
- DiscardableMemoryManagerTestBase() { |
- manager_.RegisterMemoryPressureListener(); |
- } |
+ DiscardableMemoryManagerTestBase() {} |
protected: |
enum LockStatus { |
@@ -85,10 +80,6 @@ class DiscardableMemoryManagerTestBase { |
void SetSoftMemoryLimit(size_t bytes) { manager_.SetSoftMemoryLimit(bytes); } |
- void SetBytesToKeepUnderModeratePressure(size_t bytes) { |
- manager_.SetBytesToKeepUnderModeratePressure(bytes); |
- } |
- |
void SetHardMemoryLimitExpirationTime(TimeDelta time) { |
manager_.SetHardMemoryLimitExpirationTime(time); |
} |
@@ -127,10 +118,15 @@ class DiscardableMemoryManagerTestBase { |
void SetNow(TimeTicks now) { manager_.SetNow(now); } |
+ void PurgeAll() { return manager_.PurgeAll(); } |
+ |
bool ReduceMemoryUsage() { return manager_.ReduceMemoryUsage(); } |
+ void ReduceMemoryUsageUntilWithinLimit(size_t bytes) { |
+ manager_.ReduceMemoryUsageUntilWithinLimit(bytes); |
+ } |
+ |
private: |
- MessageLoopForIO message_loop_; |
TestDiscardableMemoryManagerImpl manager_; |
}; |
@@ -192,11 +188,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 +293,14 @@ class DiscardableMemoryManagerPermutationTest |
TestAllocationImpl allocation_[3]; |
}; |
-// Verify that memory was discarded in the correct order after applying |
-// memory pressure. |
-TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscardedModeratePressure) { |
+// Verify that memory was discarded in the correct order after reducing usage to |
+// limit. |
+TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscarded) { |
RegisterAndUseAllocations(); |
- SetBytesToKeepUnderModeratePressure(1024); |
SetMemoryLimit(2048); |
- MemoryPressureListener::NotifyMemoryPressure( |
- MemoryPressureListener::MEMORY_PRESSURE_MODERATE); |
- RunLoop().RunUntilIdle(); |
+ ReduceMemoryUsageUntilWithinLimit(1024); |
EXPECT_NE(LOCK_STATUS_FAILED, Lock(allocation(2))); |
EXPECT_EQ(LOCK_STATUS_PURGED, Lock(allocation(1))); |
@@ -326,7 +315,6 @@ TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscardedModeratePressure) { |
TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscardedExceedLimit) { |
RegisterAndUseAllocations(); |
- SetBytesToKeepUnderModeratePressure(1024); |
SetMemoryLimit(2048); |
EXPECT_NE(LOCK_STATUS_FAILED, Lock(allocation(2))); |
@@ -340,7 +328,6 @@ TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscardedExceedLimit) { |
// Verify that no more memory than necessary was discarded after changing |
// memory limit. |
TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscardedAmount) { |
- SetBytesToKeepUnderModeratePressure(2048); |
SetMemoryLimit(4096); |
RegisterAndUseAllocations(); |
@@ -358,9 +345,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) |