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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/sync/engine/mock_gaia_authenticator.cc
===================================================================
--- chrome/test/sync/engine/mock_gaia_authenticator.cc (revision 0)
+++ chrome/test/sync/engine/mock_gaia_authenticator.cc (revision 0)
@@ -0,0 +1,107 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Use MockGaiaAuthenticator to test your application by faking a login session.
+// This mock object should be initialized with the response you expect it to
+// return, and then can be used in exactly the same way as the real
+// GaiaAuthenticator.
+
+#include "chrome/test/sync/engine/mock_gaia_authenticator.h"
+
+using std::string;
+
+namespace browser_sync {
+
+MockGaiaAuthenticator::MockGaiaAuthenticator(const char* user_agent,
+ const char* service_id,
+ const char* gaia_url) :
+ current_user_(""), should_save_credentials_(false) {
+ // This discards user_agent, service_id, gaia_url since the mock object
+ // doesn't care about them.
+}
+
+// Add a mock user to internal list of users.
+void MockGaiaAuthenticator::AddMockUser(MockUser mock_user) {
+ mock_credentials_[mock_user.email] = mock_user;
+}
+
+// A convenience method to add a mock user to internal list of users.
+void MockGaiaAuthenticator::AddMockUser(string email, string passwd,
+ string auth_token, string lsid,
+ string sid, enum AuthenticationError
+ auth_error, string error_url,
+ string captcha_token,
+ string captcha_url) {
+ MockUser mock_user;
+ mock_user.email = email;
+ mock_user.passwd = passwd;
+ mock_user.auth_token = auth_token;
+ mock_user.lsid = lsid;
+ mock_user.sid = sid;
+ mock_user.auth_error = auth_error;
+ mock_user.error_url = error_url;
+ mock_user.captcha_token = captcha_token;
+ mock_user.captcha_url = captcha_url;
+ AddMockUser(mock_user);
+}
+
+// A convenience method to add a mock user to internal list of users.
+void MockGaiaAuthenticator::AddMockUser(string email, string passwd,
+ string auth_token, string lsid,
+ string sid, enum AuthenticationError
+ auth_error) {
+ MockUser mock_user;
+ mock_user.email = email;
+ mock_user.passwd = passwd;
+ mock_user.auth_token = auth_token;
+ mock_user.lsid = lsid;
+ mock_user.sid = sid;
+ mock_user.auth_error = auth_error;
+ AddMockUser(mock_user);
+}
+
+void MockGaiaAuthenticator::RemoveMockUser(const char* email) {
+ mock_credentials_.erase(email);
+}
+
+void MockGaiaAuthenticator::RemoveAllMockUsers() {
+ mock_credentials_.clear();
+}
+
+bool MockGaiaAuthenticator::Authenticate() {
+ if (!should_save_credentials_) {
+ ResetCredentials();
+ return false;
+ }
+ return Authenticate(mock_credentials_[current_user_].email.c_str(),
+ mock_credentials_[current_user_].passwd.c_str(), true);
+}
+
+bool MockGaiaAuthenticator::Authenticate(const char* email,
+ const char* passwd,
+ bool should_save_credentials) {
+ // Simply assign value to field; the value is read by the accessors when
+ // reading.
+ should_save_credentials_ = should_save_credentials;
+
+ // Check if we already know about this mock user.
+ if (mock_credentials_.find(email) == mock_credentials_.end()) {
+ current_user_ = "";
+ return false;
+ }
+
+ // If found, keep the current logged-in user available for token requests.
+ current_user_ = email;
+
+ // Finding a user does not necessarily imply that the user was logged in OK.
+ // Therefore also check if the AuthenticationError is None.
+ return (mock_credentials_[current_user_].auth_error == None);
+}
+
+// Remove any stored knowledge about the currently logged-in user, but keep
+// details of mock users.
+void MockGaiaAuthenticator::ResetCredentials() {
+ current_user_ = "";
+}
+} // namespace browser_sync
Property changes on: chrome\test\sync\engine\mock_gaia_authenticator.cc
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698