James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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/message_loop/message_loop.h" |
| 9 | #include "base/power_monitor/power_monitor.h" |
| 10 | #include "base/power_monitor/power_monitor_source.h" |
| 11 | |
| 12 | namespace base { |
| 13 | |
| 14 | class PowerMonitorTestSource : public PowerMonitorSource { |
| 15 | public: |
| 16 | PowerMonitorTestSource(); |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 17 | ~PowerMonitorTestSource() override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 18 | |
| 19 | void GeneratePowerStateEvent(bool on_battery_power); |
| 20 | void GenerateSuspendEvent(); |
| 21 | void GenerateResumeEvent(); |
| 22 | |
| 23 | protected: |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 24 | bool IsOnBatteryPowerImpl() override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 25 | |
| 26 | bool test_on_battery_power_; |
| 27 | MessageLoop message_loop_; |
| 28 | }; |
| 29 | |
| 30 | class PowerMonitorTestObserver : public PowerObserver { |
| 31 | public: |
| 32 | PowerMonitorTestObserver(); |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 33 | ~PowerMonitorTestObserver() override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 34 | |
| 35 | // PowerObserver callbacks. |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 36 | void OnPowerStateChange(bool on_battery_power) override; |
| 37 | void OnSuspend() override; |
| 38 | void OnResume() override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 39 | |
| 40 | // Test status counts. |
| 41 | bool last_power_state() { return last_power_state_; } |
| 42 | int power_state_changes() { return power_state_changes_; } |
| 43 | int suspends() { return suspends_; } |
| 44 | int resumes() { return resumes_; } |
| 45 | |
| 46 | private: |
| 47 | bool last_power_state_; // Last power state we were notified of. |
| 48 | int power_state_changes_; // Count of OnPowerStateChange notifications. |
| 49 | int suspends_; // Count of OnSuspend notifications. |
| 50 | int resumes_; // Count of OnResume notifications. |
| 51 | }; |
| 52 | |
| 53 | } // namespace base |
| 54 | |
| 55 | #endif // BASE_TEST_POWER_MONITOR_TEST_BASE_H_ |