Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: chrome/test/sync/engine/mock_gaia_authenticator.cc

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 // Use MockGaiaAuthenticator to test your application by faking a login session.
6 // This mock object should be initialized with the response you expect it to
7 // return, and then can be used in exactly the same way as the real
8 // GaiaAuthenticator.
9
10 #include "chrome/test/sync/engine/mock_gaia_authenticator.h"
11
12 using std::string;
13
14 namespace browser_sync {
15
16 MockGaiaAuthenticator::MockGaiaAuthenticator(const char* user_agent,
17 const char* service_id,
18 const char* gaia_url) :
19 current_user_(""), should_save_credentials_(false) {
20 // This discards user_agent, service_id, gaia_url since the mock object
21 // doesn't care about them.
22 }
23
24 // Add a mock user to internal list of users.
25 void MockGaiaAuthenticator::AddMockUser(MockUser mock_user) {
26 mock_credentials_[mock_user.email] = mock_user;
27 }
28
29 // A convenience method to add a mock user to internal list of users.
30 void MockGaiaAuthenticator::AddMockUser(string email, string passwd,
31 string auth_token, string lsid,
32 string sid, enum AuthenticationError
33 auth_error, string error_url,
34 string captcha_token,
35 string captcha_url) {
36 MockUser mock_user;
37 mock_user.email = email;
38 mock_user.passwd = passwd;
39 mock_user.auth_token = auth_token;
40 mock_user.lsid = lsid;
41 mock_user.sid = sid;
42 mock_user.auth_error = auth_error;
43 mock_user.error_url = error_url;
44 mock_user.captcha_token = captcha_token;
45 mock_user.captcha_url = captcha_url;
46 AddMockUser(mock_user);
47 }
48
49 // A convenience method to add a mock user to internal list of users.
50 void MockGaiaAuthenticator::AddMockUser(string email, string passwd,
51 string auth_token, string lsid,
52 string sid, enum AuthenticationError
53 auth_error) {
54 MockUser mock_user;
55 mock_user.email = email;
56 mock_user.passwd = passwd;
57 mock_user.auth_token = auth_token;
58 mock_user.lsid = lsid;
59 mock_user.sid = sid;
60 mock_user.auth_error = auth_error;
61 AddMockUser(mock_user);
62 }
63
64 void MockGaiaAuthenticator::RemoveMockUser(const char* email) {
65 mock_credentials_.erase(email);
66 }
67
68 void MockGaiaAuthenticator::RemoveAllMockUsers() {
69 mock_credentials_.clear();
70 }
71
72 bool MockGaiaAuthenticator::Authenticate() {
73 if (!should_save_credentials_) {
74 ResetCredentials();
75 return false;
76 }
77 return Authenticate(mock_credentials_[current_user_].email.c_str(),
78 mock_credentials_[current_user_].passwd.c_str(), true);
79 }
80
81 bool MockGaiaAuthenticator::Authenticate(const char* email,
82 const char* passwd,
83 bool should_save_credentials) {
84 // Simply assign value to field; the value is read by the accessors when
85 // reading.
86 should_save_credentials_ = should_save_credentials;
87
88 // Check if we already know about this mock user.
89 if (mock_credentials_.find(email) == mock_credentials_.end()) {
90 current_user_ = "";
91 return false;
92 }
93
94 // If found, keep the current logged-in user available for token requests.
95 current_user_ = email;
96
97 // Finding a user does not necessarily imply that the user was logged in OK.
98 // Therefore also check if the AuthenticationError is None.
99 return (mock_credentials_[current_user_].auth_error == None);
100 }
101
102 // Remove any stored knowledge about the currently logged-in user, but keep
103 // details of mock users.
104 void MockGaiaAuthenticator::ResetCredentials() {
105 current_user_ = "";
106 }
107 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698