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

Unified Diff: components/sync_driver/generic_change_processor_unittest.cc

Issue 272043002: Invoke AttachmentUploader and update AttachmentIds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android build Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « components/sync_driver/generic_change_processor_factory.cc ('k') | components/sync_driver/sync_api_component_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698