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 23 matching lines...) Expand all Loading... |
34 explicit MockConnectionManager(syncable::Directory*); | 34 explicit MockConnectionManager(syncable::Directory*); |
35 virtual ~MockConnectionManager(); | 35 virtual ~MockConnectionManager(); |
36 | 36 |
37 // Overridden ServerConnectionManager functions. | 37 // Overridden ServerConnectionManager functions. |
38 virtual bool PostBufferToPath( | 38 virtual bool PostBufferToPath( |
39 PostBufferParams*, | 39 PostBufferParams*, |
40 const std::string& path, | 40 const std::string& path, |
41 const std::string& auth_token, | 41 const std::string& auth_token, |
42 browser_sync::ScopedServerStatusWatcher* watcher) OVERRIDE; | 42 browser_sync::ScopedServerStatusWatcher* watcher) OVERRIDE; |
43 | 43 |
44 virtual bool IsServerReachable() OVERRIDE; | |
45 virtual bool IsUserAuthenticated() OVERRIDE; | |
46 | |
47 // Control of commit response. | 44 // Control of commit response. |
48 void SetMidCommitCallback(const base::Closure& callback); | 45 void SetMidCommitCallback(const base::Closure& callback); |
49 void SetMidCommitObserver(MidCommitObserver* observer); | 46 void SetMidCommitObserver(MidCommitObserver* observer); |
50 | 47 |
51 // Set this if you want commit to perform commit time rename. Will request | 48 // Set this if you want commit to perform commit time rename. Will request |
52 // that the client renames all commited entries, prepending this string. | 49 // that the client renames all commited entries, prepending this string. |
53 void SetCommitTimeRename(std::string prepend); | 50 void SetCommitTimeRename(std::string prepend); |
54 | 51 |
55 // Generic versions of AddUpdate functions. Tests using these function should | 52 // Generic versions of AddUpdate functions. Tests using these function should |
56 // compile for both the int64 and string id based versions of the server. | 53 // compile for both the int64 and string id based versions of the server. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 const std::string& entry_id); | 110 const std::string& entry_id); |
114 void SetLastUpdatePosition(int64 position_in_parent); | 111 void SetLastUpdatePosition(int64 position_in_parent); |
115 void SetNewTimestamp(int ts); | 112 void SetNewTimestamp(int ts); |
116 void SetChangesRemaining(int64 count); | 113 void SetChangesRemaining(int64 count); |
117 | 114 |
118 // 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 |
119 // GetUpdates responses to be buffered up, since the syncer may | 116 // GetUpdates responses to be buffered up, since the syncer may |
120 // issue multiple requests during a sync cycle. | 117 // issue multiple requests during a sync cycle. |
121 void NextUpdateBatch(); | 118 void NextUpdateBatch(); |
122 | 119 |
123 // For AUTHENTICATE responses. | |
124 void SetAuthenticationResponseInfo(const std::string& valid_auth_token, | |
125 const std::string& user_display_name, | |
126 const std::string& user_display_email, | |
127 const std::string& user_obfuscated_id); | |
128 | |
129 void FailNextPostBufferToPathCall() { fail_next_postbuffer_ = true; } | 120 void FailNextPostBufferToPathCall() { fail_next_postbuffer_ = true; } |
130 | 121 |
131 void SetClearUserDataResponseStatus(sync_pb::SyncEnums::ErrorType errortype); | 122 void SetClearUserDataResponseStatus(sync_pb::SyncEnums::ErrorType errortype); |
132 | 123 |
133 // A visitor class to allow a test to change some monitoring state atomically | 124 // A visitor class to allow a test to change some monitoring state atomically |
134 // with the action of overriding the response codes sent back to the Syncer | 125 // with the action of overriding the response codes sent back to the Syncer |
135 // (for example, so you can say "ThrottleNextRequest, and assert no more | 126 // (for example, so you can say "ThrottleNextRequest, and assert no more |
136 // requests are made once throttling is in effect" in one step. | 127 // requests are made once throttling is in effect" in one step. |
137 class ResponseCodeOverrideRequestor { | 128 class ResponseCodeOverrideRequestor { |
138 public: | 129 public: |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 203 |
213 void ExpectGetUpdatesRequestPayloads( | 204 void ExpectGetUpdatesRequestPayloads( |
214 const syncable::ModelTypePayloadMap& payloads) { | 205 const syncable::ModelTypePayloadMap& payloads) { |
215 expected_payloads_ = payloads; | 206 expected_payloads_ = payloads; |
216 } | 207 } |
217 | 208 |
218 void SetServerReachable(); | 209 void SetServerReachable(); |
219 | 210 |
220 void SetServerNotReachable(); | 211 void SetServerNotReachable(); |
221 | 212 |
| 213 // Updates our internal state as if we had attempted a connection. Does not |
| 214 // send notifications as a real connection attempt would. This is useful in |
| 215 // cases where we're mocking out most of the code that performs network |
| 216 // requests. |
| 217 void UpdateConnectionStatus(); |
| 218 |
222 // Return by copy to be thread-safe. | 219 // Return by copy to be thread-safe. |
223 const std::string store_birthday() { | 220 const std::string store_birthday() { |
224 base::AutoLock lock(store_birthday_lock_); | 221 base::AutoLock lock(store_birthday_lock_); |
225 return store_birthday_; | 222 return store_birthday_; |
226 } | 223 } |
227 | 224 |
228 // Locate the most recent update message for purpose of alteration. | 225 // Locate the most recent update message for purpose of alteration. |
229 sync_pb::SyncEntity* GetMutableLastUpdate(); | 226 sync_pb::SyncEntity* GetMutableLastUpdate(); |
230 | 227 |
231 private: | 228 private: |
232 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid, | 229 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid, |
233 std::string name, int64 version, | 230 std::string name, int64 version, |
234 int64 sync_ts, | 231 int64 sync_ts, |
235 bool is_dir); | 232 bool is_dir); |
236 sync_pb::SyncEntity* AddUpdateFull(std::string id, | 233 sync_pb::SyncEntity* AddUpdateFull(std::string id, |
237 std::string parentid, std::string name, | 234 std::string parentid, std::string name, |
238 int64 version, int64 sync_ts, | 235 int64 version, int64 sync_ts, |
239 bool is_dir); | 236 bool is_dir); |
240 sync_pb::SyncEntity* AddUpdateMeta(std::string id, std::string parentid, | 237 sync_pb::SyncEntity* AddUpdateMeta(std::string id, std::string parentid, |
241 std::string name, int64 version, | 238 std::string name, int64 version, |
242 int64 sync_ts); | 239 int64 sync_ts); |
243 | 240 |
244 // Functions to handle the various types of server request. | 241 // Functions to handle the various types of server request. |
245 void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm, | 242 void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm, |
246 sync_pb::ClientToServerResponse* response); | 243 sync_pb::ClientToServerResponse* response); |
247 void ProcessAuthenticate(sync_pb::ClientToServerMessage* csm, | |
248 sync_pb::ClientToServerResponse* response, | |
249 const std::string& auth_token); | |
250 void ProcessCommit(sync_pb::ClientToServerMessage* csm, | 244 void ProcessCommit(sync_pb::ClientToServerMessage* csm, |
251 sync_pb::ClientToServerResponse* response_buffer); | 245 sync_pb::ClientToServerResponse* response_buffer); |
252 void ProcessClearData(sync_pb::ClientToServerMessage* csm, | 246 void ProcessClearData(sync_pb::ClientToServerMessage* csm, |
253 sync_pb::ClientToServerResponse* response); | 247 sync_pb::ClientToServerResponse* response); |
254 void AddDefaultBookmarkData(sync_pb::SyncEntity* entity, bool is_folder); | 248 void AddDefaultBookmarkData(sync_pb::SyncEntity* entity, bool is_folder); |
255 | 249 |
256 // Determine if one entry in a commit should be rejected with a conflict. | 250 // Determine if one entry in a commit should be rejected with a conflict. |
257 bool ShouldConflictThisCommit(); | 251 bool ShouldConflictThisCommit(); |
258 | 252 |
259 // Generate a numeric position_in_parent value. We use a global counter | 253 // Generate a numeric position_in_parent value. We use a global counter |
(...skipping 14 matching lines...) Expand all Loading... |
274 bool IsModelTypePresentInSpecifics( | 268 bool IsModelTypePresentInSpecifics( |
275 const google::protobuf::RepeatedPtrField< | 269 const google::protobuf::RepeatedPtrField< |
276 sync_pb::DataTypeProgressMarker>& filter, | 270 sync_pb::DataTypeProgressMarker>& filter, |
277 syncable::ModelType value); | 271 syncable::ModelType value); |
278 | 272 |
279 sync_pb::DataTypeProgressMarker const* GetProgressMarkerForType( | 273 sync_pb::DataTypeProgressMarker const* GetProgressMarkerForType( |
280 const google::protobuf::RepeatedPtrField< | 274 const google::protobuf::RepeatedPtrField< |
281 sync_pb::DataTypeProgressMarker>& filter, | 275 sync_pb::DataTypeProgressMarker>& filter, |
282 syncable::ModelType value); | 276 syncable::ModelType value); |
283 | 277 |
| 278 // When false, we pretend to have network connectivity issues. |
| 279 bool server_reachable_; |
| 280 |
284 // All IDs that have been committed. | 281 // All IDs that have been committed. |
285 std::vector<syncable::Id> committed_ids_; | 282 std::vector<syncable::Id> committed_ids_; |
286 | 283 |
287 // Control of when/if we return conflicts. | 284 // Control of when/if we return conflicts. |
288 bool conflict_all_commits_; | 285 bool conflict_all_commits_; |
289 int conflict_n_commits_; | 286 int conflict_n_commits_; |
290 | 287 |
291 // Commit messages we've sent, and responses we've returned. | 288 // Commit messages we've sent, and responses we've returned. |
292 ScopedVector<sync_pb::CommitMessage> commit_messages_; | 289 ScopedVector<sync_pb::CommitMessage> commit_messages_; |
293 ScopedVector<sync_pb::CommitResponse> commit_responses_; | 290 ScopedVector<sync_pb::CommitResponse> commit_responses_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 int num_get_updates_requests_; | 351 int num_get_updates_requests_; |
355 | 352 |
356 std::string next_token_; | 353 std::string next_token_; |
357 | 354 |
358 sync_pb::ClientToServerMessage last_request_; | 355 sync_pb::ClientToServerMessage last_request_; |
359 | 356 |
360 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); | 357 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); |
361 }; | 358 }; |
362 | 359 |
363 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ | 360 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ |
OLD | NEW |