OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_MEMORY_PRESSURE_TEST_MEMORY_PRESSURE_CALCULATOR_H_ | |
6 #define COMPONENTS_MEMORY_PRESSURE_TEST_MEMORY_PRESSURE_CALCULATOR_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "components/memory_pressure/memory_pressure_calculator.h" | |
10 | |
11 namespace memory_pressure { | |
12 | |
13 #if defined(MEMORY_PRESSURE_IS_POLLING) | |
14 | |
15 // A mock memory pressure calculator for unittesting. | |
16 class TestMemoryPressureCalculator : public MemoryPressureCalculator { | |
17 public: | |
18 // Defaults to no pressure. | |
19 TestMemoryPressureCalculator(); | |
20 explicit TestMemoryPressureCalculator(MemoryPressureLevel level); | |
21 ~TestMemoryPressureCalculator() override {} | |
22 | |
23 // MemoryPressureCalculator implementation. | |
24 MemoryPressureLevel CalculateCurrentPressureLevel() override; | |
25 | |
26 // Sets the mock calculator to return the given pressure level. | |
27 void SetLevel(MemoryPressureLevel level); | |
28 | |
29 // Sets the mock calculator to return no pressure. | |
30 void SetNone(); | |
31 | |
32 // Sets the mock calculator to return moderate pressure. | |
33 void SetModerate(); | |
34 | |
35 // Sets the mock calculator to return critical pressure. | |
36 void SetCritical(); | |
37 | |
38 // Resets the call counter to 'CalculateCurrentPressureLevel'. | |
39 void ResetCalls(); | |
40 | |
41 // Returns the number of calls to 'CalculateCurrentPressureLevel'. | |
42 int calls() const { return calls_; } | |
43 | |
44 private: | |
45 MemoryPressureLevel level_; | |
46 int calls_; | |
47 | |
48 DISALLOW_COPY_AND_ASSIGN(TestMemoryPressureCalculator); | |
49 }; | |
50 | |
51 #endif // defined(MEMORY_PRESSURE_IS_POLLING) | |
52 | |
53 } // namespace memory_pressure | |
54 | |
55 #endif // COMPONENTS_MEMORY_PRESSURE_TEST_MEMORY_PRESSURE_CALCULATOR_H_ | |
OLD | NEW |