| 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 "base/run_loop.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 10 |
| 12 #if defined(OS_ANDROID) | 11 #if defined(OS_ANDROID) |
| 13 #include <limits> | 12 #include <limits> |
| 14 #endif | 13 #endif |
| 15 | 14 |
| 16 namespace base { | 15 namespace base { |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 class DiscardableMemoryTest | 18 class DiscardableMemoryTest |
| 20 : public testing::TestWithParam<DiscardableMemoryType> { | 19 : public testing::TestWithParam<DiscardableMemoryType> { |
| 21 public: | |
| 22 DiscardableMemoryTest() : message_loop_(MessageLoop::TYPE_IO) { | |
| 23 // Register memory pressure listeners now that we have a message loop. | |
| 24 DiscardableMemory::RegisterMemoryPressureListeners(); | |
| 25 } | |
| 26 virtual ~DiscardableMemoryTest() { | |
| 27 DiscardableMemory::UnregisterMemoryPressureListeners(); | |
| 28 } | |
| 29 | |
| 30 protected: | 20 protected: |
| 31 scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size) { | 21 scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size) { |
| 32 return DiscardableMemory::CreateLockedMemoryWithType( | 22 return DiscardableMemory::CreateLockedMemoryWithType( |
| 33 GetParam(), size).Pass(); | 23 GetParam(), size).Pass(); |
| 34 } | 24 } |
| 35 | |
| 36 private: | |
| 37 MessageLoop message_loop_; | |
| 38 }; | 25 }; |
| 39 | 26 |
| 40 const size_t kSize = 1024; | 27 const size_t kSize = 1024; |
| 41 | 28 |
| 42 TEST_P(DiscardableMemoryTest, IsNamed) { | 29 TEST_P(DiscardableMemoryTest, IsNamed) { |
| 43 std::string type_name(DiscardableMemory::GetTypeName(GetParam())); | 30 std::string type_name(DiscardableMemory::GetTypeName(GetParam())); |
| 44 EXPECT_NE("unknown", type_name); | 31 EXPECT_NE("unknown", type_name); |
| 45 EXPECT_EQ(GetParam(), DiscardableMemory::GetNamedType(type_name)); | 32 EXPECT_EQ(GetParam(), DiscardableMemory::GetNamedType(type_name)); |
| 46 } | 33 } |
| 47 | 34 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 return supported_types; | 110 return supported_types; |
| 124 } | 111 } |
| 125 | 112 |
| 126 INSTANTIATE_TEST_CASE_P( | 113 INSTANTIATE_TEST_CASE_P( |
| 127 DiscardableMemoryTests, | 114 DiscardableMemoryTests, |
| 128 DiscardableMemoryTest, | 115 DiscardableMemoryTest, |
| 129 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); | 116 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); |
| 130 | 117 |
| 131 } // namespace | 118 } // namespace |
| 132 } // namespace base | 119 } // namespace base |
| OLD | NEW |