| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "components/sync/api/attachments/attachment_id.h" | 14 #include "components/sync/api/attachments/attachment_id.h" |
| 15 #include "components/sync/api/attachments/attachment_service.h" |
| 15 #include "components/sync/api/data_type_error_handler_mock.h" | 16 #include "components/sync/api/data_type_error_handler_mock.h" |
| 16 #include "components/sync/api/fake_syncable_service.h" | 17 #include "components/sync/api/fake_syncable_service.h" |
| 17 #include "components/sync/api/sync_change.h" | 18 #include "components/sync/api/sync_change.h" |
| 18 #include "components/sync/base/model_type.h" | 19 #include "components/sync/base/model_type.h" |
| 19 #include "components/sync/core/attachments/attachment_service_impl.h" | |
| 20 #include "components/sync/core/attachments/fake_attachment_downloader.h" | |
| 21 #include "components/sync/core/attachments/fake_attachment_uploader.h" | |
| 22 #include "components/sync/core/read_node.h" | 20 #include "components/sync/core/read_node.h" |
| 23 #include "components/sync/core/read_transaction.h" | 21 #include "components/sync/core/read_transaction.h" |
| 24 #include "components/sync/core/sync_encryption_handler.h" | 22 #include "components/sync/core/sync_encryption_handler.h" |
| 25 #include "components/sync/core/test/test_user_share.h" | 23 #include "components/sync/core/test/test_user_share.h" |
| 26 #include "components/sync/core/user_share.h" | 24 #include "components/sync/core/user_share.h" |
| 27 #include "components/sync/core/write_node.h" | 25 #include "components/sync/core/write_node.h" |
| 28 #include "components/sync/core/write_transaction.h" | 26 #include "components/sync/core/write_transaction.h" |
| 29 #include "components/sync/device_info/local_device_info_provider.h" | 27 #include "components/sync/device_info/local_device_info_provider.h" |
| 30 #include "components/sync/driver/fake_sync_client.h" | 28 #include "components/sync/driver/fake_sync_client.h" |
| 31 #include "components/sync/driver/sync_api_component_factory.h" | 29 #include "components/sync/driver/sync_api_component_factory.h" |
| 30 #include "components/sync/engine/attachments/fake_attachment_downloader.h" |
| 31 #include "components/sync/engine/attachments/fake_attachment_uploader.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 34 |
| 35 namespace syncer { | 35 namespace syncer { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // A mock that keeps track of attachments passed to UploadAttachments. | 39 // A mock that keeps track of attachments passed to UploadAttachments. |
| 40 class MockAttachmentService : public AttachmentServiceImpl { | 40 class MockAttachmentService : public AttachmentService { |
| 41 public: | 41 public: |
| 42 MockAttachmentService( | 42 MockAttachmentService() {} |
| 43 std::unique_ptr<AttachmentStoreForSync> attachment_store); | 43 ~MockAttachmentService() override {} |
| 44 ~MockAttachmentService() override; | 44 |
| 45 void UploadAttachments(const AttachmentIdList& attachment_ids) override; | 45 void GetOrDownloadAttachments( |
| 46 std::vector<AttachmentIdList>* attachment_id_lists(); | 46 const AttachmentIdList& attachment_ids, |
| 47 const GetOrDownloadCallback& callback) override {} |
| 48 |
| 49 void UploadAttachments(const AttachmentIdList& attachment_ids) override { |
| 50 attachment_id_lists_.push_back(attachment_ids); |
| 51 } |
| 52 |
| 53 std::vector<AttachmentIdList>* attachment_id_lists() { |
| 54 return &attachment_id_lists_; |
| 55 } |
| 47 | 56 |
| 48 private: | 57 private: |
| 49 std::vector<AttachmentIdList> attachment_id_lists_; | 58 std::vector<AttachmentIdList> attachment_id_lists_; |
| 50 }; | 59 }; |
| 51 | 60 |
| 52 MockAttachmentService::MockAttachmentService( | |
| 53 std::unique_ptr<AttachmentStoreForSync> attachment_store) | |
| 54 : AttachmentServiceImpl( | |
| 55 std::move(attachment_store), | |
| 56 std::unique_ptr<AttachmentUploader>(new FakeAttachmentUploader), | |
| 57 std::unique_ptr<AttachmentDownloader>(new FakeAttachmentDownloader), | |
| 58 NULL, | |
| 59 base::TimeDelta(), | |
| 60 base::TimeDelta()) {} | |
| 61 | |
| 62 MockAttachmentService::~MockAttachmentService() {} | |
| 63 | |
| 64 void MockAttachmentService::UploadAttachments( | |
| 65 const AttachmentIdList& attachment_ids) { | |
| 66 attachment_id_lists_.push_back(attachment_ids); | |
| 67 AttachmentServiceImpl::UploadAttachments(attachment_ids); | |
| 68 } | |
| 69 | |
| 70 std::vector<AttachmentIdList>* MockAttachmentService::attachment_id_lists() { | |
| 71 return &attachment_id_lists_; | |
| 72 } | |
| 73 | |
| 74 // MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and | 61 // MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and |
| 75 // pass MockAttachmentService to it. | 62 // pass MockAttachmentService to it. |
| 76 class MockSyncApiComponentFactory : public SyncApiComponentFactory { | 63 class MockSyncApiComponentFactory : public SyncApiComponentFactory { |
| 77 public: | 64 public: |
| 78 MockSyncApiComponentFactory() {} | 65 MockSyncApiComponentFactory() {} |
| 79 | 66 |
| 80 // SyncApiComponentFactory implementation. | 67 // SyncApiComponentFactory implementation. |
| 81 void RegisterDataTypes( | 68 void RegisterDataTypes( |
| 82 SyncService* sync_service, | 69 SyncService* sync_service, |
| 83 const RegisterDataTypesMethod& register_platform_types_method) override {} | 70 const RegisterDataTypesMethod& register_platform_types_method) override {} |
| (...skipping 21 matching lines...) Expand all Loading... |
| 105 std::unique_ptr<DataTypeErrorHandler> error_handler) override { | 92 std::unique_ptr<DataTypeErrorHandler> error_handler) override { |
| 106 return SyncComponents(nullptr, nullptr); | 93 return SyncComponents(nullptr, nullptr); |
| 107 } | 94 } |
| 108 | 95 |
| 109 std::unique_ptr<AttachmentService> CreateAttachmentService( | 96 std::unique_ptr<AttachmentService> CreateAttachmentService( |
| 110 std::unique_ptr<AttachmentStoreForSync> attachment_store, | 97 std::unique_ptr<AttachmentStoreForSync> attachment_store, |
| 111 const UserShare& user_share, | 98 const UserShare& user_share, |
| 112 const std::string& store_birthday, | 99 const std::string& store_birthday, |
| 113 ModelType model_type, | 100 ModelType model_type, |
| 114 AttachmentService::Delegate* delegate) override { | 101 AttachmentService::Delegate* delegate) override { |
| 115 std::unique_ptr<MockAttachmentService> attachment_service( | 102 auto attachment_service = base::MakeUnique<MockAttachmentService>(); |
| 116 new MockAttachmentService(std::move(attachment_store))); | |
| 117 // GenericChangeProcessor takes ownership of the AttachmentService, but we | 103 // GenericChangeProcessor takes ownership of the AttachmentService, but we |
| 118 // need to have a pointer to it so we can see that it was used properly. | 104 // need to have a pointer to it so we can see that it was used properly. |
| 119 // Take a pointer and trust that GenericChangeProcessor does not prematurely | 105 // Take a pointer and trust that GenericChangeProcessor does not prematurely |
| 120 // destroy it. | 106 // destroy it. |
| 121 mock_attachment_service_ = attachment_service.get(); | 107 mock_attachment_service_ = attachment_service.get(); |
| 122 return std::move(attachment_service); | 108 return std::move(attachment_service); |
| 123 } | 109 } |
| 124 | 110 |
| 125 MockAttachmentService* GetMockAttachmentService() { | 111 MockAttachmentService* GetMockAttachmentService() { |
| 126 return mock_attachment_service_; | 112 return mock_attachment_service_; |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 SyncDataList sync_data = change_processor()->GetAllSyncData(SESSIONS); | 500 SyncDataList sync_data = change_processor()->GetAllSyncData(SESSIONS); |
| 515 ASSERT_EQ(sync_data.size(), 1U); | 501 ASSERT_EQ(sync_data.size(), 1U); |
| 516 ASSERT_EQ("session tag 2", | 502 ASSERT_EQ("session tag 2", |
| 517 sync_data[0].GetSpecifics().session().session_tag()); | 503 sync_data[0].GetSpecifics().session().session_tag()); |
| 518 EXPECT_FALSE(SyncDataRemote(sync_data[0]).GetClientTagHash().empty()); | 504 EXPECT_FALSE(SyncDataRemote(sync_data[0]).GetClientTagHash().empty()); |
| 519 } | 505 } |
| 520 | 506 |
| 521 } // namespace | 507 } // namespace |
| 522 | 508 |
| 523 } // namespace syncer | 509 } // namespace syncer |
| OLD | NEW |