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