1 // Copyright (c) 2012 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 #ifndef CHROMEOS_DBUS_FAKE_UPDATE_ENGINE_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_UPDATE_ENGINE_CLIENT_H_
11 #include "chromeos/dbus/update_engine_client.h"
15 // A fake implementation of UpdateEngineClient. The user of this class can
16 // use set_update_engine_client_status() to set a fake last Status and
17 // GetLastStatus() returns the fake with no modification. Other methods do
19 class FakeUpdateEngineClient
: public UpdateEngineClient
{
21 FakeUpdateEngineClient();
22 virtual ~FakeUpdateEngineClient();
24 // UpdateEngineClient overrides
25 virtual void Init(dbus::Bus
* bus
) OVERRIDE
;
26 virtual void AddObserver(Observer
* observer
) OVERRIDE
;
27 virtual void RemoveObserver(Observer
* observer
) OVERRIDE
;
28 virtual bool HasObserver(Observer
* observer
) OVERRIDE
;
29 virtual void RequestUpdateCheck(const UpdateCheckCallback
& callback
) OVERRIDE
;
30 virtual void RebootAfterUpdate() OVERRIDE
;
31 virtual void Rollback() OVERRIDE
;
32 virtual void CanRollbackCheck(
33 const RollbackCheckCallback
& callback
) OVERRIDE
;
34 virtual Status
GetLastStatus() OVERRIDE
;
35 virtual void SetChannel(const std::string
& target_channel
,
36 bool is_powerwash_allowed
) OVERRIDE
;
37 virtual void GetChannel(bool get_current_channel
,
38 const GetChannelCallback
& callback
) OVERRIDE
;
40 // Pushes UpdateEngineClient::Status in the queue to test changing status.
41 // GetLastStatus() returns the status set by this method in FIFO order.
42 // See set_default_status().
43 void PushLastStatus(const UpdateEngineClient::Status
& status
) {
44 status_queue_
.push(status
);
47 // Sends status change notification.
48 void NotifyObserversThatStatusChanged(
49 const UpdateEngineClient::Status
& status
);
51 // Sets the default UpdateEngineClient::Status. GetLastStatus() returns the
52 // value set here if |status_queue_| is empty.
53 void set_default_status(const UpdateEngineClient::Status
& status
);
55 // Sets a value returned by RequestUpdateCheck().
56 void set_update_check_result(
57 const UpdateEngineClient::UpdateCheckResult
& result
);
59 void set_can_rollback_check_result(bool result
) {
60 can_rollback_stub_result_
= result
;
63 // Returns how many times RebootAfterUpdate() is called.
64 int reboot_after_update_call_count() const {
65 return reboot_after_update_call_count_
;
68 // Returns how many times Rollback() is called.
69 int rollback_call_count() const { return rollback_call_count_
; }
71 // Returns how many times Rollback() is called.
72 int can_rollback_call_count() const { return can_rollback_call_count_
; }
75 ObserverList
<Observer
> observers_
;
76 std::queue
<UpdateEngineClient::Status
> status_queue_
;
77 UpdateEngineClient::Status default_status_
;
78 UpdateEngineClient::UpdateCheckResult update_check_result_
;
79 bool can_rollback_stub_result_
;
80 int reboot_after_update_call_count_
;
81 int rollback_call_count_
;
82 int can_rollback_call_count_
;
85 } // namespace chromeos
87 #endif // CHROMEOS_DBUS_FAKE_UPDATE_ENGINE_CLIENT_H_