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

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

Issue 2844037: Fix handling of undeletion within the syncer. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Whitespace. Created 10 years, 5 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 9
10 #include <bitset> 10 #include <bitset>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/scoped_vector.h"
14 #include "chrome/browser/sync/engine/net/server_connection_manager.h" 15 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
15 #include "chrome/browser/sync/protocol/sync.pb.h" 16 #include "chrome/browser/sync/protocol/sync.pb.h"
16 #include "chrome/browser/sync/syncable/directory_manager.h" 17 #include "chrome/browser/sync/syncable/directory_manager.h"
17 #include "chrome/browser/sync/syncable/model_type.h" 18 #include "chrome/browser/sync/syncable/model_type.h"
18 #include "chrome/browser/sync/util/closure.h" 19 #include "chrome/browser/sync/util/closure.h"
19 20
20 namespace syncable { 21 namespace syncable {
21 class DirectoryManager; 22 class DirectoryManager;
22 class ScopedDirLookup; 23 class ScopedDirLookup;
23 } 24 }
(...skipping 26 matching lines...) Expand all
50 void SetMidCommitObserver(MidCommitObserver* observer); 51 void SetMidCommitObserver(MidCommitObserver* observer);
51 52
52 // 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
53 // that the client renames all commited entries, prepending this string. 54 // that the client renames all commited entries, prepending this string.
54 void SetCommitTimeRename(string prepend); 55 void SetCommitTimeRename(string prepend);
55 56
56 // Control of get updates response. All updates set will only be returned 57 // Control of get updates response. All updates set will only be returned
57 // once. This mock object doesn't simulate a changelist, it simulates server 58 // once. This mock object doesn't simulate a changelist, it simulates server
58 // responses. 59 // responses.
59 void ResetUpdates(); 60 void ResetUpdates();
61
60 // Generic versions of AddUpdate functions. Tests using these function should 62 // Generic versions of AddUpdate functions. Tests using these function should
61 // 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.
62 // The SyncEntity returned is only valid until the Sync is completed 64 // The SyncEntity returned is only valid until the Sync is completed
63 // (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
64 // sync, using SetLastXXX() methods and/or GetMutableLastUpdate(). 66 // sync, using SetLastXXX() methods and/or GetMutableLastUpdate().
65 sync_pb::SyncEntity* AddUpdateDirectory(syncable::Id id, 67 sync_pb::SyncEntity* AddUpdateDirectory(syncable::Id id,
66 syncable::Id parent_id, 68 syncable::Id parent_id,
67 string name, 69 string name,
68 int64 version, 70 int64 version,
69 int64 sync_ts); 71 int64 sync_ts);
(...skipping 17 matching lines...) Expand all
87 sync_pb::SyncEntity* AddUpdateDirectory(string id, 89 sync_pb::SyncEntity* AddUpdateDirectory(string id,
88 string parent_id, 90 string parent_id,
89 string name, 91 string name,
90 int64 version, 92 int64 version,
91 int64 sync_ts); 93 int64 sync_ts);
92 sync_pb::SyncEntity* AddUpdateBookmark(string id, 94 sync_pb::SyncEntity* AddUpdateBookmark(string id,
93 string parent_id, 95 string parent_id,
94 string name, 96 string name,
95 int64 version, 97 int64 version,
96 int64 sync_ts); 98 int64 sync_ts);
99
100 // Find the last commit sent by the client, and replay it for the next get
101 // updates command. This can be used to simulate the GetUpdates that happens
102 // immediately after a successful commit.
103 sync_pb::SyncEntity* AddUpdateFromLastCommit();
104
105 // Add a deleted item. Deletion records typically contain no
106 // additional information beyond the deletion, and no specifics.
107 // The server may send the originator fields.
108 void AddUpdateTombstone(const syncable::Id& id);
109
97 void SetLastUpdateDeleted(); 110 void SetLastUpdateDeleted();
98 void SetLastUpdateServerTag(const string& tag); 111 void SetLastUpdateServerTag(const string& tag);
99 void SetLastUpdateClientTag(const string& tag); 112 void SetLastUpdateClientTag(const string& tag);
100 void SetLastUpdateOriginatorFields(const string& client_id, 113 void SetLastUpdateOriginatorFields(const string& client_id,
101 const string& entry_id); 114 const string& entry_id);
102 void SetLastUpdatePosition(int64 position_in_parent); 115 void SetLastUpdatePosition(int64 position_in_parent);
103 void SetNewTimestamp(int64 ts); 116 void SetNewTimestamp(int64 ts);
104 void SetChangesRemaining(int64 timestamp); 117 void SetChangesRemaining(int64 timestamp);
105 118
106 // For AUTHENTICATE responses. 119 // For AUTHENTICATE responses.
(...skipping 20 matching lines...) Expand all
127 140
128 // Simple inspectors. 141 // Simple inspectors.
129 bool client_stuck() const { return client_stuck_; } 142 bool client_stuck() const { return client_stuck_; }
130 143
131 sync_pb::ClientCommand* GetNextClientCommand(); 144 sync_pb::ClientCommand* GetNextClientCommand();
132 145
133 const std::vector<syncable::Id>& committed_ids() const { 146 const std::vector<syncable::Id>& committed_ids() const {
134 return committed_ids_; 147 return committed_ids_;
135 } 148 }
136 const std::vector<sync_pb::CommitMessage*>& commit_messages() const { 149 const std::vector<sync_pb::CommitMessage*>& commit_messages() const {
137 return commit_messages_; 150 return commit_messages_.get();
151 }
152 const std::vector<sync_pb::CommitResponse*>& commit_responses() const {
153 return commit_responses_.get();
138 } 154 }
139 // Retrieve the last sent commit message. 155 // Retrieve the last sent commit message.
140 const sync_pb::CommitMessage& last_sent_commit() const; 156 const sync_pb::CommitMessage& last_sent_commit() const;
141 157
158 // Retrieve the last returned commit response.
159 const sync_pb::CommitResponse& last_commit_response() const;
160
142 // Retrieve the last request submitted to the server (regardless of type). 161 // Retrieve the last request submitted to the server (regardless of type).
143 const sync_pb::ClientToServerMessage& last_request() const { 162 const sync_pb::ClientToServerMessage& last_request() const {
144 return last_request_; 163 return last_request_;
145 } 164 }
146 165
147 void set_conflict_all_commits(bool value) { 166 void set_conflict_all_commits(bool value) {
148 conflict_all_commits_ = value; 167 conflict_all_commits_ = value;
149 } 168 }
150 void set_next_new_id(int value) { 169 void set_next_new_id(int value) {
151 next_new_id_ = value; 170 next_new_id_ = value;
(...skipping 20 matching lines...) Expand all
172 // the bitset. 191 // the bitset.
173 void ExpectGetUpdatesRequestTypes( 192 void ExpectGetUpdatesRequestTypes(
174 std::bitset<syncable::MODEL_TYPE_COUNT> expected_filter) { 193 std::bitset<syncable::MODEL_TYPE_COUNT> expected_filter) {
175 expected_filter_ = expected_filter; 194 expected_filter_ = expected_filter;
176 } 195 }
177 196
178 void SetServerReachable(); 197 void SetServerReachable();
179 198
180 void SetServerNotReachable(); 199 void SetServerNotReachable();
181 200
201 std::string store_birthday() { return store_birthday_; }
202
203 // Locate the most recent update message for purpose of alteration.
204 sync_pb::SyncEntity* GetMutableLastUpdate();
205
182 private: 206 private:
183 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid, 207 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid,
184 string name, int64 version, 208 string name, int64 version,
185 int64 sync_ts, 209 int64 sync_ts,
186 bool is_dir); 210 bool is_dir);
187 sync_pb::SyncEntity* AddUpdateFull(string id, string parentid, string name, 211 sync_pb::SyncEntity* AddUpdateFull(string id, string parentid, string name,
188 int64 version, int64 sync_ts, 212 int64 version, int64 sync_ts,
189 bool is_dir); 213 bool is_dir);
190 // Functions to handle the various types of server request. 214 // Functions to handle the various types of server request.
191 void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm, 215 void ProcessGetUpdates(sync_pb::ClientToServerMessage* csm,
192 sync_pb::ClientToServerResponse* response); 216 sync_pb::ClientToServerResponse* response);
193 void ProcessAuthenticate(sync_pb::ClientToServerMessage* csm, 217 void ProcessAuthenticate(sync_pb::ClientToServerMessage* csm,
194 sync_pb::ClientToServerResponse* response, 218 sync_pb::ClientToServerResponse* response,
195 const std::string& auth_token); 219 const std::string& auth_token);
196 void ProcessCommit(sync_pb::ClientToServerMessage* csm, 220 void ProcessCommit(sync_pb::ClientToServerMessage* csm,
197 sync_pb::ClientToServerResponse* response_buffer); 221 sync_pb::ClientToServerResponse* response_buffer);
198 222
199 void AddDefaultBookmarkData(sync_pb::SyncEntity* entity, bool is_folder); 223 void AddDefaultBookmarkData(sync_pb::SyncEntity* entity, bool is_folder);
200 224
201 // Locate the most recent update message for purpose of alteration.
202 sync_pb::SyncEntity* GetMutableLastUpdate();
203
204 // Determine if one entry in a commit should be rejected with a conflict. 225 // Determine if one entry in a commit should be rejected with a conflict.
205 bool ShouldConflictThisCommit(); 226 bool ShouldConflictThisCommit();
206 227
207 // Generate a numeric position_in_parent value. We use a global counter 228 // Generate a numeric position_in_parent value. We use a global counter
208 // that only decreases; this simulates new objects always being added to the 229 // that only decreases; this simulates new objects always being added to the
209 // front of the ordering. 230 // front of the ordering.
210 int64 GeneratePositionInParent() { 231 int64 GeneratePositionInParent() {
211 return next_position_in_parent_--; 232 return next_position_in_parent_--;
212 } 233 }
213 234
214 // Determine whether an EntitySpecifics filter (like that sent in 235 // Determine whether an EntitySpecifics filter (like that sent in
215 // GetUpdates.requested_types) indicates that a particular ModelType 236 // GetUpdates.requested_types) indicates that a particular ModelType
216 // should be included. 237 // should be included.
217 bool IsModelTypePresentInSpecifics(const sync_pb::EntitySpecifics& filter, 238 bool IsModelTypePresentInSpecifics(const sync_pb::EntitySpecifics& filter,
218 syncable::ModelType value); 239 syncable::ModelType value);
219 240
220 // All IDs that have been committed. 241 // All IDs that have been committed.
221 std::vector<syncable::Id> committed_ids_; 242 std::vector<syncable::Id> committed_ids_;
222 243
223 // Control of when/if we return conflicts. 244 // Control of when/if we return conflicts.
224 bool conflict_all_commits_; 245 bool conflict_all_commits_;
225 int conflict_n_commits_; 246 int conflict_n_commits_;
226 247
227 // Commit messages we've sent 248 // Commit messages we've sent, and responses we've returned.
228 std::vector<sync_pb::CommitMessage*> commit_messages_; 249 ScopedVector<sync_pb::CommitMessage> commit_messages_;
250 ScopedVector<sync_pb::CommitResponse> commit_responses_;
229 251
230 // The next id the mock will return to a commit. 252 // The next id the mock will return to a commit.
231 int next_new_id_; 253 int next_new_id_;
232 254
233 // The store birthday we send to the client. 255 // The store birthday we send to the client.
234 string store_birthday_; 256 string store_birthday_;
235 bool store_birthday_sent_; 257 bool store_birthday_sent_;
236 bool client_stuck_; 258 bool client_stuck_;
237 string commit_time_rename_prepended_string_; 259 string commit_time_rename_prepended_string_;
238 260
239 // Fail on the next call to PostBufferToPath(). 261 // Fail on the next call to PostBufferToPath().
240 bool fail_next_postbuffer_; 262 bool fail_next_postbuffer_;
241 263
242 // Our directory. 264 // Our directory.
243 syncable::DirectoryManager* directory_manager_; 265 syncable::DirectoryManager* directory_manager_;
244 std::string directory_name_; 266 std::string directory_name_;
245 267
246 // The updates we'll return to the next request. 268 // The updates we'll return to the next request.
247 sync_pb::GetUpdatesResponse updates_; 269 sync_pb::GetUpdatesResponse updates_;
248 Closure* mid_commit_callback_; 270 scoped_ptr<Closure> mid_commit_callback_;
249 MidCommitObserver* mid_commit_observer_; 271 MidCommitObserver* mid_commit_observer_;
250 272
251 // The AUTHENTICATE response we'll return for auth requests. 273 // The AUTHENTICATE response we'll return for auth requests.
252 sync_pb::AuthenticateResponse auth_response_; 274 sync_pb::AuthenticateResponse auth_response_;
253 // What we use to determine if we should return SUCCESS or BAD_AUTH_TOKEN. 275 // What we use to determine if we should return SUCCESS or BAD_AUTH_TOKEN.
254 std::string valid_auth_token_; 276 std::string valid_auth_token_;
255 277
256 // Whether we are faking a server mandating clients to throttle requests. 278 // Whether we are faking a server mandating clients to throttle requests.
257 // Protected by |response_code_override_lock_|. 279 // Protected by |response_code_override_lock_|.
258 bool throttling_; 280 bool throttling_;
(...skipping 21 matching lines...) Expand all
280 std::bitset<syncable::MODEL_TYPE_COUNT> expected_filter_; 302 std::bitset<syncable::MODEL_TYPE_COUNT> expected_filter_;
281 303
282 int num_get_updates_requests_; 304 int num_get_updates_requests_;
283 305
284 sync_pb::ClientToServerMessage last_request_; 306 sync_pb::ClientToServerMessage last_request_;
285 307
286 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); 308 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager);
287 }; 309 };
288 310
289 #endif // CHROME_TEST_SYNC_ENGINE_MOCK_CONNECTION_MANAGER_H_ 311 #endif // CHROME_TEST_SYNC_ENGINE_MOCK_CONNECTION_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/syncable_id.cc ('k') | chrome/test/sync/engine/mock_connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698