power_monitor_test_base.h 2.1 KB

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