1 // Copyright (c) 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 CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_ 6 #define CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/observer_list.h" 12 #include "base/time/time.h" 13 #include "chromeos/dbus/power_manager/policy.pb.h" 14 #include "chromeos/dbus/power_manager/suspend.pb.h" 15 #include "chromeos/dbus/power_manager_client.h" 16 17 namespace chromeos { 18 19 // A fake implementation of PowerManagerClient. This remembers the policy passed 20 // to SetPolicy() and the user of this class can inspect the last set policy by 21 // get_policy(). 22 class FakePowerManagerClient : public PowerManagerClient { 23 public: 24 FakePowerManagerClient(); 25 virtual ~FakePowerManagerClient(); 26 27 // PowerManagerClient overrides 28 virtual void Init(dbus::Bus* bus) OVERRIDE; 29 virtual void AddObserver(Observer* observer) OVERRIDE; 30 virtual void RemoveObserver(Observer* observer) OVERRIDE; 31 virtual bool HasObserver(Observer* observer) OVERRIDE; 32 virtual void DecreaseScreenBrightness(bool allow_off) OVERRIDE; 33 virtual void IncreaseScreenBrightness() OVERRIDE; 34 virtual void SetScreenBrightnessPercent( 35 double percent, bool gradual) OVERRIDE; 36 virtual void GetScreenBrightnessPercent( 37 const GetScreenBrightnessPercentCallback& callback) OVERRIDE; 38 virtual void DecreaseKeyboardBrightness() OVERRIDE; 39 virtual void IncreaseKeyboardBrightness() OVERRIDE; 40 virtual void RequestStatusUpdate() OVERRIDE; 41 virtual void RequestRestart() OVERRIDE; 42 virtual void RequestShutdown() OVERRIDE; 43 virtual void NotifyUserActivity( 44 power_manager::UserActivityType type) OVERRIDE; 45 virtual void NotifyVideoActivity(bool is_fullscreen) OVERRIDE; 46 virtual void SetPolicy( 47 const power_manager::PowerManagementPolicy& policy) OVERRIDE; 48 virtual void SetIsProjecting(bool is_projecting) OVERRIDE; 49 virtual base::Closure GetSuspendReadinessCallback() OVERRIDE; 50 virtual int GetNumPendingSuspendReadinessCallbacks() OVERRIDE; 51 get_policy()52 power_manager::PowerManagementPolicy& get_policy() { return policy_; } 53 54 // Returns how many times RequestRestart() was called. request_restart_call_count()55 int request_restart_call_count() const { 56 return request_restart_call_count_; 57 } 58 59 // Emulates that the dbus server sends a message "SuspendImminent" to the 60 // client. 61 void SendSuspendImminent(); 62 63 // Emulates that the dbus server sends a message "SuspendStateChanged" to the 64 // client. 65 void SendSuspendStateChanged( 66 const power_manager::SuspendState& suspend_state); 67 68 private: 69 power_manager::PowerManagementPolicy policy_; 70 base::Time last_suspend_wall_time_; 71 ObserverList<Observer> observers_; 72 int request_restart_call_count_; 73 74 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient); 75 }; 76 77 } // namespace chromeos 78 79 #endif // CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_ 80