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

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

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
OLDNEW
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 <stdint.h>
10
9 #include <map> 11 #include <map>
10 12
11 #include "base/location.h" 13 #include "base/location.h"
12 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
13 #include "sync/engine/syncer_proto_util.h" 15 #include "sync/engine/syncer_proto_util.h"
14 #include "sync/protocol/bookmark_specifics.pb.h" 16 #include "sync/protocol/bookmark_specifics.pb.h"
15 #include "sync/syncable/directory.h" 17 #include "sync/syncable/directory.h"
16 #include "sync/syncable/syncable_write_transaction.h" 18 #include "sync/syncable/syncable_write_transaction.h"
17 #include "sync/test/engine/test_id_factory.h" 19 #include "sync/test/engine/test_id_factory.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 entity->mutable_specifics()->mutable_bookmark()-> 209 entity->mutable_specifics()->mutable_bookmark()->
208 set_url("http://google.com"); 210 set_url("http://google.com");
209 } 211 }
210 } 212 }
211 } 213 }
212 214
213 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( 215 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory(
214 int id, 216 int id,
215 int parent_id, 217 int parent_id,
216 const string& name, 218 const string& name,
217 int64 version, 219 int64_t version,
218 int64 sync_ts, 220 int64_t sync_ts,
219 const std::string& originator_cache_guid, 221 const std::string& originator_cache_guid,
220 const std::string& originator_client_item_id) { 222 const std::string& originator_client_item_id) {
221 return AddUpdateDirectory(TestIdFactory::FromNumber(id), 223 return AddUpdateDirectory(TestIdFactory::FromNumber(id),
222 TestIdFactory::FromNumber(parent_id), 224 TestIdFactory::FromNumber(parent_id),
223 name, 225 name,
224 version, 226 version,
225 sync_ts, 227 sync_ts,
226 originator_cache_guid, 228 originator_cache_guid,
227 originator_client_item_id); 229 originator_client_item_id);
228 } 230 }
229 231
230 void MockConnectionManager::SetGUClientCommand( 232 void MockConnectionManager::SetGUClientCommand(
231 sync_pb::ClientCommand* command) { 233 sync_pb::ClientCommand* command) {
232 gu_client_command_.reset(command); 234 gu_client_command_.reset(command);
233 } 235 }
234 236
235 void MockConnectionManager::SetCommitClientCommand( 237 void MockConnectionManager::SetCommitClientCommand(
236 sync_pb::ClientCommand* command) { 238 sync_pb::ClientCommand* command) {
237 commit_client_command_.reset(command); 239 commit_client_command_.reset(command);
238 } 240 }
239 241
240 void MockConnectionManager::SetTransientErrorId(syncable::Id id) { 242 void MockConnectionManager::SetTransientErrorId(syncable::Id id) {
241 transient_error_ids_.push_back(id); 243 transient_error_ids_.push_back(id);
242 } 244 }
243 245
244 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( 246 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark(
245 int id, 247 int id,
246 int parent_id, 248 int parent_id,
247 const string& name, 249 const string& name,
248 int64 version, 250 int64_t version,
249 int64 sync_ts, 251 int64_t sync_ts,
250 const string& originator_client_item_id, 252 const string& originator_client_item_id,
251 const string& originator_cache_guid) { 253 const string& originator_cache_guid) {
252 return AddUpdateBookmark(TestIdFactory::FromNumber(id), 254 return AddUpdateBookmark(TestIdFactory::FromNumber(id),
253 TestIdFactory::FromNumber(parent_id), 255 TestIdFactory::FromNumber(parent_id),
254 name, 256 name,
255 version, 257 version,
256 sync_ts, 258 sync_ts,
257 originator_client_item_id, 259 originator_client_item_id,
258 originator_cache_guid); 260 originator_cache_guid);
259 } 261 }
260 262
261 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics( 263 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics(
262 int id, 264 int id,
263 int parent_id, 265 int parent_id,
264 const string& name, 266 const string& name,
265 int64 version, 267 int64_t version,
266 int64 sync_ts, 268 int64_t sync_ts,
267 bool is_dir, 269 bool is_dir,
268 int64 position, 270 int64_t position,
269 const sync_pb::EntitySpecifics& specifics) { 271 const sync_pb::EntitySpecifics& specifics) {
270 sync_pb::SyncEntity* ent = AddUpdateMeta( 272 sync_pb::SyncEntity* ent = AddUpdateMeta(
271 TestIdFactory::FromNumber(id).GetServerId(), 273 TestIdFactory::FromNumber(id).GetServerId(),
272 TestIdFactory::FromNumber(parent_id).GetServerId(), 274 TestIdFactory::FromNumber(parent_id).GetServerId(),
273 name, version, sync_ts); 275 name, version, sync_ts);
274 ent->set_position_in_parent(position); 276 ent->set_position_in_parent(position);
275 ent->mutable_specifics()->CopyFrom(specifics); 277 ent->mutable_specifics()->CopyFrom(specifics);
276 ent->set_folder(is_dir); 278 ent->set_folder(is_dir);
277 return ent; 279 return ent;
278 } 280 }
279 281
280 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics( 282 sync_pb::SyncEntity* MockConnectionManager::AddUpdateSpecifics(
281 int id, 283 int id,
282 int parent_id, 284 int parent_id,
283 const string& name, 285 const 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 int64 position, 289 int64_t position,
288 const sync_pb::EntitySpecifics& specifics, 290 const sync_pb::EntitySpecifics& specifics,
289 const string& originator_cache_guid, 291 const string& originator_cache_guid,
290 const string& originator_client_item_id) { 292 const string& originator_client_item_id) {
291 sync_pb::SyncEntity* ent = AddUpdateSpecifics( 293 sync_pb::SyncEntity* ent = AddUpdateSpecifics(
292 id, parent_id, name, version, sync_ts, is_dir, position, specifics); 294 id, parent_id, name, version, sync_ts, is_dir, position, specifics);
293 ent->set_originator_cache_guid(originator_cache_guid); 295 ent->set_originator_cache_guid(originator_cache_guid);
294 ent->set_originator_client_item_id(originator_client_item_id); 296 ent->set_originator_client_item_id(originator_client_item_id);
295 return ent; 297 return ent;
296 } 298 }
297 299
298 sync_pb::SyncEntity* MockConnectionManager::SetNigori( 300 sync_pb::SyncEntity* MockConnectionManager::SetNigori(
299 int id, 301 int id,
300 int64 version, 302 int64_t version,
301 int64 sync_ts, 303 int64_t sync_ts,
302 const sync_pb::EntitySpecifics& specifics) { 304 const sync_pb::EntitySpecifics& specifics) {
303 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); 305 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
304 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId()); 306 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId());
305 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId()); 307 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId());
306 ent->set_server_defined_unique_tag(ModelTypeToRootTag(NIGORI)); 308 ent->set_server_defined_unique_tag(ModelTypeToRootTag(NIGORI));
307 ent->set_name("Nigori"); 309 ent->set_name("Nigori");
308 ent->set_non_unique_name("Nigori"); 310 ent->set_non_unique_name("Nigori");
309 ent->set_version(version); 311 ent->set_version(version);
310 ent->set_sync_timestamp(sync_ts); 312 ent->set_sync_timestamp(sync_ts);
311 ent->set_mtime(sync_ts); 313 ent->set_mtime(sync_ts);
312 ent->set_ctime(1); 314 ent->set_ctime(1);
313 ent->set_position_in_parent(0); 315 ent->set_position_in_parent(0);
314 ent->set_folder(false); 316 ent->set_folder(false);
315 ent->mutable_specifics()->CopyFrom(specifics); 317 ent->mutable_specifics()->CopyFrom(specifics);
316 return ent; 318 return ent;
317 } 319 }
318 320
319 sync_pb::SyncEntity* MockConnectionManager::AddUpdatePref( 321 sync_pb::SyncEntity* MockConnectionManager::AddUpdatePref(
320 const string& id, 322 const string& id,
321 const string& parent_id, 323 const string& parent_id,
322 const string& client_tag, 324 const string& client_tag,
323 int64 version, 325 int64_t version,
324 int64 sync_ts) { 326 int64_t sync_ts) {
325 sync_pb::SyncEntity* ent = 327 sync_pb::SyncEntity* ent =
326 AddUpdateMeta(id, parent_id, " ", version, sync_ts); 328 AddUpdateMeta(id, parent_id, " ", version, sync_ts);
327 329
328 ent->set_client_defined_unique_tag(client_tag); 330 ent->set_client_defined_unique_tag(client_tag);
329 331
330 sync_pb::EntitySpecifics specifics; 332 sync_pb::EntitySpecifics specifics;
331 AddDefaultFieldValue(PREFERENCES, &specifics); 333 AddDefaultFieldValue(PREFERENCES, &specifics);
332 ent->mutable_specifics()->CopyFrom(specifics); 334 ent->mutable_specifics()->CopyFrom(specifics);
333 335
334 return ent; 336 return ent;
335 } 337 }
336 338
337 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFull( 339 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFull(
338 const string& id, 340 const string& id,
339 const string& parent_id, 341 const string& parent_id,
340 const string& name, 342 const string& name,
341 int64 version, 343 int64_t version,
342 int64 sync_ts, 344 int64_t sync_ts,
343 bool is_dir) { 345 bool is_dir) {
344 sync_pb::SyncEntity* ent = 346 sync_pb::SyncEntity* ent =
345 AddUpdateMeta(id, parent_id, name, version, sync_ts); 347 AddUpdateMeta(id, parent_id, name, version, sync_ts);
346 AddDefaultBookmarkData(ent, is_dir); 348 AddDefaultBookmarkData(ent, is_dir);
347 return ent; 349 return ent;
348 } 350 }
349 351
350 sync_pb::SyncEntity* MockConnectionManager::AddUpdateMeta( 352 sync_pb::SyncEntity* MockConnectionManager::AddUpdateMeta(
351 const string& id, 353 const string& id,
352 const string& parent_id, 354 const string& parent_id,
353 const string& name, 355 const string& name,
354 int64 version, 356 int64_t version,
355 int64 sync_ts) { 357 int64_t sync_ts) {
356 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); 358 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
357 ent->set_id_string(id); 359 ent->set_id_string(id);
358 ent->set_parent_id_string(parent_id); 360 ent->set_parent_id_string(parent_id);
359 ent->set_non_unique_name(name); 361 ent->set_non_unique_name(name);
360 ent->set_name(name); 362 ent->set_name(name);
361 ent->set_version(version); 363 ent->set_version(version);
362 ent->set_sync_timestamp(sync_ts); 364 ent->set_sync_timestamp(sync_ts);
363 ent->set_mtime(sync_ts); 365 ent->set_mtime(sync_ts);
364 ent->set_ctime(1); 366 ent->set_ctime(1);
365 ent->set_position_in_parent(GeneratePositionInParent()); 367 ent->set_position_in_parent(GeneratePositionInParent());
(...skipping 10 matching lines...) Expand all
376 ent->set_originator_cache_guid(kCacheGuid); 378 ent->set_originator_cache_guid(kCacheGuid);
377 ent->set_originator_client_item_id(id); 379 ent->set_originator_client_item_id(id);
378 380
379 return ent; 381 return ent;
380 } 382 }
381 383
382 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( 384 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory(
383 const string& id, 385 const string& id,
384 const string& parent_id, 386 const string& parent_id,
385 const string& name, 387 const string& name,
386 int64 version, 388 int64_t version,
387 int64 sync_ts, 389 int64_t sync_ts,
388 const std::string& originator_cache_guid, 390 const std::string& originator_cache_guid,
389 const std::string& originator_client_item_id) { 391 const std::string& originator_client_item_id) {
390 sync_pb::SyncEntity* ret = 392 sync_pb::SyncEntity* ret =
391 AddUpdateFull(id, parent_id, name, version, sync_ts, true); 393 AddUpdateFull(id, parent_id, name, version, sync_ts, true);
392 ret->set_originator_cache_guid(originator_cache_guid); 394 ret->set_originator_cache_guid(originator_cache_guid);
393 ret->set_originator_client_item_id(originator_client_item_id); 395 ret->set_originator_client_item_id(originator_client_item_id);
394 return ret; 396 return ret;
395 } 397 }
396 398
397 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( 399 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark(
398 const string& id, 400 const string& id,
399 const string& parent_id, 401 const string& parent_id,
400 const string& name, 402 const string& name,
401 int64 version, 403 int64_t version,
402 int64 sync_ts, 404 int64_t sync_ts,
403 const string& originator_cache_guid, 405 const string& originator_cache_guid,
404 const string& originator_client_item_id) { 406 const string& originator_client_item_id) {
405 sync_pb::SyncEntity* ret = 407 sync_pb::SyncEntity* ret =
406 AddUpdateFull(id, parent_id, name, version, sync_ts, false); 408 AddUpdateFull(id, parent_id, name, version, sync_ts, false);
407 ret->set_originator_cache_guid(originator_cache_guid); 409 ret->set_originator_cache_guid(originator_cache_guid);
408 ret->set_originator_client_item_id(originator_client_item_id); 410 ret->set_originator_client_item_id(originator_client_item_id);
409 return ret; 411 return ret;
410 } 412 }
411 413
412 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFromLastCommit() { 414 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFromLastCommit() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 } 480 }
479 481
480 void MockConnectionManager::SetLastUpdateServerTag(const string& tag) { 482 void MockConnectionManager::SetLastUpdateServerTag(const string& tag) {
481 GetMutableLastUpdate()->set_server_defined_unique_tag(tag); 483 GetMutableLastUpdate()->set_server_defined_unique_tag(tag);
482 } 484 }
483 485
484 void MockConnectionManager::SetLastUpdateClientTag(const string& tag) { 486 void MockConnectionManager::SetLastUpdateClientTag(const string& tag) {
485 GetMutableLastUpdate()->set_client_defined_unique_tag(tag); 487 GetMutableLastUpdate()->set_client_defined_unique_tag(tag);
486 } 488 }
487 489
488 void MockConnectionManager::SetLastUpdatePosition(int64 server_position) { 490 void MockConnectionManager::SetLastUpdatePosition(int64_t server_position) {
489 GetMutableLastUpdate()->set_position_in_parent(server_position); 491 GetMutableLastUpdate()->set_position_in_parent(server_position);
490 } 492 }
491 493
492 void MockConnectionManager::SetNewTimestamp(int ts) { 494 void MockConnectionManager::SetNewTimestamp(int ts) {
493 next_token_ = base::StringPrintf("mock connection ts = %d", ts); 495 next_token_ = base::StringPrintf("mock connection ts = %d", ts);
494 ApplyToken(); 496 ApplyToken();
495 } 497 }
496 498
497 sync_pb::DataTypeProgressMarker* 499 sync_pb::DataTypeProgressMarker*
498 MockConnectionManager::AddUpdateProgressMarker() { 500 MockConnectionManager::AddUpdateProgressMarker() {
499 return GetUpdateResponse()->add_new_progress_marker(); 501 return GetUpdateResponse()->add_new_progress_marker();
500 } 502 }
501 503
502 void MockConnectionManager::ApplyToken() { 504 void MockConnectionManager::ApplyToken() {
503 if (!update_queue_.empty()) { 505 if (!update_queue_.empty()) {
504 GetUpdateResponse()->clear_new_progress_marker(); 506 GetUpdateResponse()->clear_new_progress_marker();
505 sync_pb::DataTypeProgressMarker* new_marker = AddUpdateProgressMarker(); 507 sync_pb::DataTypeProgressMarker* new_marker = AddUpdateProgressMarker();
506 new_marker->set_data_type_id(-1); // Invalid -- clients shouldn't see. 508 new_marker->set_data_type_id(-1); // Invalid -- clients shouldn't see.
507 new_marker->set_token(next_token_); 509 new_marker->set_token(next_token_);
508 } 510 }
509 } 511 }
510 512
511 void MockConnectionManager::SetChangesRemaining(int64 timestamp) { 513 void MockConnectionManager::SetChangesRemaining(int64_t timestamp) {
512 GetUpdateResponse()->set_changes_remaining(timestamp); 514 GetUpdateResponse()->set_changes_remaining(timestamp);
513 } 515 }
514 516
515 void MockConnectionManager::ProcessGetUpdates( 517 void MockConnectionManager::ProcessGetUpdates(
516 sync_pb::ClientToServerMessage* csm, 518 sync_pb::ClientToServerMessage* csm,
517 sync_pb::ClientToServerResponse* response) { 519 sync_pb::ClientToServerResponse* response) {
518 CHECK(csm->has_get_updates()); 520 CHECK(csm->has_get_updates());
519 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::GET_UPDATES); 521 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::GET_UPDATES);
520 const GetUpdatesMessage& gu = csm->get_updates(); 522 const GetUpdatesMessage& gu = csm->get_updates();
521 num_get_updates_requests_++; 523 num_get_updates_requests_++;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 sync_pb::ClientToServerResponse* response) { 664 sync_pb::ClientToServerResponse* response) {
663 CHECK(csm->has_clear_server_data()); 665 CHECK(csm->has_clear_server_data());
664 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::CLEAR_SERVER_DATA); 666 ASSERT_EQ(csm->message_contents(), ClientToServerMessage::CLEAR_SERVER_DATA);
665 response->mutable_clear_server_data(); 667 response->mutable_clear_server_data();
666 } 668 }
667 669
668 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory( 670 sync_pb::SyncEntity* MockConnectionManager::AddUpdateDirectory(
669 syncable::Id id, 671 syncable::Id id,
670 syncable::Id parent_id, 672 syncable::Id parent_id,
671 const string& name, 673 const string& name,
672 int64 version, 674 int64_t version,
673 int64 sync_ts, 675 int64_t sync_ts,
674 const string& originator_cache_guid, 676 const string& originator_cache_guid,
675 const string& originator_client_item_id) { 677 const string& originator_client_item_id) {
676 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(), 678 return AddUpdateDirectory(id.GetServerId(), parent_id.GetServerId(),
677 name, version, sync_ts, originator_cache_guid, 679 name, version, sync_ts, originator_cache_guid,
678 originator_client_item_id); 680 originator_client_item_id);
679 } 681 }
680 682
681 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark( 683 sync_pb::SyncEntity* MockConnectionManager::AddUpdateBookmark(
682 syncable::Id id, 684 syncable::Id id,
683 syncable::Id parent_id, 685 syncable::Id parent_id,
684 const string& name, 686 const string& name,
685 int64 version, 687 int64_t version,
686 int64 sync_ts, 688 int64_t sync_ts,
687 const string& originator_cache_guid, 689 const string& originator_cache_guid,
688 const string& originator_client_item_id) { 690 const string& originator_client_item_id) {
689 return AddUpdateBookmark(id.GetServerId(), parent_id.GetServerId(), 691 return AddUpdateBookmark(id.GetServerId(), parent_id.GetServerId(),
690 name, version, sync_ts, originator_cache_guid, 692 name, version, sync_ts, originator_cache_guid,
691 originator_client_item_id); 693 originator_client_item_id);
692 } 694 }
693 695
694 sync_pb::SyncEntity* MockConnectionManager::GetMutableLastUpdate() { 696 sync_pb::SyncEntity* MockConnectionManager::GetMutableLastUpdate() {
695 sync_pb::GetUpdatesResponse* updates = GetUpdateResponse(); 697 sync_pb::GetUpdatesResponse* updates = GetUpdateResponse();
696 EXPECT_GT(updates->entries_size(), 0); 698 EXPECT_GT(updates->entries_size(), 0);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 server_status_ = HttpResponse::SERVER_CONNECTION_OK; 768 server_status_ = HttpResponse::SERVER_CONNECTION_OK;
767 } 769 }
768 } 770 }
769 771
770 void MockConnectionManager::SetServerStatus( 772 void MockConnectionManager::SetServerStatus(
771 HttpResponse::ServerConnectionCode server_status) { 773 HttpResponse::ServerConnectionCode server_status) {
772 server_status_ = server_status; 774 server_status_ = server_status;
773 } 775 }
774 776
775 } // namespace syncer 777 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/test/engine/mock_connection_manager.h ('k') | sync/test/engine/mock_model_type_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698