OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "sync/test/engine/mock_connection_manager.h" | 7 #include "components/sync/test/engine/mock_connection_manager.h" |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "sync/engine/syncer_proto_util.h" | 15 #include "components/sync/engine_impl/syncer_proto_util.h" |
16 #include "sync/protocol/bookmark_specifics.pb.h" | 16 #include "components/sync/protocol/bookmark_specifics.pb.h" |
17 #include "sync/syncable/directory.h" | 17 #include "components/sync/syncable/directory.h" |
18 #include "sync/syncable/syncable_write_transaction.h" | 18 #include "components/sync/syncable/syncable_write_transaction.h" |
19 #include "sync/test/engine/test_id_factory.h" | 19 #include "components/sync/test/engine/test_id_factory.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 using std::find; | 22 using std::find; |
23 using std::map; | 23 using std::map; |
24 using std::string; | 24 using std::string; |
25 using sync_pb::ClientToServerMessage; | 25 using sync_pb::ClientToServerMessage; |
26 using sync_pb::CommitMessage; | 26 using sync_pb::CommitMessage; |
27 using sync_pb::CommitResponse; | 27 using sync_pb::CommitResponse; |
28 using sync_pb::GetUpdatesMessage; | 28 using sync_pb::GetUpdatesMessage; |
29 using sync_pb::SyncEnums; | 29 using sync_pb::SyncEnums; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 commit_time_rename_prepended_string_ = prepend; | 66 commit_time_rename_prepended_string_ = prepend; |
67 } | 67 } |
68 | 68 |
69 void MockConnectionManager::SetMidCommitCallback( | 69 void MockConnectionManager::SetMidCommitCallback( |
70 const base::Closure& callback) { | 70 const base::Closure& callback) { |
71 mid_commit_callback_ = callback; | 71 mid_commit_callback_ = callback; |
72 } | 72 } |
73 | 73 |
74 void MockConnectionManager::SetMidCommitObserver( | 74 void MockConnectionManager::SetMidCommitObserver( |
75 MockConnectionManager::MidCommitObserver* observer) { | 75 MockConnectionManager::MidCommitObserver* observer) { |
76 mid_commit_observer_ = observer; | 76 mid_commit_observer_ = observer; |
77 } | 77 } |
78 | 78 |
79 bool MockConnectionManager::PostBufferToPath(PostBufferParams* params, | 79 bool MockConnectionManager::PostBufferToPath(PostBufferParams* params, |
80 const string& path, | 80 const string& path, |
81 const string& auth_token) { | 81 const string& auth_token) { |
82 ClientToServerMessage post; | 82 ClientToServerMessage post; |
83 CHECK(post.ParseFromString(params->buffer_in)); | 83 CHECK(post.ParseFromString(params->buffer_in)); |
84 CHECK(post.has_protocol_version()); | 84 CHECK(post.has_protocol_version()); |
85 CHECK(post.has_api_key()); | 85 CHECK(post.has_api_key()); |
86 CHECK(post.has_bag_of_chips()); | 86 CHECK(post.has_bag_of_chips()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 if (!server_reachable_) { | 119 if (!server_reachable_) { |
120 params->response.server_status = HttpResponse::CONNECTION_UNAVAILABLE; | 120 params->response.server_status = HttpResponse::CONNECTION_UNAVAILABLE; |
121 return false; | 121 return false; |
122 } | 122 } |
123 | 123 |
124 // Default to an ok connection. | 124 // Default to an ok connection. |
125 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK; | 125 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK; |
126 response.set_error_code(SyncEnums::SUCCESS); | 126 response.set_error_code(SyncEnums::SUCCESS); |
127 const string current_store_birthday = store_birthday(); | 127 const string current_store_birthday = store_birthday(); |
128 response.set_store_birthday(current_store_birthday); | 128 response.set_store_birthday(current_store_birthday); |
129 if (post.has_store_birthday() && post.store_birthday() != | 129 if (post.has_store_birthday() && |
130 current_store_birthday) { | 130 post.store_birthday() != current_store_birthday) { |
131 response.set_error_code(SyncEnums::NOT_MY_BIRTHDAY); | 131 response.set_error_code(SyncEnums::NOT_MY_BIRTHDAY); |
132 response.set_error_message("Merry Unbirthday!"); | 132 response.set_error_message("Merry Unbirthday!"); |
133 response.SerializeToString(¶ms->buffer_out); | 133 response.SerializeToString(¶ms->buffer_out); |
134 store_birthday_sent_ = true; | 134 store_birthday_sent_ = true; |
135 return true; | 135 return true; |
136 } | 136 } |
137 bool result = true; | 137 bool result = true; |
138 EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday() || | 138 EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday() || |
139 post.message_contents() == ClientToServerMessage::AUTHENTICATE || | 139 post.message_contents() == ClientToServerMessage::AUTHENTICATE || |
140 post.message_contents() == | 140 post.message_contents() == |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 sync_pb::SyncEntity_BookmarkData* data = entity->mutable_bookmarkdata(); | 199 sync_pb::SyncEntity_BookmarkData* data = entity->mutable_bookmarkdata(); |
200 data->set_bookmark_folder(is_folder); | 200 data->set_bookmark_folder(is_folder); |
201 | 201 |
202 if (!is_folder) { | 202 if (!is_folder) { |
203 data->set_bookmark_url("http://google.com"); | 203 data->set_bookmark_url("http://google.com"); |
204 } | 204 } |
205 } else { | 205 } else { |
206 entity->set_folder(is_folder); | 206 entity->set_folder(is_folder); |
207 entity->mutable_specifics()->mutable_bookmark(); | 207 entity->mutable_specifics()->mutable_bookmark(); |
208 if (!is_folder) { | 208 if (!is_folder) { |
209 entity->mutable_specifics()->mutable_bookmark()-> | 209 entity->mutable_specifics()->mutable_bookmark()->set_url( |
210 set_url("http://google.com"); | 210 "http://google.com"); |
211 } | 211 } |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( | 215 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( |
216 int id, | 216 int id, |
217 int parent_id, | 217 int parent_id, |
218 const string& name, | 218 const string& name, |
219 int64_t version, | 219 int64_t version, |
220 int64_t sync_ts, | 220 int64_t sync_ts, |
221 const std::string& originator_cache_guid, | 221 const std::string& originator_cache_guid, |
222 const std::string& originator_client_item_id) { | 222 const std::string& originator_client_item_id) { |
223 return AddUpdateDirectory(TestIdFactory::FromNumber(id), | 223 return AddUpdateDirectory( |
224 TestIdFactory::FromNumber(parent_id), | 224 TestIdFactory::FromNumber(id), TestIdFactory::FromNumber(parent_id), name, |
225 name, | 225 version, sync_ts, originator_cache_guid, originator_client_item_id); |
226 version, | |
227 sync_ts, | |
228 originator_cache_guid, | |
229 originator_client_item_id); | |
230 } | 226 } |
231 | 227 |
232 void MockConnectionManager::SetGUClientCommand( | 228 void MockConnectionManager::SetGUClientCommand( |
233 sync_pb::ClientCommand* command) { | 229 sync_pb::ClientCommand* command) { |
234 gu_client_command_.reset(command); | 230 gu_client_command_.reset(command); |
235 } | 231 } |
236 | 232 |
237 void MockConnectionManager::SetCommitClientCommand( | 233 void MockConnectionManager::SetCommitClientCommand( |
238 sync_pb::ClientCommand* command) { | 234 sync_pb::ClientCommand* command) { |
239 commit_client_command_.reset(command); | 235 commit_client_command_.reset(command); |
240 } | 236 } |
241 | 237 |
242 void MockConnectionManager::SetTransientErrorId(syncable::Id id) { | 238 void MockConnectionManager::SetTransientErrorId(syncable::Id id) { |
243 transient_error_ids_.push_back(id); | 239 transient_error_ids_.push_back(id); |
244 } | 240 } |
245 | 241 |
246 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( | 242 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( |
247 int id, | 243 int id, |
248 int parent_id, | 244 int parent_id, |
249 const string& name, | 245 const string& name, |
250 int64_t version, | 246 int64_t version, |
251 int64_t sync_ts, | 247 int64_t sync_ts, |
252 const string& originator_client_item_id, | 248 const string& originator_client_item_id, |
253 const string& originator_cache_guid) { | 249 const string& originator_cache_guid) { |
254 return AddUpdateBookmark(TestIdFactory::FromNumber(id), | 250 return AddUpdateBookmark( |
255 TestIdFactory::FromNumber(parent_id), | 251 TestIdFactory::FromNumber(id), TestIdFactory::FromNumber(parent_id), name, |
256 name, | 252 version, sync_ts, originator_client_item_id, originator_cache_guid); |
257 version, | |
258 sync_ts, | |
259 originator_client_item_id, | |
260 originator_cache_guid); | |
261 } | 253 } |
262 | 254 |
263 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics( | 255 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics( |
264 int id, | 256 int id, |
265 int parent_id, | 257 int parent_id, |
266 const string& name, | 258 const string& name, |
267 int64_t version, | 259 int64_t version, |
268 int64_t sync_ts, | 260 int64_t sync_ts, |
269 bool is_dir, | 261 bool is_dir, |
270 int64_t position, | 262 int64_t position, |
271 const sync_pb::EntitySpecifics& specifics) { | 263 const sync_pb::EntitySpecifics& specifics) { |
272 sync_pb::SyncEntity* ent = AddUpdateMeta( | 264 sync_pb::SyncEntity* ent = |
273 TestIdFactory::FromNumber(id).GetServerId(), | 265 AddUpdateMeta(TestIdFactory::FromNumber(id).GetServerId(), |
274 TestIdFactory::FromNumber(parent_id).GetServerId(), | 266 TestIdFactory::FromNumber(parent_id).GetServerId(), name, |
275 name, version, sync_ts); | 267 version, sync_ts); |
276 ent->set_position_in_parent(position); | 268 ent->set_position_in_parent(position); |
277 ent->mutable_specifics()->CopyFrom(specifics); | 269 ent->mutable_specifics()->CopyFrom(specifics); |
278 ent->set_folder(is_dir); | 270 ent->set_folder(is_dir); |
279 return ent; | 271 return ent; |
280 } | 272 } |
281 | 273 |
282 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics( | 274 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics( |
283 int id, | 275 int id, |
284 int parent_id, | 276 int parent_id, |
285 const string& name, | 277 const string& name, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 AddUpdateFull(id, parent_id, name, version, sync_ts, false); | 400 AddUpdateFull(id, parent_id, name, version, sync_ts, false); |
409 ret->set_originator_cache_guid(originator_cache_guid); | 401 ret->set_originator_cache_guid(originator_cache_guid); |
410 ret->set_originator_client_item_id(originator_client_item_id); | 402 ret->set_originator_client_item_id(originator_client_item_id); |
411 return ret; | 403 return ret; |
412 } | 404 } |
413 | 405 |
414 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFromLastCommit() { | 406 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFromLastCommit() { |
415 EXPECT_EQ(1, last_sent_commit().entries_size()); | 407 EXPECT_EQ(1, last_sent_commit().entries_size()); |
416 EXPECT_EQ(1, last_commit_response().entryresponse_size()); | 408 EXPECT_EQ(1, last_commit_response().entryresponse_size()); |
417 EXPECT_EQ(CommitResponse::SUCCESS, | 409 EXPECT_EQ(CommitResponse::SUCCESS, |
418 last_commit_response().entryresponse(0).response_type()); | 410 last_commit_response().entryresponse(0).response_type()); |
419 | 411 |
420 if (last_sent_commit().entries(0).deleted()) { | 412 if (last_sent_commit().entries(0).deleted()) { |
421 ModelType type = GetModelType(last_sent_commit().entries(0)); | 413 ModelType type = GetModelType(last_sent_commit().entries(0)); |
422 AddUpdateTombstone(syncable::Id::CreateFromServerId( | 414 AddUpdateTombstone(syncable::Id::CreateFromServerId( |
423 last_sent_commit().entries(0).id_string()), type); | 415 last_sent_commit().entries(0).id_string()), |
| 416 type); |
424 } else { | 417 } else { |
425 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); | 418 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); |
426 ent->CopyFrom(last_sent_commit().entries(0)); | 419 ent->CopyFrom(last_sent_commit().entries(0)); |
427 ent->clear_insert_after_item_id(); | 420 ent->clear_insert_after_item_id(); |
428 ent->clear_old_parent_id(); | 421 ent->clear_old_parent_id(); |
429 ent->set_position_in_parent( | 422 ent->set_position_in_parent( |
430 last_commit_response().entryresponse(0).position_in_parent()); | 423 last_commit_response().entryresponse(0).position_in_parent()); |
431 ent->set_version( | 424 ent->set_version(last_commit_response().entryresponse(0).version()); |
432 last_commit_response().entryresponse(0).version()); | 425 ent->set_id_string(last_commit_response().entryresponse(0).id_string()); |
433 ent->set_id_string( | |
434 last_commit_response().entryresponse(0).id_string()); | |
435 | 426 |
436 // This is the same hack as in AddUpdateMeta. See the comment in that | 427 // This is the same hack as in AddUpdateMeta. See the comment in that |
437 // function for more information. | 428 // function for more information. |
438 ent->set_originator_cache_guid(kCacheGuid); | 429 ent->set_originator_cache_guid(kCacheGuid); |
439 ent->set_originator_client_item_id( | 430 ent->set_originator_client_item_id( |
440 last_commit_response().entryresponse(0).id_string()); | 431 last_commit_response().entryresponse(0).id_string()); |
441 | 432 |
442 if (last_sent_commit().entries(0).has_unique_position()) { | 433 if (last_sent_commit().entries(0).has_unique_position()) { |
443 ent->mutable_unique_position()->CopyFrom( | 434 ent->mutable_unique_position()->CopyFrom( |
444 last_sent_commit().entries(0).unique_position()); | 435 last_sent_commit().entries(0).unique_position()); |
445 } | 436 } |
446 | 437 |
447 // Tests don't currently care about the following: | 438 // Tests don't currently care about the following: |
448 // parent_id_string, name, non_unique_name. | 439 // parent_id_string, name, non_unique_name. |
449 } | 440 } |
450 return GetMutableLastUpdate(); | 441 return GetMutableLastUpdate(); |
451 } | 442 } |
452 | 443 |
453 void MockConnectionManager::AddUpdateTombstone( | 444 void MockConnectionManager::AddUpdateTombstone(const syncable::Id& id, |
454 const syncable::Id& id, | 445 ModelType type) { |
455 ModelType type) { | |
456 // Tombstones have only the ID set and dummy values for the required fields. | 446 // Tombstones have only the ID set and dummy values for the required fields. |
457 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); | 447 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); |
458 ent->set_id_string(id.GetServerId()); | 448 ent->set_id_string(id.GetServerId()); |
459 ent->set_version(0); | 449 ent->set_version(0); |
460 ent->set_name(""); | 450 ent->set_name(""); |
461 ent->set_deleted(true); | 451 ent->set_deleted(true); |
462 | 452 |
463 // Make sure we can still extract the ModelType from this tombstone. | 453 // Make sure we can still extract the ModelType from this tombstone. |
464 AddDefaultFieldValue(type, ent->mutable_specifics()); | 454 AddDefaultFieldValue(type, ent->mutable_specifics()); |
465 } | 455 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 if (conflict_all_commits_) { | 572 if (conflict_all_commits_) { |
583 conflict = true; | 573 conflict = true; |
584 } else if (conflict_n_commits_ > 0) { | 574 } else if (conflict_n_commits_ > 0) { |
585 conflict = true; | 575 conflict = true; |
586 --conflict_n_commits_; | 576 --conflict_n_commits_; |
587 } | 577 } |
588 return conflict; | 578 return conflict; |
589 } | 579 } |
590 | 580 |
591 bool MockConnectionManager::ShouldTransientErrorThisId(syncable::Id id) { | 581 bool MockConnectionManager::ShouldTransientErrorThisId(syncable::Id id) { |
592 return find(transient_error_ids_.begin(), transient_error_ids_.end(), id) | 582 return find(transient_error_ids_.begin(), transient_error_ids_.end(), id) != |
593 != transient_error_ids_.end(); | 583 transient_error_ids_.end(); |
594 } | 584 } |
595 | 585 |
596 void MockConnectionManager::ProcessCommit( | 586 void MockConnectionManager::ProcessCommit( |
597 sync_pb::ClientToServerMessage* csm, | 587 sync_pb::ClientToServerMessage* csm, |
598 sync_pb::ClientToServerResponse* response_buffer) { | 588 sync_pb::ClientToServerResponse* response_buffer) { |
599 CHECK(csm->has_commit()); | 589 CHECK(csm->has_commit()); |
600 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::COMMIT); | 590 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::COMMIT); |
601 map <string, string> changed_ids; | 591 map<string, string> changed_ids; |
602 const CommitMessage& commit_message = csm->commit(); | 592 const CommitMessage& commit_message = csm->commit(); |
603 CommitResponse* commit_response = response_buffer->mutable_commit(); | 593 CommitResponse* commit_response = response_buffer->mutable_commit(); |
604 commit_messages_.push_back(new CommitMessage); | 594 commit_messages_.push_back(new CommitMessage); |
605 commit_messages_.back()->CopyFrom(commit_message); | 595 commit_messages_.back()->CopyFrom(commit_message); |
606 map<string, sync_pb::CommitResponse_EntryResponse*> response_map; | 596 map<string, sync_pb::CommitResponse_EntryResponse*> response_map; |
607 for (int i = 0; i < commit_message.entries_size() ; i++) { | 597 for (int i = 0; i < commit_message.entries_size(); i++) { |
608 const sync_pb::SyncEntity& entry = commit_message.entries(i); | 598 const sync_pb::SyncEntity& entry = commit_message.entries(i); |
609 CHECK(entry.has_id_string()); | 599 CHECK(entry.has_id_string()); |
610 string id_string = entry.id_string(); | 600 string id_string = entry.id_string(); |
611 ASSERT_LT(entry.name().length(), 256ul) << " name probably too long. True " | 601 ASSERT_LT(entry.name().length(), 256ul) |
612 "server name checking not implemented"; | 602 << " name probably too long. True " |
| 603 "server name checking not implemented"; |
613 syncable::Id id; | 604 syncable::Id id; |
614 if (entry.version() == 0) { | 605 if (entry.version() == 0) { |
615 // Relies on our new item string id format. (string representation of a | 606 // Relies on our new item string id format. (string representation of a |
616 // negative number). | 607 // negative number). |
617 id = syncable::Id::CreateFromClientString(id_string); | 608 id = syncable::Id::CreateFromClientString(id_string); |
618 } else { | 609 } else { |
619 id = syncable::Id::CreateFromServerId(id_string); | 610 id = syncable::Id::CreateFromServerId(id_string); |
620 } | 611 } |
621 committed_ids_.push_back(id); | 612 committed_ids_.push_back(id); |
622 | 613 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 } | 659 } |
669 | 660 |
670 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( | 661 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( |
671 syncable::Id id, | 662 syncable::Id id, |
672 syncable::Id parent_id, | 663 syncable::Id parent_id, |
673 const string& name, | 664 const string& name, |
674 int64_t version, | 665 int64_t version, |
675 int64_t sync_ts, | 666 int64_t sync_ts, |
676 const string& originator_cache_guid, | 667 const string& originator_cache_guid, |
677 const string& originator_client_item_id) { | 668 const string& originator_client_item_id) { |
678 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(), | 669 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(), name, |
679 name, version, sync_ts, originator_cache_guid, | 670 version, sync_ts, originator_cache_guid, |
680 originator_client_item_id); | 671 originator_client_item_id); |
681 } | 672 } |
682 | 673 |
683 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( | 674 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( |
684 syncable::Id id, | 675 syncable::Id id, |
685 syncable::Id parent_id, | 676 syncable::Id parent_id, |
686 const string& name, | 677 const string& name, |
687 int64_t version, | 678 int64_t version, |
688 int64_t sync_ts, | 679 int64_t sync_ts, |
689 const string& originator_cache_guid, | 680 const string& originator_cache_guid, |
690 const string& originator_client_item_id) { | 681 const string& originator_client_item_id) { |
691 return AddUpdateBookmark(id.GetServerId(), parent_id.GetServerId(), | 682 return AddUpdateBookmark(id.GetServerId(), parent_id.GetServerId(), name, |
692 name, version, sync_ts, originator_cache_guid, | 683 version, sync_ts, originator_cache_guid, |
693 originator_client_item_id); | 684 originator_client_item_id); |
694 } | 685 } |
695 | 686 |
696 sync_pb::SyncEntity* MockConnectionManager::GetMutableLastUpdate() { | 687 sync_pb::SyncEntity* MockConnectionManager::GetMutableLastUpdate() { |
697 sync_pb::GetUpdatesResponse* updates = GetUpdateResponse(); | 688 sync_pb::GetUpdatesResponse* updates = GetUpdateResponse(); |
698 EXPECT_GT(updates->entries_size(), 0); | 689 EXPECT_GT(updates->entries_size(), 0); |
699 return updates->mutable_entries()->Mutable(updates->entries_size() - 1); | 690 return updates->mutable_entries()->Mutable(updates->entries_size() - 1); |
700 } | 691 } |
701 | 692 |
702 void MockConnectionManager::NextUpdateBatch() { | 693 void MockConnectionManager::NextUpdateBatch() { |
703 update_queue_.push_back(sync_pb::GetUpdatesResponse::default_instance()); | 694 update_queue_.push_back(sync_pb::GetUpdatesResponse::default_instance()); |
704 SetChangesRemaining(0); | 695 SetChangesRemaining(0); |
705 ApplyToken(); | 696 ApplyToken(); |
706 } | 697 } |
707 | 698 |
708 const CommitMessage& MockConnectionManager::last_sent_commit() const { | 699 const CommitMessage& MockConnectionManager::last_sent_commit() const { |
709 EXPECT_TRUE(!commit_messages_.empty()); | 700 EXPECT_TRUE(!commit_messages_.empty()); |
710 return *commit_messages_.back(); | 701 return *commit_messages_.back(); |
711 } | 702 } |
712 | 703 |
713 const CommitResponse& MockConnectionManager::last_commit_response() const { | 704 const CommitResponse& MockConnectionManager::last_commit_response() const { |
714 EXPECT_TRUE(!commit_responses_.empty()); | 705 EXPECT_TRUE(!commit_responses_.empty()); |
715 return *commit_responses_.back(); | 706 return *commit_responses_.back(); |
716 } | 707 } |
717 | 708 |
718 const sync_pb::ClientToServerMessage& | 709 const sync_pb::ClientToServerMessage& MockConnectionManager::last_request() |
719 MockConnectionManager::last_request() const { | 710 const { |
720 EXPECT_TRUE(!requests_.empty()); | 711 EXPECT_TRUE(!requests_.empty()); |
721 return requests_.back(); | 712 return requests_.back(); |
722 } | 713 } |
723 | 714 |
724 const std::vector<sync_pb::ClientToServerMessage>& | 715 const std::vector<sync_pb::ClientToServerMessage>& |
725 MockConnectionManager::requests() const { | 716 MockConnectionManager::requests() const { |
726 return requests_; | 717 return requests_; |
727 } | 718 } |
728 | 719 |
729 bool MockConnectionManager::IsModelTypePresentInSpecifics( | 720 bool MockConnectionManager::IsModelTypePresentInSpecifics( |
730 const google::protobuf::RepeatedPtrField< | 721 const google::protobuf::RepeatedPtrField<sync_pb::DataTypeProgressMarker>& |
731 sync_pb::DataTypeProgressMarker>& filter, | 722 filter, |
732 ModelType value) { | 723 ModelType value) { |
733 int data_type_id = GetSpecificsFieldNumberFromModelType(value); | 724 int data_type_id = GetSpecificsFieldNumberFromModelType(value); |
734 for (int i = 0; i < filter.size(); ++i) { | 725 for (int i = 0; i < filter.size(); ++i) { |
735 if (filter.Get(i).data_type_id() == data_type_id) { | 726 if (filter.Get(i).data_type_id() == data_type_id) { |
736 return true; | 727 return true; |
737 } | 728 } |
738 } | 729 } |
739 return false; | 730 return false; |
740 } | 731 } |
741 | 732 |
742 sync_pb::DataTypeProgressMarker const* | 733 sync_pb::DataTypeProgressMarker const* |
743 MockConnectionManager::GetProgressMarkerForType( | 734 MockConnectionManager::GetProgressMarkerForType( |
744 const google::protobuf::RepeatedPtrField< | 735 const google::protobuf::RepeatedPtrField<sync_pb::DataTypeProgressMarker>& |
745 sync_pb::DataTypeProgressMarker>& filter, | 736 filter, |
746 ModelType value) { | 737 ModelType value) { |
747 int data_type_id = GetSpecificsFieldNumberFromModelType(value); | 738 int data_type_id = GetSpecificsFieldNumberFromModelType(value); |
748 for (int i = 0; i < filter.size(); ++i) { | 739 for (int i = 0; i < filter.size(); ++i) { |
749 if (filter.Get(i).data_type_id() == data_type_id) { | 740 if (filter.Get(i).data_type_id() == data_type_id) { |
750 return &(filter.Get(i)); | 741 return &(filter.Get(i)); |
751 } | 742 } |
752 } | 743 } |
753 return NULL; | 744 return NULL; |
754 } | 745 } |
755 | 746 |
756 void MockConnectionManager::SetServerReachable() { | 747 void MockConnectionManager::SetServerReachable() { |
(...skipping 11 matching lines...) Expand all Loading... |
768 server_status_ = HttpResponse::SERVER_CONNECTION_OK; | 759 server_status_ = HttpResponse::SERVER_CONNECTION_OK; |
769 } | 760 } |
770 } | 761 } |
771 | 762 |
772 void MockConnectionManager::SetServerStatus( | 763 void MockConnectionManager::SetServerStatus( |
773 HttpResponse::ServerConnectionCode server_status) { | 764 HttpResponse::ServerConnectionCode server_status) { |
774 server_status_ = server_status; | 765 server_status_ = server_status; |
775 } | 766 } |
776 | 767 |
777 } // namespace syncer | 768 } // namespace syncer |
OLD | NEW |