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

Side by Side Diff: content/browser/download/download_browsertest.cc

Issue 14958002: [Resumption 8/11] Remove intermediate files when no longer necessary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains download browser tests that are known to be runnable 5 // This file contains download browser tests that are known to be runnable
6 // in a pure content context. Over time tests should be migrated here. 6 // in a pure content context. Over time tests should be migrated here.
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 injector->InjectErrors(); 1371 injector->InjectErrors();
1372 1372
1373 // Resume and watch completion. 1373 // Resume and watch completion.
1374 DownloadUpdatedObserver completion_observer( 1374 DownloadUpdatedObserver completion_observer(
1375 download, base::Bind(DownloadCompleteFilter)); 1375 download, base::Bind(DownloadCompleteFilter));
1376 download->Resume(); 1376 download->Resume();
1377 completion_observer.WaitForEvent(); 1377 completion_observer.WaitForEvent();
1378 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); 1378 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE);
1379 } 1379 }
1380 1380
1381 // An interrupted download should remove the intermediate file when it is
1382 // cancelled.
1383 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelInterruptedDownload) {
1384 CommandLine::ForCurrentProcess()->AppendSwitch(
1385 switches::kEnableDownloadResumption);
1386 ASSERT_TRUE(test_server()->Start());
1387
1388 GURL url1 = test_server()->GetURL(
1389 base::StringPrintf("rangereset?size=%d&rst_boundary=%d",
1390 GetSafeBufferChunk() * 3, GetSafeBufferChunk()));
1391
1392 DownloadItem* download(StartDownloadAndReturnItem(url1));
1393 WaitForData(download, GetSafeBufferChunk());
1394
1395 ReleaseRSTAndConfirmInterruptForResume(download);
1396 ConfirmFileStatusForResume(
1397 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3,
1398 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload")));
1399
1400 base::FilePath intermediate_path(download->GetFullPath());
1401 ASSERT_FALSE(intermediate_path.empty());
1402 EXPECT_TRUE(file_util::PathExists(intermediate_path));
1403
1404 download->Cancel(true /* user_cancel */);
1405 RunAllPendingInMessageLoop(BrowserThread::FILE);
1406 RunAllPendingInMessageLoop();
1407
1408 // The intermediate file should now be gone.
1409 EXPECT_FALSE(file_util::PathExists(intermediate_path));
1410 }
1411
1412 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveDownload) {
1413 CommandLine::ForCurrentProcess()->AppendSwitch(
1414 switches::kEnableDownloadResumption);
1415 ASSERT_TRUE(test_server()->Start());
1416
1417 // An interrupted download should remove the intermediate file when it is
1418 // removed.
1419 {
1420 GURL url1 = test_server()->GetURL(
1421 base::StringPrintf("rangereset?size=%d&rst_boundary=%d",
1422 GetSafeBufferChunk() * 3, GetSafeBufferChunk()));
1423
1424 DownloadItem* download(StartDownloadAndReturnItem(url1));
1425 WaitForData(download, GetSafeBufferChunk());
1426 ReleaseRSTAndConfirmInterruptForResume(download);
1427 ConfirmFileStatusForResume(
1428 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3,
1429 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload")));
1430
1431 base::FilePath intermediate_path(download->GetFullPath());
1432 ASSERT_FALSE(intermediate_path.empty());
1433 EXPECT_TRUE(file_util::PathExists(intermediate_path));
1434
1435 download->Remove();
1436 RunAllPendingInMessageLoop(BrowserThread::FILE);
1437 RunAllPendingInMessageLoop();
1438
1439 // The intermediate file should now be gone.
1440 EXPECT_FALSE(file_util::PathExists(intermediate_path));
1441 }
1442
1443 // A completed download shouldn't delete the downloaded file when it is
1444 // removed.
1445 {
1446 // Start the second download and wait until it's done.
1447 base::FilePath file2(FILE_PATH_LITERAL("download-test.lib"));
1448 GURL url2(URLRequestMockHTTPJob::GetMockUrl(file2));
1449 scoped_ptr<DownloadTestObserver> completion_observer(
1450 CreateWaiter(shell(), 1));
1451 DownloadItem* download(StartDownloadAndReturnItem(url2));
1452 completion_observer->WaitForFinished();
1453
1454 // The target path should exist.
1455 base::FilePath target_path(download->GetTargetFilePath());
1456 EXPECT_TRUE(file_util::PathExists(target_path));
1457 download->Remove();
1458 RunAllPendingInMessageLoop(BrowserThread::FILE);
1459 RunAllPendingInMessageLoop();
1460
1461 // The file should still exist.
1462 EXPECT_TRUE(file_util::PathExists(target_path));
1463 }
1464 }
1465
1381 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) { 1466 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) {
1382 SetupEnsureNoPendingDownloads(); 1467 SetupEnsureNoPendingDownloads();
1383 CommandLine::ForCurrentProcess()->AppendSwitch( 1468 CommandLine::ForCurrentProcess()->AppendSwitch(
1384 switches::kEnableDownloadResumption); 1469 switches::kEnableDownloadResumption);
1385 ASSERT_TRUE(test_server()->Start()); 1470 ASSERT_TRUE(test_server()->Start());
1386 1471
1387 GURL url = test_server()->GetURL( 1472 GURL url = test_server()->GetURL(
1388 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", 1473 base::StringPrintf("rangereset?size=%d&rst_boundary=%d",
1389 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); 1474 GetSafeBufferChunk() * 3, GetSafeBufferChunk()));
1390 1475
(...skipping 17 matching lines...) Expand all
1408 download->Remove(); 1493 download->Remove();
1409 1494
1410 // Start the second download and wait until it's done. 1495 // Start the second download and wait until it's done.
1411 base::FilePath file(FILE_PATH_LITERAL("download-test.lib")); 1496 base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
1412 GURL url2(URLRequestMockHTTPJob::GetMockUrl(file)); 1497 GURL url2(URLRequestMockHTTPJob::GetMockUrl(file));
1413 // Download the file and wait. 1498 // Download the file and wait.
1414 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE); 1499 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE);
1415 1500
1416 EXPECT_TRUE(EnsureNoPendingDownloads()); 1501 EXPECT_TRUE(EnsureNoPendingDownloads());
1417 } 1502 }
1418
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.
1419 } // namespace content 1503 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_item_impl.cc » ('j') | content/browser/download/download_item_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698