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 unit tests. | 5 // Mock ServerConnectionManager class for use in client unit tests. |
| 6 | 6 |
| 7 #ifndef SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ | 7 #ifndef SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ |
| 8 #define SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ | 8 #define SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 const std::string& entry_id); | 110 const std::string& entry_id); |
| 111 void SetLastUpdatePosition(int64 position_in_parent); | 111 void SetLastUpdatePosition(int64 position_in_parent); |
| 112 void SetNewTimestamp(int ts); | 112 void SetNewTimestamp(int ts); |
| 113 void SetChangesRemaining(int64 count); | 113 void SetChangesRemaining(int64 count); |
| 114 | 114 |
| 115 // Add a new batch of updates after the current one. Allows multiple | 115 // Add a new batch of updates after the current one. Allows multiple |
| 116 // GetUpdates responses to be buffered up, since the syncer may | 116 // GetUpdates responses to be buffered up, since the syncer may |
| 117 // issue multiple requests during a sync cycle. | 117 // issue multiple requests during a sync cycle. |
| 118 void NextUpdateBatch(); | 118 void NextUpdateBatch(); |
| 119 | 119 |
| 120 void FailNextPostBufferToPathCall() { fail_next_postbuffer_ = true; } | 120 void FailNextPostBufferToPathCall() { countdown_to_postbuffer_fail_ = 1; } |
|
rlarocque
2012/04/06 20:35:09
At this point, it probably makes sense to start th
| |
| 121 void FailNthPostBufferToPathCall(int n) { countdown_to_postbuffer_fail_ = n; } | |
| 121 | 122 |
| 122 void SetClearUserDataResponseStatus(sync_pb::SyncEnums::ErrorType errortype); | 123 void SetClearUserDataResponseStatus(sync_pb::SyncEnums::ErrorType errortype); |
| 123 | 124 |
| 124 // A visitor class to allow a test to change some monitoring state atomically | 125 // A visitor class to allow a test to change some monitoring state atomically |
| 125 // with the action of overriding the response codes sent back to the Syncer | 126 // with the action of overriding the response codes sent back to the Syncer |
| 126 // (for example, so you can say "ThrottleNextRequest, and assert no more | 127 // (for example, so you can say "ThrottleNextRequest, and assert no more |
| 127 // requests are made once throttling is in effect" in one step. | 128 // requests are made once throttling is in effect" in one step. |
| 128 class ResponseCodeOverrideRequestor { | 129 class ResponseCodeOverrideRequestor { |
| 129 public: | 130 public: |
| 130 // Called with response_code_override_lock_ acquired. | 131 // Called with response_code_override_lock_ acquired. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 // cases where we're mocking out most of the code that performs network | 216 // cases where we're mocking out most of the code that performs network |
| 216 // requests. | 217 // requests. |
| 217 void UpdateConnectionStatus(); | 218 void UpdateConnectionStatus(); |
| 218 | 219 |
| 219 // Return by copy to be thread-safe. | 220 // Return by copy to be thread-safe. |
| 220 const std::string store_birthday() { | 221 const std::string store_birthday() { |
| 221 base::AutoLock lock(store_birthday_lock_); | 222 base::AutoLock lock(store_birthday_lock_); |
| 222 return store_birthday_; | 223 return store_birthday_; |
| 223 } | 224 } |
| 224 | 225 |
| 226 // Explicitly indicate that we will not be fetching some updates. | |
| 227 void ClearUpdatesQueue() { | |
| 228 update_queue_.clear(); | |
| 229 } | |
| 230 | |
| 225 // Locate the most recent update message for purpose of alteration. | 231 // Locate the most recent update message for purpose of alteration. |
| 226 sync_pb::SyncEntity* GetMutableLastUpdate(); | 232 sync_pb::SyncEntity* GetMutableLastUpdate(); |
| 227 | 233 |
| 228 private: | 234 private: |
| 229 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid, | 235 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid, |
| 230 std::string name, int64 version, | 236 std::string name, int64 version, |
| 231 int64 sync_ts, | 237 int64 sync_ts, |
| 232 bool is_dir); | 238 bool is_dir); |
| 233 sync_pb::SyncEntity* AddUpdateFull(std::string id, | 239 sync_pb::SyncEntity* AddUpdateFull(std::string id, |
| 234 std::string parentid, std::string name, | 240 std::string parentid, std::string name, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 // The next id the mock will return to a commit. | 298 // The next id the mock will return to a commit. |
| 293 int next_new_id_; | 299 int next_new_id_; |
| 294 | 300 |
| 295 // The store birthday we send to the client. | 301 // The store birthday we send to the client. |
| 296 std::string store_birthday_; | 302 std::string store_birthday_; |
| 297 base::Lock store_birthday_lock_; | 303 base::Lock store_birthday_lock_; |
| 298 bool store_birthday_sent_; | 304 bool store_birthday_sent_; |
| 299 bool client_stuck_; | 305 bool client_stuck_; |
| 300 std::string commit_time_rename_prepended_string_; | 306 std::string commit_time_rename_prepended_string_; |
| 301 | 307 |
| 302 // Fail on the next call to PostBufferToPath(). | 308 // On each PostBufferToPath() call, we decrement this counter. The call fails |
| 303 bool fail_next_postbuffer_; | 309 // iff we hit zero at that call. |
| 310 int countdown_to_postbuffer_fail_; | |
| 304 | 311 |
| 305 // Our directory. Used only to ensure that we are not holding the transaction | 312 // Our directory. Used only to ensure that we are not holding the transaction |
| 306 // lock when performing network I/O. Can be NULL if the test author is | 313 // lock when performing network I/O. Can be NULL if the test author is |
| 307 // confident this can't happen. | 314 // confident this can't happen. |
| 308 syncable::Directory* directory_; | 315 syncable::Directory* directory_; |
| 309 | 316 |
| 310 // The updates we'll return to the next request. | 317 // The updates we'll return to the next request. |
| 311 std::list<sync_pb::GetUpdatesResponse> update_queue_; | 318 std::list<sync_pb::GetUpdatesResponse> update_queue_; |
| 312 base::Closure mid_commit_callback_; | 319 base::Closure mid_commit_callback_; |
| 313 MidCommitObserver* mid_commit_observer_; | 320 MidCommitObserver* mid_commit_observer_; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 int num_get_updates_requests_; | 358 int num_get_updates_requests_; |
| 352 | 359 |
| 353 std::string next_token_; | 360 std::string next_token_; |
| 354 | 361 |
| 355 sync_pb::ClientToServerMessage last_request_; | 362 sync_pb::ClientToServerMessage last_request_; |
| 356 | 363 |
| 357 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); | 364 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); |
| 358 }; | 365 }; |
| 359 | 366 |
| 360 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ | 367 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ |
| OLD | NEW |