| Index: components/sync_driver/generic_change_processor_unittest.cc
|
| diff --git a/components/sync_driver/generic_change_processor_unittest.cc b/components/sync_driver/generic_change_processor_unittest.cc
|
| index 073ffb0df91614bd8e20ccf52ababbcf621b9961..c5259189a87219f1306b31100d3a1aac8ebc00ae 100644
|
| --- a/components/sync_driver/generic_change_processor_unittest.cc
|
| +++ b/components/sync_driver/generic_change_processor_unittest.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "components/sync_driver/data_type_error_handler_mock.h"
|
| +#include "components/sync_driver/sync_api_component_factory.h"
|
| #include "sync/api/attachments/attachment_service_impl.h"
|
| #include "sync/api/fake_syncable_service.h"
|
| #include "sync/api/sync_change.h"
|
| @@ -49,7 +50,8 @@ MockAttachmentService::MockAttachmentService()
|
| scoped_ptr<syncer::AttachmentStore>(new syncer::FakeAttachmentStore(
|
| base::MessageLoopProxy::current())),
|
| scoped_ptr<syncer::AttachmentUploader>(
|
| - new syncer::FakeAttachmentUploader)) {
|
| + new syncer::FakeAttachmentUploader),
|
| + NULL) {
|
| }
|
|
|
| MockAttachmentService::~MockAttachmentService() {
|
| @@ -66,6 +68,31 @@ std::vector<syncer::AttachmentList>* MockAttachmentService::attachment_lists() {
|
| return &attachment_lists_;
|
| }
|
|
|
| +// MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and
|
| +// pass MockAttachmentService to it.
|
| +class MockSyncApiComponentFactory : public SyncApiComponentFactory {
|
| + public:
|
| + MockSyncApiComponentFactory(
|
| + scoped_ptr<syncer::AttachmentService> attachment_service)
|
| + : attachment_service_(attachment_service.Pass()) {}
|
| +
|
| + virtual base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType(
|
| + syncer::ModelType type) OVERRIDE {
|
| + // Shouldn't be called for this test.
|
| + NOTREACHED();
|
| + return base::WeakPtr<syncer::SyncableService>();
|
| + }
|
| +
|
| + virtual scoped_ptr<syncer::AttachmentService> CreateAttachmentService(
|
| + syncer::AttachmentService::Delegate* delegate) OVERRIDE {
|
| + EXPECT_TRUE(attachment_service_ != NULL);
|
| + return attachment_service_.Pass();
|
| + }
|
| +
|
| + private:
|
| + scoped_ptr<syncer::AttachmentService> attachment_service_;
|
| +};
|
| +
|
| class SyncGenericChangeProcessorTest : public testing::Test {
|
| public:
|
| // It doesn't matter which type we use. Just pick one.
|
| @@ -93,12 +120,14 @@ class SyncGenericChangeProcessorTest : public testing::Test {
|
| // Take a pointer and trust that GenericChangeProcessor does not prematurely
|
| // destroy it.
|
| mock_attachment_service_ = mock_attachment_service.get();
|
| - change_processor_.reset(new GenericChangeProcessor(
|
| - &data_type_error_handler_,
|
| - syncable_service_ptr_factory_.GetWeakPtr(),
|
| - merge_result_ptr_factory_.GetWeakPtr(),
|
| - test_user_share_.user_share(),
|
| + sync_factory_.reset(new MockSyncApiComponentFactory(
|
| mock_attachment_service.PassAs<syncer::AttachmentService>()));
|
| + change_processor_.reset(
|
| + new GenericChangeProcessor(&data_type_error_handler_,
|
| + syncable_service_ptr_factory_.GetWeakPtr(),
|
| + merge_result_ptr_factory_.GetWeakPtr(),
|
| + test_user_share_.user_share(),
|
| + sync_factory_.get()));
|
| }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| @@ -142,6 +171,7 @@ class SyncGenericChangeProcessorTest : public testing::Test {
|
| DataTypeErrorHandlerMock data_type_error_handler_;
|
| syncer::TestUserShare test_user_share_;
|
| MockAttachmentService* mock_attachment_service_;
|
| + scoped_ptr<SyncApiComponentFactory> sync_factory_;
|
|
|
| scoped_ptr<GenericChangeProcessor> change_processor_;
|
| };
|
| @@ -346,6 +376,44 @@ TEST_F(SyncGenericChangeProcessorTest,
|
| ASSERT_EQ(new_attachments_added[0].GetId(), new_attachments[0].GetId());
|
| }
|
|
|
| +// Verify that after attachment is uploaded GenericChangeProcessor updates
|
| +// corresponding entries
|
| +TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) {
|
| + std::string tag = "client_tag";
|
| + std::string title = "client_title";
|
| + sync_pb::EntitySpecifics specifics;
|
| + sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference();
|
| + pref_specifics->set_name("test");
|
| + syncer::AttachmentList attachments;
|
| + scoped_refptr<base::RefCountedString> attachment_data =
|
| + new base::RefCountedString;
|
| + attachment_data->data() = kTestData;
|
| + attachments.push_back(syncer::Attachment::Create(attachment_data));
|
| +
|
| + // Add a SyncData with two attachments.
|
| + syncer::SyncChangeList change_list;
|
| + change_list.push_back(
|
| + syncer::SyncChange(FROM_HERE,
|
| + syncer::SyncChange::ACTION_ADD,
|
| + syncer::SyncData::CreateLocalDataWithAttachments(
|
| + tag, title, specifics, attachments)));
|
| + ASSERT_FALSE(
|
| + change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
|
| +
|
| + sync_pb::AttachmentIdProto attachment_id_proto =
|
| + attachments[0].GetId().GetProto();
|
| + syncer::AttachmentId attachment_id =
|
| + syncer::AttachmentId::CreateFromProto(attachment_id_proto);
|
| +
|
| + change_processor()->OnAttachmentUploaded(attachment_id);
|
| + syncer::ReadTransaction read_transaction(FROM_HERE, user_share());
|
| + syncer::ReadNode node(&read_transaction);
|
| + ASSERT_EQ(node.InitByClientTagLookup(syncer::PREFERENCES, tag),
|
| + syncer::BaseNode::INIT_OK);
|
| + syncer::AttachmentIdList attachment_ids = node.GetAttachmentIds();
|
| + EXPECT_EQ(1U, attachment_ids.size());
|
| +}
|
| +
|
| } // namespace
|
|
|
| } // namespace browser_sync
|
|
|