| Index: sync/internal_api/attachments/attachment_service_impl_unittest.cc
|
| diff --git a/sync/internal_api/attachments/attachment_service_impl_unittest.cc b/sync/internal_api/attachments/attachment_service_impl_unittest.cc
|
| index e72bb8fe578f469740f4744f0839c4cec1b28a48..8519244324cb745636d725800010f8feacd256e5 100644
|
| --- a/sync/internal_api/attachments/attachment_service_impl_unittest.cc
|
| +++ b/sync/internal_api/attachments/attachment_service_impl_unittest.cc
|
| @@ -8,7 +8,9 @@
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| +#include "base/thread_task_runner_handle.h"
|
| #include "base/timer/mock_timer.h"
|
| +#include "sync/api/attachments/attachment_store_backend.h"
|
| #include "sync/internal_api/public/attachments/attachment_util.h"
|
| #include "sync/internal_api/public/attachments/fake_attachment_downloader.h"
|
| #include "sync/internal_api/public/attachments/fake_attachment_uploader.h"
|
| @@ -19,37 +21,46 @@ namespace syncer {
|
|
|
| namespace {
|
|
|
| -class MockAttachmentStore : public AttachmentStore,
|
| - public base::SupportsWeakPtr<MockAttachmentStore> {
|
| +class MockAttachmentStoreBackend
|
| + : public AttachmentStoreBackend,
|
| + public base::SupportsWeakPtr<MockAttachmentStoreBackend> {
|
| public:
|
| - MockAttachmentStore() {}
|
| + MockAttachmentStoreBackend(
|
| + const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner)
|
| + : AttachmentStoreBackend(callback_task_runner) {}
|
|
|
| - void Init(const InitCallback& callback) override {
|
| - }
|
| + ~MockAttachmentStoreBackend() override {}
|
| +
|
| + void Init(const AttachmentStore::InitCallback& callback) override {}
|
|
|
| void Read(const AttachmentIdList& ids,
|
| - const ReadCallback& callback) override {
|
| + const AttachmentStore::ReadCallback& callback) override {
|
| read_ids.push_back(ids);
|
| read_callbacks.push_back(callback);
|
| }
|
|
|
| - void Write(const AttachmentList& attachments,
|
| - const WriteCallback& callback) override {
|
| + void Write(AttachmentStore::AttachmentReferrer referrer,
|
| + const AttachmentList& attachments,
|
| + const AttachmentStore::WriteCallback& callback) override {
|
| write_attachments.push_back(attachments);
|
| write_callbacks.push_back(callback);
|
| }
|
|
|
| - void Drop(const AttachmentIdList& ids,
|
| - const DropCallback& callback) override {
|
| + void Drop(AttachmentStore::AttachmentReferrer referrer,
|
| + const AttachmentIdList& ids,
|
| + const AttachmentStore::DropCallback& callback) override {
|
| NOTREACHED();
|
| }
|
|
|
| - void ReadMetadata(const AttachmentIdList& ids,
|
| - const ReadMetadataCallback& callback) override {
|
| + void ReadMetadata(
|
| + const AttachmentIdList& ids,
|
| + const AttachmentStore::ReadMetadataCallback& callback) override {
|
| NOTREACHED();
|
| }
|
|
|
| - void ReadAllMetadata(const ReadMetadataCallback& callback) override {
|
| + void ReadAllMetadata(
|
| + AttachmentStore::AttachmentReferrer referrer,
|
| + const AttachmentStore::ReadMetadataCallback& callback) override {
|
| NOTREACHED();
|
| }
|
|
|
| @@ -57,7 +68,7 @@ class MockAttachmentStore : public AttachmentStore,
|
| // returned, everything else should be reported unavailable.
|
| void RespondToRead(const AttachmentIdSet& local_attachments) {
|
| scoped_refptr<base::RefCountedString> data = new base::RefCountedString();
|
| - ReadCallback callback = read_callbacks.back();
|
| + AttachmentStore::ReadCallback callback = read_callbacks.back();
|
| AttachmentIdList ids = read_ids.back();
|
| read_callbacks.pop_back();
|
| read_ids.pop_back();
|
| @@ -76,8 +87,9 @@ class MockAttachmentStore : public AttachmentStore,
|
| unavailable_attachments->push_back(*iter);
|
| }
|
| }
|
| - Result result =
|
| - unavailable_attachments->empty() ? SUCCESS : UNSPECIFIED_ERROR;
|
| + AttachmentStore::Result result = unavailable_attachments->empty()
|
| + ? AttachmentStore::SUCCESS
|
| + : AttachmentStore::UNSPECIFIED_ERROR;
|
|
|
| base::MessageLoop::current()->PostTask(
|
| FROM_HERE,
|
| @@ -88,8 +100,8 @@ class MockAttachmentStore : public AttachmentStore,
|
| }
|
|
|
| // Respond to Write request with |result|.
|
| - void RespondToWrite(const Result& result) {
|
| - WriteCallback callback = write_callbacks.back();
|
| + void RespondToWrite(const AttachmentStore::Result& result) {
|
| + AttachmentStore::WriteCallback callback = write_callbacks.back();
|
| AttachmentList attachments = write_attachments.back();
|
| write_callbacks.pop_back();
|
| write_attachments.pop_back();
|
| @@ -98,14 +110,12 @@ class MockAttachmentStore : public AttachmentStore,
|
| }
|
|
|
| std::vector<AttachmentIdList> read_ids;
|
| - std::vector<ReadCallback> read_callbacks;
|
| + std::vector<AttachmentStore::ReadCallback> read_callbacks;
|
| std::vector<AttachmentList> write_attachments;
|
| - std::vector<WriteCallback> write_callbacks;
|
| + std::vector<AttachmentStore::WriteCallback> write_callbacks;
|
|
|
| private:
|
| - ~MockAttachmentStore() override {}
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(MockAttachmentStore);
|
| + DISALLOW_COPY_AND_ASSIGN(MockAttachmentStoreBackend);
|
| };
|
|
|
| class MockAttachmentDownloader
|
| @@ -185,7 +195,8 @@ class AttachmentServiceImplTest : public testing::Test,
|
|
|
| void TearDown() override {
|
| attachment_service_.reset();
|
| - ASSERT_FALSE(attachment_store_);
|
| + RunLoop();
|
| + ASSERT_FALSE(attachment_store_backend_);
|
| ASSERT_FALSE(attachment_uploader_);
|
| ASSERT_FALSE(attachment_downloader_);
|
| }
|
| @@ -199,9 +210,15 @@ class AttachmentServiceImplTest : public testing::Test,
|
| scoped_ptr<MockAttachmentUploader> uploader,
|
| scoped_ptr<MockAttachmentDownloader> downloader,
|
| AttachmentService::Delegate* delegate) {
|
| - scoped_refptr<MockAttachmentStore> attachment_store(
|
| - new MockAttachmentStore());
|
| - attachment_store_ = attachment_store->AsWeakPtr();
|
| + // Initialize mock attachment store
|
| + scoped_refptr<base::SingleThreadTaskRunner> runner =
|
| + base::ThreadTaskRunnerHandle::Get();
|
| + scoped_ptr<MockAttachmentStoreBackend> attachment_store_backend(
|
| + new MockAttachmentStoreBackend(runner));
|
| + attachment_store_backend_ = attachment_store_backend->AsWeakPtr();
|
| + scoped_ptr<AttachmentStore> attachment_store =
|
| + AttachmentStore::CreateMockStoreForTest(
|
| + attachment_store_backend.Pass());
|
|
|
| if (uploader.get()) {
|
| attachment_uploader_ = uploader->AsWeakPtr();
|
| @@ -209,13 +226,9 @@ class AttachmentServiceImplTest : public testing::Test,
|
| if (downloader.get()) {
|
| attachment_downloader_ = downloader->AsWeakPtr();
|
| }
|
| - attachment_service_.reset(
|
| - new AttachmentServiceImpl(attachment_store,
|
| - uploader.Pass(),
|
| - downloader.Pass(),
|
| - delegate,
|
| - base::TimeDelta::FromMinutes(1),
|
| - base::TimeDelta::FromMinutes(8)));
|
| + attachment_service_.reset(new AttachmentServiceImpl(
|
| + attachment_store.Pass(), uploader.Pass(), downloader.Pass(), delegate,
|
| + base::TimeDelta::FromMinutes(1), base::TimeDelta::FromMinutes(8)));
|
|
|
| scoped_ptr<base::MockTimer> timer_to_pass(
|
| new base::MockTimer(false, false));
|
| @@ -247,8 +260,8 @@ class AttachmentServiceImplTest : public testing::Test,
|
| RunLoop();
|
| if (mock_timer()->IsRunning()) {
|
| mock_timer()->Fire();
|
| + RunLoop();
|
| }
|
| - RunLoop();
|
| }
|
|
|
| const std::vector<AttachmentService::GetOrDownloadResult>&
|
| @@ -264,7 +277,9 @@ class AttachmentServiceImplTest : public testing::Test,
|
| return network_change_notifier_.get();
|
| }
|
|
|
| - MockAttachmentStore* store() { return attachment_store_.get(); }
|
| + MockAttachmentStoreBackend* store() {
|
| + return attachment_store_backend_.get();
|
| + }
|
|
|
| MockAttachmentDownloader* downloader() {
|
| return attachment_downloader_.get();
|
| @@ -281,7 +296,7 @@ class AttachmentServiceImplTest : public testing::Test,
|
| private:
|
| base::MessageLoop message_loop_;
|
| scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
|
| - base::WeakPtr<MockAttachmentStore> attachment_store_;
|
| + base::WeakPtr<MockAttachmentStoreBackend> attachment_store_backend_;
|
| base::WeakPtr<MockAttachmentDownloader> attachment_downloader_;
|
| base::WeakPtr<MockAttachmentUploader> attachment_uploader_;
|
| scoped_ptr<AttachmentServiceImpl> attachment_service_;
|
| @@ -292,14 +307,11 @@ class AttachmentServiceImplTest : public testing::Test,
|
| std::vector<AttachmentId> on_attachment_uploaded_list_;
|
| };
|
|
|
| -TEST_F(AttachmentServiceImplTest, GetStore) {
|
| - EXPECT_EQ(store(), attachment_service()->GetStore());
|
| -}
|
| -
|
| TEST_F(AttachmentServiceImplTest, GetOrDownload_EmptyAttachmentList) {
|
| AttachmentIdList attachment_ids;
|
| attachment_service()->GetOrDownloadAttachments(attachment_ids,
|
| download_callback());
|
| + RunLoop();
|
| store()->RespondToRead(AttachmentIdSet());
|
|
|
| RunLoop();
|
| @@ -314,6 +326,7 @@ TEST_F(AttachmentServiceImplTest, GetOrDownload_Local) {
|
| download_callback());
|
| AttachmentIdSet local_attachments;
|
| local_attachments.insert(attachment_ids[0]);
|
| + RunLoop();
|
| store()->RespondToRead(local_attachments);
|
|
|
| RunLoop();
|
| @@ -333,6 +346,7 @@ TEST_F(AttachmentServiceImplTest, GetOrDownload_LocalRemoteUnavailable) {
|
| // Call attachment service.
|
| attachment_service()->GetOrDownloadAttachments(attachment_ids,
|
| download_callback());
|
| + RunLoop();
|
| // Ensure AttachmentStore is called.
|
| EXPECT_FALSE(store()->read_ids.empty());
|
|
|
| @@ -398,6 +412,7 @@ TEST_F(AttachmentServiceImplTest, GetOrDownload_NoDownloader) {
|
| attachment_ids.push_back(AttachmentId::Create());
|
| attachment_service()->GetOrDownloadAttachments(attachment_ids,
|
| download_callback());
|
| + RunLoop();
|
| EXPECT_FALSE(store()->read_ids.empty());
|
|
|
| AttachmentIdSet local_attachments;
|
|
|