1 // Copyright 2014 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 CHROME_BROWSER_CHROMEOS_LOGIN_USERS_MOCK_USER_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_MOCK_USER_MANAGER_H_
10 #include "base/files/file_path.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/chromeos/login/user_flow.h"
13 #include "chrome/browser/chromeos/login/users/affiliation.h"
14 #include "chrome/browser/chromeos/login/users/avatar/mock_user_image_manager.h"
15 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
16 #include "components/user_manager/user.h"
17 #include "components/user_manager/user_image/user_image.h"
18 #include "testing/gmock/include/gmock/gmock.h"
22 class FakeSupervisedUserManager
;
24 class MockUserManager
: public ChromeUserManager
{
27 virtual ~MockUserManager();
29 MOCK_METHOD0(Shutdown
, void(void));
30 MOCK_CONST_METHOD0(GetUsersAllowedForMultiProfile
,
31 user_manager::UserList(void));
32 MOCK_CONST_METHOD0(GetUsersAllowedForSupervisedUsersCreation
,
33 user_manager::UserList(void));
34 MOCK_CONST_METHOD0(GetLoggedInUsers
, const user_manager::UserList
&(void));
35 MOCK_CONST_METHOD0(GetLRULoggedInUsers
, const user_manager::UserList
&(void));
36 MOCK_METHOD3(UserLoggedIn
, void(
37 const std::string
&, const std::string
&, bool));
38 MOCK_METHOD1(SwitchActiveUser
, void(const std::string
& email
));
39 MOCK_METHOD0(SessionStarted
, void(void));
40 MOCK_METHOD2(RemoveUser
,
41 void(const std::string
&, user_manager::RemoveUserDelegate
*));
42 MOCK_METHOD1(RemoveUserFromList
, void(const std::string
&));
43 MOCK_CONST_METHOD1(IsKnownUser
, bool(const std::string
&));
44 MOCK_CONST_METHOD1(FindUser
, const user_manager::User
*(const std::string
&));
45 MOCK_METHOD1(FindUserAndModify
, user_manager::User
*(const std::string
&));
46 MOCK_METHOD2(SaveUserOAuthStatus
,
47 void(const std::string
&, user_manager::User::OAuthTokenStatus
));
48 MOCK_METHOD2(SaveForceOnlineSignin
, void(const std::string
&, bool));
49 MOCK_METHOD2(SaveUserDisplayName
, void(const std::string
&,
50 const base::string16
&));
51 MOCK_METHOD2(UpdateUserAccountData
,
52 void(const std::string
&, const UserAccountData
&));
53 MOCK_CONST_METHOD1(GetUserDisplayName
, base::string16(const std::string
&));
54 MOCK_METHOD2(SaveUserDisplayEmail
, void(const std::string
&,
56 MOCK_CONST_METHOD1(GetUserDisplayEmail
, std::string(const std::string
&));
57 MOCK_CONST_METHOD0(IsCurrentUserOwner
, bool(void));
58 MOCK_CONST_METHOD0(IsCurrentUserNew
, bool(void));
59 MOCK_CONST_METHOD0(IsCurrentUserNonCryptohomeDataEphemeral
, bool(void));
60 MOCK_CONST_METHOD0(CanCurrentUserLock
, bool(void));
61 MOCK_CONST_METHOD0(IsUserLoggedIn
, bool(void));
62 MOCK_CONST_METHOD0(IsLoggedInAsUserWithGaiaAccount
, bool(void));
63 MOCK_CONST_METHOD0(IsLoggedInAsPublicAccount
, bool(void));
64 MOCK_CONST_METHOD0(IsLoggedInAsGuest
, bool(void));
65 MOCK_CONST_METHOD0(IsLoggedInAsSupervisedUser
, bool(void));
66 MOCK_CONST_METHOD0(IsLoggedInAsKioskApp
, bool(void));
67 MOCK_CONST_METHOD0(IsLoggedInAsStub
, bool(void));
68 MOCK_CONST_METHOD0(IsSessionStarted
, bool(void));
69 MOCK_CONST_METHOD1(IsUserNonCryptohomeDataEphemeral
,
70 bool(const std::string
&));
71 MOCK_METHOD1(AddObserver
, void(UserManager::Observer
*));
72 MOCK_METHOD1(RemoveObserver
, void(UserManager::Observer
*));
73 MOCK_METHOD1(AddSessionStateObserver
,
74 void(UserManager::UserSessionStateObserver
*));
75 MOCK_METHOD1(RemoveSessionStateObserver
,
76 void(UserManager::UserSessionStateObserver
*));
77 MOCK_METHOD0(NotifyLocalStateChanged
, void(void));
78 MOCK_CONST_METHOD0(AreSupervisedUsersAllowed
, bool(void));
80 // UserManagerBase overrides:
81 MOCK_CONST_METHOD0(AreEphemeralUsersEnabled
, bool(void));
82 MOCK_CONST_METHOD0(GetApplicationLocale
, const std::string
&(void));
83 MOCK_CONST_METHOD0(GetLocalState
, PrefService
*(void));
84 MOCK_CONST_METHOD2(HandleUserOAuthTokenStatusChange
,
85 void(const std::string
&,
86 user_manager::User::OAuthTokenStatus status
));
87 MOCK_CONST_METHOD0(IsEnterpriseManaged
, bool(void));
88 MOCK_METHOD1(LoadPublicAccounts
, void(std::set
<std::string
>*));
89 MOCK_METHOD0(PerformPreUserListLoadingActions
, void(void));
90 MOCK_METHOD0(PerformPostUserListLoadingActions
, void(void));
91 MOCK_METHOD1(PerformPostUserLoggedInActions
, void(bool));
92 MOCK_CONST_METHOD1(IsDemoApp
, bool(const std::string
&));
93 MOCK_CONST_METHOD1(IsKioskApp
, bool(const std::string
&));
94 MOCK_CONST_METHOD1(IsPublicAccountMarkedForRemoval
, bool(const std::string
&));
95 MOCK_METHOD0(DemoAccountLoggedIn
, void(void));
96 MOCK_METHOD1(KioskAppLoggedIn
, void(const std::string
&));
97 MOCK_METHOD1(PublicAccountUserLoggedIn
, void(user_manager::User
*));
98 MOCK_METHOD1(SupervisedUserLoggedIn
, void(const std::string
&));
99 MOCK_METHOD1(OnUserRemoved
, void(const std::string
&));
100 MOCK_METHOD2(SetUserAffiliation
,
101 void(const std::string
& user_id
,
102 const chromeos::AffiliationIDSet
& user_affiliation_ids
));
104 // You can't mock these functions easily because nobody can create
105 // User objects but the ChromeUserManager and us.
106 const user_manager::UserList
& GetUsers() const override
;
107 const user_manager::User
* GetLoggedInUser() const override
;
108 user_manager::UserList
GetUnlockUsers() const override
;
109 const std::string
& GetOwnerEmail() const override
;
110 user_manager::User
* GetLoggedInUser() override
;
111 const user_manager::User
* GetActiveUser() const override
;
112 user_manager::User
* GetActiveUser() override
;
113 const user_manager::User
* GetPrimaryUser() const override
;
115 // ChromeUserManager overrides:
116 BootstrapManager
* GetBootstrapManager() override
;
117 MultiProfileUserController
* GetMultiProfileUserController() override
;
118 UserImageManager
* GetUserImageManager(const std::string
& user_id
) override
;
119 SupervisedUserManager
* GetSupervisedUserManager() override
;
120 MOCK_METHOD2(SetUserFlow
, void(const std::string
&, UserFlow
*));
121 MOCK_METHOD1(ResetUserFlow
, void(const std::string
&));
122 UserFlow
* GetCurrentUserFlow() const override
;
123 UserFlow
* GetUserFlow(const std::string
&) const override
;
125 bool ShouldReportUser(const std::string
& user_id
) const override
;
127 // Sets a new User instance. Users previously created by this MockUserManager
129 void SetActiveUser(const std::string
& email
);
131 // Creates a new public session user. Users previously created by this
132 // MockUserManager become invalid.
133 user_manager::User
* CreatePublicAccountUser(const std::string
& email
);
135 // Creates a new kiosk app user. Users previously created by this
136 // MockUserManager become invalid.
137 user_manager::User
* CreateKioskAppUser(const std::string
& user_id
);
139 // Adds a new User instance to the back of the user list. Users previously
140 // created by this MockUserManager remain valid. The added User is not
141 // affiliated with the domain, that owns the device.
142 void AddUser(const std::string
& email
);
144 // The same as AddUser, but allows specifying affiliation with the domain,
145 // that owns the device.
146 void AddUserWithAffiliation(const std::string
& email
, bool is_affiliated
);
148 // Clears the user list and the active user. Users previously created by this
149 // MockUserManager become invalid.
150 void ClearUserList();
152 scoped_ptr
<UserFlow
> user_flow_
;
153 scoped_ptr
<MockUserImageManager
> user_image_manager_
;
154 scoped_ptr
<FakeSupervisedUserManager
> supervised_user_manager_
;
155 user_manager::UserList user_list_
;
158 } // namespace chromeos
160 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_MOCK_USER_MANAGER_H_