Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: sync/test/engine/mock_connection_manager.h

Issue 1545553003: Switch to standard integer types in sync/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/test/engine/mock_commit_queue.cc ('k') | sync/test/engine/mock_connection_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
10 #include <stdint.h>
11
10 #include <bitset> 12 #include <bitset>
11 #include <list> 13 #include <list>
12 #include <string> 14 #include <string>
13 #include <vector> 15 #include <vector>
14 16
15 #include "base/callback.h" 17 #include "base/callback.h"
16 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/macros.h"
17 #include "base/memory/scoped_vector.h" 20 #include "base/memory/scoped_vector.h"
18 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
19 #include "sync/engine/net/server_connection_manager.h" 22 #include "sync/engine/net/server_connection_manager.h"
20 #include "sync/internal_api/public/base/model_type.h" 23 #include "sync/internal_api/public/base/model_type.h"
21 #include "sync/internal_api/public/base/unique_position.h" 24 #include "sync/internal_api/public/base/unique_position.h"
22 #include "sync/protocol/sync.pb.h" 25 #include "sync/protocol/sync.pb.h"
23 26
24 namespace syncer { 27 namespace syncer {
25 28
26 class MockConnectionManager : public ServerConnectionManager { 29 class MockConnectionManager : public ServerConnectionManager {
(...skipping 18 matching lines...) Expand all
45 // Control of commit response. 48 // Control of commit response.
46 // NOTE: Commit callback is invoked only once then reset. 49 // NOTE: Commit callback is invoked only once then reset.
47 void SetMidCommitCallback(const base::Closure& callback); 50 void SetMidCommitCallback(const base::Closure& callback);
48 void SetMidCommitObserver(MidCommitObserver* observer); 51 void SetMidCommitObserver(MidCommitObserver* observer);
49 52
50 // Set this if you want commit to perform commit time rename. Will request 53 // Set this if you want commit to perform commit time rename. Will request
51 // that the client renames all commited entries, prepending this string. 54 // that the client renames all commited entries, prepending this string.
52 void SetCommitTimeRename(const std::string& prepend); 55 void SetCommitTimeRename(const std::string& prepend);
53 56
54 // Generic versions of AddUpdate functions. Tests using these function should 57 // Generic versions of AddUpdate functions. Tests using these function should
55 // compile for both the int64 and string id based versions of the server. 58 // compile for both the int64_t and string id based versions of the server.
56 // The SyncEntity returned is only valid until the Sync is completed 59 // The SyncEntity returned is only valid until the Sync is completed
57 // (e.g. with SyncShare.) It allows to add further entity properties before 60 // (e.g. with SyncShare.) It allows to add further entity properties before
58 // sync, using SetLastXXX() methods and/or GetMutableLastUpdate(). 61 // sync, using SetLastXXX() methods and/or GetMutableLastUpdate().
59 sync_pb::SyncEntity* AddUpdateDirectory( 62 sync_pb::SyncEntity* AddUpdateDirectory(
60 syncable::Id id, 63 syncable::Id id,
61 syncable::Id parent_id, 64 syncable::Id parent_id,
62 const std::string& name, 65 const std::string& name,
63 int64 version, 66 int64_t version,
64 int64 sync_ts, 67 int64_t sync_ts,
65 const std::string& originator_cache_guid, 68 const std::string& originator_cache_guid,
66 const std::string& originator_client_item_id); 69 const std::string& originator_client_item_id);
67 sync_pb::SyncEntity* AddUpdateBookmark( 70 sync_pb::SyncEntity* AddUpdateBookmark(
68 syncable::Id id, 71 syncable::Id id,
69 syncable::Id parent_id, 72 syncable::Id parent_id,
70 const std::string& name, 73 const std::string& name,
71 int64 version, 74 int64_t version,
72 int64 sync_ts, 75 int64_t sync_ts,
73 const std::string& originator_cache_guid, 76 const std::string& originator_cache_guid,
74 const std::string& originator_client_item_id); 77 const std::string& originator_client_item_id);
75 // Versions of the AddUpdate functions that accept integer IDs. 78 // Versions of the AddUpdate functions that accept integer IDs.
76 sync_pb::SyncEntity* AddUpdateDirectory( 79 sync_pb::SyncEntity* AddUpdateDirectory(
77 int id, 80 int id,
78 int parent_id, 81 int parent_id,
79 const std::string& name, 82 const std::string& name,
80 int64 version, 83 int64_t version,
81 int64 sync_ts, 84 int64_t sync_ts,
82 const std::string& originator_cache_guid, 85 const std::string& originator_cache_guid,
83 const std::string& originator_client_item_id); 86 const std::string& originator_client_item_id);
84 sync_pb::SyncEntity* AddUpdateBookmark( 87 sync_pb::SyncEntity* AddUpdateBookmark(
85 int id, 88 int id,
86 int parent_id, 89 int parent_id,
87 const std::string& name, 90 const std::string& name,
88 int64 version, 91 int64_t version,
89 int64 sync_ts, 92 int64_t sync_ts,
90 const std::string& originator_cache_guid, 93 const std::string& originator_cache_guid,
91 const std::string& originator_client_item_id); 94 const std::string& originator_client_item_id);
92 // New protocol versions of the AddUpdate functions. 95 // New protocol versions of the AddUpdate functions.
93 sync_pb::SyncEntity* AddUpdateDirectory( 96 sync_pb::SyncEntity* AddUpdateDirectory(
94 const std::string& id, 97 const std::string& id,
95 const std::string& parent_id, 98 const std::string& parent_id,
96 const std::string& name, 99 const std::string& name,
97 int64 version, 100 int64_t version,
98 int64 sync_ts, 101 int64_t sync_ts,
99 const std::string& originator_cache_guid, 102 const std::string& originator_cache_guid,
100 const std::string& originator_client_item_id); 103 const std::string& originator_client_item_id);
101 sync_pb::SyncEntity* AddUpdateBookmark( 104 sync_pb::SyncEntity* AddUpdateBookmark(
102 const std::string& id, 105 const std::string& id,
103 const std::string& parent_id, 106 const std::string& parent_id,
104 const std::string& name, 107 const std::string& name,
105 int64 version, 108 int64_t version,
106 int64 sync_ts, 109 int64_t sync_ts,
107 const std::string& originator_cache_guid, 110 const std::string& originator_cache_guid,
108 const std::string& originator_client_item_id); 111 const std::string& originator_client_item_id);
109 // Versions of the AddUpdate function that accept specifics. 112 // Versions of the AddUpdate function that accept specifics.
110 sync_pb::SyncEntity* AddUpdateSpecifics( 113 sync_pb::SyncEntity* AddUpdateSpecifics(
111 int id, 114 int id,
112 int parent_id, 115 int parent_id,
113 const std::string& name, 116 const std::string& name,
114 int64 version, 117 int64_t version,
115 int64 sync_ts, 118 int64_t sync_ts,
116 bool is_dir, 119 bool is_dir,
117 int64 position, 120 int64_t position,
118 const sync_pb::EntitySpecifics& specifics); 121 const sync_pb::EntitySpecifics& specifics);
119 sync_pb::SyncEntity* AddUpdateSpecifics( 122 sync_pb::SyncEntity* AddUpdateSpecifics(
120 int id, 123 int id,
121 int parent_id, 124 int parent_id,
122 const std::string& name, 125 const std::string& name,
123 int64 version, 126 int64_t version,
124 int64 sync_ts, 127 int64_t sync_ts,
125 bool is_dir, 128 bool is_dir,
126 int64 position, 129 int64_t position,
127 const sync_pb::EntitySpecifics& specifics, 130 const sync_pb::EntitySpecifics& specifics,
128 const std::string& originator_cache_guid, 131 const std::string& originator_cache_guid,
129 const std::string& originator_client_item_id); 132 const std::string& originator_client_item_id);
130 sync_pb::SyncEntity* SetNigori( 133 sync_pb::SyncEntity* SetNigori(int id,
131 int id, 134 int64_t version,
132 int64 version, 135 int64_t sync_ts,
133 int64 sync_ts, 136 const sync_pb::EntitySpecifics& specifics);
134 const sync_pb::EntitySpecifics& specifics);
135 // Unique client tag variant for adding items. 137 // Unique client tag variant for adding items.
136 sync_pb::SyncEntity* AddUpdatePref(const std::string& id, 138 sync_pb::SyncEntity* AddUpdatePref(const std::string& id,
137 const std::string& parent_id, 139 const std::string& parent_id,
138 const std::string& client_tag, 140 const std::string& client_tag,
139 int64 version, 141 int64_t version,
140 int64 sync_ts); 142 int64_t sync_ts);
141 143
142 // Find the last commit sent by the client, and replay it for the next get 144 // Find the last commit sent by the client, and replay it for the next get
143 // updates command. This can be used to simulate the GetUpdates that happens 145 // updates command. This can be used to simulate the GetUpdates that happens
144 // immediately after a successful commit. 146 // immediately after a successful commit.
145 sync_pb::SyncEntity* AddUpdateFromLastCommit(); 147 sync_pb::SyncEntity* AddUpdateFromLastCommit();
146 148
147 // Add a deleted item. Deletion records typically contain no 149 // Add a deleted item. Deletion records typically contain no
148 // additional information beyond the deletion, and no specifics. 150 // additional information beyond the deletion, and no specifics.
149 // The server may send the originator fields. 151 // The server may send the originator fields.
150 void AddUpdateTombstone(const syncable::Id& id, ModelType type); 152 void AddUpdateTombstone(const syncable::Id& id, ModelType type);
151 153
152 void SetLastUpdateDeleted(); 154 void SetLastUpdateDeleted();
153 void SetLastUpdateServerTag(const std::string& tag); 155 void SetLastUpdateServerTag(const std::string& tag);
154 void SetLastUpdateClientTag(const std::string& tag); 156 void SetLastUpdateClientTag(const std::string& tag);
155 void SetLastUpdateOriginatorFields(const std::string& client_id, 157 void SetLastUpdateOriginatorFields(const std::string& client_id,
156 const std::string& entry_id); 158 const std::string& entry_id);
157 void SetLastUpdatePosition(int64 position_in_parent); 159 void SetLastUpdatePosition(int64_t position_in_parent);
158 void SetNewTimestamp(int ts); 160 void SetNewTimestamp(int ts);
159 void SetChangesRemaining(int64 count); 161 void SetChangesRemaining(int64_t count);
160 162
161 // Add a new batch of updates after the current one. Allows multiple 163 // Add a new batch of updates after the current one. Allows multiple
162 // GetUpdates responses to be buffered up, since the syncer may 164 // GetUpdates responses to be buffered up, since the syncer may
163 // issue multiple requests during a sync cycle. 165 // issue multiple requests during a sync cycle.
164 void NextUpdateBatch(); 166 void NextUpdateBatch();
165 167
166 void FailNextPostBufferToPathCall() { countdown_to_postbuffer_fail_ = 1; } 168 void FailNextPostBufferToPathCall() { countdown_to_postbuffer_fail_ = 1; }
167 void FailNthPostBufferToPathCall(int n) { countdown_to_postbuffer_fail_ = n; } 169 void FailNthPostBufferToPathCall(int n) { countdown_to_postbuffer_fail_ = n; }
168 170
169 void SetKeystoreKey(const std::string& key); 171 void SetKeystoreKey(const std::string& key);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // Locate the most recent update message for purpose of alteration. 270 // Locate the most recent update message for purpose of alteration.
269 sync_pb::SyncEntity* GetMutableLastUpdate(); 271 sync_pb::SyncEntity* GetMutableLastUpdate();
270 272
271 // Adds a new progress marker to the last update. 273 // Adds a new progress marker to the last update.
272 sync_pb::DataTypeProgressMarker* AddUpdateProgressMarker(); 274 sync_pb::DataTypeProgressMarker* AddUpdateProgressMarker();
273 275
274 private: 276 private:
275 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, 277 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id,
276 syncable::Id parentid, 278 syncable::Id parentid,
277 const std::string& name, 279 const std::string& name,
278 int64 version, 280 int64_t version,
279 int64 sync_ts, 281 int64_t sync_ts,
280 bool is_dir); 282 bool is_dir);
281 sync_pb::SyncEntity* AddUpdateFull(const std::string& id, 283 sync_pb::SyncEntity* AddUpdateFull(const std::string& id,
282 const std::string& parentid, 284 const std::string& parentid,
283 const std::string& name, 285 const std::string& name,
284 int64 version, 286 int64_t version,
285 int64 sync_ts, 287 int64_t sync_ts,
286 bool is_dir); 288 bool is_dir);
287 sync_pb::SyncEntity* AddUpdateMeta(const std::string& id, 289 sync_pb::SyncEntity* AddUpdateMeta(const std::string& id,
288 const std::string& parentid, 290 const std::string& parentid,
289 const std::string& name, 291 const std::string& name,
290 int64 version, 292 int64_t version,
291 int64 sync_ts); 293 int64_t sync_ts);
292 294
293 // Functions to handle the various types of server request. 295 // Functions to handle the various types of server request.
294 void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm, 296 void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm,
295 sync_pb::ClientToServerResponse* response); 297 sync_pb::ClientToServerResponse* response);
296 void ProcessCommit(sync_pb::ClientToServerMessage* csm, 298 void ProcessCommit(sync_pb::ClientToServerMessage* csm,
297 sync_pb::ClientToServerResponse* response_buffer); 299 sync_pb::ClientToServerResponse* response_buffer);
298 void ProcessClearServerData(sync_pb::ClientToServerMessage* csm, 300 void ProcessClearServerData(sync_pb::ClientToServerMessage* csm,
299 sync_pb::ClientToServerResponse* response); 301 sync_pb::ClientToServerResponse* response);
300 void AddDefaultBookmarkData(sync_pb::SyncEntity* entity, bool is_folder); 302 void AddDefaultBookmarkData(sync_pb::SyncEntity* entity, bool is_folder);
301 303
302 // Determine if one entry in a commit should be rejected with a conflict. 304 // Determine if one entry in a commit should be rejected with a conflict.
303 bool ShouldConflictThisCommit(); 305 bool ShouldConflictThisCommit();
304 306
305 // Determine if the given item's commit request should be refused with 307 // Determine if the given item's commit request should be refused with
306 // a TRANSIENT_ERROR response. 308 // a TRANSIENT_ERROR response.
307 bool ShouldTransientErrorThisId(syncable::Id id); 309 bool ShouldTransientErrorThisId(syncable::Id id);
308 310
309 // Generate a numeric position_in_parent value. We use a global counter 311 // Generate a numeric position_in_parent value. We use a global counter
310 // that only decreases; this simulates new objects always being added to the 312 // that only decreases; this simulates new objects always being added to the
311 // front of the ordering. 313 // front of the ordering.
312 int64 GeneratePositionInParent() { 314 int64_t GeneratePositionInParent() { return next_position_in_parent_--; }
313 return next_position_in_parent_--;
314 }
315 315
316 // Get a mutable update response which will eventually be returned to the 316 // Get a mutable update response which will eventually be returned to the
317 // client. 317 // client.
318 sync_pb::GetUpdatesResponse* GetUpdateResponse(); 318 sync_pb::GetUpdatesResponse* GetUpdateResponse();
319 void ApplyToken(); 319 void ApplyToken();
320 320
321 // Determine whether an progress marker array (like that sent in 321 // Determine whether an progress marker array (like that sent in
322 // GetUpdates.from_progress_marker) indicates that a particular ModelType 322 // GetUpdates.from_progress_marker) indicates that a particular ModelType
323 // should be included. 323 // should be included.
324 bool IsModelTypePresentInSpecifics( 324 bool IsModelTypePresentInSpecifics(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 391
392 base::Lock response_code_override_lock_; 392 base::Lock response_code_override_lock_;
393 393
394 // True if we are only accepting GetUpdatesCallerInfo::PERIODIC requests. 394 // True if we are only accepting GetUpdatesCallerInfo::PERIODIC requests.
395 bool fail_non_periodic_get_updates_; 395 bool fail_non_periodic_get_updates_;
396 396
397 scoped_ptr<sync_pb::ClientCommand> gu_client_command_; 397 scoped_ptr<sync_pb::ClientCommand> gu_client_command_;
398 scoped_ptr<sync_pb::ClientCommand> commit_client_command_; 398 scoped_ptr<sync_pb::ClientCommand> commit_client_command_;
399 399
400 // The next value to use for the position_in_parent property. 400 // The next value to use for the position_in_parent property.
401 int64 next_position_in_parent_; 401 int64_t next_position_in_parent_;
402 402
403 // The default is to use the newer sync_pb::BookmarkSpecifics-style protocol. 403 // The default is to use the newer sync_pb::BookmarkSpecifics-style protocol.
404 // If this option is set to true, then the MockConnectionManager will 404 // If this option is set to true, then the MockConnectionManager will
405 // use the older sync_pb::SyncEntity_BookmarkData-style protocol. 405 // use the older sync_pb::SyncEntity_BookmarkData-style protocol.
406 bool use_legacy_bookmarks_protocol_; 406 bool use_legacy_bookmarks_protocol_;
407 407
408 ModelTypeSet expected_filter_; 408 ModelTypeSet expected_filter_;
409 409
410 ModelTypeSet throttled_type_; 410 ModelTypeSet throttled_type_;
411 411
412 int num_get_updates_requests_; 412 int num_get_updates_requests_;
413 413
414 std::string next_token_; 414 std::string next_token_;
415 415
416 std::vector<sync_pb::ClientToServerMessage> requests_; 416 std::vector<sync_pb::ClientToServerMessage> requests_;
417 417
418 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); 418 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager);
419 }; 419 };
420 420
421 } // namespace syncer 421 } // namespace syncer
422 422
423 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 423 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
OLDNEW
« no previous file with comments | « sync/test/engine/mock_commit_queue.cc ('k') | sync/test/engine/mock_connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698