| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 namespace sync_driver { | 33 namespace sync_driver { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // A mock that keeps track of attachments passed to UploadAttachments. | 37 // A mock that keeps track of attachments passed to UploadAttachments. |
| 38 class MockAttachmentService : public syncer::AttachmentServiceImpl { | 38 class MockAttachmentService : public syncer::AttachmentServiceImpl { |
| 39 public: | 39 public: |
| 40 MockAttachmentService(scoped_ptr<syncer::AttachmentStore> attachment_store); | 40 MockAttachmentService(scoped_ptr<syncer::AttachmentStore> attachment_store); |
| 41 ~MockAttachmentService() override; | 41 ~MockAttachmentService() override; |
| 42 void UploadAttachments( | 42 void UploadAttachments( |
| 43 const syncer::AttachmentIdSet& attachment_ids) override; | 43 const syncer::AttachmentIdList& attachment_ids) override; |
| 44 std::vector<syncer::AttachmentIdSet>* attachment_id_sets(); | 44 std::vector<syncer::AttachmentIdList>* attachment_id_lists(); |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 std::vector<syncer::AttachmentIdSet> attachment_id_sets_; | 47 std::vector<syncer::AttachmentIdList> attachment_id_lists_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 MockAttachmentService::MockAttachmentService( | 50 MockAttachmentService::MockAttachmentService( |
| 51 scoped_ptr<syncer::AttachmentStore> attachment_store) | 51 scoped_ptr<syncer::AttachmentStore> attachment_store) |
| 52 : AttachmentServiceImpl(attachment_store.Pass(), | 52 : AttachmentServiceImpl(attachment_store.Pass(), |
| 53 scoped_ptr<syncer::AttachmentUploader>( | 53 scoped_ptr<syncer::AttachmentUploader>( |
| 54 new syncer::FakeAttachmentUploader), | 54 new syncer::FakeAttachmentUploader), |
| 55 scoped_ptr<syncer::AttachmentDownloader>( | 55 scoped_ptr<syncer::AttachmentDownloader>( |
| 56 new syncer::FakeAttachmentDownloader), | 56 new syncer::FakeAttachmentDownloader), |
| 57 NULL, | 57 NULL, |
| 58 base::TimeDelta(), | 58 base::TimeDelta(), |
| 59 base::TimeDelta()) { | 59 base::TimeDelta()) { |
| 60 } | 60 } |
| 61 | 61 |
| 62 MockAttachmentService::~MockAttachmentService() { | 62 MockAttachmentService::~MockAttachmentService() { |
| 63 } | 63 } |
| 64 | 64 |
| 65 void MockAttachmentService::UploadAttachments( | 65 void MockAttachmentService::UploadAttachments( |
| 66 const syncer::AttachmentIdSet& attachment_ids) { | 66 const syncer::AttachmentIdList& attachment_ids) { |
| 67 attachment_id_sets_.push_back(attachment_ids); | 67 attachment_id_lists_.push_back(attachment_ids); |
| 68 AttachmentServiceImpl::UploadAttachments(attachment_ids); | 68 AttachmentServiceImpl::UploadAttachments(attachment_ids); |
| 69 } | 69 } |
| 70 | 70 |
| 71 std::vector<syncer::AttachmentIdSet>* | 71 std::vector<syncer::AttachmentIdList>* |
| 72 MockAttachmentService::attachment_id_sets() { | 72 MockAttachmentService::attachment_id_lists() { |
| 73 return &attachment_id_sets_; | 73 return &attachment_id_lists_; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and | 76 // MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and |
| 77 // pass MockAttachmentService to it. | 77 // pass MockAttachmentService to it. |
| 78 class MockSyncApiComponentFactory : public SyncApiComponentFactory { | 78 class MockSyncApiComponentFactory : public SyncApiComponentFactory { |
| 79 public: | 79 public: |
| 80 MockSyncApiComponentFactory() {} | 80 MockSyncApiComponentFactory() {} |
| 81 | 81 |
| 82 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( | 82 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( |
| 83 syncer::ModelType type) override { | 83 syncer::ModelType type) override { |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 change_list.push_back( | 378 change_list.push_back( |
| 379 syncer::SyncChange(FROM_HERE, | 379 syncer::SyncChange(FROM_HERE, |
| 380 syncer::SyncChange::ACTION_ADD, | 380 syncer::SyncChange::ACTION_ADD, |
| 381 syncer::SyncData::CreateLocalDataWithAttachments( | 381 syncer::SyncData::CreateLocalDataWithAttachments( |
| 382 tag, title, specifics, attachment_ids))); | 382 tag, title, specifics, attachment_ids))); |
| 383 ASSERT_FALSE( | 383 ASSERT_FALSE( |
| 384 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 384 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
| 385 RunLoop(); | 385 RunLoop(); |
| 386 | 386 |
| 387 // Check that the AttachmentService received the new attachments. | 387 // Check that the AttachmentService received the new attachments. |
| 388 ASSERT_EQ(mock_attachment_service()->attachment_id_sets()->size(), 1U); | 388 ASSERT_EQ(mock_attachment_service()->attachment_id_lists()->size(), 1U); |
| 389 const syncer::AttachmentIdSet& attachments_added = | 389 const syncer::AttachmentIdList& attachments_added = |
| 390 mock_attachment_service()->attachment_id_sets()->front(); | 390 mock_attachment_service()->attachment_id_lists()->front(); |
| 391 ASSERT_THAT( | 391 ASSERT_THAT( |
| 392 attachments_added, | 392 attachments_added, |
| 393 testing::UnorderedElementsAre(attachment_ids[0], attachment_ids[1])); | 393 testing::UnorderedElementsAre(attachment_ids[0], attachment_ids[1])); |
| 394 | 394 |
| 395 // Update the SyncData, replacing its two attachments with one new attachment. | 395 // Update the SyncData, replacing its two attachments with one new attachment. |
| 396 syncer::AttachmentIdList new_attachment_ids; | 396 syncer::AttachmentIdList new_attachment_ids; |
| 397 new_attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); | 397 new_attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); |
| 398 mock_attachment_service()->attachment_id_sets()->clear(); | 398 mock_attachment_service()->attachment_id_lists()->clear(); |
| 399 change_list.clear(); | 399 change_list.clear(); |
| 400 change_list.push_back( | 400 change_list.push_back( |
| 401 syncer::SyncChange(FROM_HERE, | 401 syncer::SyncChange(FROM_HERE, |
| 402 syncer::SyncChange::ACTION_UPDATE, | 402 syncer::SyncChange::ACTION_UPDATE, |
| 403 syncer::SyncData::CreateLocalDataWithAttachments( | 403 syncer::SyncData::CreateLocalDataWithAttachments( |
| 404 tag, title, specifics, new_attachment_ids))); | 404 tag, title, specifics, new_attachment_ids))); |
| 405 ASSERT_FALSE( | 405 ASSERT_FALSE( |
| 406 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 406 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
| 407 RunLoop(); | 407 RunLoop(); |
| 408 | 408 |
| 409 // Check that the AttachmentService received it. | 409 // Check that the AttachmentService received it. |
| 410 ASSERT_EQ(mock_attachment_service()->attachment_id_sets()->size(), 1U); | 410 ASSERT_EQ(mock_attachment_service()->attachment_id_lists()->size(), 1U); |
| 411 const syncer::AttachmentIdSet& new_attachments_added = | 411 const syncer::AttachmentIdList& new_attachments_added = |
| 412 mock_attachment_service()->attachment_id_sets()->front(); | 412 mock_attachment_service()->attachment_id_lists()->front(); |
| 413 ASSERT_THAT(new_attachments_added, | 413 ASSERT_THAT(new_attachments_added, |
| 414 testing::UnorderedElementsAre(new_attachment_ids[0])); | 414 testing::UnorderedElementsAre(new_attachment_ids[0])); |
| 415 } | 415 } |
| 416 | 416 |
| 417 // Verify that after attachment is uploaded GenericChangeProcessor updates | 417 // Verify that after attachment is uploaded GenericChangeProcessor updates |
| 418 // corresponding entries | 418 // corresponding entries |
| 419 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) { | 419 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) { |
| 420 std::string tag = "client_tag"; | 420 std::string tag = "client_tag"; |
| 421 std::string title = "client_title"; | 421 std::string title = "client_title"; |
| 422 sync_pb::EntitySpecifics specifics; | 422 sync_pb::EntitySpecifics specifics; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 *record1->mutable_id() = id1.GetProto(); | 466 *record1->mutable_id() = id1.GetProto(); |
| 467 sync_pb::AttachmentMetadataRecord* record2 = metadata.add_record(); | 467 sync_pb::AttachmentMetadataRecord* record2 = metadata.add_record(); |
| 468 *record2->mutable_id() = id2.GetProto(); | 468 *record2->mutable_id() = id2.GetProto(); |
| 469 record2->set_is_on_server(true); | 469 record2->set_is_on_server(true); |
| 470 node.SetAttachmentMetadata(metadata); | 470 node.SetAttachmentMetadata(metadata); |
| 471 } | 471 } |
| 472 | 472 |
| 473 // Construct the GenericChangeProcessor and see that it asks the | 473 // Construct the GenericChangeProcessor and see that it asks the |
| 474 // AttachmentService to upload id1 only. | 474 // AttachmentService to upload id1 only. |
| 475 ConstructGenericChangeProcessor(kType); | 475 ConstructGenericChangeProcessor(kType); |
| 476 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_sets()->size()); | 476 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_lists()->size()); |
| 477 ASSERT_THAT(mock_attachment_service()->attachment_id_sets()->front(), | 477 ASSERT_THAT(mock_attachment_service()->attachment_id_lists()->front(), |
| 478 testing::UnorderedElementsAre(id1)); | 478 testing::UnorderedElementsAre(id1)); |
| 479 } | 479 } |
| 480 | 480 |
| 481 } // namespace | 481 } // namespace |
| 482 | 482 |
| 483 } // namespace sync_driver | 483 } // namespace sync_driver |
| OLD | NEW |