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

Unified Diff: content/browser/download/download_item_impl_unittest.cc

Issue 23496076: WIP - Refactor programmatic downloads Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_manager_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/download_item_impl_unittest.cc
diff --git a/content/browser/download/download_item_impl_unittest.cc b/content/browser/download/download_item_impl_unittest.cc
index ff5d32602fa1a01c60f8aad2f851a92fd30f38b5..f8e712aedc67ab41456e27eb669db03b5870d1f0 100644
--- a/content/browser/download/download_item_impl_unittest.cc
+++ b/content/browser/download/download_item_impl_unittest.cc
@@ -19,6 +19,7 @@
#include "content/public/browser/download_url_parameters.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/mock_download_item.h"
+#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -87,10 +88,9 @@ class MockDelegate : public DownloadItemImplDelegate {
}
};
-class MockRequestHandle : public DownloadRequestHandleInterface {
+class MockRequestHandle : public DownloadRequestHandle {
public:
- MOCK_CONST_METHOD0(GetWebContents, WebContents*());
- MOCK_CONST_METHOD0(GetDownloadManager, DownloadManager*());
+ MOCK_METHOD1(Start, void(const RequestStartedCallback&));
MOCK_CONST_METHOD0(PauseRequest, void());
MOCK_CONST_METHOD0(ResumeRequest, void());
MOCK_CONST_METHOD0(CancelRequest, void());
@@ -231,9 +231,8 @@ class DownloadItemTest : public testing::Test {
info_->url_chain.push_back(GURL());
info_->etag = "SomethingToSatisfyResumption";
- DownloadItemImpl* download =
- new DownloadItemImpl(
- &delegate_, next_id++, *(info_.get()), net::BoundNetLog());
+ DownloadItemImpl* download = new DownloadItemImpl(
+ &delegate_, next_id++, *(info_.get()), net::BoundNetLog());
allocated_downloads_.insert(download);
return download;
}
@@ -254,7 +253,7 @@ class DownloadItemTest : public testing::Test {
EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _));
}
- scoped_ptr<DownloadRequestHandleInterface> request_handle(
+ scoped_ptr<DownloadRequestHandle> request_handle(
new NiceMock<MockRequestHandle>);
item->Start(download_file.Pass(), request_handle.Pass());
loop_.RunUntilIdle();
@@ -417,12 +416,16 @@ TEST_F(DownloadItemTest, ContinueAfterInterrupted) {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableDownloadResumption);
+ TestBrowserContext test_browser_context;
DownloadItemImpl* item = CreateDownloadItem();
MockObserver observer(item);
- DownloadItemImplDelegate::DownloadTargetCallback callback;
MockDownloadFile* download_file =
DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
+ EXPECT_CALL(*mock_delegate(), GetBrowserContext())
+ .WillRepeatedly(Return(&test_browser_context));
+ EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(_, _));
+
// Interrupt the download, using a continuable interrupt.
EXPECT_CALL(*download_file, FullPath())
.WillOnce(Return(base::FilePath()));
@@ -430,9 +433,9 @@ TEST_F(DownloadItemTest, ContinueAfterInterrupted) {
item->DestinationObserverAsWeakPtr()->DestinationError(
DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR);
ASSERT_TRUE(observer.CheckUpdated());
- // Should attempt to auto-resume. Because we don't have a mock WebContents,
- // ResumeInterruptedDownload() will abort early, with another interrupt,
- // which will be ignored.
+
+ // Should attempt to auto-resume. This is checked by verifying the expectation
+ // for the MockResumeInterruptedDownload() call for the mock_delegate() above.
ASSERT_EQ(1, observer.GetInterruptCount());
ASSERT_EQ(0, observer.GetResumeCount());
RunAllPendingInMessageLoops();
@@ -445,12 +448,17 @@ TEST_F(DownloadItemTest, RestartAfterInterrupted) {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableDownloadResumption);
+ TestBrowserContext test_browser_context;
DownloadItemImpl* item = CreateDownloadItem();
MockObserver observer(item);
- DownloadItemImplDelegate::DownloadTargetCallback callback;
MockDownloadFile* download_file =
DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
+ EXPECT_CALL(*mock_delegate(), GetBrowserContext())
+ .WillRepeatedly(Return(&test_browser_context));
+ EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(_, _))
+ .Times(0);
+
// Interrupt the download, using a restartable interrupt.
EXPECT_CALL(*download_file, Cancel());
item->DestinationObserverAsWeakPtr()->DestinationError(
@@ -468,6 +476,7 @@ TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableDownloadResumption);
+ TestBrowserContext test_browser_context;
DownloadItemImpl* item = CreateDownloadItem();
base::WeakPtr<DownloadDestinationObserver> as_observer(
item->DestinationObserverAsWeakPtr());
@@ -475,11 +484,15 @@ TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) {
MockDownloadFile* mock_download_file(NULL);
scoped_ptr<DownloadFile> download_file;
MockRequestHandle* mock_request_handle(NULL);
- scoped_ptr<DownloadRequestHandleInterface> request_handle;
+ scoped_ptr<DownloadRequestHandle> request_handle;
DownloadItemImplDelegate::DownloadTargetCallback callback;
EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _))
.WillRepeatedly(SaveArg<1>(&callback));
+ EXPECT_CALL(*mock_delegate(), GetBrowserContext())
+ .WillRepeatedly(Return(&test_browser_context));
+ EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(_, _))
+ .Times(DownloadItemImpl::kMaxAutoResumeAttempts);
for (int i = 0; i < (DownloadItemImpl::kMaxAutoResumeAttempts + 1); ++i) {
DVLOG(20) << "Loop iteration " << i;
@@ -491,14 +504,6 @@ TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) {
ON_CALL(*mock_download_file, FullPath())
.WillByDefault(Return(base::FilePath()));
- // It's too complicated to set up a WebContents instance that would cause
- // the MockDownloadItemDelegate's ResumeInterruptedDownload() function
- // to be callled, so we simply verify that GetWebContents() is called.
- if (i < (DownloadItemImpl::kMaxAutoResumeAttempts - 1)) {
- EXPECT_CALL(*mock_request_handle, GetWebContents())
- .WillRepeatedly(Return(static_cast<WebContents*>(NULL)));
- }
-
// Copied key parts of DoIntermediateRename & AddDownloadFileToDownloadItem
// to allow for holding onto the request handle.
item->Start(download_file.Pass(), request_handle.Pass());
@@ -612,7 +617,7 @@ TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
MockObserver observer(item);
MockDownloadFile* mock_download_file(new MockDownloadFile);
scoped_ptr<DownloadFile> download_file(mock_download_file);
- scoped_ptr<DownloadRequestHandleInterface> request_handle(
+ scoped_ptr<DownloadRequestHandle> request_handle(
new NiceMock<MockRequestHandle>);
EXPECT_CALL(*mock_download_file, Initialize(_));
@@ -661,7 +666,7 @@ TEST_F(DownloadItemTest, Start) {
scoped_ptr<DownloadFile> download_file(mock_download_file);
DownloadItemImpl* item = CreateDownloadItem();
EXPECT_CALL(*mock_download_file, Initialize(_));
- scoped_ptr<DownloadRequestHandleInterface> request_handle(
+ scoped_ptr<DownloadRequestHandle> request_handle(
new NiceMock<MockRequestHandle>);
EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _));
item->Start(download_file.Pass(), request_handle.Pass());
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698