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. 4 5 #ifndef CHROMEOS_DBUS_FAKE_UPDATE_ENGINE_CLIENT_H_ 6 #define CHROMEOS_DBUS_FAKE_UPDATE_ENGINE_CLIENT_H_ 7 8 #include <queue> 9 #include <string> 10 11 #include "chromeos/dbus/update_engine_client.h" 12 13 namespace chromeos { 14 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 18 // nothing. 19 class FakeUpdateEngineClient : public UpdateEngineClient { 20 public: 21 FakeUpdateEngineClient(); 22 virtual ~FakeUpdateEngineClient(); 23 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; 39 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(). PushLastStatus(const UpdateEngineClient::Status & status)43 void PushLastStatus(const UpdateEngineClient::Status& status) { 44 status_queue_.push(status); 45 } 46 47 // Sends status change notification. 48 void NotifyObserversThatStatusChanged( 49 const UpdateEngineClient::Status& status); 50 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); 54 55 // Sets a value returned by RequestUpdateCheck(). 56 void set_update_check_result( 57 const UpdateEngineClient::UpdateCheckResult& result); 58 set_can_rollback_check_result(bool result)59 void set_can_rollback_check_result(bool result) { 60 can_rollback_stub_result_ = result; 61 } 62 63 // Returns how many times RebootAfterUpdate() is called. reboot_after_update_call_count()64 int reboot_after_update_call_count() const { 65 return reboot_after_update_call_count_; 66 } 67 68 // Returns how many times Rollback() is called. rollback_call_count()69 int rollback_call_count() const { return rollback_call_count_; } 70 71 // Returns how many times Rollback() is called. can_rollback_call_count()72 int can_rollback_call_count() const { return can_rollback_call_count_; } 73 74 private: 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_; 83 }; 84 85 } // namespace chromeos 86 87 #endif // CHROMEOS_DBUS_FAKE_UPDATE_ENGINE_CLIENT_H_ 88