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.
5 #include "chrome/browser/chromeos/login/mock_authenticator.h"
8 #include "chrome/browser/chromeos/login/user.h"
9 #include "content/public/browser/browser_thread.h"
11 using content::BrowserThread
;
15 void MockAuthenticator::AuthenticateToLogin(Profile
* profile
,
16 const UserContext
& user_context
) {
17 if (expected_username_
== user_context
.username
&&
18 expected_password_
== user_context
.password
) {
19 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
20 base::Bind(&MockAuthenticator::OnLoginSuccess
, this));
23 GoogleServiceAuthError
error(
24 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS
);
25 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
26 base::Bind(&MockAuthenticator::OnLoginFailure
, this,
27 LoginFailure::FromNetworkAuthFailure(error
)));
30 void MockAuthenticator::CompleteLogin(Profile
* profile
,
31 const UserContext
& user_context
) {
32 CHECK_EQ(expected_username_
, user_context
.username
);
33 CHECK_EQ(expected_password_
, user_context
.password
);
37 void MockAuthenticator::AuthenticateToUnlock(
38 const UserContext
& user_context
) {
39 AuthenticateToLogin(NULL
/* not used */, user_context
);
42 void MockAuthenticator::LoginAsLocallyManagedUser(
43 const UserContext
& user_context
) {
44 consumer_
->OnLoginSuccess(UserContext(expected_username_
,
47 user_context
.username
)); // hash
50 void MockAuthenticator::LoginRetailMode() {
51 consumer_
->OnRetailModeLoginSuccess(UserContext("demo-mode",
57 void MockAuthenticator::LoginAsPublicAccount(const std::string
& username
) {
58 consumer_
->OnLoginSuccess(UserContext(expected_username_
,
64 void MockAuthenticator::LoginAsKioskAccount(
65 const std::string
& app_user_id
) {
66 consumer_
->OnLoginSuccess(UserContext(expected_username_
,
72 void MockAuthenticator::LoginOffTheRecord() {
73 consumer_
->OnOffTheRecordLoginSuccess();
76 void MockAuthenticator::OnRetailModeLoginSuccess() {
77 consumer_
->OnRetailModeLoginSuccess(UserContext(expected_username_
,
83 void MockAuthenticator::OnLoginSuccess() {
84 // If we want to be more like the real thing, we could save username
85 // in AuthenticateToLogin, but there's not much of a point.
86 consumer_
->OnLoginSuccess(UserContext(expected_username_
,
92 void MockAuthenticator::OnLoginFailure(const LoginFailure
& failure
) {
93 consumer_
->OnLoginFailure(failure
);
96 void MockAuthenticator::SetExpectedCredentials(
97 const std::string
& expected_username
,
98 const std::string
& expected_password
) {
99 expected_username_
= expected_username
;
100 expected_password_
= expected_password
;
103 } // namespace chromeos