Home | History | Annotate | Download | only in login
      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 FakeSupervisedUserManager;
     22 
     23 class MockUserManager : public UserManager {
     24  public:
     25   MockUserManager();
     26   virtual ~MockUserManager();
     27 
     28   MOCK_METHOD0(Shutdown, void(void));
     29   MOCK_CONST_METHOD0(GetUsersAdmittedForMultiProfile, UserList(void));
     30   MOCK_CONST_METHOD0(GetLoggedInUsers, const UserList&(void));
     31   MOCK_METHOD0(GetLRULoggedInUsers, const UserList&(void));
     32   MOCK_METHOD3(UserLoggedIn, void(
     33       const std::string&, const std::string&, bool));
     34   MOCK_METHOD1(SwitchActiveUser, void(const std::string& email));
     35   MOCK_METHOD0(SessionStarted, void(void));
     36   MOCK_METHOD0(RestoreActiveSessions, void(void));
     37   MOCK_METHOD2(RemoveUser, void(const std::string&, RemoveUserDelegate*));
     38   MOCK_METHOD1(RemoveUserFromList, void(const std::string&));
     39   MOCK_CONST_METHOD1(IsKnownUser, bool(const std::string&));
     40   MOCK_CONST_METHOD1(FindUser, const User*(const std::string&));
     41   MOCK_METHOD1(FindUserAndModify, User*(const std::string&));
     42   MOCK_METHOD2(SaveUserOAuthStatus, void(const std::string&,
     43                                          User::OAuthTokenStatus));
     44   MOCK_CONST_METHOD1(GetProfileByUser, Profile*(const User*));
     45   MOCK_METHOD2(SaveUserDisplayName, void(const std::string&,
     46                                          const base::string16&));
     47   MOCK_METHOD2(UpdateUserAccountData,
     48                void(const std::string&, const UserAccountData&));
     49   MOCK_CONST_METHOD1(GetUserDisplayName, base::string16(const std::string&));
     50   MOCK_METHOD2(SaveUserDisplayEmail, void(const std::string&,
     51                                           const std::string&));
     52   MOCK_CONST_METHOD1(GetUserDisplayEmail, std::string(const std::string&));
     53   MOCK_CONST_METHOD0(IsCurrentUserOwner, bool(void));
     54   MOCK_CONST_METHOD0(IsCurrentUserNew, bool(void));
     55   MOCK_CONST_METHOD0(IsCurrentUserNonCryptohomeDataEphemeral, bool(void));
     56   MOCK_CONST_METHOD0(CanCurrentUserLock, bool(void));
     57   MOCK_CONST_METHOD0(IsUserLoggedIn, bool(void));
     58   MOCK_CONST_METHOD0(IsLoggedInAsRegularUser, bool(void));
     59   MOCK_CONST_METHOD0(IsLoggedInAsDemoUser, bool(void));
     60   MOCK_CONST_METHOD0(IsLoggedInAsPublicAccount, bool(void));
     61   MOCK_CONST_METHOD0(IsLoggedInAsGuest, bool(void));
     62   MOCK_CONST_METHOD0(IsLoggedInAsLocallyManagedUser, bool(void));
     63   MOCK_CONST_METHOD0(IsLoggedInAsKioskApp, bool(void));
     64   MOCK_CONST_METHOD0(IsLoggedInAsStub, bool(void));
     65   MOCK_CONST_METHOD0(IsSessionStarted, bool(void));
     66   MOCK_CONST_METHOD0(UserSessionsRestored, bool(void));
     67   MOCK_CONST_METHOD0(HasBrowserRestarted, bool(void));
     68   MOCK_CONST_METHOD1(IsUserNonCryptohomeDataEphemeral,
     69                      bool(const std::string&));
     70   MOCK_METHOD1(AddObserver, void(UserManager::Observer*));
     71   MOCK_METHOD1(RemoveObserver, void(UserManager::Observer*));
     72   MOCK_METHOD1(AddSessionStateObserver,
     73                void(UserManager::UserSessionStateObserver*));
     74   MOCK_METHOD1(RemoveSessionStateObserver,
     75                void(UserManager::UserSessionStateObserver*));
     76   MOCK_METHOD0(NotifyLocalStateChanged, void(void));
     77   MOCK_METHOD2(SetUserFlow, void(const std::string&, UserFlow*));
     78   MOCK_METHOD1(ResetUserFlow, void(const std::string&));
     79 
     80   MOCK_METHOD2(GetAppModeChromeClientOAuthInfo, bool(std::string*,
     81                                                      std::string*));
     82   MOCK_METHOD2(SetAppModeChromeClientOAuthInfo, void(const std::string&,
     83                                                      const std::string&));
     84   MOCK_CONST_METHOD0(AreLocallyManagedUsersAllowed, bool(void));
     85   MOCK_CONST_METHOD1(GetUserProfileDir,
     86                      base::FilePath(const std::string& email));
     87 
     88   // You can't mock these functions easily because nobody can create
     89   // User objects but the UserManagerImpl and us.
     90   virtual const UserList& GetUsers() const OVERRIDE;
     91   virtual const User* GetLoggedInUser() const OVERRIDE;
     92   virtual UserList GetUnlockUsers() const OVERRIDE;
     93   virtual const std::string& GetOwnerEmail() OVERRIDE;
     94   virtual User* GetLoggedInUser() OVERRIDE;
     95   virtual const User* GetActiveUser() const OVERRIDE;
     96   virtual User* GetActiveUser() OVERRIDE;
     97   virtual const User* GetPrimaryUser() const OVERRIDE;
     98   virtual User* GetUserByProfile(Profile* profile) const OVERRIDE;
     99 
    100   virtual UserImageManager* GetUserImageManager() OVERRIDE;
    101   virtual SupervisedUserManager* GetSupervisedUserManager() OVERRIDE;
    102 
    103   virtual UserFlow* GetCurrentUserFlow() const OVERRIDE;
    104   virtual UserFlow* GetUserFlow(const std::string&) const OVERRIDE;
    105   virtual bool RespectLocalePreference(
    106       Profile* profile,
    107       const User* user,
    108       scoped_ptr<locale_util::SwitchLanguageCallback> callback) const OVERRIDE;
    109 
    110   // Sets a new User instance. Users previously created by this MockUserManager
    111   // become invalid.
    112   void SetActiveUser(const std::string& email);
    113 
    114   // Creates a new public session user. Users previously created by this
    115   // MockUserManager become invalid.
    116   User* CreatePublicAccountUser(const std::string& email);
    117 
    118   // Adds a new User instance to the back of the user list. Users previously
    119   // created by this MockUserManager remain valid.
    120   void AddUser(const std::string& email);
    121 
    122   // Clears the user list and the active user. Users previously created by this
    123   // MockUserManager become invalid.
    124   void ClearUserList();
    125 
    126   scoped_ptr<UserFlow> user_flow_;
    127   scoped_ptr<MockUserImageManager> user_image_manager_;
    128   scoped_ptr<FakeSupervisedUserManager> supervised_user_manager_;
    129   UserList user_list_;
    130 };
    131 
    132 }  // namespace chromeos
    133 
    134 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_USER_MANAGER_H_
    135