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

Side by Side Diff: components/sync_driver/generic_change_processor_unittest.cc

Issue 982883002: [Sync] Add size and crc32c to AttachmentId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix argument evaluation order bug. Created 5 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "components/sync_driver/generic_change_processor.h" 5 #include "components/sync_driver/generic_change_processor.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // AttachmentService. 367 // AttachmentService.
368 TEST_F(SyncGenericChangeProcessorTest, 368 TEST_F(SyncGenericChangeProcessorTest,
369 ProcessSyncChanges_AddUpdateWithAttachment) { 369 ProcessSyncChanges_AddUpdateWithAttachment) {
370 std::string tag = "client_tag"; 370 std::string tag = "client_tag";
371 std::string title = "client_title"; 371 std::string title = "client_title";
372 sync_pb::EntitySpecifics specifics; 372 sync_pb::EntitySpecifics specifics;
373 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); 373 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference();
374 pref_specifics->set_name("test"); 374 pref_specifics->set_name("test");
375 375
376 syncer::AttachmentIdList attachment_ids; 376 syncer::AttachmentIdList attachment_ids;
377 attachment_ids.push_back(syncer::AttachmentId::Create()); 377 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0));
378 attachment_ids.push_back(syncer::AttachmentId::Create()); 378 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0));
379 379
380 // Add a SyncData with two attachments. 380 // Add a SyncData with two attachments.
381 syncer::SyncChangeList change_list; 381 syncer::SyncChangeList change_list;
382 change_list.push_back( 382 change_list.push_back(
383 syncer::SyncChange(FROM_HERE, 383 syncer::SyncChange(FROM_HERE,
384 syncer::SyncChange::ACTION_ADD, 384 syncer::SyncChange::ACTION_ADD,
385 syncer::SyncData::CreateLocalDataWithAttachments( 385 syncer::SyncData::CreateLocalDataWithAttachments(
386 tag, title, specifics, attachment_ids))); 386 tag, title, specifics, attachment_ids)));
387 ASSERT_FALSE( 387 ASSERT_FALSE(
388 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); 388 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
389 RunLoop(); 389 RunLoop();
390 390
391 // Check that the AttachmentService received the new attachments. 391 // Check that the AttachmentService received the new attachments.
392 ASSERT_EQ(mock_attachment_service()->attachment_id_sets()->size(), 1U); 392 ASSERT_EQ(mock_attachment_service()->attachment_id_sets()->size(), 1U);
393 const syncer::AttachmentIdSet& attachments_added = 393 const syncer::AttachmentIdSet& attachments_added =
394 mock_attachment_service()->attachment_id_sets()->front(); 394 mock_attachment_service()->attachment_id_sets()->front();
395 ASSERT_THAT( 395 ASSERT_THAT(
396 attachments_added, 396 attachments_added,
397 testing::UnorderedElementsAre(attachment_ids[0], attachment_ids[1])); 397 testing::UnorderedElementsAre(attachment_ids[0], attachment_ids[1]));
398 398
399 // Update the SyncData, replacing its two attachments with one new attachment. 399 // Update the SyncData, replacing its two attachments with one new attachment.
400 syncer::AttachmentIdList new_attachment_ids; 400 syncer::AttachmentIdList new_attachment_ids;
401 new_attachment_ids.push_back(syncer::AttachmentId::Create()); 401 new_attachment_ids.push_back(syncer::AttachmentId::Create(0, 0));
402 mock_attachment_service()->attachment_id_sets()->clear(); 402 mock_attachment_service()->attachment_id_sets()->clear();
403 change_list.clear(); 403 change_list.clear();
404 change_list.push_back( 404 change_list.push_back(
405 syncer::SyncChange(FROM_HERE, 405 syncer::SyncChange(FROM_HERE,
406 syncer::SyncChange::ACTION_UPDATE, 406 syncer::SyncChange::ACTION_UPDATE,
407 syncer::SyncData::CreateLocalDataWithAttachments( 407 syncer::SyncData::CreateLocalDataWithAttachments(
408 tag, title, specifics, new_attachment_ids))); 408 tag, title, specifics, new_attachment_ids)));
409 ASSERT_FALSE( 409 ASSERT_FALSE(
410 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); 410 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
411 RunLoop(); 411 RunLoop();
412 412
413 // Check that the AttachmentService received it. 413 // Check that the AttachmentService received it.
414 ASSERT_EQ(mock_attachment_service()->attachment_id_sets()->size(), 1U); 414 ASSERT_EQ(mock_attachment_service()->attachment_id_sets()->size(), 1U);
415 const syncer::AttachmentIdSet& new_attachments_added = 415 const syncer::AttachmentIdSet& new_attachments_added =
416 mock_attachment_service()->attachment_id_sets()->front(); 416 mock_attachment_service()->attachment_id_sets()->front();
417 ASSERT_THAT(new_attachments_added, 417 ASSERT_THAT(new_attachments_added,
418 testing::UnorderedElementsAre(new_attachment_ids[0])); 418 testing::UnorderedElementsAre(new_attachment_ids[0]));
419 } 419 }
420 420
421 // Verify that after attachment is uploaded GenericChangeProcessor updates 421 // Verify that after attachment is uploaded GenericChangeProcessor updates
422 // corresponding entries 422 // corresponding entries
423 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) { 423 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) {
424 std::string tag = "client_tag"; 424 std::string tag = "client_tag";
425 std::string title = "client_title"; 425 std::string title = "client_title";
426 sync_pb::EntitySpecifics specifics; 426 sync_pb::EntitySpecifics specifics;
427 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); 427 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference();
428 pref_specifics->set_name("test"); 428 pref_specifics->set_name("test");
429 429
430 syncer::AttachmentIdList attachment_ids; 430 syncer::AttachmentIdList attachment_ids;
431 attachment_ids.push_back(syncer::AttachmentId::Create()); 431 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0));
432 432
433 // Add a SyncData with two attachments. 433 // Add a SyncData with two attachments.
434 syncer::SyncChangeList change_list; 434 syncer::SyncChangeList change_list;
435 change_list.push_back( 435 change_list.push_back(
436 syncer::SyncChange(FROM_HERE, 436 syncer::SyncChange(FROM_HERE,
437 syncer::SyncChange::ACTION_ADD, 437 syncer::SyncChange::ACTION_ADD,
438 syncer::SyncData::CreateLocalDataWithAttachments( 438 syncer::SyncData::CreateLocalDataWithAttachments(
439 tag, title, specifics, attachment_ids))); 439 tag, title, specifics, attachment_ids)));
440 ASSERT_FALSE( 440 ASSERT_FALSE(
441 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); 441 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
442 442
443 sync_pb::AttachmentIdProto attachment_id_proto = attachment_ids[0].GetProto(); 443 sync_pb::AttachmentIdProto attachment_id_proto = attachment_ids[0].GetProto();
444 syncer::AttachmentId attachment_id = 444 syncer::AttachmentId attachment_id =
445 syncer::AttachmentId::CreateFromProto(attachment_id_proto); 445 syncer::AttachmentId::CreateFromProto(attachment_id_proto);
446 446
447 change_processor()->OnAttachmentUploaded(attachment_id); 447 change_processor()->OnAttachmentUploaded(attachment_id);
448 syncer::ReadTransaction read_transaction(FROM_HERE, user_share()); 448 syncer::ReadTransaction read_transaction(FROM_HERE, user_share());
449 syncer::ReadNode node(&read_transaction); 449 syncer::ReadNode node(&read_transaction);
450 ASSERT_EQ(node.InitByClientTagLookup(kType, tag), syncer::BaseNode::INIT_OK); 450 ASSERT_EQ(node.InitByClientTagLookup(kType, tag), syncer::BaseNode::INIT_OK);
451 attachment_ids = node.GetAttachmentIds(); 451 attachment_ids = node.GetAttachmentIds();
452 EXPECT_EQ(1U, attachment_ids.size()); 452 EXPECT_EQ(1U, attachment_ids.size());
453 } 453 }
454 454
455 // Verify that upon construction, all attachments not yet on the server are 455 // Verify that upon construction, all attachments not yet on the server are
456 // scheduled for upload. 456 // scheduled for upload.
457 TEST_F(SyncGenericChangeProcessorTest, UploadAllAttachmentsNotOnServer) { 457 TEST_F(SyncGenericChangeProcessorTest, UploadAllAttachmentsNotOnServer) {
458 // Create two attachment ids. id2 will be marked as "on server". 458 // Create two attachment ids. id2 will be marked as "on server".
459 syncer::AttachmentId id1 = syncer::AttachmentId::Create(); 459 syncer::AttachmentId id1 = syncer::AttachmentId::Create(0, 0);
460 syncer::AttachmentId id2 = syncer::AttachmentId::Create(); 460 syncer::AttachmentId id2 = syncer::AttachmentId::Create(0, 0);
461 { 461 {
462 // Write an entry containing these two attachment ids. 462 // Write an entry containing these two attachment ids.
463 syncer::WriteTransaction trans(FROM_HERE, user_share()); 463 syncer::WriteTransaction trans(FROM_HERE, user_share());
464 syncer::ReadNode root(&trans); 464 syncer::ReadNode root(&trans);
465 ASSERT_EQ(syncer::BaseNode::INIT_OK, root.InitTypeRoot(kType)); 465 ASSERT_EQ(syncer::BaseNode::INIT_OK, root.InitTypeRoot(kType));
466 syncer::WriteNode node(&trans); 466 syncer::WriteNode node(&trans);
467 node.InitUniqueByCreation(kType, root, "some node"); 467 node.InitUniqueByCreation(kType, root, "some node");
468 sync_pb::AttachmentMetadata metadata; 468 sync_pb::AttachmentMetadata metadata;
469 sync_pb::AttachmentMetadataRecord* record1 = metadata.add_record(); 469 sync_pb::AttachmentMetadataRecord* record1 = metadata.add_record();
470 *record1->mutable_id() = id1.GetProto(); 470 *record1->mutable_id() = id1.GetProto();
471 sync_pb::AttachmentMetadataRecord* record2 = metadata.add_record(); 471 sync_pb::AttachmentMetadataRecord* record2 = metadata.add_record();
472 *record2->mutable_id() = id2.GetProto(); 472 *record2->mutable_id() = id2.GetProto();
473 record2->set_is_on_server(true); 473 record2->set_is_on_server(true);
474 node.SetAttachmentMetadata(metadata); 474 node.SetAttachmentMetadata(metadata);
475 } 475 }
476 476
477 // Construct the GenericChangeProcessor and see that it asks the 477 // Construct the GenericChangeProcessor and see that it asks the
478 // AttachmentService to upload id1 only. 478 // AttachmentService to upload id1 only.
479 ConstructGenericChangeProcessor(kType); 479 ConstructGenericChangeProcessor(kType);
480 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_sets()->size()); 480 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_sets()->size());
481 ASSERT_THAT(mock_attachment_service()->attachment_id_sets()->front(), 481 ASSERT_THAT(mock_attachment_service()->attachment_id_sets()->front(),
482 testing::UnorderedElementsAre(id1)); 482 testing::UnorderedElementsAre(id1));
483 } 483 }
484 484
485 } // namespace 485 } // namespace
486 486
487 } // namespace sync_driver 487 } // namespace sync_driver
OLDNEW
« no previous file with comments | « no previous file | sync/api/attachments/attachment.h » ('j') | sync/api/attachments/attachment_metadata_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698