Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/chromeos/login/auth/mock_authenticator.cc

Issue 296773002: Add a Key class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/auth/mock_authenticator.h" 5 #include "chrome/browser/chromeos/login/auth/mock_authenticator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/chromeos/login/auth/user_context.h" 8 #include "base/logging.h"
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 10
11 using content::BrowserThread; 11 using content::BrowserThread;
12 12
13 namespace chromeos { 13 namespace chromeos {
14 14
15 MockAuthenticator::MockAuthenticator(LoginStatusConsumer* consumer,
16 const UserContext& expected_user_context)
17 : Authenticator(consumer),
18 expected_user_context_(expected_user_context) {
19 }
20
21 void MockAuthenticator::CompleteLogin(Profile* profile,
22 const UserContext& user_context) {
23 if (expected_user_context_ != user_context)
24 NOTREACHED();
25 OnLoginSuccess();
26 }
27
15 void MockAuthenticator::AuthenticateToLogin(Profile* profile, 28 void MockAuthenticator::AuthenticateToLogin(Profile* profile,
16 const UserContext& user_context) { 29 const UserContext& user_context) {
17 if (expected_username_ == user_context.GetUserID() && 30 if (user_context == expected_user_context_) {
18 expected_password_ == user_context.GetPassword()) {
19 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 31 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
20 base::Bind(&MockAuthenticator::OnLoginSuccess, this)); 32 base::Bind(&MockAuthenticator::OnLoginSuccess, this));
21 return; 33 return;
22 } 34 }
23 GoogleServiceAuthError error( 35 GoogleServiceAuthError error(
24 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 36 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
25 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
26 base::Bind(&MockAuthenticator::OnLoginFailure, this, 38 base::Bind(&MockAuthenticator::OnLoginFailure, this,
27 LoginFailure::FromNetworkAuthFailure(error))); 39 LoginFailure::FromNetworkAuthFailure(error)));
28 } 40 }
29 41
30 void MockAuthenticator::CompleteLogin(Profile* profile,
31 const UserContext& user_context) {
32 CHECK_EQ(expected_username_, user_context.GetUserID());
33 CHECK_EQ(expected_password_, user_context.GetPassword());
34 OnLoginSuccess();
35 }
36
37 void MockAuthenticator::AuthenticateToUnlock( 42 void MockAuthenticator::AuthenticateToUnlock(
38 const UserContext& user_context) { 43 const UserContext& user_context) {
39 AuthenticateToLogin(NULL /* not used */, user_context); 44 AuthenticateToLogin(NULL /* not used */, user_context);
40 } 45 }
41 46
42 void MockAuthenticator::LoginAsLocallyManagedUser( 47 void MockAuthenticator::LoginAsLocallyManagedUser(
43 const UserContext& user_context) { 48 const UserContext& user_context) {
44 UserContext new_user_context = user_context; 49 UserContext new_user_context = user_context;
45 new_user_context.SetUserIDHash(user_context.GetUserID()); 50 new_user_context.SetUserIDHash(user_context.GetUserID());
46 consumer_->OnLoginSuccess(new_user_context); 51 consumer_->OnLoginSuccess(new_user_context);
47 } 52 }
48 53
49 void MockAuthenticator::LoginRetailMode() { 54 void MockAuthenticator::LoginRetailMode() {
50 UserContext user_context("demo-mode"); 55 UserContext user_context("demo-mode");
51 user_context.SetUserIDHash("demo-mode"); 56 user_context.SetUserIDHash("demo-mode");
52 consumer_->OnRetailModeLoginSuccess(user_context); 57 consumer_->OnRetailModeLoginSuccess(user_context);
53 } 58 }
54 59
55 void MockAuthenticator::LoginAsPublicAccount(const std::string& username) {
56 UserContext user_context(expected_username_);
57 user_context.SetUserIDHash(expected_username_);
58 consumer_->OnLoginSuccess(user_context);
59 }
60
61 void MockAuthenticator::LoginAsKioskAccount(const std::string& app_user_id,
62 bool use_guest_mount) {
63 UserContext user_context(expected_username_);
64 user_context.SetUserIDHash(expected_username_);
65 consumer_->OnLoginSuccess(user_context);
66 }
67
68 void MockAuthenticator::LoginOffTheRecord() { 60 void MockAuthenticator::LoginOffTheRecord() {
69 consumer_->OnOffTheRecordLoginSuccess(); 61 consumer_->OnOffTheRecordLoginSuccess();
70 } 62 }
71 63
64 void MockAuthenticator::LoginAsPublicAccount(const std::string& username) {
65 UserContext user_context(expected_user_context_.GetUserID());
66 user_context.SetUserIDHash(expected_user_context_.GetUserID());
67 consumer_->OnLoginSuccess(user_context);
68 }
69
70 void MockAuthenticator::LoginAsKioskAccount(const std::string& app_user_id,
71 bool use_guest_mount) {
72 UserContext user_context(expected_user_context_.GetUserID());
73 user_context.SetUserIDHash(expected_user_context_.GetUserID());
74 consumer_->OnLoginSuccess(user_context);
75 }
76
72 void MockAuthenticator::OnRetailModeLoginSuccess() { 77 void MockAuthenticator::OnRetailModeLoginSuccess() {
73 UserContext user_context(expected_username_); 78 UserContext user_context(expected_user_context_.GetUserID());
74 user_context.SetUserIDHash(expected_username_); 79 user_context.SetUserIDHash(expected_user_context_.GetUserID());
75 consumer_->OnRetailModeLoginSuccess(user_context); 80 consumer_->OnRetailModeLoginSuccess(user_context);
76 } 81 }
77 82
78 void MockAuthenticator::OnLoginSuccess() { 83 void MockAuthenticator::OnLoginSuccess() {
79 // If we want to be more like the real thing, we could save username 84 // If we want to be more like the real thing, we could save the user ID
80 // in AuthenticateToLogin, but there's not much of a point. 85 // in AuthenticateToLogin, but there's not much of a point.
81 UserContext user_context(expected_username_); 86 UserContext user_context(expected_user_context_);
82 user_context.SetPassword(expected_password_); 87 user_context.SetUserIDHash(expected_user_context_.GetUserID());
83 user_context.SetUserIDHash(expected_username_);
84 consumer_->OnLoginSuccess(user_context); 88 consumer_->OnLoginSuccess(user_context);
85 } 89 }
86 90
87 void MockAuthenticator::OnLoginFailure(const LoginFailure& failure) { 91 void MockAuthenticator::OnLoginFailure(const LoginFailure& failure) {
88 consumer_->OnLoginFailure(failure); 92 consumer_->OnLoginFailure(failure);
89 } 93 }
90 94
95 void MockAuthenticator::RecoverEncryptedData(const std::string& old_password) {
96 }
97
98 void MockAuthenticator::ResyncEncryptedData() {
99 }
100
91 void MockAuthenticator::SetExpectedCredentials( 101 void MockAuthenticator::SetExpectedCredentials(
92 const std::string& expected_username, 102 const UserContext& user_context) {
93 const std::string& expected_password) { 103 expected_user_context_ = user_context;
94 expected_username_ = expected_username; 104 }
95 expected_password_ = expected_password; 105
106 MockAuthenticator::~MockAuthenticator() {
96 } 107 }
97 108
98 } // namespace chromeos 109 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/auth/mock_authenticator.h ('k') | chrome/browser/chromeos/login/auth/online_attempt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698