| OLD | NEW |
| 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 "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 | 9 |
| 10 using content::BrowserThread; | 10 using content::BrowserThread; |
| 11 | 11 |
| 12 namespace chromeos { | 12 namespace chromeos { |
| 13 | 13 |
| 14 void MockAuthenticator::AuthenticateToLogin(Profile* profile, | 14 void MockAuthenticator::AuthenticateToLogin(Profile* profile, |
| 15 const std::string& username, | 15 const std::string& username, |
| 16 const std::string& password, | 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_ == username && expected_password_ == password) { |
| 20 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 20 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 21 base::Bind(&MockAuthenticator::OnLoginSuccess, this, false)); | 21 base::Bind(&MockAuthenticator::OnLoginSuccess, this, false)); |
| 22 return; | 22 return; |
| 23 } | 23 } |
| 24 GoogleServiceAuthError error( | 24 GoogleServiceAuthError error( |
| 25 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 25 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 26 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 26 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 27 base::Bind(&MockAuthenticator::OnLoginFailure, this, | 27 base::Bind(&MockAuthenticator::OnLoginFailure, this, |
| 28 LoginFailure::FromNetworkAuthFailure(error))); | 28 LoginFailure::FromNetworkAuthFailure(error))); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void MockAuthenticator::CompleteLogin(Profile* profile, | 31 void MockAuthenticator::CompleteLogin(Profile* profile, |
| 32 const std::string& username, | 32 const std::string& username, |
| 33 const std::string& password) { | 33 const std::string& password) { |
| 34 CHECK_EQ(expected_username_, username); | 34 CHECK_EQ(expected_username_, username); |
| 35 CHECK_EQ(expected_password_, 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(const std::string& username, |
| 40 const std::string& password) { | 40 const std::string& password) { |
| 41 AuthenticateToLogin(NULL /* not used */, username, password, | 41 AuthenticateToLogin(NULL /* not used */, username, password, |
| 42 std::string(), std::string()); | 42 std::string(), std::string()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void MockAuthenticator::LoginRetailMode() { | 45 void MockAuthenticator::LoginRetailMode() { |
| 46 consumer_->OnRetailModeLoginSuccess(); | 46 consumer_->OnRetailModeLoginSuccess(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void MockAuthenticator::LoginAsPublicAccount(const std::string& username) { | 49 void MockAuthenticator::LoginAsPublicAccount(const std::string& username) { |
| 50 consumer_->OnLoginSuccess(expected_username_, "", false, false); | 50 consumer_->OnLoginSuccess(expected_username_, "", false, false); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void MockAuthenticator::LoginOffTheRecord() { | 53 void MockAuthenticator::LoginOffTheRecord() { |
| 54 consumer_->OnOffTheRecordLoginSuccess(); | 54 consumer_->OnOffTheRecordLoginSuccess(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void MockAuthenticator::OnRetailModeLoginSuccess() { | 57 void MockAuthenticator::OnRetailModeLoginSuccess() { |
| 58 consumer_->OnRetailModeLoginSuccess(); | 58 consumer_->OnRetailModeLoginSuccess(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void MockAuthenticator::OnLoginSuccess( | 61 void MockAuthenticator::OnLoginSuccess(bool request_pending) { |
| 62 bool request_pending) { | |
| 63 // If we want to be more like the real thing, we could save username | 62 // If we want to be more like the real thing, we could save username |
| 64 // in AuthenticateToLogin, but there's not much of a point. | 63 // in AuthenticateToLogin, but there's not much of a point. |
| 65 consumer_->OnLoginSuccess(expected_username_, | 64 consumer_->OnLoginSuccess(expected_username_, |
| 66 expected_password_, | 65 expected_password_, |
| 67 request_pending, | 66 request_pending, |
| 68 false); | 67 false); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void MockAuthenticator::OnLoginFailure(const LoginFailure& failure) { | 70 void MockAuthenticator::OnLoginFailure(const LoginFailure& failure) { |
| 72 consumer_->OnLoginFailure(failure); | 71 consumer_->OnLoginFailure(failure); |
| 73 } | 72 } |
| 74 | 73 |
| 75 //////////////////////////////////////////////////////////////////////////////// | |
| 76 // TestLoginUtils | |
| 77 | |
| 78 TestLoginUtils::TestLoginUtils(const std::string& expected_username, | |
| 79 const std::string& expected_password) | |
| 80 : expected_username_(expected_username), | |
| 81 expected_password_(expected_password) { | |
| 82 } | |
| 83 | |
| 84 TestLoginUtils::~TestLoginUtils() {} | |
| 85 | |
| 86 void TestLoginUtils::PrepareProfile( | |
| 87 const std::string& username, | |
| 88 const std::string& display_email, | |
| 89 const std::string& password, | |
| 90 bool pending_requests, | |
| 91 bool using_oauth, | |
| 92 bool has_cookies, | |
| 93 Delegate* delegate) { | |
| 94 DCHECK_EQ(expected_username_, username); | |
| 95 DCHECK_EQ(expected_password_, password); | |
| 96 // Profile hasn't been loaded. | |
| 97 delegate->OnProfilePrepared(NULL); | |
| 98 } | |
| 99 | |
| 100 void TestLoginUtils::DelegateDeleted(Delegate* delegate) { | |
| 101 } | |
| 102 | |
| 103 scoped_refptr<Authenticator> TestLoginUtils::CreateAuthenticator( | |
| 104 LoginStatusConsumer* consumer) { | |
| 105 return new MockAuthenticator( | |
| 106 consumer, expected_username_, expected_password_); | |
| 107 } | |
| 108 | |
| 109 std::string TestLoginUtils::GetOffTheRecordCommandLine( | |
| 110 const GURL& start_url, | |
| 111 const CommandLine& base_command_line, | |
| 112 CommandLine* command_line) { | |
| 113 return std::string(); | |
| 114 } | |
| 115 | |
| 116 void TestLoginUtils::TransferDefaultCookiesAndServerBoundCerts( | |
| 117 Profile* default_profile, | |
| 118 Profile* new_profile) { | |
| 119 } | |
| 120 | |
| 121 void TestLoginUtils::TransferDefaultAuthCache(Profile* default_profile, | |
| 122 Profile* new_profile) { | |
| 123 } | |
| 124 | |
| 125 void TestLoginUtils::StopBackgroundFetchers() { | |
| 126 } | |
| 127 | |
| 128 } // namespace chromeos | 74 } // namespace chromeos |
| OLD | NEW |