Chromium Code Reviews| 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 |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "sync/engine/syncer_proto_util.h" | 13 #include "sync/engine/syncer_proto_util.h" |
| 14 #include "sync/test/engine/test_id_factory.h" | |
| 14 #include "sync/protocol/bookmark_specifics.pb.h" | 15 #include "sync/protocol/bookmark_specifics.pb.h" |
| 15 #include "sync/syncable/directory.h" | 16 #include "sync/syncable/directory.h" |
| 16 #include "sync/syncable/write_transaction.h" | 17 #include "sync/syncable/write_transaction.h" |
| 17 #include "sync/test/engine/test_id_factory.h" | 18 #include "sync/test/engine/test_id_factory.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 using std::map; | 21 using std::map; |
| 21 using std::string; | 22 using std::string; |
| 22 using sync_pb::ClientToServerMessage; | 23 using sync_pb::ClientToServerMessage; |
| 23 using sync_pb::CommitMessage; | 24 using sync_pb::CommitMessage; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 37 conflict_all_commits_(false), | 38 conflict_all_commits_(false), |
| 38 conflict_n_commits_(0), | 39 conflict_n_commits_(0), |
| 39 next_new_id_(10000), | 40 next_new_id_(10000), |
| 40 store_birthday_("Store BDay!"), | 41 store_birthday_("Store BDay!"), |
| 41 store_birthday_sent_(false), | 42 store_birthday_sent_(false), |
| 42 client_stuck_(false), | 43 client_stuck_(false), |
| 43 commit_time_rename_prepended_string_(""), | 44 commit_time_rename_prepended_string_(""), |
| 44 countdown_to_postbuffer_fail_(0), | 45 countdown_to_postbuffer_fail_(0), |
| 45 directory_(directory), | 46 directory_(directory), |
| 46 mid_commit_observer_(NULL), | 47 mid_commit_observer_(NULL), |
| 48 clear_user_data_response_errortype_(sync_pb::SyncEnums::SUCCESS), | |
| 49 get_key_response_errortype_(sync_pb::SyncEnums::SUCCESS), | |
| 47 throttling_(false), | 50 throttling_(false), |
| 48 fail_with_auth_invalid_(false), | 51 fail_with_auth_invalid_(false), |
| 49 fail_non_periodic_get_updates_(false), | 52 fail_non_periodic_get_updates_(false), |
| 50 client_command_(NULL), | 53 client_command_(NULL), |
| 51 next_position_in_parent_(2), | 54 next_position_in_parent_(2), |
| 52 use_legacy_bookmarks_protocol_(false), | 55 use_legacy_bookmarks_protocol_(false), |
| 53 num_get_updates_requests_(0) { | 56 num_get_updates_requests_(0) { |
| 54 SetNewTimestamp(0); | 57 SetNewTimestamp(0); |
| 55 set_auth_token(kValidAuthToken); | 58 set_auth_token(kValidAuthToken); |
| 56 } | 59 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 } | 134 } |
| 132 bool result = true; | 135 bool result = true; |
| 133 EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday() || | 136 EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday() || |
| 134 post.message_contents() == ClientToServerMessage::AUTHENTICATE); | 137 post.message_contents() == ClientToServerMessage::AUTHENTICATE); |
| 135 store_birthday_sent_ = true; | 138 store_birthday_sent_ = true; |
| 136 | 139 |
| 137 if (post.message_contents() == ClientToServerMessage::COMMIT) { | 140 if (post.message_contents() == ClientToServerMessage::COMMIT) { |
| 138 ProcessCommit(&post, &response); | 141 ProcessCommit(&post, &response); |
| 139 } else if (post.message_contents() == ClientToServerMessage::GET_UPDATES) { | 142 } else if (post.message_contents() == ClientToServerMessage::GET_UPDATES) { |
| 140 ProcessGetUpdates(&post, &response); | 143 ProcessGetUpdates(&post, &response); |
| 144 } else if (post.message_contents() == | |
| 145 ClientToServerMessage::GET_ENCRYPTION_KEY) { | |
| 146 ProcessGetKey(&post, &response); | |
| 141 } else { | 147 } else { |
| 142 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage"; | 148 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage"; |
| 143 return false; | 149 return false; |
| 144 } | 150 } |
| 145 if (client_command_.get()) { | 151 if (client_command_.get()) { |
| 146 response.mutable_client_command()->CopyFrom(*client_command_.get()); | 152 response.mutable_client_command()->CopyFrom(*client_command_.get()); |
| 147 } | 153 } |
| 148 | 154 |
| 149 { | 155 { |
| 150 base::AutoLock lock(response_code_override_lock_); | 156 base::AutoLock lock(response_code_override_lock_); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 sync_pb::DataTypeProgressMarker* new_marker = | 450 sync_pb::DataTypeProgressMarker* new_marker = |
| 445 response->mutable_get_updates()->add_new_progress_marker(); | 451 response->mutable_get_updates()->add_new_progress_marker(); |
| 446 new_marker->set_data_type_id(gu.from_progress_marker(i).data_type_id()); | 452 new_marker->set_data_type_id(gu.from_progress_marker(i).data_type_id()); |
| 447 new_marker->set_token(token); | 453 new_marker->set_token(token); |
| 448 } | 454 } |
| 449 } | 455 } |
| 450 | 456 |
| 451 update_queue_.pop_front(); | 457 update_queue_.pop_front(); |
| 452 } | 458 } |
| 453 | 459 |
| 460 void MockConnectionManager::SetKeystoreKey(const std::string& key) { | |
| 461 // Note: this is not a thread-safe set, ok for now. NOT ok if tests | |
| 462 // run the syncer on the background thread while this method is called. | |
| 463 keystore_key_ = key; | |
| 464 } | |
| 465 | |
| 466 void MockConnectionManager::SetGetKeyResponseStatus( | |
| 467 sync_pb::SyncEnums::ErrorType errortype ) { | |
| 468 // Note: this is not a thread-safe set, ok for now. NOT ok if tests | |
| 469 // run the syncer on the background thread while this method is called. | |
| 470 get_key_response_errortype_ = errortype; | |
| 471 } | |
| 472 | |
| 473 void MockConnectionManager::ProcessGetKey( | |
| 474 sync_pb::ClientToServerMessage* csm, | |
| 475 sync_pb::ClientToServerResponse* response) { | |
| 476 CHECK(csm->has_get_encryption_key()); | |
|
tim (not reviewing)
2012/07/19 21:42:03
why CHECK over ASSERT_TRUE?
Nicolas Zea
2012/07/24 22:51:24
Done.
| |
| 477 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::GET_ENCRYPTION_KEY); | |
| 478 response->mutable_get_encryption_key()->set_key(keystore_key_); | |
| 479 response->set_error_code(get_key_response_errortype_); | |
| 480 } | |
| 481 | |
| 454 bool MockConnectionManager::ShouldConflictThisCommit() { | 482 bool MockConnectionManager::ShouldConflictThisCommit() { |
| 455 bool conflict = false; | 483 bool conflict = false; |
| 456 if (conflict_all_commits_) { | 484 if (conflict_all_commits_) { |
| 457 conflict = true; | 485 conflict = true; |
| 458 } else if (conflict_n_commits_ > 0) { | 486 } else if (conflict_n_commits_ > 0) { |
| 459 conflict = true; | 487 conflict = true; |
| 460 --conflict_n_commits_; | 488 --conflict_n_commits_; |
| 461 } | 489 } |
| 462 return conflict; | 490 return conflict; |
| 463 } | 491 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 | 617 |
| 590 void MockConnectionManager::UpdateConnectionStatus() { | 618 void MockConnectionManager::UpdateConnectionStatus() { |
| 591 if (!server_reachable_) { | 619 if (!server_reachable_) { |
| 592 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; | 620 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; |
| 593 } else { | 621 } else { |
| 594 server_status_ = HttpResponse::SERVER_CONNECTION_OK; | 622 server_status_ = HttpResponse::SERVER_CONNECTION_OK; |
| 595 } | 623 } |
| 596 } | 624 } |
| 597 | 625 |
| 598 } // namespace syncer | 626 } // namespace syncer |
| OLD | NEW |