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 #include "chromeos/login/auth/mock_authenticator.h"
8 #include "base/location.h"
9 #include "base/logging.h"
13 MockAuthenticator::MockAuthenticator(AuthStatusConsumer
* consumer
,
14 const UserContext
& expected_user_context
)
15 : Authenticator(consumer
),
16 expected_user_context_(expected_user_context
),
17 message_loop_(base::MessageLoopProxy::current()) {
20 void MockAuthenticator::CompleteLogin(Profile
* profile
,
21 const UserContext
& user_context
) {
22 if (expected_user_context_
!= user_context
)
27 void MockAuthenticator::AuthenticateToLogin(Profile
* profile
,
28 const UserContext
& user_context
) {
29 if (user_context
== expected_user_context_
) {
30 message_loop_
->PostTask(
31 FROM_HERE
, base::Bind(&MockAuthenticator::OnAuthSuccess
, this));
34 GoogleServiceAuthError
error(
35 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS
);
36 message_loop_
->PostTask(
38 base::Bind(&MockAuthenticator::OnAuthFailure
,
40 AuthFailure::FromNetworkAuthFailure(error
)));
43 void MockAuthenticator::AuthenticateToUnlock(const UserContext
& user_context
) {
44 AuthenticateToLogin(NULL
/* not used */, user_context
);
47 void MockAuthenticator::LoginAsSupervisedUser(const UserContext
& user_context
) {
48 UserContext new_user_context
= user_context
;
49 new_user_context
.SetUserIDHash(user_context
.GetUserID());
50 consumer_
->OnAuthSuccess(new_user_context
);
53 void MockAuthenticator::LoginRetailMode() {
54 UserContext
user_context("demo-mode");
55 user_context
.SetUserIDHash("demo-mode");
56 consumer_
->OnRetailModeAuthSuccess(user_context
);
59 void MockAuthenticator::LoginOffTheRecord() {
60 consumer_
->OnOffTheRecordAuthSuccess();
63 void MockAuthenticator::LoginAsPublicSession(const UserContext
& user_context
) {
64 UserContext logged_in_user_context
= user_context
;
65 logged_in_user_context
.SetUserIDHash(logged_in_user_context
.GetUserID());
66 consumer_
->OnAuthSuccess(logged_in_user_context
);
69 void MockAuthenticator::LoginAsKioskAccount(const std::string
& app_user_id
,
70 bool use_guest_mount
) {
71 UserContext
user_context(expected_user_context_
.GetUserID());
72 user_context
.SetUserIDHash(expected_user_context_
.GetUserID());
73 consumer_
->OnAuthSuccess(user_context
);
76 void MockAuthenticator::OnRetailModeAuthSuccess() {
77 UserContext
user_context(expected_user_context_
.GetUserID());
78 user_context
.SetUserIDHash(expected_user_context_
.GetUserID());
79 consumer_
->OnRetailModeAuthSuccess(user_context
);
82 void MockAuthenticator::OnAuthSuccess() {
83 // If we want to be more like the real thing, we could save the user ID
84 // in AuthenticateToLogin, but there's not much of a point.
85 UserContext
user_context(expected_user_context_
);
86 user_context
.SetUserIDHash(expected_user_context_
.GetUserID());
87 consumer_
->OnAuthSuccess(user_context
);
90 void MockAuthenticator::OnAuthFailure(const AuthFailure
& failure
) {
91 consumer_
->OnAuthFailure(failure
);
94 void MockAuthenticator::RecoverEncryptedData(const std::string
& old_password
) {
97 void MockAuthenticator::ResyncEncryptedData() {
100 void MockAuthenticator::SetExpectedCredentials(
101 const UserContext
& user_context
) {
102 expected_user_context_
= user_context
;
105 MockAuthenticator::~MockAuthenticator() {
108 } // namespace chromeos