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 275b4d2c292290039ffd93b9d999ba3dd98a86d7..a79a981957d0daa29d8336069739c2d395ad664b 100644 |
--- a/content/browser/download/download_item_impl_unittest.cc |
+++ b/content/browser/download/download_item_impl_unittest.cc |
@@ -2,6 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/callback.h" |
#include "base/command_line.h" |
#include "base/message_loop.h" |
#include "base/stl_util.h" |
@@ -13,8 +14,8 @@ |
#include "content/browser/download/download_item_impl_delegate.h" |
#include "content/browser/download/download_request_handle.h" |
#include "content/browser/download/mock_download_file.h" |
-#include "content/public/browser/download_id.h" |
#include "content/public/browser/download_destination_observer.h" |
+#include "content/public/browser/download_id.h" |
#include "content/public/browser/download_interrupt_reasons.h" |
#include "content/public/browser/download_url_parameters.h" |
#include "content/public/common/content_switches.h" |
@@ -324,6 +325,11 @@ class DownloadItemTest : public testing::Test { |
return &delegate_; |
} |
+ void OnDownloadFileAcquired(base::FilePath* return_path, |
+ const base::FilePath& path) { |
+ *return_path = path; |
+ } |
+ |
private: |
base::MessageLoopForUI loop_; |
TestBrowserThread ui_thread_; // UI thread |
@@ -430,6 +436,8 @@ TEST_F(DownloadItemTest, ContinueAfterInterrupted) { |
MockDownloadFile* download_file = DoIntermediateRename(item); |
// Interrupt the download, using a continuable interrupt. |
+ EXPECT_CALL(*download_file, FullPath()) |
+ .WillOnce(Return(base::FilePath())); |
EXPECT_CALL(*download_file, Detach()); |
item->DestinationObserverAsWeakPtr()->DestinationError( |
DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR); |
@@ -491,6 +499,9 @@ TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) { |
mock_request_handle = new NiceMock<MockRequestHandle>; |
request_handle.reset(mock_request_handle); |
+ 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. |
@@ -696,6 +707,8 @@ TEST_F(DownloadItemTest, CallbackAfterRename) { |
EXPECT_CALL(*download_file, RenameAndAnnotate(final_path, _)) |
.WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
final_path)); |
+ EXPECT_CALL(*download_file, FullPath()) |
+ .WillOnce(Return(base::FilePath())); |
EXPECT_CALL(*download_file, Detach()); |
item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
RunAllPendingInMessageLoops(); |
@@ -861,6 +874,8 @@ TEST_F(DownloadItemTest, EnabledActionsForNormalDownload) { |
base::FilePath(kDummyPath))); |
EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
.WillOnce(Return(true)); |
+ EXPECT_CALL(*download_file, FullPath()) |
+ .WillOnce(Return(base::FilePath())); |
EXPECT_CALL(*download_file, Detach()); |
item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
RunAllPendingInMessageLoops(); |
@@ -888,6 +903,8 @@ TEST_F(DownloadItemTest, EnabledActionsForTemporaryDownload) { |
EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) |
.WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
base::FilePath(kDummyPath))); |
+ EXPECT_CALL(*download_file, FullPath()) |
+ .WillOnce(Return(base::FilePath())); |
EXPECT_CALL(*download_file, Detach()); |
item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
RunAllPendingInMessageLoops(); |
@@ -947,6 +964,8 @@ TEST_F(DownloadItemTest, CompleteDelegate_ReturnTrue) { |
base::FilePath(kDummyPath))); |
EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
.WillOnce(Return(true)); |
+ EXPECT_CALL(*download_file, FullPath()) |
+ .WillOnce(Return(base::FilePath())); |
EXPECT_CALL(*download_file, Detach()); |
RunAllPendingInMessageLoops(); |
EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
@@ -982,6 +1001,8 @@ TEST_F(DownloadItemTest, CompleteDelegate_BlockOnce) { |
base::FilePath(kDummyPath))); |
EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
.WillOnce(Return(true)); |
+ EXPECT_CALL(*download_file, FullPath()) |
+ .WillOnce(Return(base::FilePath())); |
EXPECT_CALL(*download_file, Detach()); |
RunAllPendingInMessageLoops(); |
EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
@@ -1020,6 +1041,8 @@ TEST_F(DownloadItemTest, CompleteDelegate_SetDanger) { |
base::FilePath(kDummyPath))); |
EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
.WillOnce(Return(true)); |
+ EXPECT_CALL(*download_file, FullPath()) |
+ .WillOnce(Return(base::FilePath())); |
EXPECT_CALL(*download_file, Detach()); |
RunAllPendingInMessageLoops(); |
EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
@@ -1068,11 +1091,33 @@ TEST_F(DownloadItemTest, CompleteDelegate_BlockTwice) { |
base::FilePath(kDummyPath))); |
EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
.WillOnce(Return(true)); |
+ EXPECT_CALL(*download_file, FullPath()) |
+ .WillOnce(Return(base::FilePath())); |
EXPECT_CALL(*download_file, Detach()); |
RunAllPendingInMessageLoops(); |
EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
} |
+TEST_F(DownloadItemTest, AcquireFileAndDeleteDownload) { |
+ DownloadItemImpl* item = CreateDownloadItem(); |
+ MockDownloadFile* download_file = DoIntermediateRename(item); |
+ base::FilePath full_path(FILE_PATH_LITERAL("foo.txt")); |
+ |
+ EXPECT_CALL(*download_file, FullPath()) |
+ .WillOnce(Return(full_path)); |
+ EXPECT_CALL(*download_file, Detach()); |
+ EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); |
+ |
+ base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); |
+ base::FilePath returned_path; |
+ item->AcquireFileAndDeleteDownload( |
+ base::Bind(&DownloadItemTest::OnDownloadFileAcquired, |
+ weak_ptr_factory.GetWeakPtr(), |
+ base::Unretained(&returned_path))); |
+ RunAllPendingInMessageLoops(); |
+ EXPECT_EQ(full_path, returned_path); |
+} |
+ |
TEST(MockDownloadItem, Compiles) { |
MockDownloadItem mock_item; |
} |