OLD | NEW |
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 "chromeos/login/auth/mock_authenticator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "content/public/browser/browser_thread.h" | |
10 | |
11 using content::BrowserThread; | |
12 | 10 |
13 namespace chromeos { | 11 namespace chromeos { |
14 | 12 |
15 MockAuthenticator::MockAuthenticator(AuthStatusConsumer* consumer, | 13 MockAuthenticator::MockAuthenticator(AuthStatusConsumer* consumer, |
16 const UserContext& expected_user_context) | 14 const UserContext& expected_user_context) |
17 : Authenticator(consumer), expected_user_context_(expected_user_context) { | 15 : Authenticator(consumer), |
| 16 expected_user_context_(expected_user_context), |
| 17 message_loop_(base::MessageLoopProxy::current()) { |
18 } | 18 } |
19 | 19 |
20 void MockAuthenticator::CompleteLogin(Profile* profile, | 20 void MockAuthenticator::CompleteLogin(Profile* profile, |
21 const UserContext& user_context) { | 21 const UserContext& user_context) { |
22 if (expected_user_context_ != user_context) | 22 if (expected_user_context_ != user_context) |
23 NOTREACHED(); | 23 NOTREACHED(); |
24 OnAuthSuccess(); | 24 OnAuthSuccess(); |
25 } | 25 } |
26 | 26 |
27 void MockAuthenticator::AuthenticateToLogin(Profile* profile, | 27 void MockAuthenticator::AuthenticateToLogin(Profile* profile, |
28 const UserContext& user_context) { | 28 const UserContext& user_context) { |
29 if (user_context == expected_user_context_) { | 29 if (user_context == expected_user_context_) { |
30 BrowserThread::PostTask( | 30 message_loop_->PostTask( |
31 BrowserThread::UI, | 31 FROM_HERE, base::Bind(&MockAuthenticator::OnAuthSuccess, this)); |
32 FROM_HERE, | |
33 base::Bind(&MockAuthenticator::OnAuthSuccess, this)); | |
34 return; | 32 return; |
35 } | 33 } |
36 GoogleServiceAuthError error( | 34 GoogleServiceAuthError error( |
37 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 35 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
38 BrowserThread::PostTask( | 36 message_loop_->PostTask( |
39 BrowserThread::UI, | |
40 FROM_HERE, | 37 FROM_HERE, |
41 base::Bind(&MockAuthenticator::OnAuthFailure, | 38 base::Bind(&MockAuthenticator::OnAuthFailure, |
42 this, | 39 this, |
43 AuthFailure::FromNetworkAuthFailure(error))); | 40 AuthFailure::FromNetworkAuthFailure(error))); |
44 } | 41 } |
45 | 42 |
46 void MockAuthenticator::AuthenticateToUnlock( | 43 void MockAuthenticator::AuthenticateToUnlock(const UserContext& user_context) { |
47 const UserContext& user_context) { | |
48 AuthenticateToLogin(NULL /* not used */, user_context); | 44 AuthenticateToLogin(NULL /* not used */, user_context); |
49 } | 45 } |
50 | 46 |
51 void MockAuthenticator::LoginAsSupervisedUser( | 47 void MockAuthenticator::LoginAsSupervisedUser(const UserContext& user_context) { |
52 const UserContext& user_context) { | |
53 UserContext new_user_context = user_context; | 48 UserContext new_user_context = user_context; |
54 new_user_context.SetUserIDHash(user_context.GetUserID()); | 49 new_user_context.SetUserIDHash(user_context.GetUserID()); |
55 consumer_->OnAuthSuccess(new_user_context); | 50 consumer_->OnAuthSuccess(new_user_context); |
56 } | 51 } |
57 | 52 |
58 void MockAuthenticator::LoginRetailMode() { | 53 void MockAuthenticator::LoginRetailMode() { |
59 UserContext user_context("demo-mode"); | 54 UserContext user_context("demo-mode"); |
60 user_context.SetUserIDHash("demo-mode"); | 55 user_context.SetUserIDHash("demo-mode"); |
61 consumer_->OnRetailModeAuthSuccess(user_context); | 56 consumer_->OnRetailModeAuthSuccess(user_context); |
62 } | 57 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 99 |
105 void MockAuthenticator::SetExpectedCredentials( | 100 void MockAuthenticator::SetExpectedCredentials( |
106 const UserContext& user_context) { | 101 const UserContext& user_context) { |
107 expected_user_context_ = user_context; | 102 expected_user_context_ = user_context; |
108 } | 103 } |
109 | 104 |
110 MockAuthenticator::~MockAuthenticator() { | 105 MockAuthenticator::~MockAuthenticator() { |
111 } | 106 } |
112 | 107 |
113 } // namespace chromeos | 108 } // namespace chromeos |
OLD | NEW |