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 #ifndef CHROMEOS_DBUS_FAKE_SESSION_MANAGER_CLIENT_H_ 6 #define CHROMEOS_DBUS_FAKE_SESSION_MANAGER_CLIENT_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/basictypes.h" 12 #include "base/compiler_specific.h" 13 #include "base/observer_list.h" 14 #include "chromeos/dbus/session_manager_client.h" 15 16 namespace chromeos { 17 18 // A fake implementation of session_manager. Accepts policy blobs to be set and 19 // returns them unmodified. 20 class FakeSessionManagerClient : public SessionManagerClient { 21 public: 22 FakeSessionManagerClient(); 23 virtual ~FakeSessionManagerClient(); 24 25 // SessionManagerClient overrides 26 virtual void Init(dbus::Bus* bus) OVERRIDE; 27 virtual void AddObserver(Observer* observer) OVERRIDE; 28 virtual void RemoveObserver(Observer* observer) OVERRIDE; 29 virtual bool HasObserver(Observer* observer) OVERRIDE; 30 virtual void EmitLoginPromptReady() OVERRIDE; 31 virtual void EmitLoginPromptVisible() OVERRIDE; 32 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE; 33 virtual void StartSession(const std::string& user_email) OVERRIDE; 34 virtual void StopSession() OVERRIDE; 35 virtual void StartDeviceWipe() OVERRIDE; 36 virtual void RequestLockScreen() OVERRIDE; 37 virtual void NotifyLockScreenShown() OVERRIDE; 38 virtual void NotifyLockScreenDismissed() OVERRIDE; 39 virtual void RetrieveActiveSessions( 40 const ActiveSessionsCallback& callback) OVERRIDE; 41 virtual void RetrieveDevicePolicy( 42 const RetrievePolicyCallback& callback) OVERRIDE; 43 virtual void RetrievePolicyForUser( 44 const std::string& username, 45 const RetrievePolicyCallback& callback) OVERRIDE; 46 virtual std::string BlockingRetrievePolicyForUser( 47 const std::string& username) OVERRIDE; 48 virtual void RetrieveDeviceLocalAccountPolicy( 49 const std::string& account_id, 50 const RetrievePolicyCallback& callback) OVERRIDE; 51 virtual void StoreDevicePolicy(const std::string& policy_blob, 52 const StorePolicyCallback& callback) OVERRIDE; 53 virtual void StorePolicyForUser(const std::string& username, 54 const std::string& policy_blob, 55 const std::string& policy_key, 56 const StorePolicyCallback& callback) OVERRIDE; 57 virtual void StoreDeviceLocalAccountPolicy( 58 const std::string& account_id, 59 const std::string& policy_blob, 60 const StorePolicyCallback& callback) OVERRIDE; 61 virtual void SetFlagsForUser(const std::string& username, 62 const std::vector<std::string>& flags) OVERRIDE; 63 64 const std::string& device_policy() const; 65 void set_device_policy(const std::string& policy_blob); 66 67 const std::string& user_policy(const std::string& username) const; 68 void set_user_policy(const std::string& username, 69 const std::string& policy_blob); 70 71 const std::string& device_local_account_policy( 72 const std::string& account_id) const; 73 void set_device_local_account_policy(const std::string& account_id, 74 const std::string& policy_blob); 75 76 // Notify observers about a property change completion. 77 void OnPropertyChangeComplete(bool success); 78 79 // Returns how many times EmitLoginPromptReady() is called. emit_login_prompt_ready_call_count()80 int emit_login_prompt_ready_call_count() const { 81 return emit_login_prompt_ready_call_count_; 82 } 83 start_device_wipe_call_count()84 int start_device_wipe_call_count() const { 85 return start_device_wipe_call_count_; 86 } 87 88 // Returns how many times LockScreenShown() was called. notify_lock_screen_shown_call_count()89 int notify_lock_screen_shown_call_count() const { 90 return notify_lock_screen_shown_call_count_; 91 } 92 93 // Returns how many times LockScreenDismissed() was called. notify_lock_screen_dismissed_call_count()94 int notify_lock_screen_dismissed_call_count() const { 95 return notify_lock_screen_dismissed_call_count_; 96 } 97 98 private: 99 std::string device_policy_; 100 std::map<std::string, std::string> user_policies_; 101 std::map<std::string, std::string> device_local_account_policy_; 102 ObserverList<Observer> observers_; 103 SessionManagerClient::ActiveSessionsMap user_sessions_; 104 105 int emit_login_prompt_ready_call_count_; 106 int start_device_wipe_call_count_; 107 int notify_lock_screen_shown_call_count_; 108 int notify_lock_screen_dismissed_call_count_; 109 110 DISALLOW_COPY_AND_ASSIGN(FakeSessionManagerClient); 111 }; 112 113 } // namespace chromeos 114 115 #endif // CHROMEOS_DBUS_FAKE_SESSION_MANAGER_CLIENT_H_ 116