1 // Copyright 2013 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 BASE_TEST_POWER_MONITOR_TEST_BASE_H_
6 #define BASE_TEST_POWER_MONITOR_TEST_BASE_H_
7 
8 #include "base/power_monitor/power_monitor.h"
9 #include "base/power_monitor/power_monitor_source.h"
10 
11 namespace base {
12 
13 class PowerMonitorTestSource : public PowerMonitorSource {
14  public:
15   PowerMonitorTestSource();
16   ~PowerMonitorTestSource() override;
17   PowerObserver::DeviceThermalState GetCurrentThermalState() override;
18 
19   void GeneratePowerStateEvent(bool on_battery_power);
20   void GenerateSuspendEvent();
21   void GenerateResumeEvent();
22   void GenerateThermalThrottlingEvent(
23       PowerObserver::DeviceThermalState new_thermal_state);
24 
25  protected:
26   bool IsOnBatteryPowerImpl() override;
27 
28   bool test_on_battery_power_ = false;
29   PowerObserver::DeviceThermalState current_thermal_state_ =
30       PowerObserver::DeviceThermalState::kUnknown;
31 };
32 
33 class PowerMonitorTestObserver : public PowerObserver {
34  public:
35   PowerMonitorTestObserver();
36   ~PowerMonitorTestObserver() override;
37 
38   // PowerObserver callbacks.
39   void OnPowerStateChange(bool on_battery_power) override;
40   void OnSuspend() override;
41   void OnResume() override;
42   void OnThermalStateChange(
43       PowerObserver::DeviceThermalState new_state) override;
44 
45   // Test status counts.
last_power_state()46   bool last_power_state() const { return last_power_state_; }
power_state_changes()47   int power_state_changes() const { return power_state_changes_; }
suspends()48   int suspends() const { return suspends_; }
resumes()49   int resumes() const { return resumes_; }
last_thermal_state()50   PowerObserver::DeviceThermalState last_thermal_state() const {
51     return last_thermal_state_;
52   }
53 
54  private:
55   bool last_power_state_;    // Last power state we were notified of.
56   int power_state_changes_;  // Count of OnPowerStateChange notifications.
57   int suspends_;             // Count of OnSuspend notifications.
58   int resumes_;              // Count of OnResume notifications.
59   PowerObserver::DeviceThermalState last_thermal_state_;
60 };
61 
62 }  // namespace base
63 
64 #endif  // BASE_TEST_POWER_MONITOR_TEST_BASE_H_
65