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

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

Issue 12704002: Support for auth code based authentication flow for both app and web UI driven flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase4 Created 7 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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/mock_authenticator.h" 5 #include "chrome/browser/chromeos/login/mock_authenticator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/chromeos/login/user.h"
8 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
9 10
10 using content::BrowserThread; 11 using content::BrowserThread;
11 12
12 namespace chromeos { 13 namespace chromeos {
13 14
14 void MockAuthenticator::AuthenticateToLogin(Profile* profile, 15 void MockAuthenticator::AuthenticateToLogin(Profile* profile,
15 const std::string& username, 16 const UserCredentials& credentials,
16 const std::string& password,
17 const std::string& login_token, 17 const std::string& login_token,
18 const std::string& login_captcha) { 18 const std::string& login_captcha) {
19 if (expected_username_ == username && expected_password_ == password) { 19 if (expected_username_ == credentials.username &&
20 expected_password_ == credentials.password) {
20 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 21 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
21 base::Bind(&MockAuthenticator::OnLoginSuccess, this, false)); 22 base::Bind(&MockAuthenticator::OnLoginSuccess, this, false));
22 return; 23 return;
23 } 24 }
24 GoogleServiceAuthError error( 25 GoogleServiceAuthError error(
25 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 26 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
26 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 27 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
27 base::Bind(&MockAuthenticator::OnLoginFailure, this, 28 base::Bind(&MockAuthenticator::OnLoginFailure, this,
28 LoginFailure::FromNetworkAuthFailure(error))); 29 LoginFailure::FromNetworkAuthFailure(error)));
29 } 30 }
30 31
31 void MockAuthenticator::CompleteLogin(Profile* profile, 32 void MockAuthenticator::CompleteLogin(Profile* profile,
32 const std::string& username, 33 const UserCredentials& credentials) {
33 const std::string& password) { 34 CHECK_EQ(expected_username_, credentials.username);
34 CHECK_EQ(expected_username_, username); 35 CHECK_EQ(expected_password_, credentials.password);
35 CHECK_EQ(expected_password_, password);
36 OnLoginSuccess(false); 36 OnLoginSuccess(false);
37 } 37 }
38 38
39 void MockAuthenticator::AuthenticateToUnlock(const std::string& username, 39 void MockAuthenticator::AuthenticateToUnlock(
40 const std::string& password) { 40 const UserCredentials& credentials) {
41 AuthenticateToLogin(NULL /* not used */, username, password, 41 AuthenticateToLogin(NULL /* not used */, credentials,
42 std::string(), std::string()); 42 std::string(), std::string());
43 } 43 }
44 44
45 void MockAuthenticator::LoginAsLocallyManagedUser(const std::string& username, 45 void MockAuthenticator::LoginAsLocallyManagedUser(
46 const std::string& password) { 46 const UserCredentials& credentials) {
47 consumer_->OnLoginSuccess(expected_username_, "", false, false); 47 consumer_->OnLoginSuccess(UserCredentials(expected_username_, "", ""),
48 false,
49 false);
48 } 50 }
49 51
50 void MockAuthenticator::LoginRetailMode() { 52 void MockAuthenticator::LoginRetailMode() {
51 consumer_->OnRetailModeLoginSuccess(); 53 consumer_->OnRetailModeLoginSuccess();
52 } 54 }
53 55
54 void MockAuthenticator::LoginAsPublicAccount(const std::string& username) { 56 void MockAuthenticator::LoginAsPublicAccount(const std::string& username) {
55 consumer_->OnLoginSuccess(expected_username_, "", false, false); 57 consumer_->OnLoginSuccess(UserCredentials(expected_username_, "", ""),
58 false,
59 false);
56 } 60 }
57 61
58 void MockAuthenticator::LoginOffTheRecord() { 62 void MockAuthenticator::LoginOffTheRecord() {
59 consumer_->OnOffTheRecordLoginSuccess(); 63 consumer_->OnOffTheRecordLoginSuccess();
60 } 64 }
61 65
62 void MockAuthenticator::OnRetailModeLoginSuccess() { 66 void MockAuthenticator::OnRetailModeLoginSuccess() {
63 consumer_->OnRetailModeLoginSuccess(); 67 consumer_->OnRetailModeLoginSuccess();
64 } 68 }
65 69
66 void MockAuthenticator::OnLoginSuccess(bool request_pending) { 70 void MockAuthenticator::OnLoginSuccess(bool request_pending) {
67 // If we want to be more like the real thing, we could save username 71 // If we want to be more like the real thing, we could save username
68 // in AuthenticateToLogin, but there's not much of a point. 72 // in AuthenticateToLogin, but there's not much of a point.
69 consumer_->OnLoginSuccess(expected_username_, 73 consumer_->OnLoginSuccess(UserCredentials(expected_username_,
70 expected_password_, 74 expected_password_,
75 ""),
71 request_pending, 76 request_pending,
72 false); 77 false);
73 } 78 }
74 79
75 void MockAuthenticator::OnLoginFailure(const LoginFailure& failure) { 80 void MockAuthenticator::OnLoginFailure(const LoginFailure& failure) {
76 consumer_->OnLoginFailure(failure); 81 consumer_->OnLoginFailure(failure);
77 } 82 }
78 83
79 } // namespace chromeos 84 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/mock_authenticator.h ('k') | chrome/browser/chromeos/login/mock_login_status_consumer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698