1 // Copyright 2017 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 ASH_LOGIN_MOCK_LOGIN_SCREEN_CLIENT_H_
6 #define ASH_LOGIN_MOCK_LOGIN_SCREEN_CLIENT_H_
7 
8 #include "ash/public/cpp/login_screen_client.h"
9 #include "base/time/time.h"
10 #include "components/password_manager/core/browser/hash_password_manager.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 
13 namespace ash {
14 
15 class MockLoginScreenClient : public LoginScreenClient {
16  public:
17   MockLoginScreenClient();
18   ~MockLoginScreenClient() override;
19 
20   MOCK_METHOD(void,
21               AuthenticateUserWithPasswordOrPin_,
22               (const AccountId& account_id,
23                const std::string& password,
24                bool authenticated_by_pin,
25                base::OnceCallback<void(bool)>& callback));
26   MOCK_METHOD(void,
27               AuthenticateUserWithChallengeResponse_,
28               (const AccountId& account_id,
29                base::OnceCallback<void(bool)>& callback));
30   MOCK_METHOD(bool,
31               ValidateParentAccessCode_,
32               (const AccountId& account_id,
33                const std::string& access_code,
34                base::Time validation_time));
35 
36   // Set the result that should be passed to |callback| in
37   // |AuthenticateUserWithPasswordOrPin|.
set_authenticate_user_callback_result(bool value)38   void set_authenticate_user_callback_result(bool value) {
39     authenticate_user_callback_result_ = value;
40   }
41 
42   // Sets the result that should be passed to |callback| in
43   // |ValidateParentAccessCode|.
set_validate_parent_access_code_result(bool value)44   void set_validate_parent_access_code_result(bool value) {
45     validate_parent_access_code_result_ = value;
46   }
47 
48   // If set to non-null, when |AuthenticateUser| is called the callback will be
49   // stored in |storage| instead of being executed.
set_authenticate_user_with_password_or_pin_callback_storage(base::OnceCallback<void (bool)> * storage)50   void set_authenticate_user_with_password_or_pin_callback_storage(
51       base::OnceCallback<void(bool)>* storage) {
52     authenticate_user_with_password_or_pin_callback_storage_ = storage;
53   }
54 
55   // LoginScreenClient:
56   void AuthenticateUserWithPasswordOrPin(
57       const AccountId& account_id,
58       const std::string& password,
59       bool authenticated_by_pin,
60       base::OnceCallback<void(bool)> callback) override;
61   void AuthenticateUserWithChallengeResponse(
62       const AccountId& account_id,
63       base::OnceCallback<void(bool)> callback) override;
64   bool ValidateParentAccessCode(const AccountId& account_id,
65                                 const std::string& code,
66                                 base::Time validation_time) override;
67   MOCK_METHOD(void,
68               AuthenticateUserWithEasyUnlock,
69               (const AccountId& account_id),
70               (override));
71   MOCK_METHOD(void, HardlockPod, (const AccountId& account_id), (override));
72   MOCK_METHOD(void, OnFocusPod, (const AccountId& account_id), (override));
73   MOCK_METHOD(void, OnNoPodFocused, (), (override));
74   MOCK_METHOD(void, LoadWallpaper, (const AccountId& account_id), (override));
75   MOCK_METHOD(void, SignOutUser, (), (override));
76   MOCK_METHOD(void, CancelAddUser, (), (override));
77   MOCK_METHOD(void, LoginAsGuest, (), (override));
78   MOCK_METHOD(void,
79               OnMaxIncorrectPasswordAttempted,
80               (const AccountId& account_id),
81               (override));
82   MOCK_METHOD(void, FocusLockScreenApps, (bool reverse), (override));
83   MOCK_METHOD(void,
84               ShowGaiaSignin,
85               (const AccountId& prefilled_account),
86               (override));
87   MOCK_METHOD(void, OnRemoveUserWarningShown, (), (override));
88   MOCK_METHOD(void, RemoveUser, (const AccountId& account_id), (override));
89   MOCK_METHOD(void,
90               LaunchPublicSession,
91               (const AccountId& account_id,
92                const std::string& locale,
93                const std::string& input_method),
94               (override));
95   MOCK_METHOD(void,
96               RequestPublicSessionKeyboardLayouts,
97               (const AccountId& account_id, const std::string& locale),
98               (override));
99   MOCK_METHOD(void,
100               HandleAccelerator,
101               (ash::LoginAcceleratorAction action),
102               (override));
103   MOCK_METHOD(void, ShowAccountAccessHelpApp, (gfx::NativeWindow), (override));
104   MOCK_METHOD(void, ShowParentAccessHelpApp, (gfx::NativeWindow), (override));
105   MOCK_METHOD(void, ShowLockScreenNotificationSettings, (), (override));
106   MOCK_METHOD(void, FocusOobeDialog, (), (override));
107   MOCK_METHOD(void, OnFocusLeavingSystemTray, (bool reverse), (override));
108   MOCK_METHOD(void, OnUserActivity, (), (override));
109   MOCK_METHOD(void, OnLoginScreenShown, (), (override));
110 
111  private:
112   bool authenticate_user_callback_result_ = true;
113   bool validate_parent_access_code_result_ = true;
114   base::OnceCallback<void(bool)>*
115       authenticate_user_with_password_or_pin_callback_storage_ = nullptr;
116 
117   DISALLOW_COPY_AND_ASSIGN(MockLoginScreenClient);
118 };
119 
120 }  // namespace ash
121 
122 #endif  // ASH_LOGIN_MOCK_LOGIN_SCREEN_CLIENT_H_
123