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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 namespace sync_driver { | 32 namespace sync_driver { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 const char kTestData[] = "some data"; | 36 const char kTestData[] = "some data"; |
37 | 37 |
38 // A mock that keeps track of attachments passed to UploadAttachments. | 38 // A mock that keeps track of attachments passed to UploadAttachments. |
39 class MockAttachmentService : public syncer::AttachmentServiceImpl { | 39 class MockAttachmentService : public syncer::AttachmentServiceImpl { |
40 public: | 40 public: |
41 MockAttachmentService(); | 41 MockAttachmentService( |
| 42 const scoped_refptr<syncer::AttachmentStore>& attachment_store); |
42 virtual ~MockAttachmentService(); | 43 virtual ~MockAttachmentService(); |
43 virtual void UploadAttachments( | 44 virtual void UploadAttachments( |
44 const syncer::AttachmentIdSet& attachment_ids) OVERRIDE; | 45 const syncer::AttachmentIdSet& attachment_ids) OVERRIDE; |
45 std::vector<syncer::AttachmentIdSet>* attachment_id_sets(); | 46 std::vector<syncer::AttachmentIdSet>* attachment_id_sets(); |
46 | 47 |
47 private: | 48 private: |
48 std::vector<syncer::AttachmentIdSet> attachment_id_sets_; | 49 std::vector<syncer::AttachmentIdSet> attachment_id_sets_; |
49 }; | 50 }; |
50 | 51 |
51 MockAttachmentService::MockAttachmentService() | 52 MockAttachmentService::MockAttachmentService( |
52 : AttachmentServiceImpl( | 53 const scoped_refptr<syncer::AttachmentStore>& attachment_store) |
53 scoped_ptr<syncer::AttachmentStore>(new syncer::FakeAttachmentStore( | 54 : AttachmentServiceImpl(attachment_store, |
54 base::MessageLoopProxy::current())), | 55 scoped_ptr<syncer::AttachmentUploader>( |
55 scoped_ptr<syncer::AttachmentUploader>( | 56 new syncer::FakeAttachmentUploader), |
56 new syncer::FakeAttachmentUploader), | 57 scoped_ptr<syncer::AttachmentDownloader>( |
57 scoped_ptr<syncer::AttachmentDownloader>( | 58 new syncer::FakeAttachmentDownloader), |
58 new syncer::FakeAttachmentDownloader), | 59 NULL) { |
59 NULL) { | |
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::AttachmentIdSet& attachment_ids) { |
67 attachment_id_sets_.push_back(attachment_ids); | 67 attachment_id_sets_.push_back(attachment_ids); |
68 AttachmentServiceImpl::UploadAttachments(attachment_ids); | 68 AttachmentServiceImpl::UploadAttachments(attachment_ids); |
69 } | 69 } |
(...skipping 12 matching lines...) Expand all Loading... |
82 : attachment_service_(attachment_service.Pass()) {} | 82 : attachment_service_(attachment_service.Pass()) {} |
83 | 83 |
84 virtual base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( | 84 virtual base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( |
85 syncer::ModelType type) OVERRIDE { | 85 syncer::ModelType type) OVERRIDE { |
86 // Shouldn't be called for this test. | 86 // Shouldn't be called for this test. |
87 NOTREACHED(); | 87 NOTREACHED(); |
88 return base::WeakPtr<syncer::SyncableService>(); | 88 return base::WeakPtr<syncer::SyncableService>(); |
89 } | 89 } |
90 | 90 |
91 virtual scoped_ptr<syncer::AttachmentService> CreateAttachmentService( | 91 virtual scoped_ptr<syncer::AttachmentService> CreateAttachmentService( |
| 92 const scoped_refptr<syncer::AttachmentStore>& attachment_store, |
92 const syncer::UserShare& user_share, | 93 const syncer::UserShare& user_share, |
93 syncer::AttachmentService::Delegate* delegate) OVERRIDE { | 94 syncer::AttachmentService::Delegate* delegate) OVERRIDE { |
94 EXPECT_TRUE(attachment_service_ != NULL); | 95 EXPECT_TRUE(attachment_service_ != NULL); |
95 return attachment_service_.Pass(); | 96 return attachment_service_.Pass(); |
96 } | 97 } |
97 | 98 |
98 private: | 99 private: |
99 scoped_ptr<syncer::AttachmentService> attachment_service_; | 100 scoped_ptr<syncer::AttachmentService> attachment_service_; |
100 }; | 101 }; |
101 | 102 |
(...skipping 10 matching lines...) Expand all Loading... |
112 | 113 |
113 virtual void SetUp() OVERRIDE { | 114 virtual void SetUp() OVERRIDE { |
114 test_user_share_.SetUp(); | 115 test_user_share_.SetUp(); |
115 syncer::ModelTypeSet types = syncer::ProtocolTypes(); | 116 syncer::ModelTypeSet types = syncer::ProtocolTypes(); |
116 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good(); | 117 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good(); |
117 iter.Inc()) { | 118 iter.Inc()) { |
118 syncer::TestUserShare::CreateRoot(iter.Get(), | 119 syncer::TestUserShare::CreateRoot(iter.Get(), |
119 test_user_share_.user_share()); | 120 test_user_share_.user_share()); |
120 } | 121 } |
121 test_user_share_.encryption_handler()->Init(); | 122 test_user_share_.encryption_handler()->Init(); |
| 123 scoped_refptr<syncer::AttachmentStore> attachment_store( |
| 124 new syncer::FakeAttachmentStore(base::MessageLoopProxy::current())); |
| 125 |
122 scoped_ptr<MockAttachmentService> mock_attachment_service( | 126 scoped_ptr<MockAttachmentService> mock_attachment_service( |
123 new MockAttachmentService); | 127 new MockAttachmentService(attachment_store)); |
124 // GenericChangeProcessor takes ownership of the AttachmentService, but we | 128 // GenericChangeProcessor takes ownership of the AttachmentService, but we |
125 // need to have a pointer to it so we can see that it was used properly. | 129 // need to have a pointer to it so we can see that it was used properly. |
126 // Take a pointer and trust that GenericChangeProcessor does not prematurely | 130 // Take a pointer and trust that GenericChangeProcessor does not prematurely |
127 // destroy it. | 131 // destroy it. |
128 mock_attachment_service_ = mock_attachment_service.get(); | 132 mock_attachment_service_ = mock_attachment_service.get(); |
129 sync_factory_.reset(new MockSyncApiComponentFactory( | 133 sync_factory_.reset(new MockSyncApiComponentFactory( |
130 mock_attachment_service.PassAs<syncer::AttachmentService>())); | 134 mock_attachment_service.PassAs<syncer::AttachmentService>())); |
131 change_processor_.reset( | 135 change_processor_.reset( |
132 new GenericChangeProcessor(&data_type_error_handler_, | 136 new GenericChangeProcessor(&data_type_error_handler_, |
133 syncable_service_ptr_factory_.GetWeakPtr(), | 137 syncable_service_ptr_factory_.GetWeakPtr(), |
134 merge_result_ptr_factory_.GetWeakPtr(), | 138 merge_result_ptr_factory_.GetWeakPtr(), |
135 test_user_share_.user_share(), | 139 test_user_share_.user_share(), |
136 sync_factory_.get())); | 140 sync_factory_.get(), |
| 141 attachment_store)); |
137 } | 142 } |
138 | 143 |
139 virtual void TearDown() OVERRIDE { | 144 virtual void TearDown() OVERRIDE { |
140 mock_attachment_service_ = NULL; | 145 mock_attachment_service_ = NULL; |
141 test_user_share_.TearDown(); | 146 test_user_share_.TearDown(); |
142 } | 147 } |
143 | 148 |
144 void BuildChildNodes(int n) { | 149 void BuildChildNodes(int n) { |
145 syncer::WriteTransaction trans(FROM_HERE, user_share()); | 150 syncer::WriteTransaction trans(FROM_HERE, user_share()); |
146 syncer::ReadNode root(&trans); | 151 syncer::ReadNode root(&trans); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 syncer::ReadNode node(&read_transaction); | 427 syncer::ReadNode node(&read_transaction); |
423 ASSERT_EQ(node.InitByClientTagLookup(syncer::PREFERENCES, tag), | 428 ASSERT_EQ(node.InitByClientTagLookup(syncer::PREFERENCES, tag), |
424 syncer::BaseNode::INIT_OK); | 429 syncer::BaseNode::INIT_OK); |
425 syncer::AttachmentIdList attachment_ids = node.GetAttachmentIds(); | 430 syncer::AttachmentIdList attachment_ids = node.GetAttachmentIds(); |
426 EXPECT_EQ(1U, attachment_ids.size()); | 431 EXPECT_EQ(1U, attachment_ids.size()); |
427 } | 432 } |
428 | 433 |
429 } // namespace | 434 } // namespace |
430 | 435 |
431 } // namespace sync_driver | 436 } // namespace sync_driver |
OLD | NEW |