Index: content/browser/download/download_browsertest.cc |
diff --git a/content/browser/download/download_browsertest.cc b/content/browser/download/download_browsertest.cc |
index f535d1846af250bcfe3462f9f577b886612ec8c7..3c9f38d7f660a3d98253a1e410328b98f1509042 100644 |
--- a/content/browser/download/download_browsertest.cc |
+++ b/content/browser/download/download_browsertest.cc |
@@ -1378,6 +1378,91 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithFileFinalRenameError) { |
EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
} |
+// An interrupted download should remove the intermediate file when it is |
+// cancelled. |
+IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelInterruptedDownload) { |
+ CommandLine::ForCurrentProcess()->AppendSwitch( |
+ switches::kEnableDownloadResumption); |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ GURL url1 = test_server()->GetURL( |
+ base::StringPrintf("rangereset?size=%d&rst_boundary=%d", |
+ GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
+ |
+ DownloadItem* download(StartDownloadAndReturnItem(url1)); |
+ WaitForData(download, GetSafeBufferChunk()); |
+ |
+ ReleaseRSTAndConfirmInterruptForResume(download); |
+ ConfirmFileStatusForResume( |
+ download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, |
+ base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload"))); |
+ |
+ base::FilePath intermediate_path(download->GetFullPath()); |
+ ASSERT_FALSE(intermediate_path.empty()); |
+ EXPECT_TRUE(file_util::PathExists(intermediate_path)); |
+ |
+ download->Cancel(true /* user_cancel */); |
+ RunAllPendingInMessageLoop(BrowserThread::FILE); |
+ RunAllPendingInMessageLoop(); |
+ |
+ // The intermediate file should now be gone. |
+ EXPECT_FALSE(file_util::PathExists(intermediate_path)); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveDownload) { |
+ CommandLine::ForCurrentProcess()->AppendSwitch( |
+ switches::kEnableDownloadResumption); |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ // An interrupted download should remove the intermediate file when it is |
+ // removed. |
+ { |
+ GURL url1 = test_server()->GetURL( |
+ base::StringPrintf("rangereset?size=%d&rst_boundary=%d", |
+ GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
+ |
+ DownloadItem* download(StartDownloadAndReturnItem(url1)); |
+ WaitForData(download, GetSafeBufferChunk()); |
+ ReleaseRSTAndConfirmInterruptForResume(download); |
+ ConfirmFileStatusForResume( |
+ download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, |
+ base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload"))); |
+ |
+ base::FilePath intermediate_path(download->GetFullPath()); |
+ ASSERT_FALSE(intermediate_path.empty()); |
+ EXPECT_TRUE(file_util::PathExists(intermediate_path)); |
+ |
+ download->Remove(); |
+ RunAllPendingInMessageLoop(BrowserThread::FILE); |
+ RunAllPendingInMessageLoop(); |
+ |
+ // The intermediate file should now be gone. |
+ EXPECT_FALSE(file_util::PathExists(intermediate_path)); |
+ } |
+ |
+ // A completed download shouldn't delete the downloaded file when it is |
+ // removed. |
+ { |
+ // Start the second download and wait until it's done. |
+ base::FilePath file2(FILE_PATH_LITERAL("download-test.lib")); |
+ GURL url2(URLRequestMockHTTPJob::GetMockUrl(file2)); |
+ scoped_ptr<DownloadTestObserver> completion_observer( |
+ CreateWaiter(shell(), 1)); |
+ DownloadItem* download(StartDownloadAndReturnItem(url2)); |
+ completion_observer->WaitForFinished(); |
+ |
+ // The target path should exist. |
+ base::FilePath target_path(download->GetTargetFilePath()); |
+ EXPECT_TRUE(file_util::PathExists(target_path)); |
+ download->Remove(); |
+ RunAllPendingInMessageLoop(BrowserThread::FILE); |
+ RunAllPendingInMessageLoop(); |
+ |
+ // The file should still exist. |
+ EXPECT_TRUE(file_util::PathExists(target_path)); |
+ } |
+} |
+ |
IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) { |
SetupEnsureNoPendingDownloads(); |
CommandLine::ForCurrentProcess()->AppendSwitch( |
@@ -1415,5 +1500,4 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) { |
EXPECT_TRUE(EnsureNoPendingDownloads()); |
} |
- |
Randy Smith (Not in Mondays)
2013/05/15 15:34:56
I had thought it was convention to have a space be
asanka
2013/05/21 21:09:02
Added back. This was unintentional.
|
} // namespace content |