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
3 // found in the LICENSE file.
5 #include "base/mac/memory_pressure_monitor_mac.h"
6 #include "testing/gtest/include/gtest/gtest.h"
10 class TestMemoryPressureMonitorMac
: public MemoryPressureMonitorMac
{
12 using MemoryPressureMonitorMac::MemoryPressureLevelForMacMemoryPressure
;
14 TestMemoryPressureMonitorMac() { }
17 DISALLOW_COPY_AND_ASSIGN(TestMemoryPressureMonitorMac
);
20 TEST(TestMemoryPressureMonitorMac
, MemoryPressureFromMacMemoryPressure
) {
21 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE
,
22 TestMemoryPressureMonitorMac::
23 MemoryPressureLevelForMacMemoryPressure(
24 DISPATCH_MEMORYPRESSURE_NORMAL
));
25 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE
,
26 TestMemoryPressureMonitorMac::
27 MemoryPressureLevelForMacMemoryPressure(
28 DISPATCH_MEMORYPRESSURE_WARN
));
29 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL
,
30 TestMemoryPressureMonitorMac::
31 MemoryPressureLevelForMacMemoryPressure(
32 DISPATCH_MEMORYPRESSURE_CRITICAL
));
33 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE
,
34 TestMemoryPressureMonitorMac::
35 MemoryPressureLevelForMacMemoryPressure(0));
36 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE
,
37 TestMemoryPressureMonitorMac::
38 MemoryPressureLevelForMacMemoryPressure(3));
39 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE
,
40 TestMemoryPressureMonitorMac::
41 MemoryPressureLevelForMacMemoryPressure(5));
42 EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE
,
43 TestMemoryPressureMonitorMac::
44 MemoryPressureLevelForMacMemoryPressure(-1));
47 TEST(TestMemoryPressureMonitorMac
, CurrentMemoryPressure
) {
48 TestMemoryPressureMonitorMac monitor
;
49 MemoryPressureListener::MemoryPressureLevel memory_pressure
=
50 monitor
.GetCurrentPressureLevel();
51 EXPECT_TRUE(memory_pressure
==
52 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE
||
54 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE
||
56 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL
);