summaryrefslogtreecommitdiffstats
path: root/chrome/test/sync/engine/mock_server_connection.cc
diff options
context:
space:
mode:
authortim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 23:57:20 +0000
committertim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 23:57:20 +0000
commit3c47992ef36d4737f1ca8f6c701f047c05b12481 (patch)
treea745663ad77f4b5baf9904adfbbbc65de3bbb22c /chrome/test/sync/engine/mock_server_connection.cc
parentd9735af55ab6fe947c68eb27c686df901d260398 (diff)
downloadchromium_src-3c47992ef36d4737f1ca8f6c701f047c05b12481.zip
chromium_src-3c47992ef36d4737f1ca8f6c701f047c05b12481.tar.gz
chromium_src-3c47992ef36d4737f1ca8f6c701f047c05b12481.tar.bz2
Sync: Remove pthreads from auth_watcher.
BUG=19895 TEST=AuthWatcherTest Review URL: http://codereview.chromium.org/246098 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28352 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/sync/engine/mock_server_connection.cc')
-rw-r--r--chrome/test/sync/engine/mock_server_connection.cc43
1 files changed, 37 insertions, 6 deletions
diff --git a/chrome/test/sync/engine/mock_server_connection.cc b/chrome/test/sync/engine/mock_server_connection.cc
index c4595bd..46ec870 100644
--- a/chrome/test/sync/engine/mock_server_connection.cc
+++ b/chrome/test/sync/engine/mock_server_connection.cc
@@ -70,22 +70,23 @@ void MockConnectionManager::SetMidCommitObserver(
bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params,
const string& path,
const string& auth_token) {
-
- ScopedDirLookup directory(directory_manager_, directory_name_);
- CHECK(directory.good());
-
ClientToServerMessage post;
CHECK(post.ParseFromString(params->buffer_in));
client_stuck_ = post.sync_problem_detected();
ClientToServerResponse response;
response.Clear();
+
+ ScopedDirLookup directory(directory_manager_, directory_name_);
+ // For any non-AUTHENTICATE requests, a valid directory should be set up.
// If the Directory's locked when we do this, it's a problem as in normal
// use this function could take a while to return because it accesses the
// network. As we can't test this we do the next best thing and hang here
// when there's an issue.
- {
+ if (post.message_contents() != ClientToServerMessage::AUTHENTICATE) {
+ CHECK(directory.good());
WriteTransaction wt(directory, syncable::UNITTEST, __FILE__, __LINE__);
}
+
if (fail_next_postbuffer_) {
fail_next_postbuffer_ = false;
return false;
@@ -101,12 +102,15 @@ bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params,
return true;
}
bool result = true;
- EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday());
+ EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday() ||
+ post.message_contents() == ClientToServerMessage::AUTHENTICATE);
store_birthday_sent_ = true;
if (post.message_contents() == ClientToServerMessage::COMMIT) {
ProcessCommit(&post, &response);
} else if (post.message_contents() == ClientToServerMessage::GET_UPDATES) {
ProcessGetUpdates(&post, &response);
+ } else if (post.message_contents() == ClientToServerMessage::AUTHENTICATE) {
+ ProcessAuthenticate(&post, &response, auth_token);
} else {
EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage";
return false;
@@ -249,6 +253,33 @@ void MockConnectionManager::ProcessGetUpdates(ClientToServerMessage* csm,
ResetUpdates();
}
+void MockConnectionManager::ProcessAuthenticate(ClientToServerMessage* csm,
+ ClientToServerResponse* response, const std::string& auth_token){
+ ASSERT_EQ(csm->message_contents(), ClientToServerMessage::AUTHENTICATE);
+ EXPECT_FALSE(auth_token.empty());
+
+ if (auth_token != valid_auth_token_) {
+ response->set_error_code(ClientToServerResponse::AUTH_INVALID);
+ return;
+ }
+
+ response->set_error_code(ClientToServerResponse::SUCCESS);
+ response->mutable_authenticate()->CopyFrom(auth_response_);
+ auth_response_.Clear();
+}
+
+void MockConnectionManager::SetAuthenticationResponseInfo(
+ const std::string& valid_auth_token,
+ const std::string& user_display_name,
+ const std::string& user_display_email,
+ const std::string& user_obfuscated_id) {
+ valid_auth_token_ = valid_auth_token;
+ sync_pb::UserIdentification* user = auth_response_.mutable_user();
+ user->set_display_name(user_display_name);
+ user->set_email(user_display_email);
+ user->set_obfuscated_id(user_obfuscated_id);
+}
+
bool MockConnectionManager::ShouldConflictThisCommit() {
bool conflict = false;
if (conflict_all_commits_) {