Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / sync / test / engine / mock_connection_manager.cc
blob8a4ba9c47f38876518ba38079deb329f696ecd47
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
3 // found in the LICENSE file.
4 //
5 // Mock ServerConnectionManager class for use in client regression tests.
7 #include "sync/test/engine/mock_connection_manager.h"
9 #include <map>
11 #include "base/location.h"
12 #include "base/strings/stringprintf.h"
13 #include "sync/engine/syncer_proto_util.h"
14 #include "sync/protocol/bookmark_specifics.pb.h"
15 #include "sync/syncable/directory.h"
16 #include "sync/syncable/syncable_write_transaction.h"
17 #include "sync/test/engine/test_id_factory.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 using std::find;
21 using std::map;
22 using std::string;
23 using sync_pb::ClientToServerMessage;
24 using sync_pb::CommitMessage;
25 using sync_pb::CommitResponse;
26 using sync_pb::GetUpdatesMessage;
27 using sync_pb::SyncEnums;
29 namespace syncer {
31 using syncable::WriteTransaction;
33 static char kValidAuthToken[] = "AuthToken";
34 static char kCacheGuid[] = "kqyg7097kro6GSUod+GSg==";
36 MockConnectionManager::MockConnectionManager(syncable::Directory* directory,
37 CancelationSignal* signal)
38 : ServerConnectionManager("unused", 0, false, signal),
39 server_reachable_(true),
40 conflict_all_commits_(false),
41 conflict_n_commits_(0),
42 next_new_id_(10000),
43 store_birthday_("Store BDay!"),
44 store_birthday_sent_(false),
45 client_stuck_(false),
46 countdown_to_postbuffer_fail_(0),
47 directory_(directory),
48 mid_commit_observer_(NULL),
49 throttling_(false),
50 partialThrottling_(false),
51 fail_with_auth_invalid_(false),
52 fail_non_periodic_get_updates_(false),
53 next_position_in_parent_(2),
54 use_legacy_bookmarks_protocol_(false),
55 num_get_updates_requests_(0) {
56 SetNewTimestamp(0);
57 SetAuthToken(kValidAuthToken);
60 MockConnectionManager::~MockConnectionManager() {
61 EXPECT_TRUE(update_queue_.empty()) << "Unfetched updates.";
64 void MockConnectionManager::SetCommitTimeRename(string prepend) {
65 commit_time_rename_prepended_string_ = prepend;
68 void MockConnectionManager::SetMidCommitCallback(
69 const base::Closure& callback) {
70 mid_commit_callback_ = callback;
73 void MockConnectionManager::SetMidCommitObserver(
74 MockConnectionManager::MidCommitObserver* observer) {
75 mid_commit_observer_ = observer;
78 bool MockConnectionManager::PostBufferToPath(PostBufferParams* params,
79 const string& path,
80 const string& auth_token,
81 ScopedServerStatusWatcher* watcher) {
82 ClientToServerMessage post;
83 CHECK(post.ParseFromString(params->buffer_in));
84 CHECK(post.has_protocol_version());
85 CHECK(post.has_api_key());
86 CHECK(post.has_bag_of_chips());
88 requests_.push_back(post);
89 client_stuck_ = post.sync_problem_detected();
90 sync_pb::ClientToServerResponse response;
91 response.Clear();
93 if (directory_) {
94 // If the Directory's locked when we do this, it's a problem as in normal
95 // use this function could take a while to return because it accesses the
96 // network. As we can't test this we do the next best thing and hang here
97 // when there's an issue.
98 CHECK(directory_->good());
99 WriteTransaction wt(FROM_HERE, syncable::UNITTEST, directory_);
102 if (auth_token.empty()) {
103 params->response.server_status = HttpResponse::SYNC_AUTH_ERROR;
104 return false;
107 if (auth_token != kValidAuthToken) {
108 // Simulate server-side auth failure.
109 params->response.server_status = HttpResponse::SYNC_AUTH_ERROR;
110 InvalidateAndClearAuthToken();
113 if (--countdown_to_postbuffer_fail_ == 0) {
114 // Fail as countdown hits zero.
115 params->response.server_status = HttpResponse::SYNC_SERVER_ERROR;
116 return false;
119 if (!server_reachable_) {
120 params->response.server_status = HttpResponse::CONNECTION_UNAVAILABLE;
121 return false;
124 // Default to an ok connection.
125 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK;
126 response.set_error_code(SyncEnums::SUCCESS);
127 const string current_store_birthday = store_birthday();
128 response.set_store_birthday(current_store_birthday);
129 if (post.has_store_birthday() && post.store_birthday() !=
130 current_store_birthday) {
131 response.set_error_code(SyncEnums::NOT_MY_BIRTHDAY);
132 response.set_error_message("Merry Unbirthday!");
133 response.SerializeToString(&params->buffer_out);
134 store_birthday_sent_ = true;
135 return true;
137 bool result = true;
138 EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday() ||
139 post.message_contents() == ClientToServerMessage::AUTHENTICATE);
140 store_birthday_sent_ = true;
142 if (post.message_contents() == ClientToServerMessage::COMMIT) {
143 ProcessCommit(&post, &response);
144 } else if (post.message_contents() == ClientToServerMessage::GET_UPDATES) {
145 ProcessGetUpdates(&post, &response);
146 } else {
147 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage";
148 return false;
152 base::AutoLock lock(response_code_override_lock_);
153 if (throttling_) {
154 response.set_error_code(SyncEnums::THROTTLED);
155 throttling_ = false;
158 if (partialThrottling_) {
159 sync_pb::ClientToServerResponse_Error* response_error =
160 response.mutable_error();
161 response_error->set_error_type(SyncEnums::PARTIAL_FAILURE);
162 for (ModelTypeSet::Iterator it = throttled_type_.First(); it.Good();
163 it.Inc()) {
164 response_error->add_error_data_type_ids(
165 GetSpecificsFieldNumberFromModelType(it.Get()));
167 partialThrottling_ = false;
170 if (fail_with_auth_invalid_)
171 response.set_error_code(SyncEnums::AUTH_INVALID);
174 response.SerializeToString(&params->buffer_out);
175 if (post.message_contents() == ClientToServerMessage::COMMIT &&
176 !mid_commit_callback_.is_null()) {
177 mid_commit_callback_.Run();
178 mid_commit_callback_.Reset();
180 if (mid_commit_observer_) {
181 mid_commit_observer_->Observe();
184 return result;
187 sync_pb::GetUpdatesResponse* MockConnectionManager::GetUpdateResponse() {
188 if (update_queue_.empty()) {
189 NextUpdateBatch();
191 return &update_queue_.back();
194 void MockConnectionManager::AddDefaultBookmarkData(sync_pb::SyncEntity* entity,
195 bool is_folder) {
196 if (use_legacy_bookmarks_protocol_) {
197 sync_pb::SyncEntity_BookmarkData* data = entity->mutable_bookmarkdata();
198 data->set_bookmark_folder(is_folder);
200 if (!is_folder) {
201 data->set_bookmark_url("http://google.com");
203 } else {
204 entity->set_folder(is_folder);
205 entity->mutable_specifics()->mutable_bookmark();
206 if (!is_folder) {
207 entity->mutable_specifics()->mutable_bookmark()->
208 set_url("http://google.com");
213 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory(
214 int id,
215 int parent_id,
216 string name,
217 int64 version,
218 int64 sync_ts,
219 std::string originator_cache_guid,
220 std::string originator_client_item_id) {
221 return AddUpdateDirectory(TestIdFactory::FromNumber(id),
222 TestIdFactory::FromNumber(parent_id),
223 name,
224 version,
225 sync_ts,
226 originator_cache_guid,
227 originator_client_item_id);
230 void MockConnectionManager::SetGUClientCommand(
231 sync_pb::ClientCommand* command) {
232 gu_client_command_.reset(command);
235 void MockConnectionManager::SetCommitClientCommand(
236 sync_pb::ClientCommand* command) {
237 commit_client_command_.reset(command);
240 void MockConnectionManager::SetTransientErrorId(syncable::Id id) {
241 transient_error_ids_.push_back(id);
244 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark(
245 int id, int parent_id,
246 string name, int64 version,
247 int64 sync_ts,
248 string originator_client_item_id,
249 string originator_cache_guid) {
250 return AddUpdateBookmark(TestIdFactory::FromNumber(id),
251 TestIdFactory::FromNumber(parent_id),
252 name,
253 version,
254 sync_ts,
255 originator_client_item_id,
256 originator_cache_guid);
259 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics(
260 int id,
261 int parent_id,
262 string name,
263 int64 version,
264 int64 sync_ts,
265 bool is_dir,
266 int64 position,
267 const sync_pb::EntitySpecifics& specifics) {
268 sync_pb::SyncEntity* ent = AddUpdateMeta(
269 TestIdFactory::FromNumber(id).GetServerId(),
270 TestIdFactory::FromNumber(parent_id).GetServerId(),
271 name, version, sync_ts);
272 ent->set_position_in_parent(position);
273 ent->mutable_specifics()->CopyFrom(specifics);
274 ent->set_folder(is_dir);
275 return ent;
278 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics(
279 int id,
280 int parent_id,
281 string name,
282 int64 version,
283 int64 sync_ts,
284 bool is_dir,
285 int64 position,
286 const sync_pb::EntitySpecifics& specifics,
287 string originator_cache_guid,
288 string originator_client_item_id) {
289 sync_pb::SyncEntity* ent = AddUpdateSpecifics(
290 id, parent_id, name, version, sync_ts, is_dir, position, specifics);
291 ent->set_originator_cache_guid(originator_cache_guid);
292 ent->set_originator_client_item_id(originator_client_item_id);
293 return ent;
296 sync_pb::SyncEntity* MockConnectionManager::SetNigori(
297 int id,
298 int64 version,
299 int64 sync_ts,
300 const sync_pb::EntitySpecifics& specifics) {
301 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
302 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId());
303 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId());
304 ent->set_server_defined_unique_tag(ModelTypeToRootTag(NIGORI));
305 ent->set_name("Nigori");
306 ent->set_non_unique_name("Nigori");
307 ent->set_version(version);
308 ent->set_sync_timestamp(sync_ts);
309 ent->set_mtime(sync_ts);
310 ent->set_ctime(1);
311 ent->set_position_in_parent(0);
312 ent->set_folder(false);
313 ent->mutable_specifics()->CopyFrom(specifics);
314 return ent;
317 sync_pb::SyncEntity* MockConnectionManager::AddUpdatePref(string id,
318 string parent_id,
319 string client_tag,
320 int64 version,
321 int64 sync_ts) {
322 sync_pb::SyncEntity* ent =
323 AddUpdateMeta(id, parent_id, " ", version, sync_ts);
325 ent->set_client_defined_unique_tag(client_tag);
327 sync_pb::EntitySpecifics specifics;
328 AddDefaultFieldValue(PREFERENCES, &specifics);
329 ent->mutable_specifics()->CopyFrom(specifics);
331 return ent;
334 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFull(
335 string id, string parent_id,
336 string name, int64 version,
337 int64 sync_ts, bool is_dir) {
338 sync_pb::SyncEntity* ent =
339 AddUpdateMeta(id, parent_id, name, version, sync_ts);
340 AddDefaultBookmarkData(ent, is_dir);
341 return ent;
344 sync_pb::SyncEntity* MockConnectionManager::AddUpdateMeta(
345 string id, string parent_id,
346 string name, int64 version,
347 int64 sync_ts) {
348 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
349 ent->set_id_string(id);
350 ent->set_parent_id_string(parent_id);
351 ent->set_non_unique_name(name);
352 ent->set_name(name);
353 ent->set_version(version);
354 ent->set_sync_timestamp(sync_ts);
355 ent->set_mtime(sync_ts);
356 ent->set_ctime(1);
357 ent->set_position_in_parent(GeneratePositionInParent());
359 // This isn't perfect, but it works well enough. This is an update, which
360 // means the ID is a server ID, which means it never changes. By making
361 // kCacheGuid also never change, we guarantee that the same item always has
362 // the same originator_cache_guid and originator_client_item_id.
364 // Unfortunately, neither this class nor the tests that use it explicitly
365 // track sync entitites, so supporting proper cache guids and client item IDs
366 // would require major refactoring. The ID used here ought to be the "c-"
367 // style ID that was sent up on the commit.
368 ent->set_originator_cache_guid(kCacheGuid);
369 ent->set_originator_client_item_id(id);
371 return ent;
374 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory(
375 string id,
376 string parent_id,
377 string name,
378 int64 version,
379 int64 sync_ts,
380 std::string originator_cache_guid,
381 std::string originator_client_item_id) {
382 sync_pb::SyncEntity* ret =
383 AddUpdateFull(id, parent_id, name, version, sync_ts, true);
384 ret->set_originator_cache_guid(originator_cache_guid);
385 ret->set_originator_client_item_id(originator_client_item_id);
386 return ret;
389 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark(
390 string id,
391 string parent_id,
392 string name, int64 version,
393 int64 sync_ts,
394 string originator_cache_guid,
395 string originator_client_item_id) {
396 sync_pb::SyncEntity* ret =
397 AddUpdateFull(id, parent_id, name, version, sync_ts, false);
398 ret->set_originator_cache_guid(originator_cache_guid);
399 ret->set_originator_client_item_id(originator_client_item_id);
400 return ret;
403 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFromLastCommit() {
404 EXPECT_EQ(1, last_sent_commit().entries_size());
405 EXPECT_EQ(1, last_commit_response().entryresponse_size());
406 EXPECT_EQ(CommitResponse::SUCCESS,
407 last_commit_response().entryresponse(0).response_type());
409 if (last_sent_commit().entries(0).deleted()) {
410 ModelType type = GetModelType(last_sent_commit().entries(0));
411 AddUpdateTombstone(syncable::Id::CreateFromServerId(
412 last_sent_commit().entries(0).id_string()), type);
413 } else {
414 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
415 ent->CopyFrom(last_sent_commit().entries(0));
416 ent->clear_insert_after_item_id();
417 ent->clear_old_parent_id();
418 ent->set_position_in_parent(
419 last_commit_response().entryresponse(0).position_in_parent());
420 ent->set_version(
421 last_commit_response().entryresponse(0).version());
422 ent->set_id_string(
423 last_commit_response().entryresponse(0).id_string());
425 // This is the same hack as in AddUpdateMeta. See the comment in that
426 // function for more information.
427 ent->set_originator_cache_guid(kCacheGuid);
428 ent->set_originator_client_item_id(
429 last_commit_response().entryresponse(0).id_string());
431 if (last_sent_commit().entries(0).has_unique_position()) {
432 ent->mutable_unique_position()->CopyFrom(
433 last_sent_commit().entries(0).unique_position());
436 // Tests don't currently care about the following:
437 // parent_id_string, name, non_unique_name.
439 return GetMutableLastUpdate();
442 void MockConnectionManager::AddUpdateTombstone(
443 const syncable::Id& id,
444 ModelType type) {
445 // Tombstones have only the ID set and dummy values for the required fields.
446 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
447 ent->set_id_string(id.GetServerId());
448 ent->set_version(0);
449 ent->set_name("");
450 ent->set_deleted(true);
452 // Make sure we can still extract the ModelType from this tombstone.
453 AddDefaultFieldValue(type, ent->mutable_specifics());
456 void MockConnectionManager::SetLastUpdateDeleted() {
457 // Tombstones have only the ID set. Wipe anything else.
458 string id_string = GetMutableLastUpdate()->id_string();
459 ModelType type = GetModelType(*GetMutableLastUpdate());
460 GetUpdateResponse()->mutable_entries()->RemoveLast();
461 AddUpdateTombstone(syncable::Id::CreateFromServerId(id_string), type);
464 void MockConnectionManager::SetLastUpdateOriginatorFields(
465 const string& client_id,
466 const string& entry_id) {
467 GetMutableLastUpdate()->set_originator_cache_guid(client_id);
468 GetMutableLastUpdate()->set_originator_client_item_id(entry_id);
471 void MockConnectionManager::SetLastUpdateServerTag(const string& tag) {
472 GetMutableLastUpdate()->set_server_defined_unique_tag(tag);
475 void MockConnectionManager::SetLastUpdateClientTag(const string& tag) {
476 GetMutableLastUpdate()->set_client_defined_unique_tag(tag);
479 void MockConnectionManager::SetLastUpdatePosition(int64 server_position) {
480 GetMutableLastUpdate()->set_position_in_parent(server_position);
483 void MockConnectionManager::SetNewTimestamp(int ts) {
484 next_token_ = base::StringPrintf("mock connection ts = %d", ts);
485 ApplyToken();
488 void MockConnectionManager::ApplyToken() {
489 if (!update_queue_.empty()) {
490 GetUpdateResponse()->clear_new_progress_marker();
491 sync_pb::DataTypeProgressMarker* new_marker =
492 GetUpdateResponse()->add_new_progress_marker();
493 new_marker->set_data_type_id(-1); // Invalid -- clients shouldn't see.
494 new_marker->set_token(next_token_);
498 void MockConnectionManager::SetChangesRemaining(int64 timestamp) {
499 GetUpdateResponse()->set_changes_remaining(timestamp);
502 void MockConnectionManager::ProcessGetUpdates(
503 sync_pb::ClientToServerMessage* csm,
504 sync_pb::ClientToServerResponse* response) {
505 CHECK(csm->has_get_updates());
506 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::GET_UPDATES);
507 const GetUpdatesMessage& gu = csm->get_updates();
508 num_get_updates_requests_++;
509 EXPECT_FALSE(gu.has_from_timestamp());
510 EXPECT_FALSE(gu.has_requested_types());
512 if (fail_non_periodic_get_updates_) {
513 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC,
514 gu.caller_info().source());
517 // Verify that the items we're about to send back to the client are of
518 // the types requested by the client. If this fails, it probably indicates
519 // a test bug.
520 EXPECT_TRUE(gu.fetch_folders());
521 EXPECT_FALSE(gu.has_requested_types());
522 if (update_queue_.empty()) {
523 GetUpdateResponse();
525 sync_pb::GetUpdatesResponse* updates = &update_queue_.front();
526 for (int i = 0; i < updates->entries_size(); ++i) {
527 if (!updates->entries(i).deleted()) {
528 ModelType entry_type = GetModelType(updates->entries(i));
529 EXPECT_TRUE(
530 IsModelTypePresentInSpecifics(gu.from_progress_marker(), entry_type))
531 << "Syncer did not request updates being provided by the test.";
535 response->mutable_get_updates()->CopyFrom(*updates);
537 // Set appropriate progress markers, overriding the value squirreled
538 // away by ApplyToken().
539 std::string token = response->get_updates().new_progress_marker(0).token();
540 response->mutable_get_updates()->clear_new_progress_marker();
541 for (int i = 0; i < gu.from_progress_marker_size(); ++i) {
542 sync_pb::DataTypeProgressMarker* new_marker =
543 response->mutable_get_updates()->add_new_progress_marker();
544 new_marker->set_data_type_id(gu.from_progress_marker(i).data_type_id());
545 new_marker->set_token(token);
548 // Fill the keystore key if requested.
549 if (gu.need_encryption_key())
550 response->mutable_get_updates()->add_encryption_keys(keystore_key_);
552 update_queue_.pop_front();
554 if (gu_client_command_) {
555 response->mutable_client_command()->CopyFrom(*gu_client_command_.get());
559 void MockConnectionManager::SetKeystoreKey(const std::string& key) {
560 // Note: this is not a thread-safe set, ok for now. NOT ok if tests
561 // run the syncer on the background thread while this method is called.
562 keystore_key_ = key;
565 bool MockConnectionManager::ShouldConflictThisCommit() {
566 bool conflict = false;
567 if (conflict_all_commits_) {
568 conflict = true;
569 } else if (conflict_n_commits_ > 0) {
570 conflict = true;
571 --conflict_n_commits_;
573 return conflict;
576 bool MockConnectionManager::ShouldTransientErrorThisId(syncable::Id id) {
577 return find(transient_error_ids_.begin(), transient_error_ids_.end(), id)
578 != transient_error_ids_.end();
581 void MockConnectionManager::ProcessCommit(
582 sync_pb::ClientToServerMessage* csm,
583 sync_pb::ClientToServerResponse* response_buffer) {
584 CHECK(csm->has_commit());
585 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::COMMIT);
586 map <string, string> changed_ids;
587 const CommitMessage& commit_message = csm->commit();
588 CommitResponse* commit_response = response_buffer->mutable_commit();
589 commit_messages_.push_back(new CommitMessage);
590 commit_messages_.back()->CopyFrom(commit_message);
591 map<string, sync_pb::CommitResponse_EntryResponse*> response_map;
592 for (int i = 0; i < commit_message.entries_size() ; i++) {
593 const sync_pb::SyncEntity& entry = commit_message.entries(i);
594 CHECK(entry.has_id_string());
595 string id_string = entry.id_string();
596 ASSERT_LT(entry.name().length(), 256ul) << " name probably too long. True "
597 "server name checking not implemented";
598 syncable::Id id;
599 if (entry.version() == 0) {
600 // Relies on our new item string id format. (string representation of a
601 // negative number).
602 id = syncable::Id::CreateFromClientString(id_string);
603 } else {
604 id = syncable::Id::CreateFromServerId(id_string);
606 committed_ids_.push_back(id);
608 if (response_map.end() == response_map.find(id_string))
609 response_map[id_string] = commit_response->add_entryresponse();
610 sync_pb::CommitResponse_EntryResponse* er = response_map[id_string];
611 if (ShouldConflictThisCommit()) {
612 er->set_response_type(CommitResponse::CONFLICT);
613 continue;
615 if (ShouldTransientErrorThisId(id)) {
616 er->set_response_type(CommitResponse::TRANSIENT_ERROR);
617 continue;
619 er->set_response_type(CommitResponse::SUCCESS);
620 er->set_version(entry.version() + 1);
621 if (!commit_time_rename_prepended_string_.empty()) {
622 // Commit time rename sent down from the server.
623 er->set_name(commit_time_rename_prepended_string_ + entry.name());
625 string parent_id_string = entry.parent_id_string();
626 // Remap id's we've already assigned.
627 if (changed_ids.end() != changed_ids.find(parent_id_string)) {
628 parent_id_string = changed_ids[parent_id_string];
629 er->set_parent_id_string(parent_id_string);
631 if (entry.has_version() && 0 != entry.version()) {
632 er->set_id_string(id_string); // Allows verification.
633 } else {
634 string new_id = base::StringPrintf("mock_server:%d", next_new_id_++);
635 changed_ids[id_string] = new_id;
636 er->set_id_string(new_id);
639 commit_responses_.push_back(new CommitResponse(*commit_response));
641 if (commit_client_command_) {
642 response_buffer->mutable_client_command()->CopyFrom(
643 *commit_client_command_.get());
647 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory(
648 syncable::Id id,
649 syncable::Id parent_id,
650 string name,
651 int64 version,
652 int64 sync_ts,
653 string originator_cache_guid,
654 string originator_client_item_id) {
655 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(),
656 name, version, sync_ts, originator_cache_guid,
657 originator_client_item_id);
660 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark(
661 syncable::Id id,
662 syncable::Id parent_id,
663 string name,
664 int64 version,
665 int64 sync_ts,
666 string originator_cache_guid,
667 string originator_client_item_id) {
668 return AddUpdateBookmark(id.GetServerId(), parent_id.GetServerId(),
669 name, version, sync_ts, originator_cache_guid,
670 originator_client_item_id);
673 sync_pb::SyncEntity* MockConnectionManager::GetMutableLastUpdate() {
674 sync_pb::GetUpdatesResponse* updates = GetUpdateResponse();
675 EXPECT_GT(updates->entries_size(), 0);
676 return updates->mutable_entries()->Mutable(updates->entries_size() - 1);
679 void MockConnectionManager::NextUpdateBatch() {
680 update_queue_.push_back(sync_pb::GetUpdatesResponse::default_instance());
681 SetChangesRemaining(0);
682 ApplyToken();
685 const CommitMessage& MockConnectionManager::last_sent_commit() const {
686 EXPECT_TRUE(!commit_messages_.empty());
687 return *commit_messages_.back();
690 const CommitResponse& MockConnectionManager::last_commit_response() const {
691 EXPECT_TRUE(!commit_responses_.empty());
692 return *commit_responses_.back();
695 const sync_pb::ClientToServerMessage&
696 MockConnectionManager::last_request() const {
697 EXPECT_TRUE(!requests_.empty());
698 return requests_.back();
701 const std::vector<sync_pb::ClientToServerMessage>&
702 MockConnectionManager::requests() const {
703 return requests_;
706 bool MockConnectionManager::IsModelTypePresentInSpecifics(
707 const google::protobuf::RepeatedPtrField<
708 sync_pb::DataTypeProgressMarker>& filter,
709 ModelType value) {
710 int data_type_id = GetSpecificsFieldNumberFromModelType(value);
711 for (int i = 0; i < filter.size(); ++i) {
712 if (filter.Get(i).data_type_id() == data_type_id) {
713 return true;
716 return false;
719 sync_pb::DataTypeProgressMarker const*
720 MockConnectionManager::GetProgressMarkerForType(
721 const google::protobuf::RepeatedPtrField<
722 sync_pb::DataTypeProgressMarker>& filter,
723 ModelType value) {
724 int data_type_id = GetSpecificsFieldNumberFromModelType(value);
725 for (int i = 0; i < filter.size(); ++i) {
726 if (filter.Get(i).data_type_id() == data_type_id) {
727 return &(filter.Get(i));
730 return NULL;
733 void MockConnectionManager::SetServerReachable() {
734 server_reachable_ = true;
737 void MockConnectionManager::SetServerNotReachable() {
738 server_reachable_ = false;
741 void MockConnectionManager::UpdateConnectionStatus() {
742 if (!server_reachable_) {
743 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE;
744 } else {
745 server_status_ = HttpResponse::SERVER_CONNECTION_OK;
749 void MockConnectionManager::SetServerStatus(
750 HttpResponse::ServerConnectionCode server_status) {
751 server_status_ = server_status;
754 } // namespace syncer