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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 DiscardableMemory::CreateLockedMemory(size)); | 275 DiscardableMemory::CreateLockedMemory(size)); |
276 EXPECT_TRUE(IsRegistered(discardable.get())); | 276 EXPECT_TRUE(IsRegistered(discardable.get())); |
277 EXPECT_NE(static_cast<void*>(NULL), Memory(discardable.get())); | 277 EXPECT_NE(static_cast<void*>(NULL), Memory(discardable.get())); |
278 EXPECT_EQ(1024u, BytesAllocated()); | 278 EXPECT_EQ(1024u, BytesAllocated()); |
279 EXPECT_FALSE(CanBePurged(discardable.get())); | 279 EXPECT_FALSE(CanBePurged(discardable.get())); |
280 } | 280 } |
281 // Should have ignored the "locked" status and freed the discardable memory. | 281 // Should have ignored the "locked" status and freed the discardable memory. |
282 EXPECT_EQ(0u, BytesAllocated()); | 282 EXPECT_EQ(0u, BytesAllocated()); |
283 } | 283 } |
284 | 284 |
285 #if !defined(NDEBUG) && !defined(OS_ANDROID) | 285 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS) |
286 // Death tests are not supported with Android APKs. | 286 // Death tests are not supported with Android APKs. |
287 TEST_F(DiscardableMemoryProviderTest, UnlockedMemoryAccessCrashesInDebugMode) { | 287 TEST_F(DiscardableMemoryProviderTest, UnlockedMemoryAccessCrashesInDebugMode) { |
288 size_t size = 1024; | 288 size_t size = 1024; |
289 const scoped_ptr<DiscardableMemory> discardable( | 289 const scoped_ptr<DiscardableMemory> discardable( |
290 DiscardableMemory::CreateLockedMemory(size)); | 290 DiscardableMemory::CreateLockedMemory(size)); |
291 EXPECT_TRUE(IsRegistered(discardable.get())); | 291 EXPECT_TRUE(IsRegistered(discardable.get())); |
292 EXPECT_NE(static_cast<void*>(NULL), Memory(discardable.get())); | 292 EXPECT_NE(static_cast<void*>(NULL), Memory(discardable.get())); |
293 EXPECT_EQ(1024u, BytesAllocated()); | 293 EXPECT_EQ(1024u, BytesAllocated()); |
294 EXPECT_FALSE(CanBePurged(discardable.get())); | 294 EXPECT_FALSE(CanBePurged(discardable.get())); |
295 discardable->Unlock(); | 295 discardable->Unlock(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 Bind(&ThreadedDiscardableMemoryProviderTest::UseMemoryHelper, | 338 Bind(&ThreadedDiscardableMemoryProviderTest::UseMemoryHelper, |
339 Unretained(this))); | 339 Unretained(this))); |
340 memory_usage_thread_.message_loop()->PostTask( | 340 memory_usage_thread_.message_loop()->PostTask( |
341 FROM_HERE, | 341 FROM_HERE, |
342 Bind(&ThreadedDiscardableMemoryProviderTest::SignalHelper, | 342 Bind(&ThreadedDiscardableMemoryProviderTest::SignalHelper, |
343 Unretained(this))); | 343 Unretained(this))); |
344 thread_sync_.Wait(); | 344 thread_sync_.Wait(); |
345 } | 345 } |
346 | 346 |
347 } // namespace base | 347 } // namespace base |
OLD | NEW |