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