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