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 CHROME_BROWSER_CHROMEOS_LOGIN_FAKE_USER_MANAGER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_FAKE_USER_MANAGER_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/memory/scoped_ptr.h" 12 #include "chrome/browser/chromeos/login/user.h" 13 #include "chrome/browser/chromeos/login/user_flow.h" 14 #include "chrome/browser/chromeos/login/user_image.h" 15 #include "chrome/browser/chromeos/login/user_manager.h" 16 17 namespace chromeos { 18 19 class FakeSupervisedUserManager; 20 21 // Fake user manager with a barebones implementation. Users can be added 22 // and set as logged in, and those users can be returned. 23 class FakeUserManager : public UserManager { 24 public: 25 FakeUserManager(); 26 virtual ~FakeUserManager(); 27 28 // Create and add a new user. 29 const User* AddUser(const std::string& email); 30 31 // Create and add a kiosk app user. 32 void AddKioskAppUser(const std::string& kiosk_app_username); 33 34 // Calculates the user name hash and calls UserLoggedIn to login a user. 35 void LoginUser(const std::string& email); 36 37 // Associates |profile| with |user|, for GetProfileByUser(). 38 void SetProfileForUser(const User* user, Profile* profile); 39 40 // UserManager overrides. 41 virtual const UserList& GetUsers() const OVERRIDE; 42 virtual UserList GetUsersAdmittedForMultiProfile() const OVERRIDE; 43 virtual const UserList& GetLoggedInUsers() const OVERRIDE; 44 45 // Set the user as logged in. 46 virtual void UserLoggedIn(const std::string& email, 47 const std::string& username_hash, 48 bool browser_restart) OVERRIDE; 49 50 virtual const User* GetActiveUser() const OVERRIDE; 51 virtual User* GetActiveUser() OVERRIDE; 52 virtual void SwitchActiveUser(const std::string& email) OVERRIDE; 53 virtual void SaveUserDisplayName(const std::string& username, 54 const base::string16& display_name) OVERRIDE; 55 56 // Not implemented. 57 virtual void UpdateUserAccountData( 58 const std::string& user_id, 59 const UserAccountData& account_data) OVERRIDE {} 60 virtual void Shutdown() OVERRIDE {} 61 virtual UserImageManager* GetUserImageManager() OVERRIDE; 62 virtual SupervisedUserManager* GetSupervisedUserManager() OVERRIDE; 63 virtual const UserList& GetLRULoggedInUsers() OVERRIDE; 64 virtual UserList GetUnlockUsers() const OVERRIDE; 65 virtual const std::string& GetOwnerEmail() OVERRIDE; 66 virtual void SessionStarted() OVERRIDE {} 67 virtual void RestoreActiveSessions() OVERRIDE {} 68 virtual void RemoveUser(const std::string& email, 69 RemoveUserDelegate* delegate) OVERRIDE {} 70 virtual void RemoveUserFromList(const std::string& email) OVERRIDE {} 71 virtual bool IsKnownUser(const std::string& email) const OVERRIDE; 72 virtual const User* FindUser(const std::string& email) const OVERRIDE; 73 virtual User* FindUserAndModify(const std::string& email) OVERRIDE; 74 virtual const User* GetLoggedInUser() const OVERRIDE; 75 virtual User* GetLoggedInUser() OVERRIDE; 76 virtual const User* GetPrimaryUser() const OVERRIDE; 77 virtual Profile* GetProfileByUser(const User* profile) const OVERRIDE; 78 virtual User* GetUserByProfile(Profile* profile) const OVERRIDE; 79 virtual void SaveUserOAuthStatus( 80 const std::string& username, 81 User::OAuthTokenStatus oauth_token_status) OVERRIDE {} 82 virtual base::string16 GetUserDisplayName( 83 const std::string& username) const OVERRIDE; 84 virtual void SaveUserDisplayEmail(const std::string& username, 85 const std::string& display_email) OVERRIDE {} 86 virtual std::string GetUserDisplayEmail( 87 const std::string& username) const OVERRIDE; 88 virtual bool IsCurrentUserOwner() const OVERRIDE; 89 virtual bool IsCurrentUserNew() const OVERRIDE; 90 virtual bool IsCurrentUserNonCryptohomeDataEphemeral() const OVERRIDE; 91 virtual bool CanCurrentUserLock() const OVERRIDE; 92 virtual bool IsUserLoggedIn() const OVERRIDE; 93 virtual bool IsLoggedInAsRegularUser() const OVERRIDE; 94 virtual bool IsLoggedInAsDemoUser() const OVERRIDE; 95 virtual bool IsLoggedInAsPublicAccount() const OVERRIDE; 96 virtual bool IsLoggedInAsGuest() const OVERRIDE; 97 virtual bool IsLoggedInAsLocallyManagedUser() const OVERRIDE; 98 virtual bool IsLoggedInAsKioskApp() const OVERRIDE; 99 virtual bool IsLoggedInAsStub() const OVERRIDE; 100 virtual bool IsSessionStarted() const OVERRIDE; 101 virtual bool UserSessionsRestored() const OVERRIDE; 102 virtual bool HasBrowserRestarted() const OVERRIDE; 103 virtual bool IsUserNonCryptohomeDataEphemeral( 104 const std::string& email) const OVERRIDE; 105 virtual void SetUserFlow(const std::string& email, UserFlow* flow) OVERRIDE {} 106 virtual UserFlow* GetCurrentUserFlow() const OVERRIDE; 107 virtual UserFlow* GetUserFlow(const std::string& email) const OVERRIDE; 108 virtual void ResetUserFlow(const std::string& email) OVERRIDE {} 109 virtual bool GetAppModeChromeClientOAuthInfo( 110 std::string* chrome_client_id, 111 std::string* chrome_client_secret) OVERRIDE; 112 virtual void SetAppModeChromeClientOAuthInfo( 113 const std::string& chrome_client_id, 114 const std::string& chrome_client_secret) OVERRIDE {} 115 virtual void AddObserver(Observer* obs) OVERRIDE {} 116 virtual void RemoveObserver(Observer* obs) OVERRIDE {} 117 virtual void AddSessionStateObserver( 118 UserSessionStateObserver* obs) OVERRIDE {} 119 virtual void RemoveSessionStateObserver( 120 UserSessionStateObserver* obs) OVERRIDE {} 121 virtual void NotifyLocalStateChanged() OVERRIDE {} 122 virtual bool AreLocallyManagedUsersAllowed() const OVERRIDE; 123 virtual base::FilePath GetUserProfileDir(const std::string& email) const 124 OVERRIDE; 125 virtual bool RespectLocalePreference( 126 Profile* profile, 127 const User* user, 128 scoped_ptr<locale_util::SwitchLanguageCallback> callback) const OVERRIDE; 129 130 void set_owner_email(const std::string& owner_email) { 131 owner_email_ = owner_email; 132 } 133 134 private: 135 // We use this internal function for const-correctness. 136 User* GetActiveUserInternal() const; 137 138 scoped_ptr<FakeSupervisedUserManager> supervised_user_manager_; 139 UserList user_list_; 140 UserList logged_in_users_; 141 std::string owner_email_; 142 User* primary_user_; 143 std::map<const User*, Profile*> user_to_profile_; 144 145 // If set this is the active user. If empty, the first created user is the 146 // active user. 147 std::string active_user_id_; 148 149 DISALLOW_COPY_AND_ASSIGN(FakeUserManager); 150 }; 151 152 } // namespace chromeos 153 154 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_FAKE_USER_MANAGER_H_ 155