| 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: | 20 public: |
| 22 DiscardableMemoryTest() : message_loop_(MessageLoop::TYPE_IO) { | 21 DiscardableMemoryTest() {} |
| 23 // Register memory pressure listeners now that we have a message loop. | |
| 24 DiscardableMemory::RegisterMemoryPressureListeners(); | |
| 25 } | |
| 26 virtual ~DiscardableMemoryTest() { | 22 virtual ~DiscardableMemoryTest() { |
| 27 DiscardableMemory::UnregisterMemoryPressureListeners(); | |
| 28 } | 23 } |
| 29 | 24 |
| 30 protected: | 25 protected: |
| 31 scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size) { | 26 scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size) { |
| 32 return DiscardableMemory::CreateLockedMemoryWithType( | 27 return DiscardableMemory::CreateLockedMemoryWithType( |
| 33 GetParam(), size).Pass(); | 28 GetParam(), size).Pass(); |
| 34 } | 29 } |
| 35 | |
| 36 private: | |
| 37 MessageLoop message_loop_; | |
| 38 }; | 30 }; |
| 39 | 31 |
| 40 const size_t kSize = 1024; | 32 const size_t kSize = 1024; |
| 41 | 33 |
| 42 TEST_P(DiscardableMemoryTest, IsNamed) { | 34 TEST_P(DiscardableMemoryTest, IsNamed) { |
| 43 std::string type_name(DiscardableMemory::GetTypeName(GetParam())); | 35 std::string type_name(DiscardableMemory::GetTypeName(GetParam())); |
| 44 EXPECT_NE("unknown", type_name); | 36 EXPECT_NE("unknown", type_name); |
| 45 EXPECT_EQ(GetParam(), DiscardableMemory::GetNamedType(type_name)); | 37 EXPECT_EQ(GetParam(), DiscardableMemory::GetNamedType(type_name)); |
| 46 } | 38 } |
| 47 | 39 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 return supported_types; | 110 return supported_types; |
| 119 } | 111 } |
| 120 | 112 |
| 121 INSTANTIATE_TEST_CASE_P( | 113 INSTANTIATE_TEST_CASE_P( |
| 122 DiscardableMemoryTests, | 114 DiscardableMemoryTests, |
| 123 DiscardableMemoryTest, | 115 DiscardableMemoryTest, |
| 124 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); | 116 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); |
| 125 | 117 |
| 126 } // namespace | 118 } // namespace |
| 127 } // namespace base | 119 } // namespace base |
| OLD | NEW |