Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / memory_pressure / test_memory_pressure_calculator.h
blobd41a3d060f2824a44762b8c3e3a70d1618427c00
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 #ifndef COMPONENTS_MEMORY_PRESSURE_TEST_MEMORY_PRESSURE_CALCULATOR_H_
6 #define COMPONENTS_MEMORY_PRESSURE_TEST_MEMORY_PRESSURE_CALCULATOR_H_
8 #include "components/memory_pressure/memory_pressure_calculator.h"
10 namespace memory_pressure {
12 #if defined(MEMORY_PRESSURE_IS_POLLING)
14 // A mock memory pressure calculator for unittesting.
15 class TestMemoryPressureCalculator : public MemoryPressureCalculator {
16 public:
17 TestMemoryPressureCalculator();
18 ~TestMemoryPressureCalculator() override {}
20 // MemoryPressureCalculator implementation.
21 MemoryPressureLevel CalculateCurrentPressureLevel() override;
23 // Sets the mock calculator to return no pressure.
24 void SetNone();
26 // Sets the mock calculator to return moderate pressure.
27 void SetModerate();
29 // Sets the mock calculator to return critical pressure.
30 void SetCritical();
32 // Resets the call counter to 'CalculateCurrentPressureLevel'.
33 void ResetCalls();
35 // Returns the number of calls to 'CalculateCurrentPressureLevel'.
36 int calls() const { return calls_; }
38 private:
39 MemoryPressureLevel level_;
40 int calls_;
42 DISALLOW_COPY_AND_ASSIGN(TestMemoryPressureCalculator);
45 #endif // defined(MEMORY_PRESSURE_IS_POLLING)
47 } // namespace memory_pressure
49 #endif // COMPONENTS_MEMORY_PRESSURE_TEST_MEMORY_PRESSURE_CALCULATOR_H_