Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / mock_authenticator.cc
blob696db2c34484e73d67ea7bbdebb5ed8b1c8692e7
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"
7 #include "base/bind.h"
8 #include "chrome/browser/chromeos/login/user.h"
9 #include "content/public/browser/browser_thread.h"
11 using content::BrowserThread;
13 namespace chromeos {
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));
21 return;
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);
34 OnLoginSuccess();
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_,
45 std::string(),
46 std::string(),
47 user_context.username)); // hash
50 void MockAuthenticator::LoginRetailMode() {
51 consumer_->OnRetailModeLoginSuccess(UserContext("demo-mode",
52 std::string(),
53 std::string(),
54 "demo-mode"));
57 void MockAuthenticator::LoginAsPublicAccount(const std::string& username) {
58 consumer_->OnLoginSuccess(UserContext(expected_username_,
59 std::string(),
60 std::string(),
61 expected_username_));
64 void MockAuthenticator::LoginAsKioskAccount(
65 const std::string& app_user_id) {
66 consumer_->OnLoginSuccess(UserContext(expected_username_,
67 std::string(),
68 std::string(),
69 expected_username_));
72 void MockAuthenticator::LoginOffTheRecord() {
73 consumer_->OnOffTheRecordLoginSuccess();
76 void MockAuthenticator::OnRetailModeLoginSuccess() {
77 consumer_->OnRetailModeLoginSuccess(UserContext(expected_username_,
78 std::string(),
79 std::string(),
80 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_,
87 expected_password_,
88 std::string(),
89 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