Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chromeos / dbus / fake_power_manager_client.h
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   power_manager::PowerManagementPolicy& policy() { return policy_; }
28   int num_request_restart_calls() const {
29     return num_request_restart_calls_;
30   }
31   int num_set_policy_calls() const {
32     return num_set_policy_calls_;
33   }
34   int num_set_is_projecting_calls() const {
35     return num_set_is_projecting_calls_;
36   }
37   bool is_projecting() const {
38     return is_projecting_;
39   }
40
41   // PowerManagerClient overrides
42   virtual void Init(dbus::Bus* bus) OVERRIDE;
43   virtual void AddObserver(Observer* observer) OVERRIDE;
44   virtual void RemoveObserver(Observer* observer) OVERRIDE;
45   virtual bool HasObserver(Observer* observer) OVERRIDE;
46   virtual void DecreaseScreenBrightness(bool allow_off) OVERRIDE;
47   virtual void IncreaseScreenBrightness() OVERRIDE;
48   virtual void SetScreenBrightnessPercent(
49       double percent, bool gradual) OVERRIDE;
50   virtual void GetScreenBrightnessPercent(
51       const GetScreenBrightnessPercentCallback& callback) OVERRIDE;
52   virtual void DecreaseKeyboardBrightness() OVERRIDE;
53   virtual void IncreaseKeyboardBrightness() OVERRIDE;
54   virtual void RequestStatusUpdate() OVERRIDE;
55   virtual void RequestRestart() OVERRIDE;
56   virtual void RequestShutdown() OVERRIDE;
57   virtual void NotifyUserActivity(
58       power_manager::UserActivityType type) OVERRIDE;
59   virtual void NotifyVideoActivity(bool is_fullscreen) OVERRIDE;
60   virtual void SetPolicy(
61       const power_manager::PowerManagementPolicy& policy) OVERRIDE;
62   virtual void SetIsProjecting(bool is_projecting) OVERRIDE;
63   virtual base::Closure GetSuspendReadinessCallback() OVERRIDE;
64   virtual int GetNumPendingSuspendReadinessCallbacks() OVERRIDE;
65
66   // Emulates that the dbus server sends a message "SuspendImminent" to the
67   // client.
68   void SendSuspendImminent();
69
70   // Emulates that the dbus server sends a message "SuspendStateChanged" to the
71   // client.
72   void SendSuspendStateChanged(
73       const power_manager::SuspendState& suspend_state);
74
75  private:
76   ObserverList<Observer> observers_;
77
78   // Last policy passed to SetPolicy().
79   power_manager::PowerManagementPolicy policy_;
80
81   // Last time passed to a SUSPEND_TO_MEMORY call to SendSuspendStateChanged().
82   base::Time last_suspend_wall_time_;
83
84   // Number of times that RequestRestart() has been called.
85   int num_request_restart_calls_;
86
87   // Number of times that SetPolicy() has been called.
88   int num_set_policy_calls_;
89
90   // Count the number of times SetIsProjecting() has been called.
91   int num_set_is_projecting_calls_;
92
93   // Last projecting state set in SetIsProjecting().
94   bool is_projecting_;
95
96   DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient);
97 };
98
99 }  // namespace chromeos
100
101 #endif  // CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_