OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTHENTICATOR_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTHENTICATOR_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTHENTICATOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTHENTICATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 expected_password_(expected_password) { | 30 expected_password_(expected_password) { |
31 } | 31 } |
32 | 32 |
33 // Returns true after posting task to UI thread to call OnLoginSuccess(). | 33 // Returns true after posting task to UI thread to call OnLoginSuccess(). |
34 // This is called on the FILE thread now, so we need to do this. | 34 // This is called on the FILE thread now, so we need to do this. |
35 virtual bool AuthenticateToLogin(Profile* profile, | 35 virtual bool AuthenticateToLogin(Profile* profile, |
36 const std::string& username, | 36 const std::string& username, |
37 const std::string& password, | 37 const std::string& password, |
38 const std::string& login_token, | 38 const std::string& login_token, |
39 const std::string& login_captcha) { | 39 const std::string& login_captcha) { |
40 if (expected_username_ == username && | 40 if (expected_username_ == username && expected_password_ == password) { |
41 expected_password_ == password) { | 41 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
42 BrowserThread::PostTask( | 42 NewRunnableMethod(this, &MockAuthenticator::OnLoginSuccess, |
43 BrowserThread::UI, FROM_HERE, | 43 GaiaAuthConsumer::ClientLoginResult(), false)); |
44 NewRunnableMethod(this, | |
45 &MockAuthenticator::OnLoginSuccess, | |
46 GaiaAuthConsumer::ClientLoginResult(), | |
47 false)); | |
48 return true; | 44 return true; |
49 } else { | |
50 GoogleServiceAuthError error( | |
51 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | |
52 BrowserThread::PostTask( | |
53 BrowserThread::UI, FROM_HERE, | |
54 NewRunnableMethod(this, | |
55 &MockAuthenticator::OnLoginFailure, | |
56 LoginFailure::FromNetworkAuthFailure(error))); | |
57 return false; | |
58 } | 45 } |
| 46 GoogleServiceAuthError error( |
| 47 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 48 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 49 NewRunnableMethod(this, &MockAuthenticator::OnLoginFailure, |
| 50 LoginFailure::FromNetworkAuthFailure(error))); |
| 51 return false; |
59 } | 52 } |
60 | 53 |
61 virtual bool AuthenticateToUnlock(const std::string& username, | 54 virtual bool AuthenticateToUnlock(const std::string& username, |
62 const std::string& password) { | 55 const std::string& password) { |
63 return AuthenticateToLogin(NULL /* not used */, username, password, | 56 return AuthenticateToLogin(NULL /* not used */, username, password, |
64 std::string(), std::string()); | 57 std::string(), std::string()); |
65 } | 58 } |
66 | 59 |
67 virtual void LoginOffTheRecord() { | 60 virtual void LoginOffTheRecord() { |
68 consumer_->OnOffTheRecordLoginSuccess(); | 61 consumer_->OnOffTheRecordLoginSuccess(); |
69 } | 62 } |
70 | 63 |
71 void OnLoginSuccess(const GaiaAuthConsumer::ClientLoginResult& credentials, | 64 void OnLoginSuccess(const GaiaAuthConsumer::ClientLoginResult& credentials, |
72 bool request_pending) { | 65 bool request_pending) { |
73 // If we want to be more like the real thing, we could save username | 66 // If we want to be more like the real thing, we could save username |
74 // in AuthenticateToLogin, but there's not much of a point. | 67 // in AuthenticateToLogin, but there's not much of a point. |
75 consumer_->OnLoginSuccess(expected_username_, | 68 consumer_->OnLoginSuccess(expected_username_, |
76 credentials, | 69 credentials, |
77 request_pending); | 70 request_pending); |
78 } | 71 } |
79 | 72 |
80 void OnLoginFailure(const LoginFailure& failure) { | 73 void OnLoginFailure(const LoginFailure& failure) { |
81 consumer_->OnLoginFailure(failure); | 74 consumer_->OnLoginFailure(failure); |
82 LOG(INFO) << "Posting a QuitTask to UI thread"; | 75 VLOG(1) << "Posting a QuitTask to UI thread"; |
83 BrowserThread::PostTask( | 76 BrowserThread::PostTask( |
84 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask); | 77 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask); |
85 } | 78 } |
86 | 79 |
87 virtual void RecoverEncryptedData( | 80 virtual void RecoverEncryptedData( |
88 const std::string& old_password, | 81 const std::string& old_password, |
89 const GaiaAuthConsumer::ClientLoginResult& credentials) {} | 82 const GaiaAuthConsumer::ClientLoginResult& credentials) {} |
90 | 83 |
91 virtual void ResyncEncryptedData( | 84 virtual void ResyncEncryptedData( |
92 const GaiaAuthConsumer::ClientLoginResult& credentials) {} | 85 const GaiaAuthConsumer::ClientLoginResult& credentials) {} |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 std::string expected_username_; | 137 std::string expected_username_; |
145 std::string expected_password_; | 138 std::string expected_password_; |
146 std::string auth_token_; | 139 std::string auth_token_; |
147 | 140 |
148 DISALLOW_COPY_AND_ASSIGN(MockLoginUtils); | 141 DISALLOW_COPY_AND_ASSIGN(MockLoginUtils); |
149 }; | 142 }; |
150 | 143 |
151 } // namespace chromeos | 144 } // namespace chromeos |
152 | 145 |
153 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTHENTICATOR_H_ | 146 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTHENTICATOR_H_ |
OLD | NEW |