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

Side by Side Diff: components/sync/driver/generic_change_processor_unittest.cc

Issue 2399953002: [Sync] Move attachments code out of core/. (Closed)
Patch Set: Fix some things. Created 4 years, 2 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 <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
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 std::unique_ptr<MockAttachmentService> attachment_service(
skym 2016/10/07 18:22:16 base::MakeUnique()?
maxbogue 2016/10/07 19:21:50 Done.
116 new MockAttachmentService(std::move(attachment_store))); 103 new MockAttachmentService());
117 // GenericChangeProcessor takes ownership of the AttachmentService, but we 104 // 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. 105 // 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 106 // Take a pointer and trust that GenericChangeProcessor does not prematurely
120 // destroy it. 107 // destroy it.
121 mock_attachment_service_ = attachment_service.get(); 108 mock_attachment_service_ = attachment_service.get();
122 return std::move(attachment_service); 109 return std::move(attachment_service);
123 } 110 }
124 111
125 MockAttachmentService* GetMockAttachmentService() { 112 MockAttachmentService* GetMockAttachmentService() {
126 return mock_attachment_service_; 113 return mock_attachment_service_;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 SyncDataList sync_data = change_processor()->GetAllSyncData(SESSIONS); 501 SyncDataList sync_data = change_processor()->GetAllSyncData(SESSIONS);
515 ASSERT_EQ(sync_data.size(), 1U); 502 ASSERT_EQ(sync_data.size(), 1U);
516 ASSERT_EQ("session tag 2", 503 ASSERT_EQ("session tag 2",
517 sync_data[0].GetSpecifics().session().session_tag()); 504 sync_data[0].GetSpecifics().session().session_tag());
518 EXPECT_FALSE(SyncDataRemote(sync_data[0]).GetClientTagHash().empty()); 505 EXPECT_FALSE(SyncDataRemote(sync_data[0]).GetClientTagHash().empty());
519 } 506 }
520 507
521 } // namespace 508 } // namespace
522 509
523 } // namespace syncer 510 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698