| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/auth/mock_authenticator.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 | |
| 11 using content::BrowserThread; | |
| 12 | |
| 13 namespace chromeos { | |
| 14 | |
| 15 MockAuthenticator::MockAuthenticator(AuthStatusConsumer* consumer, | |
| 16 const UserContext& expected_user_context) | |
| 17 : Authenticator(consumer), expected_user_context_(expected_user_context) { | |
| 18 } | |
| 19 | |
| 20 void MockAuthenticator::CompleteLogin(Profile* profile, | |
| 21 const UserContext& user_context) { | |
| 22 if (expected_user_context_ != user_context) | |
| 23 NOTREACHED(); | |
| 24 OnAuthSuccess(); | |
| 25 } | |
| 26 | |
| 27 void MockAuthenticator::AuthenticateToLogin(Profile* profile, | |
| 28 const UserContext& user_context) { | |
| 29 if (user_context == expected_user_context_) { | |
| 30 BrowserThread::PostTask( | |
| 31 BrowserThread::UI, | |
| 32 FROM_HERE, | |
| 33 base::Bind(&MockAuthenticator::OnAuthSuccess, this)); | |
| 34 return; | |
| 35 } | |
| 36 GoogleServiceAuthError error( | |
| 37 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | |
| 38 BrowserThread::PostTask( | |
| 39 BrowserThread::UI, | |
| 40 FROM_HERE, | |
| 41 base::Bind(&MockAuthenticator::OnAuthFailure, | |
| 42 this, | |
| 43 AuthFailure::FromNetworkAuthFailure(error))); | |
| 44 } | |
| 45 | |
| 46 void MockAuthenticator::AuthenticateToUnlock( | |
| 47 const UserContext& user_context) { | |
| 48 AuthenticateToLogin(NULL /* not used */, user_context); | |
| 49 } | |
| 50 | |
| 51 void MockAuthenticator::LoginAsSupervisedUser( | |
| 52 const UserContext& user_context) { | |
| 53 UserContext new_user_context = user_context; | |
| 54 new_user_context.SetUserIDHash(user_context.GetUserID()); | |
| 55 consumer_->OnAuthSuccess(new_user_context); | |
| 56 } | |
| 57 | |
| 58 void MockAuthenticator::LoginRetailMode() { | |
| 59 UserContext user_context("demo-mode"); | |
| 60 user_context.SetUserIDHash("demo-mode"); | |
| 61 consumer_->OnRetailModeAuthSuccess(user_context); | |
| 62 } | |
| 63 | |
| 64 void MockAuthenticator::LoginOffTheRecord() { | |
| 65 consumer_->OnOffTheRecordAuthSuccess(); | |
| 66 } | |
| 67 | |
| 68 void MockAuthenticator::LoginAsPublicAccount(const std::string& username) { | |
| 69 UserContext user_context(expected_user_context_.GetUserID()); | |
| 70 user_context.SetUserIDHash(expected_user_context_.GetUserID()); | |
| 71 consumer_->OnAuthSuccess(user_context); | |
| 72 } | |
| 73 | |
| 74 void MockAuthenticator::LoginAsKioskAccount(const std::string& app_user_id, | |
| 75 bool use_guest_mount) { | |
| 76 UserContext user_context(expected_user_context_.GetUserID()); | |
| 77 user_context.SetUserIDHash(expected_user_context_.GetUserID()); | |
| 78 consumer_->OnAuthSuccess(user_context); | |
| 79 } | |
| 80 | |
| 81 void MockAuthenticator::OnRetailModeAuthSuccess() { | |
| 82 UserContext user_context(expected_user_context_.GetUserID()); | |
| 83 user_context.SetUserIDHash(expected_user_context_.GetUserID()); | |
| 84 consumer_->OnRetailModeAuthSuccess(user_context); | |
| 85 } | |
| 86 | |
| 87 void MockAuthenticator::OnAuthSuccess() { | |
| 88 // If we want to be more like the real thing, we could save the user ID | |
| 89 // in AuthenticateToLogin, but there's not much of a point. | |
| 90 UserContext user_context(expected_user_context_); | |
| 91 user_context.SetUserIDHash(expected_user_context_.GetUserID()); | |
| 92 consumer_->OnAuthSuccess(user_context); | |
| 93 } | |
| 94 | |
| 95 void MockAuthenticator::OnAuthFailure(const AuthFailure& failure) { | |
| 96 consumer_->OnAuthFailure(failure); | |
| 97 } | |
| 98 | |
| 99 void MockAuthenticator::RecoverEncryptedData(const std::string& old_password) { | |
| 100 } | |
| 101 | |
| 102 void MockAuthenticator::ResyncEncryptedData() { | |
| 103 } | |
| 104 | |
| 105 void MockAuthenticator::SetExpectedCredentials( | |
| 106 const UserContext& user_context) { | |
| 107 expected_user_context_ = user_context; | |
| 108 } | |
| 109 | |
| 110 MockAuthenticator::~MockAuthenticator() { | |
| 111 } | |
| 112 | |
| 113 } // namespace chromeos | |
| OLD | NEW |