| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/mac/memory_pressure_monitor_mac.h" | 5 #include "base/memory/memory_pressure_monitor_mac.h" |
| 6 |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 8 |
| 8 namespace base { | 9 namespace base { |
| 10 namespace mac { |
| 9 | 11 |
| 10 class TestMemoryPressureMonitorMac : public MemoryPressureMonitorMac { | 12 class TestMemoryPressureMonitor : public MemoryPressureMonitor { |
| 11 public: | 13 public: |
| 12 using MemoryPressureMonitorMac::MemoryPressureLevelForMacMemoryPressure; | 14 using MemoryPressureMonitor::MemoryPressureLevelForMacMemoryPressure; |
| 13 | 15 |
| 14 TestMemoryPressureMonitorMac() { } | 16 TestMemoryPressureMonitor() { } |
| 15 | 17 |
| 16 private: | 18 private: |
| 17 DISALLOW_COPY_AND_ASSIGN(TestMemoryPressureMonitorMac); | 19 DISALLOW_COPY_AND_ASSIGN(TestMemoryPressureMonitor); |
| 18 }; | 20 }; |
| 19 | 21 |
| 20 TEST(TestMemoryPressureMonitorMac, MemoryPressureFromMacMemoryPressure) { | 22 TEST(MacMemoryPressureMonitorTest, MemoryPressureFromMacMemoryPressure) { |
| 21 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, | 23 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, |
| 22 TestMemoryPressureMonitorMac:: | 24 TestMemoryPressureMonitor:: |
| 23 MemoryPressureLevelForMacMemoryPressure( | 25 MemoryPressureLevelForMacMemoryPressure( |
| 24 DISPATCH_MEMORYPRESSURE_NORMAL)); | 26 DISPATCH_MEMORYPRESSURE_NORMAL)); |
| 25 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE, | 27 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE, |
| 26 TestMemoryPressureMonitorMac:: | 28 TestMemoryPressureMonitor:: |
| 27 MemoryPressureLevelForMacMemoryPressure( | 29 MemoryPressureLevelForMacMemoryPressure( |
| 28 DISPATCH_MEMORYPRESSURE_WARN)); | 30 DISPATCH_MEMORYPRESSURE_WARN)); |
| 29 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL, | 31 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL, |
| 30 TestMemoryPressureMonitorMac:: | 32 TestMemoryPressureMonitor:: |
| 31 MemoryPressureLevelForMacMemoryPressure( | 33 MemoryPressureLevelForMacMemoryPressure( |
| 32 DISPATCH_MEMORYPRESSURE_CRITICAL)); | 34 DISPATCH_MEMORYPRESSURE_CRITICAL)); |
| 33 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, | 35 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, |
| 34 TestMemoryPressureMonitorMac:: | 36 TestMemoryPressureMonitor:: |
| 35 MemoryPressureLevelForMacMemoryPressure(0)); | 37 MemoryPressureLevelForMacMemoryPressure(0)); |
| 36 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, | 38 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, |
| 37 TestMemoryPressureMonitorMac:: | 39 TestMemoryPressureMonitor:: |
| 38 MemoryPressureLevelForMacMemoryPressure(3)); | 40 MemoryPressureLevelForMacMemoryPressure(3)); |
| 39 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, | 41 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, |
| 40 TestMemoryPressureMonitorMac:: | 42 TestMemoryPressureMonitor:: |
| 41 MemoryPressureLevelForMacMemoryPressure(5)); | 43 MemoryPressureLevelForMacMemoryPressure(5)); |
| 42 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, | 44 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, |
| 43 TestMemoryPressureMonitorMac:: | 45 TestMemoryPressureMonitor:: |
| 44 MemoryPressureLevelForMacMemoryPressure(-1)); | 46 MemoryPressureLevelForMacMemoryPressure(-1)); |
| 45 } | 47 } |
| 46 | 48 |
| 47 TEST(TestMemoryPressureMonitorMac, CurrentMemoryPressure) { | 49 TEST(MacMemoryPressureMonitorTest, CurrentMemoryPressure) { |
| 48 TestMemoryPressureMonitorMac monitor; | 50 TestMemoryPressureMonitor monitor; |
| 49 MemoryPressureListener::MemoryPressureLevel memory_pressure = | 51 MemoryPressureListener::MemoryPressureLevel memory_pressure = |
| 50 monitor.GetCurrentPressureLevel(); | 52 monitor.GetCurrentPressureLevel(); |
| 51 EXPECT_TRUE(memory_pressure == | 53 EXPECT_TRUE(memory_pressure == |
| 52 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE || | 54 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE || |
| 53 memory_pressure == | 55 memory_pressure == |
| 54 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE || | 56 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE || |
| 55 memory_pressure == | 57 memory_pressure == |
| 56 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | 58 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 57 } | 59 } |
| 58 | 60 |
| 61 } // namespace mac |
| 59 } // namespace base | 62 } // namespace base |
| OLD | NEW |