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

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

Issue 2844037: Fix handling of undeletion within the syncer. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Whitespace. Created 10 years, 5 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
« no previous file with comments | « chrome/test/sync/engine/mock_connection_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_connection_manager.h" 7 #include "chrome/test/sync/engine/mock_connection_manager.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/protocol/bookmark_specifics.pb.h" 10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
(...skipping 26 matching lines...) Expand all
37 conflict_all_commits_(false), 37 conflict_all_commits_(false),
38 conflict_n_commits_(0), 38 conflict_n_commits_(0),
39 next_new_id_(10000), 39 next_new_id_(10000),
40 store_birthday_("Store BDay!"), 40 store_birthday_("Store BDay!"),
41 store_birthday_sent_(false), 41 store_birthday_sent_(false),
42 client_stuck_(false), 42 client_stuck_(false),
43 commit_time_rename_prepended_string_(""), 43 commit_time_rename_prepended_string_(""),
44 fail_next_postbuffer_(false), 44 fail_next_postbuffer_(false),
45 directory_manager_(dirmgr), 45 directory_manager_(dirmgr),
46 directory_name_(name), 46 directory_name_(name),
47 mid_commit_callback_(NULL),
48 mid_commit_observer_(NULL), 47 mid_commit_observer_(NULL),
49 throttling_(false), 48 throttling_(false),
50 fail_with_auth_invalid_(false), 49 fail_with_auth_invalid_(false),
51 fail_non_periodic_get_updates_(false), 50 fail_non_periodic_get_updates_(false),
52 client_command_(NULL), 51 client_command_(NULL),
53 next_position_in_parent_(2), 52 next_position_in_parent_(2),
54 use_legacy_bookmarks_protocol_(false), 53 use_legacy_bookmarks_protocol_(false),
55 num_get_updates_requests_(0) { 54 num_get_updates_requests_(0) {
56 server_reachable_ = true; 55 server_reachable_ = true;
57 }; 56 };
58 57
59 MockConnectionManager::~MockConnectionManager() { 58 MockConnectionManager::~MockConnectionManager() {
60 for (size_t i = 0; i < commit_messages_.size(); i++)
61 delete commit_messages_[i];
62 delete mid_commit_callback_;
63 } 59 }
64 60
65 void MockConnectionManager::SetCommitTimeRename(string prepend) { 61 void MockConnectionManager::SetCommitTimeRename(string prepend) {
66 commit_time_rename_prepended_string_ = prepend; 62 commit_time_rename_prepended_string_ = prepend;
67 } 63 }
68 64
69 void MockConnectionManager::SetMidCommitCallback(Closure* callback) { 65 void MockConnectionManager::SetMidCommitCallback(Closure* callback) {
70 mid_commit_callback_ = callback; 66 mid_commit_callback_.reset(callback);
71 } 67 }
72 68
73 void MockConnectionManager::SetMidCommitObserver( 69 void MockConnectionManager::SetMidCommitObserver(
74 MockConnectionManager::MidCommitObserver* observer) { 70 MockConnectionManager::MidCommitObserver* observer) {
75 mid_commit_observer_ = observer; 71 mid_commit_observer_ = observer;
76 } 72 }
77 73
78 bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params, 74 bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params,
79 const string& path, 75 const string& path,
80 const string& auth_token, 76 const string& auth_token,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (throttling_) { 137 if (throttling_) {
142 response.set_error_code(ClientToServerResponse::THROTTLED); 138 response.set_error_code(ClientToServerResponse::THROTTLED);
143 throttling_ = false; 139 throttling_ = false;
144 } 140 }
145 141
146 if (fail_with_auth_invalid_) 142 if (fail_with_auth_invalid_)
147 response.set_error_code(ClientToServerResponse::AUTH_INVALID); 143 response.set_error_code(ClientToServerResponse::AUTH_INVALID);
148 } 144 }
149 145
150 response.SerializeToString(params->buffer_out); 146 response.SerializeToString(params->buffer_out);
151 if (mid_commit_callback_) { 147 if (post.message_contents() == ClientToServerMessage::COMMIT &&
148 mid_commit_callback_.get()) {
152 mid_commit_callback_->Run(); 149 mid_commit_callback_->Run();
153 } 150 }
154 if (mid_commit_observer_) { 151 if (mid_commit_observer_) {
155 mid_commit_observer_->Observe(); 152 mid_commit_observer_->Observe();
156 } 153 }
157 154
158 return result; 155 return result;
159 } 156 }
160 157
161 bool MockConnectionManager::IsServerReachable() { 158 bool MockConnectionManager::IsServerReachable() {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 return AddUpdateFull(id, parent_id, name, version, sync_ts, true); 240 return AddUpdateFull(id, parent_id, name, version, sync_ts, true);
244 } 241 }
245 242
246 SyncEntity* MockConnectionManager::AddUpdateBookmark(string id, 243 SyncEntity* MockConnectionManager::AddUpdateBookmark(string id,
247 string parent_id, 244 string parent_id,
248 string name, int64 version, 245 string name, int64 version,
249 int64 sync_ts) { 246 int64 sync_ts) {
250 return AddUpdateFull(id, parent_id, name, version, sync_ts, false); 247 return AddUpdateFull(id, parent_id, name, version, sync_ts, false);
251 } 248 }
252 249
250 SyncEntity* MockConnectionManager::AddUpdateFromLastCommit() {
251 EXPECT_EQ(1, last_sent_commit().entries_size());
252 EXPECT_EQ(1, last_commit_response().entryresponse_size());
253 EXPECT_EQ(CommitResponse::SUCCESS,
254 last_commit_response().entryresponse(0).response_type());
255
256 if (last_sent_commit().entries(0).deleted()) {
257 AddUpdateTombstone(syncable::Id::CreateFromServerId(
258 last_sent_commit().entries(0).id_string()));
259 } else {
260 SyncEntity* ent = updates_.add_entries();
261 ent->CopyFrom(last_sent_commit().entries(0));
262 ent->clear_insert_after_item_id();
263 ent->clear_old_parent_id();
264 ent->set_position_in_parent(
265 last_commit_response().entryresponse(0).position_in_parent());
266 ent->set_version(
267 last_commit_response().entryresponse(0).version());
268 ent->set_id_string(
269 last_commit_response().entryresponse(0).id_string());
270 // Tests don't currently care about the following:
271 // originator_cache_guid, originator_client_item_id, parent_id_string,
272 // name, non_unique_name.
273 }
274 return GetMutableLastUpdate();
275 }
276
277 void MockConnectionManager::AddUpdateTombstone(const syncable::Id& id) {
278 // Tombstones have only the ID set and dummy values for the required fields.
279 SyncEntity* ent = updates_.add_entries();
280 ent->set_id_string(id.GetServerId());
281 ent->set_version(0);
282 ent->set_name("");
283 ent->set_deleted(true);
284 }
285
253 void MockConnectionManager::SetLastUpdateDeleted() { 286 void MockConnectionManager::SetLastUpdateDeleted() {
254 GetMutableLastUpdate()->set_deleted(true); 287 // Tombstones have only the ID set. Wipe anything else.
288 string id_string = GetMutableLastUpdate()->id_string();
289 updates_.mutable_entries()->RemoveLast();
290 AddUpdateTombstone(syncable::Id::CreateFromServerId(id_string));
255 } 291 }
256 292
257 void MockConnectionManager::SetLastUpdateOriginatorFields( 293 void MockConnectionManager::SetLastUpdateOriginatorFields(
258 const string& client_id, 294 const string& client_id,
259 const string& entry_id) { 295 const string& entry_id) {
260 GetMutableLastUpdate()->set_originator_cache_guid(client_id); 296 GetMutableLastUpdate()->set_originator_cache_guid(client_id);
261 GetMutableLastUpdate()->set_originator_client_item_id(entry_id); 297 GetMutableLastUpdate()->set_originator_client_item_id(entry_id);
262 } 298 }
263 299
264 void MockConnectionManager::SetLastUpdateServerTag(const string& tag) { 300 void MockConnectionManager::SetLastUpdateServerTag(const string& tag) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 return conflict; 397 return conflict;
362 } 398 }
363 399
364 void MockConnectionManager::ProcessCommit(ClientToServerMessage* csm, 400 void MockConnectionManager::ProcessCommit(ClientToServerMessage* csm,
365 ClientToServerResponse* response_buffer) { 401 ClientToServerResponse* response_buffer) {
366 CHECK(csm->has_commit()); 402 CHECK(csm->has_commit());
367 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::COMMIT); 403 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::COMMIT);
368 map <string, string> changed_ids; 404 map <string, string> changed_ids;
369 const CommitMessage& commit_message = csm->commit(); 405 const CommitMessage& commit_message = csm->commit();
370 CommitResponse* commit_response = response_buffer->mutable_commit(); 406 CommitResponse* commit_response = response_buffer->mutable_commit();
371 commit_messages_.push_back(new CommitMessage); 407 commit_messages_->push_back(new CommitMessage);
372 commit_messages_.back()->CopyFrom(commit_message); 408 commit_messages_->back()->CopyFrom(commit_message);
373 map<string, CommitResponse_EntryResponse*> response_map; 409 map<string, CommitResponse_EntryResponse*> response_map;
374 for (int i = 0; i < commit_message.entries_size() ; i++) { 410 for (int i = 0; i < commit_message.entries_size() ; i++) {
375 const sync_pb::SyncEntity& entry = commit_message.entries(i); 411 const sync_pb::SyncEntity& entry = commit_message.entries(i);
376 CHECK(entry.has_id_string()); 412 CHECK(entry.has_id_string());
377 string id = entry.id_string(); 413 string id = entry.id_string();
378 ASSERT_LT(entry.name().length(), 256ul) << " name probably too long. True " 414 ASSERT_LT(entry.name().length(), 256ul) << " name probably too long. True "
379 "server name checking not implemented"; 415 "server name checking not implemented";
380 if (entry.version() == 0) { 416 if (entry.version() == 0) {
381 // Relies on our new item string id format. (string representation of a 417 // Relies on our new item string id format. (string representation of a
382 // negative number). 418 // negative number).
(...skipping 21 matching lines...) Expand all
404 er->set_parent_id_string(parent_id); 440 er->set_parent_id_string(parent_id);
405 } 441 }
406 if (entry.has_version() && 0 != entry.version()) { 442 if (entry.has_version() && 0 != entry.version()) {
407 er->set_id_string(id); // Allows verification. 443 er->set_id_string(id); // Allows verification.
408 } else { 444 } else {
409 string new_id = StringPrintf("mock_server:%d", next_new_id_++); 445 string new_id = StringPrintf("mock_server:%d", next_new_id_++);
410 changed_ids[id] = new_id; 446 changed_ids[id] = new_id;
411 er->set_id_string(new_id); 447 er->set_id_string(new_id);
412 } 448 }
413 } 449 }
450 commit_responses_->push_back(new CommitResponse(*commit_response));
414 } 451 }
415 452
416 SyncEntity* MockConnectionManager::AddUpdateDirectory( 453 SyncEntity* MockConnectionManager::AddUpdateDirectory(
417 syncable::Id id, syncable::Id parent_id, string name, int64 version, 454 syncable::Id id, syncable::Id parent_id, string name, int64 version,
418 int64 sync_ts) { 455 int64 sync_ts) {
419 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(), 456 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(),
420 name, version, sync_ts); 457 name, version, sync_ts);
421 } 458 }
422 459
423 SyncEntity* MockConnectionManager::AddUpdateBookmark( 460 SyncEntity* MockConnectionManager::AddUpdateBookmark(
424 syncable::Id id, syncable::Id parent_id, string name, int64 version, 461 syncable::Id id, syncable::Id parent_id, string name, int64 version,
425 int64 sync_ts) { 462 int64 sync_ts) {
426 return AddUpdateBookmark(id.GetServerId(), parent_id.GetServerId(), 463 return AddUpdateBookmark(id.GetServerId(), parent_id.GetServerId(),
427 name, version, sync_ts); 464 name, version, sync_ts);
428 } 465 }
429 466
430 SyncEntity* MockConnectionManager::GetMutableLastUpdate() { 467 SyncEntity* MockConnectionManager::GetMutableLastUpdate() {
431 DCHECK(updates_.entries_size() > 0); 468 EXPECT_TRUE(updates_.entries_size() > 0);
432 return updates_.mutable_entries()->Mutable(updates_.entries_size() - 1); 469 return updates_.mutable_entries()->Mutable(updates_.entries_size() - 1);
433 } 470 }
434 471
435 const CommitMessage& MockConnectionManager::last_sent_commit() const { 472 const CommitMessage& MockConnectionManager::last_sent_commit() const {
436 DCHECK(!commit_messages_.empty()); 473 EXPECT_TRUE(!commit_messages_.empty());
437 return *commit_messages_.back(); 474 return *commit_messages_->back();
475 }
476
477 const CommitResponse& MockConnectionManager::last_commit_response() const {
478 EXPECT_TRUE(!commit_responses_.empty());
479 return *commit_responses_->back();
438 } 480 }
439 481
440 void MockConnectionManager::ThrottleNextRequest( 482 void MockConnectionManager::ThrottleNextRequest(
441 ResponseCodeOverrideRequestor* visitor) { 483 ResponseCodeOverrideRequestor* visitor) {
442 AutoLock lock(response_code_override_lock_); 484 AutoLock lock(response_code_override_lock_);
443 throttling_ = true; 485 throttling_ = true;
444 if (visitor) 486 if (visitor)
445 visitor->OnOverrideComplete(); 487 visitor->OnOverrideComplete();
446 } 488 }
447 489
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 526
485 void MockConnectionManager::SetServerNotReachable() { 527 void MockConnectionManager::SetServerNotReachable() {
486 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; 528 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE;
487 server_reachable_ = false; 529 server_reachable_ = false;
488 browser_sync::ServerConnectionEvent event = { 530 browser_sync::ServerConnectionEvent event = {
489 browser_sync::ServerConnectionEvent::STATUS_CHANGED, 531 browser_sync::ServerConnectionEvent::STATUS_CHANGED,
490 server_status_, 532 server_status_,
491 server_reachable_ }; 533 server_reachable_ };
492 channel_->NotifyListeners(event); 534 channel_->NotifyListeners(event);
493 } 535 }
OLDNEW
« no previous file with comments | « chrome/test/sync/engine/mock_connection_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698