• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   void Shutdown() override;
18 
19   void GeneratePowerStateEvent(bool on_battery_power);
20   void GenerateSuspendEvent();
21   void GenerateResumeEvent();
22 
23  protected:
24   bool IsOnBatteryPowerImpl() override;
25 
26   bool test_on_battery_power_;
27 };
28 
29 class PowerMonitorTestObserver : public PowerObserver {
30  public:
31   PowerMonitorTestObserver();
32   ~PowerMonitorTestObserver() override;
33 
34   // PowerObserver callbacks.
35   void OnPowerStateChange(bool on_battery_power) override;
36   void OnSuspend() override;
37   void OnResume() override;
38 
39   // Test status counts.
last_power_state()40   bool last_power_state() { return last_power_state_; }
power_state_changes()41   int power_state_changes() { return power_state_changes_; }
suspends()42   int suspends() { return suspends_; }
resumes()43   int resumes() { return resumes_; }
44 
45  private:
46   bool last_power_state_; // Last power state we were notified of.
47   int power_state_changes_;  // Count of OnPowerStateChange notifications.
48   int suspends_;  // Count of OnSuspend notifications.
49   int resumes_;  // Count of OnResume notifications.
50 };
51 
52 }  // namespace base
53 
54 #endif  // BASE_TEST_POWER_MONITOR_TEST_BASE_H_
55