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 19 matching lines...) Expand all Loading... |
30 #include "testing/gmock/include/gmock/gmock-matchers.h" | 30 #include "testing/gmock/include/gmock/gmock-matchers.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
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( |
| 41 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store); |
41 ~MockAttachmentService() override; | 42 ~MockAttachmentService() override; |
42 void UploadAttachments( | 43 void UploadAttachments( |
43 const syncer::AttachmentIdList& attachment_ids) override; | 44 const syncer::AttachmentIdList& attachment_ids) override; |
44 std::vector<syncer::AttachmentIdList>* attachment_id_lists(); | 45 std::vector<syncer::AttachmentIdList>* attachment_id_lists(); |
45 | 46 |
46 private: | 47 private: |
47 std::vector<syncer::AttachmentIdList> attachment_id_lists_; | 48 std::vector<syncer::AttachmentIdList> attachment_id_lists_; |
48 }; | 49 }; |
49 | 50 |
50 MockAttachmentService::MockAttachmentService( | 51 MockAttachmentService::MockAttachmentService( |
51 scoped_ptr<syncer::AttachmentStore> attachment_store) | 52 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store) |
52 : AttachmentServiceImpl(attachment_store.Pass(), | 53 : AttachmentServiceImpl(attachment_store.Pass(), |
53 scoped_ptr<syncer::AttachmentUploader>( | 54 scoped_ptr<syncer::AttachmentUploader>( |
54 new syncer::FakeAttachmentUploader), | 55 new syncer::FakeAttachmentUploader), |
55 scoped_ptr<syncer::AttachmentDownloader>( | 56 scoped_ptr<syncer::AttachmentDownloader>( |
56 new syncer::FakeAttachmentDownloader), | 57 new syncer::FakeAttachmentDownloader), |
57 NULL, | 58 NULL, |
58 base::TimeDelta(), | 59 base::TimeDelta(), |
59 base::TimeDelta()) { | 60 base::TimeDelta()) { |
60 } | 61 } |
61 | 62 |
(...skipping 18 matching lines...) Expand all Loading... |
80 MockSyncApiComponentFactory() {} | 81 MockSyncApiComponentFactory() {} |
81 | 82 |
82 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( | 83 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( |
83 syncer::ModelType type) override { | 84 syncer::ModelType type) override { |
84 // Shouldn't be called for this test. | 85 // Shouldn't be called for this test. |
85 NOTREACHED(); | 86 NOTREACHED(); |
86 return base::WeakPtr<syncer::SyncableService>(); | 87 return base::WeakPtr<syncer::SyncableService>(); |
87 } | 88 } |
88 | 89 |
89 scoped_ptr<syncer::AttachmentService> CreateAttachmentService( | 90 scoped_ptr<syncer::AttachmentService> CreateAttachmentService( |
90 scoped_ptr<syncer::AttachmentStore> attachment_store, | 91 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store, |
91 const syncer::UserShare& user_share, | 92 const syncer::UserShare& user_share, |
92 const std::string& store_birthday, | 93 const std::string& store_birthday, |
93 syncer::ModelType model_type, | 94 syncer::ModelType model_type, |
94 syncer::AttachmentService::Delegate* delegate) override { | 95 syncer::AttachmentService::Delegate* delegate) override { |
95 scoped_ptr<MockAttachmentService> attachment_service( | 96 scoped_ptr<MockAttachmentService> attachment_service( |
96 new MockAttachmentService(attachment_store.Pass())); | 97 new MockAttachmentService(attachment_store.Pass())); |
97 // GenericChangeProcessor takes ownership of the AttachmentService, but we | 98 // GenericChangeProcessor takes ownership of the AttachmentService, but we |
98 // need to have a pointer to it so we can see that it was used properly. | 99 // need to have a pointer to it so we can see that it was used properly. |
99 // Take a pointer and trust that GenericChangeProcessor does not prematurely | 100 // Take a pointer and trust that GenericChangeProcessor does not prematurely |
100 // destroy it. | 101 // destroy it. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 157 } |
157 | 158 |
158 void ConstructGenericChangeProcessor(syncer::ModelType type) { | 159 void ConstructGenericChangeProcessor(syncer::ModelType type) { |
159 MockSyncApiComponentFactory sync_factory; | 160 MockSyncApiComponentFactory sync_factory; |
160 scoped_ptr<syncer::AttachmentStore> attachment_store = | 161 scoped_ptr<syncer::AttachmentStore> attachment_store = |
161 syncer::AttachmentStore::CreateInMemoryStore(); | 162 syncer::AttachmentStore::CreateInMemoryStore(); |
162 change_processor_.reset(new GenericChangeProcessor( | 163 change_processor_.reset(new GenericChangeProcessor( |
163 type, &data_type_error_handler_, | 164 type, &data_type_error_handler_, |
164 syncable_service_ptr_factory_.GetWeakPtr(), | 165 syncable_service_ptr_factory_.GetWeakPtr(), |
165 merge_result_ptr_factory_->GetWeakPtr(), test_user_share_->user_share(), | 166 merge_result_ptr_factory_->GetWeakPtr(), test_user_share_->user_share(), |
166 &sync_factory, attachment_store.Pass())); | 167 &sync_factory, attachment_store->CreateAttachmentStoreForSync())); |
167 mock_attachment_service_ = sync_factory.GetMockAttachmentService(); | 168 mock_attachment_service_ = sync_factory.GetMockAttachmentService(); |
168 } | 169 } |
169 | 170 |
170 void BuildChildNodes(syncer::ModelType type, int n) { | 171 void BuildChildNodes(syncer::ModelType type, int n) { |
171 syncer::WriteTransaction trans(FROM_HERE, user_share()); | 172 syncer::WriteTransaction trans(FROM_HERE, user_share()); |
172 syncer::ReadNode root(&trans); | 173 syncer::ReadNode root(&trans); |
173 ASSERT_EQ(syncer::BaseNode::INIT_OK, root.InitTypeRoot(type)); | 174 ASSERT_EQ(syncer::BaseNode::INIT_OK, root.InitTypeRoot(type)); |
174 for (int i = 0; i < n; ++i) { | 175 for (int i = 0; i < n; ++i) { |
175 syncer::WriteNode node(&trans); | 176 syncer::WriteNode node(&trans); |
176 node.InitUniqueByCreation(type, root, base::StringPrintf("node%05d", i)); | 177 node.InitUniqueByCreation(type, root, base::StringPrintf("node%05d", i)); |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 // AttachmentService to upload id1 only. | 475 // AttachmentService to upload id1 only. |
475 ConstructGenericChangeProcessor(kType); | 476 ConstructGenericChangeProcessor(kType); |
476 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_lists()->size()); | 477 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_lists()->size()); |
477 ASSERT_THAT(mock_attachment_service()->attachment_id_lists()->front(), | 478 ASSERT_THAT(mock_attachment_service()->attachment_id_lists()->front(), |
478 testing::UnorderedElementsAre(id1)); | 479 testing::UnorderedElementsAre(id1)); |
479 } | 480 } |
480 | 481 |
481 } // namespace | 482 } // namespace |
482 | 483 |
483 } // namespace sync_driver | 484 } // namespace sync_driver |
OLD | NEW |