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 "sync/test/engine/mock_connection_manager.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 bool MockConnectionManager::PostBufferToPath(PostBufferParams* params, | 77 bool MockConnectionManager::PostBufferToPath(PostBufferParams* params, |
78 const string& path, | 78 const string& path, |
79 const string& auth_token, | 79 const string& auth_token, |
80 ScopedServerStatusWatcher* watcher) { | 80 ScopedServerStatusWatcher* watcher) { |
81 ClientToServerMessage post; | 81 ClientToServerMessage post; |
82 CHECK(post.ParseFromString(params->buffer_in)); | 82 CHECK(post.ParseFromString(params->buffer_in)); |
83 CHECK(post.has_protocol_version()); | 83 CHECK(post.has_protocol_version()); |
84 CHECK(post.has_api_key()); | 84 CHECK(post.has_api_key()); |
85 CHECK(post.has_bag_of_chips()); | 85 CHECK(post.has_bag_of_chips()); |
86 last_request_.CopyFrom(post); | 86 |
| 87 requests_.push_back(post); |
87 client_stuck_ = post.sync_problem_detected(); | 88 client_stuck_ = post.sync_problem_detected(); |
88 sync_pb::ClientToServerResponse response; | 89 sync_pb::ClientToServerResponse response; |
89 response.Clear(); | 90 response.Clear(); |
90 | 91 |
91 if (directory_) { | 92 if (directory_) { |
92 // If the Directory's locked when we do this, it's a problem as in normal | 93 // If the Directory's locked when we do this, it's a problem as in normal |
93 // use this function could take a while to return because it accesses the | 94 // use this function could take a while to return because it accesses the |
94 // network. As we can't test this we do the next best thing and hang here | 95 // network. As we can't test this we do the next best thing and hang here |
95 // when there's an issue. | 96 // when there's an issue. |
96 CHECK(directory_->good()); | 97 CHECK(directory_->good()); |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 const CommitMessage& MockConnectionManager::last_sent_commit() const { | 680 const CommitMessage& MockConnectionManager::last_sent_commit() const { |
680 EXPECT_TRUE(!commit_messages_.empty()); | 681 EXPECT_TRUE(!commit_messages_.empty()); |
681 return *commit_messages_.back(); | 682 return *commit_messages_.back(); |
682 } | 683 } |
683 | 684 |
684 const CommitResponse& MockConnectionManager::last_commit_response() const { | 685 const CommitResponse& MockConnectionManager::last_commit_response() const { |
685 EXPECT_TRUE(!commit_responses_.empty()); | 686 EXPECT_TRUE(!commit_responses_.empty()); |
686 return *commit_responses_.back(); | 687 return *commit_responses_.back(); |
687 } | 688 } |
688 | 689 |
| 690 const sync_pb::ClientToServerMessage& |
| 691 MockConnectionManager::last_request() const { |
| 692 EXPECT_TRUE(!requests_.empty()); |
| 693 return requests_.back(); |
| 694 } |
| 695 |
| 696 const std::vector<sync_pb::ClientToServerMessage>& |
| 697 MockConnectionManager::requests() const { |
| 698 return requests_; |
| 699 } |
| 700 |
689 bool MockConnectionManager::IsModelTypePresentInSpecifics( | 701 bool MockConnectionManager::IsModelTypePresentInSpecifics( |
690 const google::protobuf::RepeatedPtrField< | 702 const google::protobuf::RepeatedPtrField< |
691 sync_pb::DataTypeProgressMarker>& filter, | 703 sync_pb::DataTypeProgressMarker>& filter, |
692 ModelType value) { | 704 ModelType value) { |
693 int data_type_id = GetSpecificsFieldNumberFromModelType(value); | 705 int data_type_id = GetSpecificsFieldNumberFromModelType(value); |
694 for (int i = 0; i < filter.size(); ++i) { | 706 for (int i = 0; i < filter.size(); ++i) { |
695 if (filter.Get(i).data_type_id() == data_type_id) { | 707 if (filter.Get(i).data_type_id() == data_type_id) { |
696 return true; | 708 return true; |
697 } | 709 } |
698 } | 710 } |
(...skipping 29 matching lines...) Expand all Loading... |
728 server_status_ = HttpResponse::SERVER_CONNECTION_OK; | 740 server_status_ = HttpResponse::SERVER_CONNECTION_OK; |
729 } | 741 } |
730 } | 742 } |
731 | 743 |
732 void MockConnectionManager::SetServerStatus( | 744 void MockConnectionManager::SetServerStatus( |
733 HttpResponse::ServerConnectionCode server_status) { | 745 HttpResponse::ServerConnectionCode server_status) { |
734 server_status_ = server_status; | 746 server_status_ = server_status; |
735 } | 747 } |
736 | 748 |
737 } // namespace syncer | 749 } // namespace syncer |
OLD | NEW |