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 MockConnectionManager::MockConnectionManager(syncable::Directory* directory) | 41 MockConnectionManager::MockConnectionManager(syncable::Directory* directory) |
42 : ServerConnectionManager("unused", 0, false, "version"), | 42 : ServerConnectionManager("unused", 0, false, "version"), |
43 server_reachable_(true), | 43 server_reachable_(true), |
44 conflict_all_commits_(false), | 44 conflict_all_commits_(false), |
45 conflict_n_commits_(0), | 45 conflict_n_commits_(0), |
46 next_new_id_(10000), | 46 next_new_id_(10000), |
47 store_birthday_("Store BDay!"), | 47 store_birthday_("Store BDay!"), |
48 store_birthday_sent_(false), | 48 store_birthday_sent_(false), |
49 client_stuck_(false), | 49 client_stuck_(false), |
50 commit_time_rename_prepended_string_(""), | 50 commit_time_rename_prepended_string_(""), |
51 fail_next_postbuffer_(false), | 51 countdown_to_postbuffer_fail_(0), |
52 directory_(directory), | 52 directory_(directory), |
53 mid_commit_observer_(NULL), | 53 mid_commit_observer_(NULL), |
54 throttling_(false), | 54 throttling_(false), |
55 fail_with_auth_invalid_(false), | 55 fail_with_auth_invalid_(false), |
56 fail_non_periodic_get_updates_(false), | 56 fail_non_periodic_get_updates_(false), |
57 client_command_(NULL), | 57 client_command_(NULL), |
58 next_position_in_parent_(2), | 58 next_position_in_parent_(2), |
59 use_legacy_bookmarks_protocol_(false), | 59 use_legacy_bookmarks_protocol_(false), |
60 num_get_updates_requests_(0) { | 60 num_get_updates_requests_(0) { |
61 SetNewTimestamp(0); | 61 SetNewTimestamp(0); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 params->response.server_status = HttpResponse::SYNC_AUTH_ERROR; | 104 params->response.server_status = HttpResponse::SYNC_AUTH_ERROR; |
105 return false; | 105 return false; |
106 } | 106 } |
107 | 107 |
108 if (auth_token != kValidAuthToken) { | 108 if (auth_token != kValidAuthToken) { |
109 // Simulate server-side auth failure. | 109 // Simulate server-side auth failure. |
110 params->response.server_status = HttpResponse::SYNC_AUTH_ERROR; | 110 params->response.server_status = HttpResponse::SYNC_AUTH_ERROR; |
111 InvalidateAndClearAuthToken(); | 111 InvalidateAndClearAuthToken(); |
112 } | 112 } |
113 | 113 |
114 if (fail_next_postbuffer_) { | 114 if (--countdown_to_postbuffer_fail_ == 0) { |
115 fail_next_postbuffer_ = false; | 115 // Fail as countdown hits zero. |
| 116 params->response.server_status = HttpResponse::SYNC_SERVER_ERROR; |
116 return false; | 117 return false; |
117 } | 118 } |
118 | 119 |
119 if (!server_reachable_) { | 120 if (!server_reachable_) { |
120 params->response.server_status = HttpResponse::CONNECTION_UNAVAILABLE; | 121 params->response.server_status = HttpResponse::CONNECTION_UNAVAILABLE; |
121 return false; | 122 return false; |
122 } | 123 } |
123 | 124 |
124 // Default to an ok connection. | 125 // Default to an ok connection. |
125 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK; | 126 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 const CommitMessage& MockConnectionManager::last_sent_commit() const { | 558 const CommitMessage& MockConnectionManager::last_sent_commit() const { |
558 EXPECT_TRUE(!commit_messages_.empty()); | 559 EXPECT_TRUE(!commit_messages_.empty()); |
559 return *commit_messages_->back(); | 560 return *commit_messages_->back(); |
560 } | 561 } |
561 | 562 |
562 const CommitResponse& MockConnectionManager::last_commit_response() const { | 563 const CommitResponse& MockConnectionManager::last_commit_response() const { |
563 EXPECT_TRUE(!commit_responses_.empty()); | 564 EXPECT_TRUE(!commit_responses_.empty()); |
564 return *commit_responses_->back(); | 565 return *commit_responses_->back(); |
565 } | 566 } |
566 | 567 |
567 void MockConnectionManager::ThrottleNextRequest( | |
568 ResponseCodeOverrideRequestor* visitor) { | |
569 base::AutoLock lock(response_code_override_lock_); | |
570 throttling_ = true; | |
571 if (visitor) | |
572 visitor->OnOverrideComplete(); | |
573 } | |
574 | |
575 void MockConnectionManager::FailWithAuthInvalid( | |
576 ResponseCodeOverrideRequestor* visitor) { | |
577 base::AutoLock lock(response_code_override_lock_); | |
578 fail_with_auth_invalid_ = true; | |
579 if (visitor) | |
580 visitor->OnOverrideComplete(); | |
581 } | |
582 | |
583 void MockConnectionManager::StopFailingWithAuthInvalid( | |
584 ResponseCodeOverrideRequestor* visitor) { | |
585 base::AutoLock lock(response_code_override_lock_); | |
586 fail_with_auth_invalid_ = false; | |
587 if (visitor) | |
588 visitor->OnOverrideComplete(); | |
589 } | |
590 | |
591 bool MockConnectionManager::IsModelTypePresentInSpecifics( | 568 bool MockConnectionManager::IsModelTypePresentInSpecifics( |
592 const google::protobuf::RepeatedPtrField< | 569 const google::protobuf::RepeatedPtrField< |
593 sync_pb::DataTypeProgressMarker>& filter, | 570 sync_pb::DataTypeProgressMarker>& filter, |
594 syncable::ModelType value) { | 571 syncable::ModelType value) { |
595 int data_type_id = syncable::GetSpecificsFieldNumberFromModelType(value); | 572 int data_type_id = syncable::GetSpecificsFieldNumberFromModelType(value); |
596 for (int i = 0; i < filter.size(); ++i) { | 573 for (int i = 0; i < filter.size(); ++i) { |
597 if (filter.Get(i).data_type_id() == data_type_id) { | 574 if (filter.Get(i).data_type_id() == data_type_id) { |
598 return true; | 575 return true; |
599 } | 576 } |
600 } | 577 } |
(...skipping 22 matching lines...) Expand all Loading... |
623 server_reachable_ = false; | 600 server_reachable_ = false; |
624 } | 601 } |
625 | 602 |
626 void MockConnectionManager::UpdateConnectionStatus() { | 603 void MockConnectionManager::UpdateConnectionStatus() { |
627 if (!server_reachable_) { | 604 if (!server_reachable_) { |
628 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; | 605 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; |
629 } else { | 606 } else { |
630 server_status_ = HttpResponse::SERVER_CONNECTION_OK; | 607 server_status_ = HttpResponse::SERVER_CONNECTION_OK; |
631 } | 608 } |
632 } | 609 } |
OLD | NEW |