OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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.h" | 5 #include "base/memory/discardable_memory.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 memory->Unlock(); | 76 memory->Unlock(); |
77 } | 77 } |
78 | 78 |
79 // Test delete a discardable memory while it is locked. | 79 // Test delete a discardable memory while it is locked. |
80 TEST_P(DiscardableMemoryTest, DeleteWhileLocked) { | 80 TEST_P(DiscardableMemoryTest, DeleteWhileLocked) { |
81 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); | 81 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); |
82 ASSERT_TRUE(memory); | 82 ASSERT_TRUE(memory); |
83 } | 83 } |
84 | 84 |
85 // Test forced purging. | |
86 TEST_P(DiscardableMemoryTest, Purge) { | |
87 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); | |
88 ASSERT_TRUE(memory); | |
89 memory->Unlock(); | |
90 | |
91 DiscardableMemory::PurgeForTesting(); | |
92 EXPECT_EQ(DISCARDABLE_MEMORY_LOCK_STATUS_PURGED, memory->Lock()); | |
93 } | |
94 | |
95 #if !defined(NDEBUG) && !defined(OS_ANDROID) | 85 #if !defined(NDEBUG) && !defined(OS_ANDROID) |
96 // Death tests are not supported with Android APKs. | 86 // Death tests are not supported with Android APKs. |
97 TEST_P(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) { | 87 TEST_P(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) { |
98 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); | 88 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); |
99 ASSERT_TRUE(memory); | 89 ASSERT_TRUE(memory); |
100 memory->Unlock(); | 90 memory->Unlock(); |
101 ASSERT_DEATH_IF_SUPPORTED( | 91 ASSERT_DEATH_IF_SUPPORTED( |
102 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); | 92 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); |
103 } | 93 } |
104 #endif | 94 #endif |
(...skipping 24 matching lines...) Expand all Loading... |
129 return supported_types; | 119 return supported_types; |
130 } | 120 } |
131 | 121 |
132 INSTANTIATE_TEST_CASE_P( | 122 INSTANTIATE_TEST_CASE_P( |
133 DiscardableMemoryTests, | 123 DiscardableMemoryTests, |
134 DiscardableMemoryTest, | 124 DiscardableMemoryTest, |
135 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); | 125 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); |
136 | 126 |
137 } // namespace | 127 } // namespace |
138 } // namespace base | 128 } // namespace base |
OLD | NEW |