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

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

Issue 246098: Sync: Remove pthreads from auth_watcher. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Mock ServerConnectionManager class for use in client regression tests. 5 // Mock ServerConnectionManager class for use in client regression tests.
6 6
7 #include "chrome/test/sync/engine/mock_server_connection.h" 7 #include "chrome/test/sync/engine/mock_server_connection.h"
8 8
9 #include "chrome/browser/sync/engine/syncer_proto_util.h" 9 #include "chrome/browser/sync/engine/syncer_proto_util.h"
10 #include "chrome/browser/sync/util/character_set_converters.h" 10 #include "chrome/browser/sync/util/character_set_converters.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 void MockConnectionManager::SetMidCommitObserver( 65 void MockConnectionManager::SetMidCommitObserver(
66 MockConnectionManager::MidCommitObserver* observer) { 66 MockConnectionManager::MidCommitObserver* observer) {
67 mid_commit_observer_ = observer; 67 mid_commit_observer_ = observer;
68 } 68 }
69 69
70 bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params, 70 bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params,
71 const string& path, 71 const string& path,
72 const string& auth_token) { 72 const string& auth_token) {
73
74 ScopedDirLookup directory(directory_manager_, directory_name_);
75 CHECK(directory.good());
76
77 ClientToServerMessage post; 73 ClientToServerMessage post;
78 CHECK(post.ParseFromString(params->buffer_in)); 74 CHECK(post.ParseFromString(params->buffer_in));
79 client_stuck_ = post.sync_problem_detected(); 75 client_stuck_ = post.sync_problem_detected();
80 ClientToServerResponse response; 76 ClientToServerResponse response;
81 response.Clear(); 77 response.Clear();
78
79 ScopedDirLookup directory(directory_manager_, directory_name_);
80 // For any non-AUTHENTICATE requests, a valid directory should be set up.
82 // If the Directory's locked when we do this, it's a problem as in normal 81 // If the Directory's locked when we do this, it's a problem as in normal
83 // use this function could take a while to return because it accesses the 82 // use this function could take a while to return because it accesses the
84 // network. As we can't test this we do the next best thing and hang here 83 // network. As we can't test this we do the next best thing and hang here
85 // when there's an issue. 84 // when there's an issue.
86 { 85 if (post.message_contents() != ClientToServerMessage::AUTHENTICATE) {
86 CHECK(directory.good());
87 WriteTransaction wt(directory, syncable::UNITTEST, __FILE__, __LINE__); 87 WriteTransaction wt(directory, syncable::UNITTEST, __FILE__, __LINE__);
88 } 88 }
89
89 if (fail_next_postbuffer_) { 90 if (fail_next_postbuffer_) {
90 fail_next_postbuffer_ = false; 91 fail_next_postbuffer_ = false;
91 return false; 92 return false;
92 } 93 }
93 // Default to an ok connection. 94 // Default to an ok connection.
94 params->response->server_status = HttpResponse::SERVER_CONNECTION_OK; 95 params->response->server_status = HttpResponse::SERVER_CONNECTION_OK;
95 response.set_store_birthday(store_birthday_); 96 response.set_store_birthday(store_birthday_);
96 if (post.has_store_birthday() && post.store_birthday() != store_birthday_) { 97 if (post.has_store_birthday() && post.store_birthday() != store_birthday_) {
97 response.set_error_code(ClientToServerResponse::NOT_MY_BIRTHDAY); 98 response.set_error_code(ClientToServerResponse::NOT_MY_BIRTHDAY);
98 response.set_error_message("Merry Unbirthday!"); 99 response.set_error_message("Merry Unbirthday!");
99 response.SerializeToString(params->buffer_out); 100 response.SerializeToString(params->buffer_out);
100 store_birthday_sent_ = true; 101 store_birthday_sent_ = true;
101 return true; 102 return true;
102 } 103 }
103 bool result = true; 104 bool result = true;
104 EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday()); 105 EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday() ||
106 post.message_contents() == ClientToServerMessage::AUTHENTICATE);
105 store_birthday_sent_ = true; 107 store_birthday_sent_ = true;
106 if (post.message_contents() == ClientToServerMessage::COMMIT) { 108 if (post.message_contents() == ClientToServerMessage::COMMIT) {
107 ProcessCommit(&post, &response); 109 ProcessCommit(&post, &response);
108 } else if (post.message_contents() == ClientToServerMessage::GET_UPDATES) { 110 } else if (post.message_contents() == ClientToServerMessage::GET_UPDATES) {
109 ProcessGetUpdates(&post, &response); 111 ProcessGetUpdates(&post, &response);
112 } else if (post.message_contents() == ClientToServerMessage::AUTHENTICATE) {
113 ProcessAuthenticate(&post, &response, auth_token);
110 } else { 114 } else {
111 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage"; 115 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage";
112 return false; 116 return false;
113 } 117 }
114 if (client_command_.get()) { 118 if (client_command_.get()) {
115 response.mutable_client_command()->CopyFrom(*client_command_.get()); 119 response.mutable_client_command()->CopyFrom(*client_command_.get());
116 } 120 }
117 response.SerializeToString(params->buffer_out); 121 response.SerializeToString(params->buffer_out);
118 if (mid_commit_callback_function_) { 122 if (mid_commit_callback_function_) {
119 if (mid_commit_callback_function_(directory)) 123 if (mid_commit_callback_function_(directory))
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 ClientToServerResponse* response) { 246 ClientToServerResponse* response) {
243 CHECK(csm->has_get_updates()); 247 CHECK(csm->has_get_updates());
244 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::GET_UPDATES); 248 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::GET_UPDATES);
245 const GetUpdatesMessage& gu = csm->get_updates(); 249 const GetUpdatesMessage& gu = csm->get_updates();
246 EXPECT_TRUE(gu.has_from_timestamp()); 250 EXPECT_TRUE(gu.has_from_timestamp());
247 // TODO(sync): filter results dependant on timestamp? or check limits? 251 // TODO(sync): filter results dependant on timestamp? or check limits?
248 response->mutable_get_updates()->CopyFrom(updates_); 252 response->mutable_get_updates()->CopyFrom(updates_);
249 ResetUpdates(); 253 ResetUpdates();
250 } 254 }
251 255
256 void MockConnectionManager::ProcessAuthenticate(ClientToServerMessage* csm,
257 ClientToServerResponse* response, const std::string& auth_token){
258 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::AUTHENTICATE);
259 EXPECT_FALSE(auth_token.empty());
260
261 if (auth_token != valid_auth_token_) {
262 response->set_error_code(ClientToServerResponse::AUTH_INVALID);
263 return;
264 }
265
266 response->set_error_code(ClientToServerResponse::SUCCESS);
267 response->mutable_authenticate()->CopyFrom(auth_response_);
268 auth_response_.Clear();
269 }
270
271 void MockConnectionManager::SetAuthenticationResponseInfo(
272 const std::string& valid_auth_token,
273 const std::string& user_display_name,
274 const std::string& user_display_email,
275 const std::string& user_obfuscated_id) {
276 valid_auth_token_ = valid_auth_token;
277 sync_pb::UserIdentification* user = auth_response_.mutable_user();
278 user->set_display_name(user_display_name);
279 user->set_email(user_display_email);
280 user->set_obfuscated_id(user_obfuscated_id);
281 }
282
252 bool MockConnectionManager::ShouldConflictThisCommit() { 283 bool MockConnectionManager::ShouldConflictThisCommit() {
253 bool conflict = false; 284 bool conflict = false;
254 if (conflict_all_commits_) { 285 if (conflict_all_commits_) {
255 conflict = true; 286 conflict = true;
256 } else if (conflict_n_commits_ > 0) { 287 } else if (conflict_n_commits_ > 0) {
257 conflict = true; 288 conflict = true;
258 --conflict_n_commits_; 289 --conflict_n_commits_;
259 } 290 }
260 return conflict; 291 return conflict;
261 } 292 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 373
343 SyncEntity* MockConnectionManager::GetMutableLastUpdate() { 374 SyncEntity* MockConnectionManager::GetMutableLastUpdate() {
344 DCHECK(updates_.entries_size() > 0); 375 DCHECK(updates_.entries_size() > 0);
345 return updates_.mutable_entries()->Mutable(updates_.entries_size() - 1); 376 return updates_.mutable_entries()->Mutable(updates_.entries_size() - 1);
346 } 377 }
347 378
348 const CommitMessage& MockConnectionManager::last_sent_commit() const { 379 const CommitMessage& MockConnectionManager::last_sent_commit() const {
349 DCHECK(!commit_messages_.empty()); 380 DCHECK(!commit_messages_.empty());
350 return *commit_messages_.back(); 381 return *commit_messages_.back();
351 } 382 }
OLDNEW
« no previous file with comments | « chrome/test/sync/engine/mock_server_connection.h ('k') | chrome/test/sync/engine/test_directory_setter_upper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698