OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 regression tests. | 5 // Mock ServerConnectionManager class for use in client regression tests. |
6 | 6 |
7 #include "sync/test/engine/mock_connection_manager.h" | 7 #include "sync/test/engine/mock_connection_manager.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 use_legacy_bookmarks_protocol_(false), | 54 use_legacy_bookmarks_protocol_(false), |
55 num_get_updates_requests_(0) { | 55 num_get_updates_requests_(0) { |
56 SetNewTimestamp(0); | 56 SetNewTimestamp(0); |
57 SetAuthToken(kValidAuthToken); | 57 SetAuthToken(kValidAuthToken); |
58 } | 58 } |
59 | 59 |
60 MockConnectionManager::~MockConnectionManager() { | 60 MockConnectionManager::~MockConnectionManager() { |
61 EXPECT_TRUE(update_queue_.empty()) << "Unfetched updates."; | 61 EXPECT_TRUE(update_queue_.empty()) << "Unfetched updates."; |
62 } | 62 } |
63 | 63 |
64 void MockConnectionManager::SetCommitTimeRename(string prepend) { | 64 void MockConnectionManager::SetCommitTimeRename(const string& prepend) { |
65 commit_time_rename_prepended_string_ = prepend; | 65 commit_time_rename_prepended_string_ = prepend; |
66 } | 66 } |
67 | 67 |
68 void MockConnectionManager::SetMidCommitCallback( | 68 void MockConnectionManager::SetMidCommitCallback( |
69 const base::Closure& callback) { | 69 const base::Closure& callback) { |
70 mid_commit_callback_ = callback; | 70 mid_commit_callback_ = callback; |
71 } | 71 } |
72 | 72 |
73 void MockConnectionManager::SetMidCommitObserver( | 73 void MockConnectionManager::SetMidCommitObserver( |
74 MockConnectionManager::MidCommitObserver* observer) { | 74 MockConnectionManager::MidCommitObserver* observer) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 if (!is_folder) { | 211 if (!is_folder) { |
212 entity->mutable_specifics()->mutable_bookmark()-> | 212 entity->mutable_specifics()->mutable_bookmark()-> |
213 set_url("http://google.com"); | 213 set_url("http://google.com"); |
214 } | 214 } |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
218 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( | 218 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( |
219 int id, | 219 int id, |
220 int parent_id, | 220 int parent_id, |
221 string name, | 221 const string& name, |
222 int64 version, | 222 int64 version, |
223 int64 sync_ts, | 223 int64 sync_ts, |
224 std::string originator_cache_guid, | 224 const std::string& originator_cache_guid, |
225 std::string originator_client_item_id) { | 225 const std::string& originator_client_item_id) { |
226 return AddUpdateDirectory(TestIdFactory::FromNumber(id), | 226 return AddUpdateDirectory(TestIdFactory::FromNumber(id), |
227 TestIdFactory::FromNumber(parent_id), | 227 TestIdFactory::FromNumber(parent_id), |
228 name, | 228 name, |
229 version, | 229 version, |
230 sync_ts, | 230 sync_ts, |
231 originator_cache_guid, | 231 originator_cache_guid, |
232 originator_client_item_id); | 232 originator_client_item_id); |
233 } | 233 } |
234 | 234 |
235 void MockConnectionManager::SetGUClientCommand( | 235 void MockConnectionManager::SetGUClientCommand( |
236 sync_pb::ClientCommand* command) { | 236 sync_pb::ClientCommand* command) { |
237 gu_client_command_.reset(command); | 237 gu_client_command_.reset(command); |
238 } | 238 } |
239 | 239 |
240 void MockConnectionManager::SetCommitClientCommand( | 240 void MockConnectionManager::SetCommitClientCommand( |
241 sync_pb::ClientCommand* command) { | 241 sync_pb::ClientCommand* command) { |
242 commit_client_command_.reset(command); | 242 commit_client_command_.reset(command); |
243 } | 243 } |
244 | 244 |
245 void MockConnectionManager::SetTransientErrorId(syncable::Id id) { | 245 void MockConnectionManager::SetTransientErrorId(syncable::Id id) { |
246 transient_error_ids_.push_back(id); | 246 transient_error_ids_.push_back(id); |
247 } | 247 } |
248 | 248 |
249 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( | 249 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( |
250 int id, int parent_id, | 250 int id, |
251 string name, int64 version, | 251 int parent_id, |
| 252 const string& name, |
| 253 int64 version, |
252 int64 sync_ts, | 254 int64 sync_ts, |
253 string originator_client_item_id, | 255 const string& originator_client_item_id, |
254 string originator_cache_guid) { | 256 const string& originator_cache_guid) { |
255 return AddUpdateBookmark(TestIdFactory::FromNumber(id), | 257 return AddUpdateBookmark(TestIdFactory::FromNumber(id), |
256 TestIdFactory::FromNumber(parent_id), | 258 TestIdFactory::FromNumber(parent_id), |
257 name, | 259 name, |
258 version, | 260 version, |
259 sync_ts, | 261 sync_ts, |
260 originator_client_item_id, | 262 originator_client_item_id, |
261 originator_cache_guid); | 263 originator_cache_guid); |
262 } | 264 } |
263 | 265 |
264 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics( | 266 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics( |
265 int id, | 267 int id, |
266 int parent_id, | 268 int parent_id, |
267 string name, | 269 const string& name, |
268 int64 version, | 270 int64 version, |
269 int64 sync_ts, | 271 int64 sync_ts, |
270 bool is_dir, | 272 bool is_dir, |
271 int64 position, | 273 int64 position, |
272 const sync_pb::EntitySpecifics& specifics) { | 274 const sync_pb::EntitySpecifics& specifics) { |
273 sync_pb::SyncEntity* ent = AddUpdateMeta( | 275 sync_pb::SyncEntity* ent = AddUpdateMeta( |
274 TestIdFactory::FromNumber(id).GetServerId(), | 276 TestIdFactory::FromNumber(id).GetServerId(), |
275 TestIdFactory::FromNumber(parent_id).GetServerId(), | 277 TestIdFactory::FromNumber(parent_id).GetServerId(), |
276 name, version, sync_ts); | 278 name, version, sync_ts); |
277 ent->set_position_in_parent(position); | 279 ent->set_position_in_parent(position); |
278 ent->mutable_specifics()->CopyFrom(specifics); | 280 ent->mutable_specifics()->CopyFrom(specifics); |
279 ent->set_folder(is_dir); | 281 ent->set_folder(is_dir); |
280 return ent; | 282 return ent; |
281 } | 283 } |
282 | 284 |
283 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics( | 285 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics( |
284 int id, | 286 int id, |
285 int parent_id, | 287 int parent_id, |
286 string name, | 288 const string& name, |
287 int64 version, | 289 int64 version, |
288 int64 sync_ts, | 290 int64 sync_ts, |
289 bool is_dir, | 291 bool is_dir, |
290 int64 position, | 292 int64 position, |
291 const sync_pb::EntitySpecifics& specifics, | 293 const sync_pb::EntitySpecifics& specifics, |
292 string originator_cache_guid, | 294 const string& originator_cache_guid, |
293 string originator_client_item_id) { | 295 const string& originator_client_item_id) { |
294 sync_pb::SyncEntity* ent = AddUpdateSpecifics( | 296 sync_pb::SyncEntity* ent = AddUpdateSpecifics( |
295 id, parent_id, name, version, sync_ts, is_dir, position, specifics); | 297 id, parent_id, name, version, sync_ts, is_dir, position, specifics); |
296 ent->set_originator_cache_guid(originator_cache_guid); | 298 ent->set_originator_cache_guid(originator_cache_guid); |
297 ent->set_originator_client_item_id(originator_client_item_id); | 299 ent->set_originator_client_item_id(originator_client_item_id); |
298 return ent; | 300 return ent; |
299 } | 301 } |
300 | 302 |
301 sync_pb::SyncEntity* MockConnectionManager::SetNigori( | 303 sync_pb::SyncEntity* MockConnectionManager::SetNigori( |
302 int id, | 304 int id, |
303 int64 version, | 305 int64 version, |
304 int64 sync_ts, | 306 int64 sync_ts, |
305 const sync_pb::EntitySpecifics& specifics) { | 307 const sync_pb::EntitySpecifics& specifics) { |
306 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); | 308 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); |
307 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId()); | 309 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId()); |
308 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId()); | 310 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId()); |
309 ent->set_server_defined_unique_tag(ModelTypeToRootTag(NIGORI)); | 311 ent->set_server_defined_unique_tag(ModelTypeToRootTag(NIGORI)); |
310 ent->set_name("Nigori"); | 312 ent->set_name("Nigori"); |
311 ent->set_non_unique_name("Nigori"); | 313 ent->set_non_unique_name("Nigori"); |
312 ent->set_version(version); | 314 ent->set_version(version); |
313 ent->set_sync_timestamp(sync_ts); | 315 ent->set_sync_timestamp(sync_ts); |
314 ent->set_mtime(sync_ts); | 316 ent->set_mtime(sync_ts); |
315 ent->set_ctime(1); | 317 ent->set_ctime(1); |
316 ent->set_position_in_parent(0); | 318 ent->set_position_in_parent(0); |
317 ent->set_folder(false); | 319 ent->set_folder(false); |
318 ent->mutable_specifics()->CopyFrom(specifics); | 320 ent->mutable_specifics()->CopyFrom(specifics); |
319 return ent; | 321 return ent; |
320 } | 322 } |
321 | 323 |
322 sync_pb::SyncEntity* MockConnectionManager::AddUpdatePref(string id, | 324 sync_pb::SyncEntity* MockConnectionManager::AddUpdatePref( |
323 string parent_id, | 325 const string& id, |
324 string client_tag, | 326 const string& parent_id, |
325 int64 version, | 327 const string& client_tag, |
326 int64 sync_ts) { | 328 int64 version, |
| 329 int64 sync_ts) { |
327 sync_pb::SyncEntity* ent = | 330 sync_pb::SyncEntity* ent = |
328 AddUpdateMeta(id, parent_id, " ", version, sync_ts); | 331 AddUpdateMeta(id, parent_id, " ", version, sync_ts); |
329 | 332 |
330 ent->set_client_defined_unique_tag(client_tag); | 333 ent->set_client_defined_unique_tag(client_tag); |
331 | 334 |
332 sync_pb::EntitySpecifics specifics; | 335 sync_pb::EntitySpecifics specifics; |
333 AddDefaultFieldValue(PREFERENCES, &specifics); | 336 AddDefaultFieldValue(PREFERENCES, &specifics); |
334 ent->mutable_specifics()->CopyFrom(specifics); | 337 ent->mutable_specifics()->CopyFrom(specifics); |
335 | 338 |
336 return ent; | 339 return ent; |
337 } | 340 } |
338 | 341 |
339 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFull( | 342 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFull( |
340 string id, string parent_id, | 343 const string& id, |
341 string name, int64 version, | 344 const string& parent_id, |
342 int64 sync_ts, bool is_dir) { | 345 const string& name, |
| 346 int64 version, |
| 347 int64 sync_ts, |
| 348 bool is_dir) { |
343 sync_pb::SyncEntity* ent = | 349 sync_pb::SyncEntity* ent = |
344 AddUpdateMeta(id, parent_id, name, version, sync_ts); | 350 AddUpdateMeta(id, parent_id, name, version, sync_ts); |
345 AddDefaultBookmarkData(ent, is_dir); | 351 AddDefaultBookmarkData(ent, is_dir); |
346 return ent; | 352 return ent; |
347 } | 353 } |
348 | 354 |
349 sync_pb::SyncEntity* MockConnectionManager::AddUpdateMeta( | 355 sync_pb::SyncEntity* MockConnectionManager::AddUpdateMeta( |
350 string id, string parent_id, | 356 const string& id, |
351 string name, int64 version, | 357 const string& parent_id, |
| 358 const string& name, |
| 359 int64 version, |
352 int64 sync_ts) { | 360 int64 sync_ts) { |
353 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); | 361 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); |
354 ent->set_id_string(id); | 362 ent->set_id_string(id); |
355 ent->set_parent_id_string(parent_id); | 363 ent->set_parent_id_string(parent_id); |
356 ent->set_non_unique_name(name); | 364 ent->set_non_unique_name(name); |
357 ent->set_name(name); | 365 ent->set_name(name); |
358 ent->set_version(version); | 366 ent->set_version(version); |
359 ent->set_sync_timestamp(sync_ts); | 367 ent->set_sync_timestamp(sync_ts); |
360 ent->set_mtime(sync_ts); | 368 ent->set_mtime(sync_ts); |
361 ent->set_ctime(1); | 369 ent->set_ctime(1); |
362 ent->set_position_in_parent(GeneratePositionInParent()); | 370 ent->set_position_in_parent(GeneratePositionInParent()); |
363 | 371 |
364 // This isn't perfect, but it works well enough. This is an update, which | 372 // This isn't perfect, but it works well enough. This is an update, which |
365 // means the ID is a server ID, which means it never changes. By making | 373 // means the ID is a server ID, which means it never changes. By making |
366 // kCacheGuid also never change, we guarantee that the same item always has | 374 // kCacheGuid also never change, we guarantee that the same item always has |
367 // the same originator_cache_guid and originator_client_item_id. | 375 // the same originator_cache_guid and originator_client_item_id. |
368 // | 376 // |
369 // Unfortunately, neither this class nor the tests that use it explicitly | 377 // Unfortunately, neither this class nor the tests that use it explicitly |
370 // track sync entitites, so supporting proper cache guids and client item IDs | 378 // track sync entitites, so supporting proper cache guids and client item IDs |
371 // would require major refactoring. The ID used here ought to be the "c-" | 379 // would require major refactoring. The ID used here ought to be the "c-" |
372 // style ID that was sent up on the commit. | 380 // style ID that was sent up on the commit. |
373 ent->set_originator_cache_guid(kCacheGuid); | 381 ent->set_originator_cache_guid(kCacheGuid); |
374 ent->set_originator_client_item_id(id); | 382 ent->set_originator_client_item_id(id); |
375 | 383 |
376 return ent; | 384 return ent; |
377 } | 385 } |
378 | 386 |
379 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( | 387 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( |
380 string id, | 388 const string& id, |
381 string parent_id, | 389 const string& parent_id, |
382 string name, | 390 const string& name, |
383 int64 version, | 391 int64 version, |
384 int64 sync_ts, | 392 int64 sync_ts, |
385 std::string originator_cache_guid, | 393 const std::string& originator_cache_guid, |
386 std::string originator_client_item_id) { | 394 const std::string& originator_client_item_id) { |
387 sync_pb::SyncEntity* ret = | 395 sync_pb::SyncEntity* ret = |
388 AddUpdateFull(id, parent_id, name, version, sync_ts, true); | 396 AddUpdateFull(id, parent_id, name, version, sync_ts, true); |
389 ret->set_originator_cache_guid(originator_cache_guid); | 397 ret->set_originator_cache_guid(originator_cache_guid); |
390 ret->set_originator_client_item_id(originator_client_item_id); | 398 ret->set_originator_client_item_id(originator_client_item_id); |
391 return ret; | 399 return ret; |
392 } | 400 } |
393 | 401 |
394 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( | 402 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( |
395 string id, | 403 const string& id, |
396 string parent_id, | 404 const string& parent_id, |
397 string name, int64 version, | 405 const string& name, |
| 406 int64 version, |
398 int64 sync_ts, | 407 int64 sync_ts, |
399 string originator_cache_guid, | 408 const string& originator_cache_guid, |
400 string originator_client_item_id) { | 409 const string& originator_client_item_id) { |
401 sync_pb::SyncEntity* ret = | 410 sync_pb::SyncEntity* ret = |
402 AddUpdateFull(id, parent_id, name, version, sync_ts, false); | 411 AddUpdateFull(id, parent_id, name, version, sync_ts, false); |
403 ret->set_originator_cache_guid(originator_cache_guid); | 412 ret->set_originator_cache_guid(originator_cache_guid); |
404 ret->set_originator_client_item_id(originator_client_item_id); | 413 ret->set_originator_client_item_id(originator_client_item_id); |
405 return ret; | 414 return ret; |
406 } | 415 } |
407 | 416 |
408 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFromLastCommit() { | 417 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFromLastCommit() { |
409 EXPECT_EQ(1, last_sent_commit().entries_size()); | 418 EXPECT_EQ(1, last_sent_commit().entries_size()); |
410 EXPECT_EQ(1, last_commit_response().entryresponse_size()); | 419 EXPECT_EQ(1, last_commit_response().entryresponse_size()); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 sync_pb::ClientToServerMessage* csm, | 662 sync_pb::ClientToServerMessage* csm, |
654 sync_pb::ClientToServerResponse* response) { | 663 sync_pb::ClientToServerResponse* response) { |
655 CHECK(csm->has_clear_server_data()); | 664 CHECK(csm->has_clear_server_data()); |
656 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::CLEAR_SERVER_DATA); | 665 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::CLEAR_SERVER_DATA); |
657 response->mutable_clear_server_data(); | 666 response->mutable_clear_server_data(); |
658 } | 667 } |
659 | 668 |
660 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( | 669 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( |
661 syncable::Id id, | 670 syncable::Id id, |
662 syncable::Id parent_id, | 671 syncable::Id parent_id, |
663 string name, | 672 const string& name, |
664 int64 version, | 673 int64 version, |
665 int64 sync_ts, | 674 int64 sync_ts, |
666 string originator_cache_guid, | 675 const string& originator_cache_guid, |
667 string originator_client_item_id) { | 676 const string& originator_client_item_id) { |
668 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(), | 677 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(), |
669 name, version, sync_ts, originator_cache_guid, | 678 name, version, sync_ts, originator_cache_guid, |
670 originator_client_item_id); | 679 originator_client_item_id); |
671 } | 680 } |
672 | 681 |
673 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( | 682 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( |
674 syncable::Id id, | 683 syncable::Id id, |
675 syncable::Id parent_id, | 684 syncable::Id parent_id, |
676 string name, | 685 const string& name, |
677 int64 version, | 686 int64 version, |
678 int64 sync_ts, | 687 int64 sync_ts, |
679 string originator_cache_guid, | 688 const string& originator_cache_guid, |
680 string originator_client_item_id) { | 689 const string& originator_client_item_id) { |
681 return AddUpdateBookmark(id.GetServerId(), parent_id.GetServerId(), | 690 return AddUpdateBookmark(id.GetServerId(), parent_id.GetServerId(), |
682 name, version, sync_ts, originator_cache_guid, | 691 name, version, sync_ts, originator_cache_guid, |
683 originator_client_item_id); | 692 originator_client_item_id); |
684 } | 693 } |
685 | 694 |
686 sync_pb::SyncEntity* MockConnectionManager::GetMutableLastUpdate() { | 695 sync_pb::SyncEntity* MockConnectionManager::GetMutableLastUpdate() { |
687 sync_pb::GetUpdatesResponse* updates = GetUpdateResponse(); | 696 sync_pb::GetUpdatesResponse* updates = GetUpdateResponse(); |
688 EXPECT_GT(updates->entries_size(), 0); | 697 EXPECT_GT(updates->entries_size(), 0); |
689 return updates->mutable_entries()->Mutable(updates->entries_size() - 1); | 698 return updates->mutable_entries()->Mutable(updates->entries_size() - 1); |
690 } | 699 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 server_status_ = HttpResponse::SERVER_CONNECTION_OK; | 767 server_status_ = HttpResponse::SERVER_CONNECTION_OK; |
759 } | 768 } |
760 } | 769 } |
761 | 770 |
762 void MockConnectionManager::SetServerStatus( | 771 void MockConnectionManager::SetServerStatus( |
763 HttpResponse::ServerConnectionCode server_status) { | 772 HttpResponse::ServerConnectionCode server_status) { |
764 server_status_ = server_status; | 773 server_status_ = server_status; |
765 } | 774 } |
766 | 775 |
767 } // namespace syncer | 776 } // namespace syncer |
OLD | NEW |