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" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "components/sync_driver/data_type_error_handler_mock.h" | 12 #include "components/sync_driver/data_type_error_handler_mock.h" |
13 #include "components/sync_driver/sync_api_component_factory.h" | 13 #include "components/sync_driver/sync_api_component_factory.h" |
| 14 #include "sync/api/attachments/attachment_id.h" |
14 #include "sync/api/attachments/fake_attachment_store.h" | 15 #include "sync/api/attachments/fake_attachment_store.h" |
15 #include "sync/api/fake_syncable_service.h" | 16 #include "sync/api/fake_syncable_service.h" |
16 #include "sync/api/sync_change.h" | 17 #include "sync/api/sync_change.h" |
17 #include "sync/api/sync_merge_result.h" | 18 #include "sync/api/sync_merge_result.h" |
18 #include "sync/internal_api/public/attachments/attachment_service_impl.h" | 19 #include "sync/internal_api/public/attachments/attachment_service_impl.h" |
19 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" | 20 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" |
20 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" | 21 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" |
21 #include "sync/internal_api/public/base/model_type.h" | 22 #include "sync/internal_api/public/base/model_type.h" |
22 #include "sync/internal_api/public/read_node.h" | 23 #include "sync/internal_api/public/read_node.h" |
23 #include "sync/internal_api/public/read_transaction.h" | 24 #include "sync/internal_api/public/read_transaction.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 new base::WeakPtrFactory<syncer::SyncMergeResult>( | 136 new base::WeakPtrFactory<syncer::SyncMergeResult>( |
136 sync_merge_result_.get())); | 137 sync_merge_result_.get())); |
137 | 138 |
138 syncer::ModelTypeSet types = syncer::ProtocolTypes(); | 139 syncer::ModelTypeSet types = syncer::ProtocolTypes(); |
139 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good(); | 140 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good(); |
140 iter.Inc()) { | 141 iter.Inc()) { |
141 syncer::TestUserShare::CreateRoot(iter.Get(), | 142 syncer::TestUserShare::CreateRoot(iter.Get(), |
142 test_user_share_->user_share()); | 143 test_user_share_->user_share()); |
143 } | 144 } |
144 test_user_share_->encryption_handler()->Init(); | 145 test_user_share_->encryption_handler()->Init(); |
| 146 ConstructGenericChangeProcessor(type); |
| 147 } |
| 148 |
| 149 void ConstructGenericChangeProcessor(syncer::ModelType type) { |
145 scoped_refptr<syncer::AttachmentStore> attachment_store( | 150 scoped_refptr<syncer::AttachmentStore> attachment_store( |
146 new syncer::FakeAttachmentStore(base::MessageLoopProxy::current())); | 151 new syncer::FakeAttachmentStore(base::MessageLoopProxy::current())); |
147 | |
148 scoped_ptr<MockAttachmentService> mock_attachment_service( | 152 scoped_ptr<MockAttachmentService> mock_attachment_service( |
149 new MockAttachmentService(attachment_store)); | 153 new MockAttachmentService(attachment_store)); |
150 // GenericChangeProcessor takes ownership of the AttachmentService, but we | 154 // GenericChangeProcessor takes ownership of the AttachmentService, but we |
151 // need to have a pointer to it so we can see that it was used properly. | 155 // need to have a pointer to it so we can see that it was used properly. |
152 // Take a pointer and trust that GenericChangeProcessor does not prematurely | 156 // Take a pointer and trust that GenericChangeProcessor does not prematurely |
153 // destroy it. | 157 // destroy it. |
154 mock_attachment_service_ = mock_attachment_service.get(); | 158 mock_attachment_service_ = mock_attachment_service.get(); |
155 sync_factory_.reset(new MockSyncApiComponentFactory( | 159 sync_factory_.reset(new MockSyncApiComponentFactory( |
156 mock_attachment_service.PassAs<syncer::AttachmentService>())); | 160 mock_attachment_service.PassAs<syncer::AttachmentService>())); |
157 change_processor_.reset( | 161 change_processor_.reset( |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 syncer::AttachmentId::CreateFromProto(attachment_id_proto); | 443 syncer::AttachmentId::CreateFromProto(attachment_id_proto); |
440 | 444 |
441 change_processor()->OnAttachmentUploaded(attachment_id); | 445 change_processor()->OnAttachmentUploaded(attachment_id); |
442 syncer::ReadTransaction read_transaction(FROM_HERE, user_share()); | 446 syncer::ReadTransaction read_transaction(FROM_HERE, user_share()); |
443 syncer::ReadNode node(&read_transaction); | 447 syncer::ReadNode node(&read_transaction); |
444 ASSERT_EQ(node.InitByClientTagLookup(kType, tag), syncer::BaseNode::INIT_OK); | 448 ASSERT_EQ(node.InitByClientTagLookup(kType, tag), syncer::BaseNode::INIT_OK); |
445 attachment_ids = node.GetAttachmentIds(); | 449 attachment_ids = node.GetAttachmentIds(); |
446 EXPECT_EQ(1U, attachment_ids.size()); | 450 EXPECT_EQ(1U, attachment_ids.size()); |
447 } | 451 } |
448 | 452 |
| 453 // Verify that upon construction, all attachments not yet on the server are |
| 454 // scheduled for upload. |
| 455 TEST_F(SyncGenericChangeProcessorTest, UploadAllAttachmentsNotOnServer) { |
| 456 // Create two attachment ids. id2 will be marked as "on server". |
| 457 syncer::AttachmentId id1 = syncer::AttachmentId::Create(); |
| 458 syncer::AttachmentId id2 = syncer::AttachmentId::Create(); |
| 459 { |
| 460 // Write an entry containing these two attachment ids. |
| 461 syncer::WriteTransaction trans(FROM_HERE, user_share()); |
| 462 syncer::ReadNode root(&trans); |
| 463 ASSERT_EQ(syncer::BaseNode::INIT_OK, root.InitTypeRoot(kType)); |
| 464 syncer::WriteNode node(&trans); |
| 465 node.InitUniqueByCreation(kType, root, "some node"); |
| 466 sync_pb::AttachmentMetadata metadata; |
| 467 sync_pb::AttachmentMetadataRecord* record1 = metadata.add_record(); |
| 468 *record1->mutable_id() = id1.GetProto(); |
| 469 sync_pb::AttachmentMetadataRecord* record2 = metadata.add_record(); |
| 470 *record2->mutable_id() = id2.GetProto(); |
| 471 record2->set_is_on_server(true); |
| 472 node.SetAttachmentMetadata(metadata); |
| 473 } |
| 474 |
| 475 // Construct the GenericChangeProcessor and see that it asks the |
| 476 // AttachmentService to upload id1 only. |
| 477 ConstructGenericChangeProcessor(kType); |
| 478 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_sets()->size()); |
| 479 ASSERT_THAT(mock_attachment_service()->attachment_id_sets()->front(), |
| 480 testing::UnorderedElementsAre(id1)); |
| 481 } |
| 482 |
449 } // namespace | 483 } // namespace |
450 | 484 |
451 } // namespace sync_driver | 485 } // namespace sync_driver |
OLD | NEW |