Home | History | Annotate | Download | only in test
      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 
     13 PowerMonitorTestSource::PowerMonitorTestSource()
     14     : test_on_battery_power_(false) {
     15 }
     16 
     17 PowerMonitorTestSource::~PowerMonitorTestSource() {
     18 }
     19 
     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();
     24 }
     25 
     26 void PowerMonitorTestSource::GenerateSuspendEvent() {
     27   ProcessPowerEvent(SUSPEND_EVENT);
     28   message_loop_.RunUntilIdle();
     29 }
     30 
     31 void PowerMonitorTestSource::GenerateResumeEvent() {
     32   ProcessPowerEvent(RESUME_EVENT);
     33   message_loop_.RunUntilIdle();
     34 }
     35 
     36 bool PowerMonitorTestSource::IsOnBatteryPowerImpl() {
     37   return test_on_battery_power_;
     38 };
     39 
     40 PowerMonitorTestObserver::PowerMonitorTestObserver()
     41     : last_power_state_(false),
     42       power_state_changes_(0),
     43       suspends_(0),
     44       resumes_(0) {
     45 }
     46 
     47 PowerMonitorTestObserver::~PowerMonitorTestObserver() {
     48 }
     49 
     50 // PowerObserver callbacks.
     51 void PowerMonitorTestObserver::OnPowerStateChange(bool on_battery_power) {
     52   last_power_state_ = on_battery_power;
     53   power_state_changes_++;
     54 }
     55 
     56 void PowerMonitorTestObserver::OnSuspend() {
     57   suspends_++;
     58 }
     59 
     60 void PowerMonitorTestObserver::OnResume() {
     61   resumes_++;
     62 }
     63 
     64 }  // namespace base
     65