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 #include "base/test/power_monitor_test_base.h" 6 7 #include "base/message_loop/message_loop.h" 8 #include "base/power_monitor/power_monitor.h" 9 #include "base/power_monitor/power_monitor_source.h" 10 11 namespace base { 12 PowerMonitorTestSource()13PowerMonitorTestSource::PowerMonitorTestSource() 14 : test_on_battery_power_(false) { 15 } 16 ~PowerMonitorTestSource()17PowerMonitorTestSource::~PowerMonitorTestSource() { 18 } 19 GeneratePowerStateEvent(bool on_battery_power)20void PowerMonitorTestSource::GeneratePowerStateEvent(bool on_battery_power) { 21 test_on_battery_power_ = on_battery_power; 22 ProcessPowerEvent(POWER_STATE_EVENT); 23 message_loop_.RunUntilIdle(); 24 } 25 GenerateSuspendEvent()26void PowerMonitorTestSource::GenerateSuspendEvent() { 27 ProcessPowerEvent(SUSPEND_EVENT); 28 message_loop_.RunUntilIdle(); 29 } 30 GenerateResumeEvent()31void PowerMonitorTestSource::GenerateResumeEvent() { 32 ProcessPowerEvent(RESUME_EVENT); 33 message_loop_.RunUntilIdle(); 34 } 35 IsOnBatteryPowerImpl()36bool PowerMonitorTestSource::IsOnBatteryPowerImpl() { 37 return test_on_battery_power_; 38 }; 39 PowerMonitorTestObserver()40PowerMonitorTestObserver::PowerMonitorTestObserver() 41 : last_power_state_(false), 42 power_state_changes_(0), 43 suspends_(0), 44 resumes_(0) { 45 } 46 ~PowerMonitorTestObserver()47PowerMonitorTestObserver::~PowerMonitorTestObserver() { 48 } 49 50 // PowerObserver callbacks. OnPowerStateChange(bool on_battery_power)51void PowerMonitorTestObserver::OnPowerStateChange(bool on_battery_power) { 52 last_power_state_ = on_battery_power; 53 power_state_changes_++; 54 } 55 OnSuspend()56void PowerMonitorTestObserver::OnSuspend() { 57 suspends_++; 58 } 59 OnResume()60void PowerMonitorTestObserver::OnResume() { 61 resumes_++; 62 } 63 64 } // namespace base 65