OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ | 5 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ |
6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ | 6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const sync_pb::SyncEnums::Action& action); | 87 const sync_pb::SyncEnums::Action& action); |
88 | 88 |
89 // Adds |observer| to FakeServer's observer list. This should be called | 89 // Adds |observer| to FakeServer's observer list. This should be called |
90 // before the Profile associated with |observer| is connected to the server. | 90 // before the Profile associated with |observer| is connected to the server. |
91 void AddObserver(Observer* observer); | 91 void AddObserver(Observer* observer); |
92 | 92 |
93 // Removes |observer| from the FakeServer's observer list. This method | 93 // Removes |observer| from the FakeServer's observer list. This method |
94 // must be called if AddObserver was ever called with |observer|. | 94 // must be called if AddObserver was ever called with |observer|. |
95 void RemoveObserver(Observer* observer); | 95 void RemoveObserver(Observer* observer); |
96 | 96 |
| 97 // Undoes the effects of DisableNetwork. |
| 98 void EnableNetwork(); |
| 99 |
| 100 // Forces every request to fail in a way that simulates a network failure. |
| 101 // This can be used to trigger exponential backoff in the client. |
| 102 void DisableNetwork(); |
| 103 |
97 private: | 104 private: |
98 typedef std::map<std::string, FakeServerEntity*> EntityMap; | 105 typedef std::map<std::string, FakeServerEntity*> EntityMap; |
99 | 106 |
100 // Processes a GetUpdates call. | 107 // Processes a GetUpdates call. |
101 bool HandleGetUpdatesRequest(const sync_pb::GetUpdatesMessage& get_updates, | 108 bool HandleGetUpdatesRequest(const sync_pb::GetUpdatesMessage& get_updates, |
102 sync_pb::GetUpdatesResponse* response); | 109 sync_pb::GetUpdatesResponse* response); |
103 | 110 |
104 // Processes a Commit call. | 111 // Processes a Commit call. |
105 bool HandleCommitRequest(const sync_pb::CommitMessage& message, | 112 bool HandleCommitRequest(const sync_pb::CommitMessage& message, |
106 const std::string& invalidator_client_id, | 113 const std::string& invalidator_client_id, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Used as the error_code field of ClientToServerResponse on all responses | 168 // Used as the error_code field of ClientToServerResponse on all responses |
162 // except when |triggered_actionable_error_| is set. | 169 // except when |triggered_actionable_error_| is set. |
163 sync_pb::SyncEnums::ErrorType error_type_; | 170 sync_pb::SyncEnums::ErrorType error_type_; |
164 | 171 |
165 // Used as the error field of ClientToServerResponse when its pointer is not | 172 // Used as the error field of ClientToServerResponse when its pointer is not |
166 // NULL. | 173 // NULL. |
167 scoped_ptr<sync_pb::ClientToServerResponse_Error> triggered_actionable_error_; | 174 scoped_ptr<sync_pb::ClientToServerResponse_Error> triggered_actionable_error_; |
168 | 175 |
169 // FakeServer's observers. | 176 // FakeServer's observers. |
170 ObserverList<Observer, true> observers_; | 177 ObserverList<Observer, true> observers_; |
| 178 |
| 179 // When true, the server operates normally. When false, a failure is returned |
| 180 // on every request. This is used to simulate a network failure on the client. |
| 181 bool network_enabled_; |
171 }; | 182 }; |
172 | 183 |
173 } // namespace fake_server | 184 } // namespace fake_server |
174 | 185 |
175 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ | 186 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ |
OLD | NEW |