| 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 30 matching lines...) Expand all Loading... |
| 41 store_birthday_("Store BDay!"), | 41 store_birthday_("Store BDay!"), |
| 42 store_birthday_sent_(false), | 42 store_birthday_sent_(false), |
| 43 client_stuck_(false), | 43 client_stuck_(false), |
| 44 commit_time_rename_prepended_string_(""), | 44 commit_time_rename_prepended_string_(""), |
| 45 countdown_to_postbuffer_fail_(0), | 45 countdown_to_postbuffer_fail_(0), |
| 46 directory_(directory), | 46 directory_(directory), |
| 47 mid_commit_observer_(NULL), | 47 mid_commit_observer_(NULL), |
| 48 throttling_(false), | 48 throttling_(false), |
| 49 fail_with_auth_invalid_(false), | 49 fail_with_auth_invalid_(false), |
| 50 fail_non_periodic_get_updates_(false), | 50 fail_non_periodic_get_updates_(false), |
| 51 client_command_(NULL), | 51 gu_client_command_(NULL), |
| 52 commit_client_command_(NULL), |
| 52 next_position_in_parent_(2), | 53 next_position_in_parent_(2), |
| 53 use_legacy_bookmarks_protocol_(false), | 54 use_legacy_bookmarks_protocol_(false), |
| 54 num_get_updates_requests_(0) { | 55 num_get_updates_requests_(0) { |
| 55 SetNewTimestamp(0); | 56 SetNewTimestamp(0); |
| 56 set_auth_token(kValidAuthToken); | 57 set_auth_token(kValidAuthToken); |
| 57 } | 58 } |
| 58 | 59 |
| 59 MockConnectionManager::~MockConnectionManager() { | 60 MockConnectionManager::~MockConnectionManager() { |
| 60 EXPECT_TRUE(update_queue_.empty()) << "Unfetched updates."; | 61 EXPECT_TRUE(update_queue_.empty()) << "Unfetched updates."; |
| 61 } | 62 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 store_birthday_sent_ = true; | 137 store_birthday_sent_ = true; |
| 137 | 138 |
| 138 if (post.message_contents() == ClientToServerMessage::COMMIT) { | 139 if (post.message_contents() == ClientToServerMessage::COMMIT) { |
| 139 ProcessCommit(&post, &response); | 140 ProcessCommit(&post, &response); |
| 140 } else if (post.message_contents() == ClientToServerMessage::GET_UPDATES) { | 141 } else if (post.message_contents() == ClientToServerMessage::GET_UPDATES) { |
| 141 ProcessGetUpdates(&post, &response); | 142 ProcessGetUpdates(&post, &response); |
| 142 } else { | 143 } else { |
| 143 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage"; | 144 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage"; |
| 144 return false; | 145 return false; |
| 145 } | 146 } |
| 146 if (client_command_.get()) { | |
| 147 response.mutable_client_command()->CopyFrom(*client_command_.get()); | |
| 148 } | |
| 149 | 147 |
| 150 { | 148 { |
| 151 base::AutoLock lock(response_code_override_lock_); | 149 base::AutoLock lock(response_code_override_lock_); |
| 152 if (throttling_) { | 150 if (throttling_) { |
| 153 response.set_error_code(SyncEnums::THROTTLED); | 151 response.set_error_code(SyncEnums::THROTTLED); |
| 154 throttling_ = false; | 152 throttling_ = false; |
| 155 } | 153 } |
| 156 | 154 |
| 157 if (fail_with_auth_invalid_) | 155 if (fail_with_auth_invalid_) |
| 158 response.set_error_code(SyncEnums::AUTH_INVALID); | 156 response.set_error_code(SyncEnums::AUTH_INVALID); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 string name, | 201 string name, |
| 204 int64 version, | 202 int64 version, |
| 205 int64 sync_ts) { | 203 int64 sync_ts) { |
| 206 return AddUpdateDirectory(TestIdFactory::FromNumber(id), | 204 return AddUpdateDirectory(TestIdFactory::FromNumber(id), |
| 207 TestIdFactory::FromNumber(parent_id), | 205 TestIdFactory::FromNumber(parent_id), |
| 208 name, | 206 name, |
| 209 version, | 207 version, |
| 210 sync_ts); | 208 sync_ts); |
| 211 } | 209 } |
| 212 | 210 |
| 213 sync_pb::ClientCommand* MockConnectionManager::GetNextClientCommand() { | 211 void MockConnectionManager::SetGUClientCommand( |
| 214 if (!client_command_.get()) | 212 sync_pb::ClientCommand* command) { |
| 215 client_command_.reset(new sync_pb::ClientCommand()); | 213 gu_client_command_.reset(command); |
| 216 return client_command_.get(); | 214 } |
| 215 |
| 216 void MockConnectionManager::SetCommitClientCommand( |
| 217 sync_pb::ClientCommand* command) { |
| 218 commit_client_command_.reset(command); |
| 217 } | 219 } |
| 218 | 220 |
| 219 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( | 221 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( |
| 220 int id, int parent_id, | 222 int id, int parent_id, |
| 221 string name, int64 version, | 223 string name, int64 version, |
| 222 int64 sync_ts) { | 224 int64 sync_ts) { |
| 223 return AddUpdateBookmark(TestIdFactory::FromNumber(id), | 225 return AddUpdateBookmark(TestIdFactory::FromNumber(id), |
| 224 TestIdFactory::FromNumber(parent_id), | 226 TestIdFactory::FromNumber(parent_id), |
| 225 name, | 227 name, |
| 226 version, | 228 version, |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 new_marker->set_data_type_id(gu.from_progress_marker(i).data_type_id()); | 448 new_marker->set_data_type_id(gu.from_progress_marker(i).data_type_id()); |
| 447 new_marker->set_token(token); | 449 new_marker->set_token(token); |
| 448 } | 450 } |
| 449 } | 451 } |
| 450 | 452 |
| 451 // Fill the keystore key if requested. | 453 // Fill the keystore key if requested. |
| 452 if (gu.need_encryption_key()) | 454 if (gu.need_encryption_key()) |
| 453 response->mutable_get_updates()->set_encryption_key(keystore_key_); | 455 response->mutable_get_updates()->set_encryption_key(keystore_key_); |
| 454 | 456 |
| 455 update_queue_.pop_front(); | 457 update_queue_.pop_front(); |
| 458 |
| 459 if (gu_client_command_.get()) { |
| 460 response->mutable_client_command()->CopyFrom(*gu_client_command_.get()); |
| 461 } |
| 456 } | 462 } |
| 457 | 463 |
| 458 void MockConnectionManager::SetKeystoreKey(const std::string& key) { | 464 void MockConnectionManager::SetKeystoreKey(const std::string& key) { |
| 459 // Note: this is not a thread-safe set, ok for now. NOT ok if tests | 465 // Note: this is not a thread-safe set, ok for now. NOT ok if tests |
| 460 // run the syncer on the background thread while this method is called. | 466 // run the syncer on the background thread while this method is called. |
| 461 keystore_key_ = key; | 467 keystore_key_ = key; |
| 462 } | 468 } |
| 463 | 469 |
| 464 bool MockConnectionManager::ShouldConflictThisCommit() { | 470 bool MockConnectionManager::ShouldConflictThisCommit() { |
| 465 bool conflict = false; | 471 bool conflict = false; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 } | 523 } |
| 518 if (entry.has_version() && 0 != entry.version()) { | 524 if (entry.has_version() && 0 != entry.version()) { |
| 519 er->set_id_string(id); // Allows verification. | 525 er->set_id_string(id); // Allows verification. |
| 520 } else { | 526 } else { |
| 521 string new_id = base::StringPrintf("mock_server:%d", next_new_id_++); | 527 string new_id = base::StringPrintf("mock_server:%d", next_new_id_++); |
| 522 changed_ids[id] = new_id; | 528 changed_ids[id] = new_id; |
| 523 er->set_id_string(new_id); | 529 er->set_id_string(new_id); |
| 524 } | 530 } |
| 525 } | 531 } |
| 526 commit_responses_.push_back(new CommitResponse(*commit_response)); | 532 commit_responses_.push_back(new CommitResponse(*commit_response)); |
| 533 |
| 534 if (commit_client_command_.get()) { |
| 535 response_buffer->mutable_client_command()->CopyFrom( |
| 536 *commit_client_command_.get()); |
| 537 } |
| 527 } | 538 } |
| 528 | 539 |
| 529 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( | 540 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( |
| 530 syncable::Id id, syncable::Id parent_id, string name, int64 version, | 541 syncable::Id id, syncable::Id parent_id, string name, int64 version, |
| 531 int64 sync_ts) { | 542 int64 sync_ts) { |
| 532 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(), | 543 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(), |
| 533 name, version, sync_ts); | 544 name, version, sync_ts); |
| 534 } | 545 } |
| 535 | 546 |
| 536 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( | 547 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 | 610 |
| 600 void MockConnectionManager::UpdateConnectionStatus() { | 611 void MockConnectionManager::UpdateConnectionStatus() { |
| 601 if (!server_reachable_) { | 612 if (!server_reachable_) { |
| 602 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; | 613 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; |
| 603 } else { | 614 } else { |
| 604 server_status_ = HttpResponse::SERVER_CONNECTION_OK; | 615 server_status_ = HttpResponse::SERVER_CONNECTION_OK; |
| 605 } | 616 } |
| 606 } | 617 } |
| 607 | 618 |
| 608 } // namespace syncer | 619 } // namespace syncer |
| OLD | NEW |