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 CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_USER_MANAGER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_USER_MANAGER_H_ 7 8 #include <string> 9 10 #include "base/files/file_path.h" 11 #include "base/memory/weak_ptr.h" 12 #include "chrome/browser/chromeos/login/mock_user_image_manager.h" 13 #include "chrome/browser/chromeos/login/user.h" 14 #include "chrome/browser/chromeos/login/user_flow.h" 15 #include "chrome/browser/chromeos/login/user_image.h" 16 #include "chrome/browser/chromeos/login/user_manager.h" 17 #include "testing/gmock/include/gmock/gmock.h" 18 19 namespace chromeos { 20 21 class MockUserManager : public UserManager { 22 public: 23 MockUserManager(); 24 virtual ~MockUserManager(); 25 26 MOCK_METHOD0(Shutdown, void(void)); 27 MOCK_CONST_METHOD0(GetUsers, const UserList&(void)); 28 MOCK_CONST_METHOD0(GetUsersAdmittedForMultiProfile, UserList(void)); 29 MOCK_CONST_METHOD0(GetLoggedInUsers, const UserList&(void)); 30 MOCK_METHOD0(GetLRULoggedInUsers, const UserList&(void)); 31 MOCK_METHOD3(UserLoggedIn, void( 32 const std::string&, const std::string&, bool)); 33 MOCK_METHOD1(SwitchActiveUser, void(const std::string& email)); 34 MOCK_METHOD0(SessionStarted, void(void)); 35 MOCK_METHOD0(RestoreActiveSessions, void(void)); 36 MOCK_METHOD2(RemoveUser, void(const std::string&, RemoveUserDelegate*)); 37 MOCK_METHOD1(RemoveUserFromList, void(const std::string&)); 38 MOCK_CONST_METHOD1(IsKnownUser, bool(const std::string&)); 39 MOCK_CONST_METHOD1(FindUser, const User*(const std::string&)); 40 MOCK_CONST_METHOD1(FindLocallyManagedUser, const User*(const string16&)); 41 MOCK_METHOD2(SaveUserOAuthStatus, void(const std::string&, 42 User::OAuthTokenStatus)); 43 MOCK_METHOD2(SaveUserDisplayName, void(const std::string&, 44 const string16&)); 45 MOCK_CONST_METHOD1(GetUserDisplayName, string16(const std::string&)); 46 MOCK_METHOD2(SaveUserDisplayEmail, void(const std::string&, 47 const std::string&)); 48 MOCK_CONST_METHOD1(GetUserDisplayEmail, std::string(const std::string&)); 49 MOCK_CONST_METHOD0(IsCurrentUserOwner, bool(void)); 50 MOCK_CONST_METHOD0(IsCurrentUserNew, bool(void)); 51 MOCK_CONST_METHOD0(IsCurrentUserNonCryptohomeDataEphemeral, bool(void)); 52 MOCK_CONST_METHOD0(CanCurrentUserLock, bool(void)); 53 MOCK_CONST_METHOD0(IsUserLoggedIn, bool(void)); 54 MOCK_CONST_METHOD0(IsLoggedInAsRegularUser, bool(void)); 55 MOCK_CONST_METHOD0(IsLoggedInAsDemoUser, bool(void)); 56 MOCK_CONST_METHOD0(IsLoggedInAsPublicAccount, bool(void)); 57 MOCK_CONST_METHOD0(IsLoggedInAsGuest, bool(void)); 58 MOCK_CONST_METHOD0(IsLoggedInAsLocallyManagedUser, bool(void)); 59 MOCK_CONST_METHOD0(IsLoggedInAsKioskApp, bool(void)); 60 MOCK_CONST_METHOD0(IsLoggedInAsStub, bool(void)); 61 MOCK_CONST_METHOD0(IsSessionStarted, bool(void)); 62 MOCK_CONST_METHOD0(UserSessionsRestored, bool(void)); 63 MOCK_CONST_METHOD0(HasBrowserRestarted, bool(void)); 64 MOCK_CONST_METHOD1(IsUserNonCryptohomeDataEphemeral, 65 bool(const std::string&)); 66 MOCK_METHOD1(AddObserver, void(UserManager::Observer*)); 67 MOCK_METHOD1(RemoveObserver, void(UserManager::Observer*)); 68 MOCK_METHOD1(AddSessionStateObserver, 69 void(UserManager::UserSessionStateObserver*)); 70 MOCK_METHOD1(RemoveSessionStateObserver, 71 void(UserManager::UserSessionStateObserver*)); 72 MOCK_METHOD0(NotifyLocalStateChanged, void(void)); 73 MOCK_CONST_METHOD0(GetMergeSessionState, MergeSessionState(void)); 74 MOCK_METHOD1(SetMergeSessionState, void(MergeSessionState)); 75 MOCK_METHOD2(SetUserFlow, void(const std::string&, UserFlow*)); 76 MOCK_METHOD1(ResetUserFlow, void(const std::string&)); 77 MOCK_METHOD4(CreateLocallyManagedUserRecord, const User*( 78 const std::string&, 79 const std::string&, 80 const std::string&, 81 const string16&)); 82 MOCK_CONST_METHOD1(GetManagedUserSyncId, std::string( 83 const std::string& managed_user_id)); 84 MOCK_CONST_METHOD1(GetManagerDisplayNameForManagedUser, string16( 85 const std::string&)); 86 MOCK_CONST_METHOD1(GetManagerUserIdForManagedUser, std::string( 87 const std::string&)); 88 MOCK_CONST_METHOD1(GetManagerDisplayEmailForManagedUser, std::string( 89 const std::string&)); 90 MOCK_METHOD0(GenerateUniqueLocallyManagedUserId, std::string(void)); 91 MOCK_METHOD1(StartLocallyManagedUserCreationTransaction, 92 void(const string16&)); 93 MOCK_METHOD1(SetLocallyManagedUserCreationTransactionUserId, 94 void(const std::string&)); 95 MOCK_METHOD0(CommitLocallyManagedUserCreationTransaction, void(void)); 96 97 MOCK_METHOD2(GetAppModeChromeClientOAuthInfo, bool(std::string*, 98 std::string*)); 99 MOCK_METHOD2(SetAppModeChromeClientOAuthInfo, void(const std::string&, 100 const std::string&)); 101 MOCK_CONST_METHOD0(AreLocallyManagedUsersAllowed, bool(void)); 102 103 // You can't mock these functions easily because nobody can create 104 // User objects but the UserManagerImpl and us. 105 virtual const User* GetLoggedInUser() const OVERRIDE; 106 virtual User* GetLoggedInUser() OVERRIDE; 107 virtual const User* GetActiveUser() const OVERRIDE; 108 virtual User* GetActiveUser() OVERRIDE; 109 110 virtual UserImageManager* GetUserImageManager() OVERRIDE; 111 112 virtual UserFlow* GetCurrentUserFlow() const OVERRIDE; 113 virtual UserFlow* GetUserFlow(const std::string&) const OVERRIDE; 114 115 // Sets a new User instance. 116 void SetActiveUser(const std::string& email); 117 118 // Creates a new public session user. Users previously created by this 119 // MockUserManager become invalid. 120 User* CreatePublicAccountUser(const std::string& email); 121 122 User* user_; 123 scoped_ptr<MockUserImageManager> user_image_manager_; 124 scoped_ptr<UserFlow> user_flow_; 125 }; 126 127 } // namespace chromeos 128 129 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_USER_MANAGER_H_ 130