Roll src/third_party/WebKit 57aef96:a1089e6 (svn 201978:201979)
[chromium-blink-merge.git] / base / test / power_monitor_test_base.cc
blob73438ea3e94958585642afcd645b8293b2c1c705
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.
5 #include "base/test/power_monitor_test_base.h"
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"
11 namespace base {
13 PowerMonitorTestSource::PowerMonitorTestSource()
14 : test_on_battery_power_(false) {
17 PowerMonitorTestSource::~PowerMonitorTestSource() {
20 void PowerMonitorTestSource::GeneratePowerStateEvent(bool on_battery_power) {
21 test_on_battery_power_ = on_battery_power;
22 ProcessPowerEvent(POWER_STATE_EVENT);
23 message_loop_.RunUntilIdle();
26 void PowerMonitorTestSource::GenerateSuspendEvent() {
27 ProcessPowerEvent(SUSPEND_EVENT);
28 message_loop_.RunUntilIdle();
31 void PowerMonitorTestSource::GenerateResumeEvent() {
32 ProcessPowerEvent(RESUME_EVENT);
33 message_loop_.RunUntilIdle();
36 bool PowerMonitorTestSource::IsOnBatteryPowerImpl() {
37 return test_on_battery_power_;
40 PowerMonitorTestObserver::PowerMonitorTestObserver()
41 : last_power_state_(false),
42 power_state_changes_(0),
43 suspends_(0),
44 resumes_(0) {
47 PowerMonitorTestObserver::~PowerMonitorTestObserver() {
50 // PowerObserver callbacks.
51 void PowerMonitorTestObserver::OnPowerStateChange(bool on_battery_power) {
52 last_power_state_ = on_battery_power;
53 power_state_changes_++;
56 void PowerMonitorTestObserver::OnSuspend() {
57 suspends_++;
60 void PowerMonitorTestObserver::OnResume() {
61 resumes_++;
64 } // namespace base