OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "sync/test/engine/mock_connection_manager.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 return conflict; | 463 return conflict; |
464 } | 464 } |
465 | 465 |
466 void MockConnectionManager::ProcessCommit(ClientToServerMessage* csm, | 466 void MockConnectionManager::ProcessCommit(ClientToServerMessage* csm, |
467 ClientToServerResponse* response_buffer) { | 467 ClientToServerResponse* response_buffer) { |
468 CHECK(csm->has_commit()); | 468 CHECK(csm->has_commit()); |
469 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::COMMIT); | 469 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::COMMIT); |
470 map <string, string> changed_ids; | 470 map <string, string> changed_ids; |
471 const CommitMessage& commit_message = csm->commit(); | 471 const CommitMessage& commit_message = csm->commit(); |
472 CommitResponse* commit_response = response_buffer->mutable_commit(); | 472 CommitResponse* commit_response = response_buffer->mutable_commit(); |
473 commit_messages_->push_back(new CommitMessage); | 473 commit_messages_.push_back(new CommitMessage); |
474 commit_messages_->back()->CopyFrom(commit_message); | 474 commit_messages_.back()->CopyFrom(commit_message); |
475 map<string, CommitResponse_EntryResponse*> response_map; | 475 map<string, CommitResponse_EntryResponse*> response_map; |
476 for (int i = 0; i < commit_message.entries_size() ; i++) { | 476 for (int i = 0; i < commit_message.entries_size() ; i++) { |
477 const sync_pb::SyncEntity& entry = commit_message.entries(i); | 477 const sync_pb::SyncEntity& entry = commit_message.entries(i); |
478 CHECK(entry.has_id_string()); | 478 CHECK(entry.has_id_string()); |
479 string id = entry.id_string(); | 479 string id = entry.id_string(); |
480 ASSERT_LT(entry.name().length(), 256ul) << " name probably too long. True " | 480 ASSERT_LT(entry.name().length(), 256ul) << " name probably too long. True " |
481 "server name checking not implemented"; | 481 "server name checking not implemented"; |
482 if (entry.version() == 0) { | 482 if (entry.version() == 0) { |
483 // Relies on our new item string id format. (string representation of a | 483 // Relies on our new item string id format. (string representation of a |
484 // negative number). | 484 // negative number). |
(...skipping 21 matching lines...) Expand all Loading... |
506 er->set_parent_id_string(parent_id); | 506 er->set_parent_id_string(parent_id); |
507 } | 507 } |
508 if (entry.has_version() && 0 != entry.version()) { | 508 if (entry.has_version() && 0 != entry.version()) { |
509 er->set_id_string(id); // Allows verification. | 509 er->set_id_string(id); // Allows verification. |
510 } else { | 510 } else { |
511 string new_id = base::StringPrintf("mock_server:%d", next_new_id_++); | 511 string new_id = base::StringPrintf("mock_server:%d", next_new_id_++); |
512 changed_ids[id] = new_id; | 512 changed_ids[id] = new_id; |
513 er->set_id_string(new_id); | 513 er->set_id_string(new_id); |
514 } | 514 } |
515 } | 515 } |
516 commit_responses_->push_back(new CommitResponse(*commit_response)); | 516 commit_responses_.push_back(new CommitResponse(*commit_response)); |
517 } | 517 } |
518 | 518 |
519 SyncEntity* MockConnectionManager::AddUpdateDirectory( | 519 SyncEntity* MockConnectionManager::AddUpdateDirectory( |
520 syncable::Id id, syncable::Id parent_id, string name, int64 version, | 520 syncable::Id id, syncable::Id parent_id, string name, int64 version, |
521 int64 sync_ts) { | 521 int64 sync_ts) { |
522 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(), | 522 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(), |
523 name, version, sync_ts); | 523 name, version, sync_ts); |
524 } | 524 } |
525 | 525 |
526 SyncEntity* MockConnectionManager::AddUpdateBookmark( | 526 SyncEntity* MockConnectionManager::AddUpdateBookmark( |
(...skipping 10 matching lines...) Expand all Loading... |
537 } | 537 } |
538 | 538 |
539 void MockConnectionManager::NextUpdateBatch() { | 539 void MockConnectionManager::NextUpdateBatch() { |
540 update_queue_.push_back(sync_pb::GetUpdatesResponse::default_instance()); | 540 update_queue_.push_back(sync_pb::GetUpdatesResponse::default_instance()); |
541 SetChangesRemaining(0); | 541 SetChangesRemaining(0); |
542 ApplyToken(); | 542 ApplyToken(); |
543 } | 543 } |
544 | 544 |
545 const CommitMessage& MockConnectionManager::last_sent_commit() const { | 545 const CommitMessage& MockConnectionManager::last_sent_commit() const { |
546 EXPECT_TRUE(!commit_messages_.empty()); | 546 EXPECT_TRUE(!commit_messages_.empty()); |
547 return *commit_messages_->back(); | 547 return *commit_messages_.back(); |
548 } | 548 } |
549 | 549 |
550 const CommitResponse& MockConnectionManager::last_commit_response() const { | 550 const CommitResponse& MockConnectionManager::last_commit_response() const { |
551 EXPECT_TRUE(!commit_responses_.empty()); | 551 EXPECT_TRUE(!commit_responses_.empty()); |
552 return *commit_responses_->back(); | 552 return *commit_responses_.back(); |
553 } | 553 } |
554 | 554 |
555 bool MockConnectionManager::IsModelTypePresentInSpecifics( | 555 bool MockConnectionManager::IsModelTypePresentInSpecifics( |
556 const google::protobuf::RepeatedPtrField< | 556 const google::protobuf::RepeatedPtrField< |
557 sync_pb::DataTypeProgressMarker>& filter, | 557 sync_pb::DataTypeProgressMarker>& filter, |
558 syncable::ModelType value) { | 558 syncable::ModelType value) { |
559 int data_type_id = syncable::GetSpecificsFieldNumberFromModelType(value); | 559 int data_type_id = syncable::GetSpecificsFieldNumberFromModelType(value); |
560 for (int i = 0; i < filter.size(); ++i) { | 560 for (int i = 0; i < filter.size(); ++i) { |
561 if (filter.Get(i).data_type_id() == data_type_id) { | 561 if (filter.Get(i).data_type_id() == data_type_id) { |
562 return true; | 562 return true; |
(...skipping 24 matching lines...) Expand all Loading... |
587 server_reachable_ = false; | 587 server_reachable_ = false; |
588 } | 588 } |
589 | 589 |
590 void MockConnectionManager::UpdateConnectionStatus() { | 590 void MockConnectionManager::UpdateConnectionStatus() { |
591 if (!server_reachable_) { | 591 if (!server_reachable_) { |
592 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; | 592 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; |
593 } else { | 593 } else { |
594 server_status_ = HttpResponse::SERVER_CONNECTION_OK; | 594 server_status_ = HttpResponse::SERVER_CONNECTION_OK; |
595 } | 595 } |
596 } | 596 } |
OLD | NEW |