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

Unified Diff: chrome/browser/android/download/download_manager_service_unittest.cc

Issue 1781983002: [Downloads] Introduce GUIDs for downloads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/download/download_history.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/download/download_manager_service_unittest.cc
diff --git a/chrome/browser/android/download/download_manager_service_unittest.cc b/chrome/browser/android/download/download_manager_service_unittest.cc
index 7b26c2a7546a287078a5b05a70ef79507a785f7c..b987c8b4f72dea7780e239fc77f927ccda07d16a 100644
--- a/chrome/browser/android/download/download_manager_service_unittest.cc
+++ b/chrome/browser/android/download/download_manager_service_unittest.cc
@@ -12,6 +12,8 @@
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/download_url_parameters.h"
+#include "content/public/test/mock_download_item.h"
+#include "content/public/test/mock_download_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/origin.h"
@@ -25,143 +27,6 @@ class DownloadManagerDelegate;
struct DownloadCreateInfo;
}
-// Mock implementation of content::DownloadItem.
-class MockDownloadItem : public content::DownloadItem {
- public:
- explicit MockDownloadItem(bool can_resume) : can_resume_(can_resume) {}
- ~MockDownloadItem() override {}
- bool CanResume() const override { return can_resume_; }
-
- MOCK_METHOD1(AddObserver, void(content::DownloadItem::Observer*));
- MOCK_METHOD1(RemoveObserver, void(content::DownloadItem::Observer*));
- MOCK_METHOD0(UpdateObservers, void());
- MOCK_METHOD0(ValidateDangerousDownload, void());
- MOCK_METHOD1(StealDangerousDownload,
- void(const content::DownloadItem::AcquireFileCallback&));
- MOCK_METHOD0(Pause, void());
- MOCK_METHOD0(Resume, void());
- MOCK_METHOD1(Cancel, void(bool));
- MOCK_METHOD0(Remove, void());
- MOCK_METHOD0(OpenDownload, void());
- MOCK_METHOD0(ShowDownloadInShell, void());
- MOCK_CONST_METHOD0(GetId, uint32_t());
- MOCK_CONST_METHOD0(GetState, content::DownloadItem::DownloadState());
- MOCK_CONST_METHOD0(GetLastReason, content::DownloadInterruptReason());
- MOCK_CONST_METHOD0(IsPaused, bool());
- MOCK_CONST_METHOD0(IsTemporary, bool());
- MOCK_CONST_METHOD0(IsDone, bool());
- MOCK_CONST_METHOD0(GetURL, const GURL&());
- MOCK_CONST_METHOD0(GetUrlChain, std::vector<GURL>&());
- MOCK_CONST_METHOD0(GetOriginalUrl, const GURL&());
- MOCK_CONST_METHOD0(GetReferrerUrl, const GURL&());
- MOCK_CONST_METHOD0(GetTabUrl, const GURL&());
- MOCK_CONST_METHOD0(GetTabReferrerUrl, const GURL&());
- MOCK_CONST_METHOD0(GetSuggestedFilename, std::string());
- MOCK_CONST_METHOD0(GetContentDisposition, std::string());
- MOCK_CONST_METHOD0(GetMimeType, std::string());
- MOCK_CONST_METHOD0(GetOriginalMimeType, std::string());
- MOCK_CONST_METHOD0(GetRemoteAddress, std::string());
- MOCK_CONST_METHOD0(HasUserGesture, bool());
- MOCK_CONST_METHOD0(GetTransitionType, ui::PageTransition());
- MOCK_CONST_METHOD0(GetLastModifiedTime, const std::string&());
- MOCK_CONST_METHOD0(GetETag, const std::string&());
- MOCK_CONST_METHOD0(IsSavePackageDownload, bool());
- MOCK_CONST_METHOD0(GetFullPath, const base::FilePath&());
- MOCK_CONST_METHOD0(GetTargetFilePath, const base::FilePath&());
- MOCK_CONST_METHOD0(GetForcedFilePath, const base::FilePath&());
- MOCK_CONST_METHOD0(GetFileNameToReportUser, base::FilePath());
- MOCK_CONST_METHOD0(GetTargetDisposition,
- content::DownloadItem::TargetDisposition());
- MOCK_CONST_METHOD0(GetHash, const std::string&());
- MOCK_CONST_METHOD0(GetHashState, const std::string&());
- MOCK_CONST_METHOD0(GetFileExternallyRemoved, bool());
- MOCK_METHOD1(DeleteFile, void(const base::Callback<void(bool)>&));
- MOCK_CONST_METHOD0(IsDangerous, bool());
- MOCK_CONST_METHOD0(GetDangerType, content::DownloadDangerType());
- MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*));
- MOCK_CONST_METHOD0(CurrentSpeed, int64_t());
- MOCK_CONST_METHOD0(PercentComplete, int());
- MOCK_CONST_METHOD0(AllDataSaved, bool());
- MOCK_CONST_METHOD0(GetTotalBytes, int64_t());
- MOCK_CONST_METHOD0(GetReceivedBytes, int64_t());
- MOCK_CONST_METHOD0(GetStartTime, base::Time());
- MOCK_CONST_METHOD0(GetEndTime, base::Time());
- MOCK_METHOD0(CanShowInFolder, bool());
- MOCK_METHOD0(CanOpenDownload, bool());
- MOCK_METHOD0(ShouldOpenFileBasedOnExtension, bool());
- MOCK_CONST_METHOD0(GetOpenWhenComplete, bool());
- MOCK_METHOD0(GetAutoOpened, bool());
- MOCK_CONST_METHOD0(GetOpened, bool());
- MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*());
- MOCK_CONST_METHOD0(GetWebContents, content::WebContents*());
- MOCK_METHOD1(OnContentCheckCompleted, void(content::DownloadDangerType));
- MOCK_METHOD1(SetOpenWhenComplete, void(bool));
- MOCK_METHOD1(SetIsTemporary, void(bool));
- MOCK_METHOD1(SetOpened, void(bool));
- MOCK_METHOD1(SetDisplayName, void(const base::FilePath&));
- MOCK_CONST_METHOD1(DebugString, std::string(bool));
-
- private:
- bool can_resume_;
-};
-
-// Mock implementation of content::DownloadManager.
-class MockDownloadManager : public content::DownloadManager {
- public:
- MockDownloadManager() {}
- ~MockDownloadManager() override {}
-
- MOCK_METHOD1(SetDelegate, void(content::DownloadManagerDelegate*));
- MOCK_CONST_METHOD0(GetDelegate, content::DownloadManagerDelegate*());
- MOCK_METHOD0(Shutdown, void());
- MOCK_METHOD1(GetAllDownloads, void(DownloadVector*));
- MOCK_METHOD3(RemoveDownloadsByURLAndTime,
- int(const base::Callback<bool(const GURL&)>& url_filter,
- base::Time,
- base::Time));
- MOCK_METHOD2(RemoveDownloadsBetween, int(base::Time, base::Time));
- MOCK_METHOD1(RemoveDownloads, int(base::Time));
- MOCK_METHOD0(RemoveAllDownloads, int());
- void DownloadUrl(scoped_ptr<content::DownloadUrlParameters>) override {}
- MOCK_METHOD1(AddObserver, void(content::DownloadManager::Observer*));
- MOCK_METHOD1(RemoveObserver, void(content::DownloadManager::Observer*));
- MOCK_CONST_METHOD0(InProgressCount, int());
- MOCK_CONST_METHOD0(NonMaliciousInProgressCount, int());
- MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*());
- MOCK_METHOD0(CheckForHistoryFilesRemoval, void());
- void StartDownload(
- scoped_ptr<content::DownloadCreateInfo>,
- scoped_ptr<content::ByteStreamReader>,
- const content::DownloadUrlParameters::OnStartedCallback&) override {}
- content::DownloadItem* CreateDownloadItem(
- uint32_t id,
- const base::FilePath& current_path,
- const base::FilePath& target_path,
- const std::vector<GURL>& url_chain,
- const GURL& referrer_url,
- const std::string& mime_type,
- const std::string& original_mime_type,
- const base::Time& start_time,
- const base::Time& end_time,
- const std::string& etag,
- const std::string& last_modified,
- int64_t received_bytes,
- int64_t total_bytes,
- content::DownloadItem::DownloadState state,
- content::DownloadDangerType danger_type,
- content::DownloadInterruptReason interrupt_reason,
- bool opened) override {
- return nullptr;
- }
- content::DownloadItem* GetDownload(uint32_t id) override {
- return download_item_.get();
- }
- void SetDownload(MockDownloadItem* item) { download_item_.reset(item); }
-
- private:
- scoped_ptr<MockDownloadItem> download_item_;
-};
-
class DownloadManagerServiceTest : public testing::Test {
public:
DownloadManagerServiceTest()
@@ -170,7 +35,11 @@ class DownloadManagerServiceTest : public testing::Test {
nullptr,
&manager_)),
finished_(false),
- success_(false) {}
+ success_(false) {
+ ON_CALL(manager_, GetDownload(_))
+ .WillByDefault(
+ ::testing::Invoke(this, &DownloadManagerServiceTest::GetDownload));
+ }
void OnResumptionDone(bool success) {
finished_ = true;
@@ -189,12 +58,17 @@ class DownloadManagerServiceTest : public testing::Test {
}
void CreateDownloadItem(bool can_resume) {
- manager_.SetDownload(new MockDownloadItem(can_resume));
+ download_.reset(new content::MockDownloadItem());
+ ON_CALL(*download_, CanResume())
+ .WillByDefault(::testing::Return(can_resume));
}
protected:
+ content::DownloadItem* GetDownload(uint32_t) { return download_.get(); }
+
base::MessageLoop message_loop_;
- MockDownloadManager manager_;
+ scoped_ptr<content::MockDownloadItem> download_;
+ content::MockDownloadManager manager_;
DownloadManagerService* service_;
bool finished_;
bool success_;
« no previous file with comments | « no previous file | chrome/browser/download/download_history.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698