OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_TEST_SYNC_ENGINE_MOCK_CONNECTION_MANAGER_H_ | 7 #ifndef CHROME_TEST_SYNC_ENGINE_MOCK_CONNECTION_MANAGER_H_ |
8 #define CHROME_TEST_SYNC_ENGINE_MOCK_CONNECTION_MANAGER_H_ | 8 #define CHROME_TEST_SYNC_ENGINE_MOCK_CONNECTION_MANAGER_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 virtual bool IsUserAuthenticated(); | 51 virtual bool IsUserAuthenticated(); |
52 | 52 |
53 // Control of commit response. | 53 // Control of commit response. |
54 void SetMidCommitCallback(Callback0::Type* callback); | 54 void SetMidCommitCallback(Callback0::Type* callback); |
55 void SetMidCommitObserver(MidCommitObserver* observer); | 55 void SetMidCommitObserver(MidCommitObserver* observer); |
56 | 56 |
57 // Set this if you want commit to perform commit time rename. Will request | 57 // Set this if you want commit to perform commit time rename. Will request |
58 // that the client renames all commited entries, prepending this string. | 58 // that the client renames all commited entries, prepending this string. |
59 void SetCommitTimeRename(string prepend); | 59 void SetCommitTimeRename(string prepend); |
60 | 60 |
61 // Control of get updates response. All updates set will only be returned | |
62 // once. This mock object doesn't simulate a changelist, it simulates server | |
63 // responses. | |
64 void ResetUpdates(); | |
65 | |
66 // Generic versions of AddUpdate functions. Tests using these function should | 61 // Generic versions of AddUpdate functions. Tests using these function should |
67 // compile for both the int64 and string id based versions of the server. | 62 // compile for both the int64 and string id based versions of the server. |
68 // The SyncEntity returned is only valid until the Sync is completed | 63 // The SyncEntity returned is only valid until the Sync is completed |
69 // (e.g. with SyncShare.) It allows to add further entity properties before | 64 // (e.g. with SyncShare.) It allows to add further entity properties before |
70 // sync, using SetLastXXX() methods and/or GetMutableLastUpdate(). | 65 // sync, using SetLastXXX() methods and/or GetMutableLastUpdate(). |
71 sync_pb::SyncEntity* AddUpdateDirectory(syncable::Id id, | 66 sync_pb::SyncEntity* AddUpdateDirectory(syncable::Id id, |
72 syncable::Id parent_id, | 67 syncable::Id parent_id, |
73 string name, | 68 string name, |
74 int64 version, | 69 int64 version, |
75 int64 sync_ts); | 70 int64 sync_ts); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // additional information beyond the deletion, and no specifics. | 105 // additional information beyond the deletion, and no specifics. |
111 // The server may send the originator fields. | 106 // The server may send the originator fields. |
112 void AddUpdateTombstone(const syncable::Id& id); | 107 void AddUpdateTombstone(const syncable::Id& id); |
113 | 108 |
114 void SetLastUpdateDeleted(); | 109 void SetLastUpdateDeleted(); |
115 void SetLastUpdateServerTag(const string& tag); | 110 void SetLastUpdateServerTag(const string& tag); |
116 void SetLastUpdateClientTag(const string& tag); | 111 void SetLastUpdateClientTag(const string& tag); |
117 void SetLastUpdateOriginatorFields(const string& client_id, | 112 void SetLastUpdateOriginatorFields(const string& client_id, |
118 const string& entry_id); | 113 const string& entry_id); |
119 void SetLastUpdatePosition(int64 position_in_parent); | 114 void SetLastUpdatePosition(int64 position_in_parent); |
120 void SetNewTimestamp(int64 ts); | 115 void SetNewTimestamp(int ts); |
121 void SetChangesRemaining(int64 timestamp); | 116 void SetChangesRemaining(int64 count); |
| 117 |
| 118 // Add a new batch of updates after the current one. Allows multiple |
| 119 // GetUpdates responses to be buffered up, since the syncer may |
| 120 // issue multiple requests during a sync cycle. |
| 121 void NextUpdateBatch(); |
122 | 122 |
123 // For AUTHENTICATE responses. | 123 // For AUTHENTICATE responses. |
124 void SetAuthenticationResponseInfo(const std::string& valid_auth_token, | 124 void SetAuthenticationResponseInfo(const std::string& valid_auth_token, |
125 const std::string& user_display_name, | 125 const std::string& user_display_name, |
126 const std::string& user_display_email, | 126 const std::string& user_display_email, |
127 const std::string& user_obfuscated_id); | 127 const std::string& user_obfuscated_id); |
128 | 128 |
129 void FailNextPostBufferToPathCall() { fail_next_postbuffer_ = true; } | 129 void FailNextPostBufferToPathCall() { fail_next_postbuffer_ = true; } |
130 | 130 |
131 void SetClearUserDataResponseStatus( | 131 void SetClearUserDataResponseStatus( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 // Determine if one entry in a commit should be rejected with a conflict. | 248 // Determine if one entry in a commit should be rejected with a conflict. |
249 bool ShouldConflictThisCommit(); | 249 bool ShouldConflictThisCommit(); |
250 | 250 |
251 // Generate a numeric position_in_parent value. We use a global counter | 251 // Generate a numeric position_in_parent value. We use a global counter |
252 // that only decreases; this simulates new objects always being added to the | 252 // that only decreases; this simulates new objects always being added to the |
253 // front of the ordering. | 253 // front of the ordering. |
254 int64 GeneratePositionInParent() { | 254 int64 GeneratePositionInParent() { |
255 return next_position_in_parent_--; | 255 return next_position_in_parent_--; |
256 } | 256 } |
257 | 257 |
258 // Determine whether an EntitySpecifics filter (like that sent in | 258 // Get a mutable update response which will eventually be returned to the |
259 // GetUpdates.requested_types) indicates that a particular ModelType | 259 // client. |
| 260 sync_pb::GetUpdatesResponse* GetUpdateResponse(); |
| 261 void ApplyToken(); |
| 262 |
| 263 // Determine whether an progress marker array (like that sent in |
| 264 // GetUpdates.from_progress_marker) indicates that a particular ModelType |
260 // should be included. | 265 // should be included. |
261 bool IsModelTypePresentInSpecifics(const sync_pb::EntitySpecifics& filter, | 266 bool IsModelTypePresentInSpecifics( |
| 267 const google::protobuf::RepeatedPtrField< |
| 268 sync_pb::DataTypeProgressMarker>& filter, |
262 syncable::ModelType value); | 269 syncable::ModelType value); |
263 | 270 |
264 // All IDs that have been committed. | 271 // All IDs that have been committed. |
265 std::vector<syncable::Id> committed_ids_; | 272 std::vector<syncable::Id> committed_ids_; |
266 | 273 |
267 // Control of when/if we return conflicts. | 274 // Control of when/if we return conflicts. |
268 bool conflict_all_commits_; | 275 bool conflict_all_commits_; |
269 int conflict_n_commits_; | 276 int conflict_n_commits_; |
270 | 277 |
271 // Commit messages we've sent, and responses we've returned. | 278 // Commit messages we've sent, and responses we've returned. |
(...skipping 11 matching lines...) Expand all Loading... |
283 string commit_time_rename_prepended_string_; | 290 string commit_time_rename_prepended_string_; |
284 | 291 |
285 // Fail on the next call to PostBufferToPath(). | 292 // Fail on the next call to PostBufferToPath(). |
286 bool fail_next_postbuffer_; | 293 bool fail_next_postbuffer_; |
287 | 294 |
288 // Our directory. | 295 // Our directory. |
289 syncable::DirectoryManager* directory_manager_; | 296 syncable::DirectoryManager* directory_manager_; |
290 std::string directory_name_; | 297 std::string directory_name_; |
291 | 298 |
292 // The updates we'll return to the next request. | 299 // The updates we'll return to the next request. |
293 sync_pb::GetUpdatesResponse updates_; | 300 std::list<sync_pb::GetUpdatesResponse> update_queue_; |
294 scoped_ptr<Callback0::Type> mid_commit_callback_; | 301 scoped_ptr<Callback0::Type> mid_commit_callback_; |
295 MidCommitObserver* mid_commit_observer_; | 302 MidCommitObserver* mid_commit_observer_; |
296 | 303 |
297 // The clear data response we'll return in the next response | 304 // The clear data response we'll return in the next response |
298 sync_pb::ClientToServerResponse::ErrorType | 305 sync_pb::ClientToServerResponse::ErrorType |
299 clear_user_data_response_errortype_; | 306 clear_user_data_response_errortype_; |
300 | 307 |
301 // The AUTHENTICATE response we'll return for auth requests. | 308 // The AUTHENTICATE response we'll return for auth requests. |
302 sync_pb::AuthenticateResponse auth_response_; | 309 sync_pb::AuthenticateResponse auth_response_; |
303 // What we use to determine if we should return SUCCESS or BAD_AUTH_TOKEN. | 310 // What we use to determine if we should return SUCCESS or BAD_AUTH_TOKEN. |
(...skipping 20 matching lines...) Expand all Loading... |
324 | 331 |
325 // The default is to use the newer sync_pb::BookmarkSpecifics-style protocol. | 332 // The default is to use the newer sync_pb::BookmarkSpecifics-style protocol. |
326 // If this option is set to true, then the MockConnectionManager will | 333 // If this option is set to true, then the MockConnectionManager will |
327 // use the older sync_pb::SyncEntity_BookmarkData-style protocol. | 334 // use the older sync_pb::SyncEntity_BookmarkData-style protocol. |
328 bool use_legacy_bookmarks_protocol_; | 335 bool use_legacy_bookmarks_protocol_; |
329 | 336 |
330 std::bitset<syncable::MODEL_TYPE_COUNT> expected_filter_; | 337 std::bitset<syncable::MODEL_TYPE_COUNT> expected_filter_; |
331 | 338 |
332 int num_get_updates_requests_; | 339 int num_get_updates_requests_; |
333 | 340 |
| 341 std::string next_token_; |
| 342 |
334 sync_pb::ClientToServerMessage last_request_; | 343 sync_pb::ClientToServerMessage last_request_; |
335 | 344 |
336 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); | 345 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); |
337 }; | 346 }; |
338 | 347 |
339 #endif // CHROME_TEST_SYNC_ENGINE_MOCK_CONNECTION_MANAGER_H_ | 348 #endif // CHROME_TEST_SYNC_ENGINE_MOCK_CONNECTION_MANAGER_H_ |
OLD | NEW |