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/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(const UserContext& user_context) { | |
47 AuthenticateToLogin(NULL /* not used */, user_context); | |
48 } | |
49 | |
50 void MockAuthenticator::LoginAsSupervisedUser(const UserContext& user_context) { | |
51 UserContext new_user_context = user_context; | |
52 new_user_context.SetUserIDHash(user_context.GetUserID()); | |
53 consumer_->OnAuthSuccess(new_user_context); | |
54 } | |
55 | |
56 void MockAuthenticator::LoginRetailMode() { | |
57 UserContext user_context("demo-mode"); | |
58 user_context.SetUserIDHash("demo-mode"); | |
59 consumer_->OnRetailModeAuthSuccess(user_context); | |
60 } | |
61 | |
62 void MockAuthenticator::LoginOffTheRecord() { | |
63 consumer_->OnOffTheRecordAuthSuccess(); | |
64 } | |
65 | |
66 void MockAuthenticator::LoginAsPublicAccount(const std::string& username) { | |
67 UserContext user_context(expected_user_context_.GetUserID()); | |
68 user_context.SetUserIDHash(expected_user_context_.GetUserID()); | |
69 consumer_->OnAuthSuccess(user_context); | |
70 } | |
71 | |
72 void MockAuthenticator::LoginAsKioskAccount(const std::string& app_user_id, | |
73 bool use_guest_mount) { | |
74 UserContext user_context(expected_user_context_.GetUserID()); | |
75 user_context.SetUserIDHash(expected_user_context_.GetUserID()); | |
76 consumer_->OnAuthSuccess(user_context); | |
77 } | |
78 | |
79 void MockAuthenticator::OnRetailModeAuthSuccess() { | |
80 UserContext user_context(expected_user_context_.GetUserID()); | |
81 user_context.SetUserIDHash(expected_user_context_.GetUserID()); | |
82 consumer_->OnRetailModeAuthSuccess(user_context); | |
83 } | |
84 | |
85 void MockAuthenticator::OnAuthSuccess() { | |
86 // If we want to be more like the real thing, we could save the user ID | |
87 // in AuthenticateToLogin, but there's not much of a point. | |
88 UserContext user_context(expected_user_context_); | |
89 user_context.SetUserIDHash(expected_user_context_.GetUserID()); | |
90 consumer_->OnAuthSuccess(user_context); | |
91 } | |
92 | |
93 void MockAuthenticator::OnAuthFailure(const AuthFailure& failure) { | |
94 consumer_->OnAuthFailure(failure); | |
95 } | |
96 | |
97 void MockAuthenticator::RecoverEncryptedData(const std::string& old_password) { | |
98 } | |
99 | |
100 void MockAuthenticator::ResyncEncryptedData() { | |
101 } | |
102 | |
103 void MockAuthenticator::SetExpectedCredentials( | |
104 const UserContext& user_context) { | |
105 expected_user_context_ = user_context; | |
106 } | |
107 | |
108 MockAuthenticator::~MockAuthenticator() { | |
109 } | |
110 | |
111 } // namespace chromeos | |
OLD | NEW |