Chromium Code Reviews| 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 8dde06ffed63ca80a3b77ef5e4d04b7f7f00e274..c23716fa4704db00d3c18d5c7ec50460b1177300 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" |
| @@ -60,7 +61,7 @@ class MockDelegate : public DownloadItemImplDelegate { |
| MOCK_METHOD2(MockResumeInterruptedDownload, |
| void(DownloadUrlParameters* params, uint32 id)); |
| - BrowserContext* GetBrowserContext() const override { return nullptr; } |
| + MOCK_CONST_METHOD0(GetBrowserContext, BrowserContext*()); |
| MOCK_METHOD1(UpdatePersistence, void(DownloadItemImpl*)); |
| MOCK_METHOD1(DownloadOpened, void(DownloadItemImpl*)); |
| MOCK_METHOD1(DownloadRemoved, void(DownloadItemImpl*)); |
| @@ -411,6 +412,7 @@ TEST_F(DownloadItemTest, ContinueAfterInterrupted) { |
| base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| switches::kEnableDownloadResumption); |
| + TestBrowserContext test_browser_context; |
| DownloadItemImpl* item = CreateDownloadItem(); |
| MockObserver observer(item); |
| DownloadItemImplDelegate::DownloadTargetCallback callback; |
| @@ -421,13 +423,16 @@ TEST_F(DownloadItemTest, ContinueAfterInterrupted) { |
| EXPECT_CALL(*download_file, FullPath()) |
| .WillOnce(Return(base::FilePath())); |
| EXPECT_CALL(*download_file, Detach()); |
| + EXPECT_CALL(*mock_delegate(), GetBrowserContext()) |
| + .WillRepeatedly(Return(&test_browser_context)); |
| + EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(_, _)).Times(1); |
| 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. |
| ASSERT_EQ(1, observer.GetInterruptCount()); |
| + |
| + // Test expectations verify that ResumeInterruptedDownload() is called when |
| + // the download is interrupted. But the mock doesn't actually invoke |
|
svaldez
2015/12/11 20:53:04
nit: Maybe clarify where we cancel the resume?
asanka
2015/12/11 21:23:40
Done.
|
| ASSERT_EQ(0, observer.GetResumeCount()); |
| RunAllPendingInMessageLoops(); |
| @@ -493,6 +498,7 @@ TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) { |
| base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| switches::kEnableDownloadResumption); |
| + TestBrowserContext test_browser_context; |
| DownloadItemImpl* item = CreateDownloadItem(); |
| base::WeakPtr<DownloadDestinationObserver> as_observer( |
| item->DestinationObserverAsWeakPtr()); |
| @@ -505,6 +511,10 @@ TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) { |
| 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; |
| @@ -516,14 +526,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()); |