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