| 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 EXPECT_TRUE(gu.fetch_folders()); | 422 EXPECT_TRUE(gu.fetch_folders()); |
| 422 EXPECT_FALSE(gu.has_requested_types()); | 423 EXPECT_FALSE(gu.has_requested_types()); |
| 423 if (update_queue_.empty()) { | 424 if (update_queue_.empty()) { |
| 424 GetUpdateResponse(); | 425 GetUpdateResponse(); |
| 425 } | 426 } |
| 426 sync_pb::GetUpdatesResponse* updates = &update_queue_.front(); | 427 sync_pb::GetUpdatesResponse* updates = &update_queue_.front(); |
| 427 for (int i = 0; i < updates->entries_size(); ++i) { | 428 for (int i = 0; i < updates->entries_size(); ++i) { |
| 428 if (!updates->entries(i).deleted()) { | 429 if (!updates->entries(i).deleted()) { |
| 429 ModelType entry_type = syncer::GetModelType(updates->entries(i)); | 430 ModelType entry_type = syncer::GetModelType(updates->entries(i)); |
| 430 EXPECT_TRUE( | 431 EXPECT_TRUE( |
| 431 IsModelTypePresentInSpecifics(gu.from_progress_marker(), entry_type)) | 432 IsModelTypePresentInSpecifics(gu.from_progress_marker(), entry_type)) |
| 432 << "Syncer did not request updates being provided by the test."; | 433 << "Syncer did not request updates being provided by the test."; |
| 433 } | 434 } |
| 434 } | 435 } |
| 435 | 436 |
| 436 response->mutable_get_updates()->CopyFrom(*updates); | 437 response->mutable_get_updates()->CopyFrom(*updates); |
| 437 | 438 |
| 438 // Set appropriate progress markers, overriding the value squirreled | 439 // Set appropriate progress markers, overriding the value squirreled |
| 439 // away by ApplyToken(). | 440 // away by ApplyToken(). |
| 440 std::string token = response->get_updates().new_progress_marker(0).token(); | 441 std::string token = response->get_updates().new_progress_marker(0).token(); |
| 441 response->mutable_get_updates()->clear_new_progress_marker(); | 442 response->mutable_get_updates()->clear_new_progress_marker(); |
| 442 for (int i = 0; i < gu.from_progress_marker_size(); ++i) { | 443 for (int i = 0; i < gu.from_progress_marker_size(); ++i) { |
| 443 if (gu.from_progress_marker(i).token() != token) { | 444 if (gu.from_progress_marker(i).token() != token) { |
| 444 sync_pb::DataTypeProgressMarker* new_marker = | 445 sync_pb::DataTypeProgressMarker* new_marker = |
| 445 response->mutable_get_updates()->add_new_progress_marker(); | 446 response->mutable_get_updates()->add_new_progress_marker(); |
| 446 new_marker->set_data_type_id(gu.from_progress_marker(i).data_type_id()); | 447 new_marker->set_data_type_id(gu.from_progress_marker(i).data_type_id()); |
| 447 new_marker->set_token(token); | 448 new_marker->set_token(token); |
| 448 } | 449 } |
| 449 } | 450 } |
| 450 | 451 |
| 452 // Fill the keystore key if requested. |
| 453 if (gu.need_encryption_key()) |
| 454 response->mutable_get_updates()->set_encryption_key(keystore_key_); |
| 455 |
| 451 update_queue_.pop_front(); | 456 update_queue_.pop_front(); |
| 452 } | 457 } |
| 453 | 458 |
| 459 void MockConnectionManager::SetKeystoreKey(const std::string& key) { |
| 460 // Note: this is not a thread-safe set, ok for now. NOT ok if tests |
| 461 // run the syncer on the background thread while this method is called. |
| 462 keystore_key_ = key; |
| 463 } |
| 464 |
| 454 bool MockConnectionManager::ShouldConflictThisCommit() { | 465 bool MockConnectionManager::ShouldConflictThisCommit() { |
| 455 bool conflict = false; | 466 bool conflict = false; |
| 456 if (conflict_all_commits_) { | 467 if (conflict_all_commits_) { |
| 457 conflict = true; | 468 conflict = true; |
| 458 } else if (conflict_n_commits_ > 0) { | 469 } else if (conflict_n_commits_ > 0) { |
| 459 conflict = true; | 470 conflict = true; |
| 460 --conflict_n_commits_; | 471 --conflict_n_commits_; |
| 461 } | 472 } |
| 462 return conflict; | 473 return conflict; |
| 463 } | 474 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 600 |
| 590 void MockConnectionManager::UpdateConnectionStatus() { | 601 void MockConnectionManager::UpdateConnectionStatus() { |
| 591 if (!server_reachable_) { | 602 if (!server_reachable_) { |
| 592 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; | 603 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; |
| 593 } else { | 604 } else { |
| 594 server_status_ = HttpResponse::SERVER_CONNECTION_OK; | 605 server_status_ = HttpResponse::SERVER_CONNECTION_OK; |
| 595 } | 606 } |
| 596 } | 607 } |
| 597 | 608 |
| 598 } // namespace syncer | 609 } // namespace syncer |
| OLD | NEW |