OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/discardable_memory_provider.h" | 5 #include "base/memory/discardable_memory_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/discardable_memory.h" | 8 #include "base/memory/discardable_memory.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 225 |
226 SetBytesToReclaimUnderModeratePressure(1024); | 226 SetBytesToReclaimUnderModeratePressure(1024); |
227 SetDiscardableMemoryLimit(2048); | 227 SetDiscardableMemoryLimit(2048); |
228 | 228 |
229 EXPECT_NE(DISCARDABLE_MEMORY_FAILED, discardable(2)->Lock()); | 229 EXPECT_NE(DISCARDABLE_MEMORY_FAILED, discardable(2)->Lock()); |
230 EXPECT_NE(DISCARDABLE_MEMORY_SUCCESS, discardable(1)->Lock()); | 230 EXPECT_NE(DISCARDABLE_MEMORY_SUCCESS, discardable(1)->Lock()); |
231 // 0 should still be locked. | 231 // 0 should still be locked. |
232 EXPECT_NE(static_cast<void*>(NULL), Memory(discardable(0))); | 232 EXPECT_NE(static_cast<void*>(NULL), Memory(discardable(0))); |
233 } | 233 } |
234 | 234 |
| 235 // Verify that no more memory than necessary was discarded after changing |
| 236 // memory limit. |
| 237 TEST_P(DiscardableMemoryProviderPermutationTest, LRUDiscardedAmount) { |
| 238 SetBytesToReclaimUnderModeratePressure(2048); |
| 239 SetDiscardableMemoryLimit(4096); |
| 240 |
| 241 CreateAndUseDiscardableMemory(); |
| 242 |
| 243 SetDiscardableMemoryLimit(2048); |
| 244 |
| 245 EXPECT_EQ(DISCARDABLE_MEMORY_SUCCESS, discardable(2)->Lock()); |
| 246 EXPECT_EQ(DISCARDABLE_MEMORY_PURGED, discardable(1)->Lock()); |
| 247 // 0 should still be locked. |
| 248 EXPECT_NE(static_cast<void*>(NULL), Memory(discardable(0))); |
| 249 } |
| 250 |
235 TEST_P(DiscardableMemoryProviderPermutationTest, | 251 TEST_P(DiscardableMemoryProviderPermutationTest, |
236 CriticalPressureFreesAllUnlocked) { | 252 CriticalPressureFreesAllUnlocked) { |
237 CreateAndUseDiscardableMemory(); | 253 CreateAndUseDiscardableMemory(); |
238 | 254 |
239 MemoryPressureListener::NotifyMemoryPressure( | 255 MemoryPressureListener::NotifyMemoryPressure( |
240 MemoryPressureListener::MEMORY_PRESSURE_CRITICAL); | 256 MemoryPressureListener::MEMORY_PRESSURE_CRITICAL); |
241 RunLoop().RunUntilIdle(); | 257 RunLoop().RunUntilIdle(); |
242 | 258 |
243 for (int i = 0; i < 3; ++i) { | 259 for (int i = 0; i < 3; ++i) { |
244 if (i == 0) | 260 if (i == 0) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 Bind(&ThreadedDiscardableMemoryProviderTest::UseMemoryHelper, | 354 Bind(&ThreadedDiscardableMemoryProviderTest::UseMemoryHelper, |
339 Unretained(this))); | 355 Unretained(this))); |
340 memory_usage_thread_.message_loop()->PostTask( | 356 memory_usage_thread_.message_loop()->PostTask( |
341 FROM_HERE, | 357 FROM_HERE, |
342 Bind(&ThreadedDiscardableMemoryProviderTest::SignalHelper, | 358 Bind(&ThreadedDiscardableMemoryProviderTest::SignalHelper, |
343 Unretained(this))); | 359 Unretained(this))); |
344 thread_sync_.Wait(); | 360 thread_sync_.Wait(); |
345 } | 361 } |
346 | 362 |
347 } // namespace base | 363 } // namespace base |
OLD | NEW |