Index: base/memory/discardable_memory_unittest.cc |
diff --git a/base/memory/discardable_memory_unittest.cc b/base/memory/discardable_memory_unittest.cc |
index eb730f19f18e8482fde972598c99378f2c30447a..c900551535d9581348788825ac8d8563ffb7eeaa 100644 |
--- a/base/memory/discardable_memory_unittest.cc |
+++ b/base/memory/discardable_memory_unittest.cc |
@@ -2,6 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include <limits> |
+ |
#include "base/memory/discardable_memory.h" |
willchan no longer on Chromium
2013/12/01 00:58:56
foo.h always goes first in foo_unittest.cc, see th
Philippe
2013/12/02 10:56:39
Done.
|
#include "testing/gtest/include/gtest/gtest.h" |
@@ -9,6 +11,18 @@ namespace base { |
const size_t kSize = 1024; |
+TEST(DiscardableMemoryTest, TooLargeAllocationFails) { |
+ const size_t kPageSize = 4096; |
+ const size_t max_allowed_allocation_size = |
+ std::numeric_limits<size_t>::max() - kPageSize + 1; |
+ scoped_ptr<DiscardableMemory> memory( |
+ DiscardableMemory::CreateLockedMemory(max_allowed_allocation_size + 1)); |
+ // On certain platforms (e.g. Android), page-alignment would have caused an |
+ // overflow resulting in a small allocation if the input size wasn't checked |
+ // correctly. |
+ ASSERT_FALSE(memory); |
+} |
+ |
TEST(DiscardableMemoryTest, SupportedNatively) { |
#if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY) |
ASSERT_TRUE(DiscardableMemory::SupportedNatively()); |