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 3// found in the LICENSE file. 4 5#include "sync/internal_api/public/attachments/fake_attachment_downloader.h" 6 7#include "base/bind.h" 8#include "base/message_loop/message_loop.h" 9#include "base/run_loop.h" 10#include "sync/api/attachments/attachment.h" 11#include "testing/gtest/include/gtest/gtest.h" 12 13namespace syncer { 14 15class FakeAttachmentDownloaderTest : public testing::Test { 16 protected: 17 FakeAttachmentDownloaderTest() {} 18 19 virtual void SetUp() OVERRIDE {} 20 21 virtual void TearDown() OVERRIDE {} 22 23 AttachmentDownloader* downloader() { 24 return &attachment_downloader_; 25 } 26 27 AttachmentDownloader::DownloadCallback download_callback() { 28 return base::Bind(&FakeAttachmentDownloaderTest::DownloadDone, 29 base::Unretained(this)); 30 } 31 32 const std::vector<AttachmentDownloader::DownloadResult>& download_results() { 33 return download_results_; 34 } 35 36 void RunMessageLoop() { 37 base::RunLoop run_loop; 38 run_loop.RunUntilIdle(); 39 } 40 41 private: 42 void DownloadDone(const AttachmentDownloader::DownloadResult& result, 43 scoped_ptr<Attachment> attachment) { 44 download_results_.push_back(result); 45 } 46 47 base::MessageLoop message_loop_; 48 FakeAttachmentDownloader attachment_downloader_; 49 std::vector<AttachmentDownloader::DownloadResult> download_results_; 50}; 51 52TEST_F(FakeAttachmentDownloaderTest, DownloadAttachment) { 53 AttachmentId attachment_id = AttachmentId::Create(); 54 downloader()->DownloadAttachment(attachment_id, download_callback()); 55 RunMessageLoop(); 56 EXPECT_EQ(1U, download_results().size()); 57 EXPECT_EQ(AttachmentDownloader::DOWNLOAD_SUCCESS, download_results()[0]); 58} 59 60} // namespace syncer 61