Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(639)

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

Issue 14947007: [Downloads] Allow acquiring dangerous download file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix UMA and support stealing interrupted downloads 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 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 CreateInProgressWaiter(shell(), 1)); 694 CreateInProgressWaiter(shell(), 1));
695 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 695 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
696 observer->WaitForFinished(); 696 observer->WaitForFinished();
697 697
698 std::vector<DownloadItem*> downloads; 698 std::vector<DownloadItem*> downloads;
699 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 699 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
700 ASSERT_EQ(1u, downloads.size()); 700 ASSERT_EQ(1u, downloads.size());
701 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); 701 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
702 702
703 // Cancel the download and wait for download system quiesce. 703 // Cancel the download and wait for download system quiesce.
704 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 704 downloads[0]->Cancel(true);
Randy Smith (Not in Mondays) 2013/05/28 17:29:40 Not a blocking comment, just for my curiosity: Why
asanka 2013/05/28 22:01:39 I though that Cancel() is what agrees with the int
705 scoped_refptr<DownloadTestFlushObserver> flush_observer( 705 scoped_refptr<DownloadTestFlushObserver> flush_observer(
706 new DownloadTestFlushObserver(DownloadManagerForShell(shell()))); 706 new DownloadTestFlushObserver(DownloadManagerForShell(shell())));
707 flush_observer->WaitForFlush(); 707 flush_observer->WaitForFlush();
708 708
709 // Get the important info from other threads and check it. 709 // Get the important info from other threads and check it.
710 EXPECT_TRUE(EnsureNoPendingDownloads()); 710 EXPECT_TRUE(EnsureNoPendingDownloads());
711 } 711 }
712 712
713 // Check that downloading multiple (in this case, 2) files does not result in 713 // Check that downloading multiple (in this case, 2) files does not result in
714 // corrupted files. 714 // corrupted files.
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload"))); 1535 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload")));
1536 1536
1537 base::FilePath intermediate_path(download->GetFullPath()); 1537 base::FilePath intermediate_path(download->GetFullPath());
1538 ASSERT_FALSE(intermediate_path.empty()); 1538 ASSERT_FALSE(intermediate_path.empty());
1539 EXPECT_TRUE(file_util::PathExists(intermediate_path)); 1539 EXPECT_TRUE(file_util::PathExists(intermediate_path));
1540 1540
1541 // Resume and cancel download. We expect only a single OnDownloadCreated() 1541 // Resume and cancel download. We expect only a single OnDownloadCreated()
1542 // call, and that's for the second download created below. 1542 // call, and that's for the second download created below.
1543 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); 1543 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1);
1544 download->Resume(); 1544 download->Resume();
1545 download->Cancel(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 1545 download->Cancel(true);
1546 1546
1547 // The intermediate file should now be gone. 1547 // The intermediate file should now be gone.
1548 RunAllPendingInMessageLoop(BrowserThread::FILE); 1548 RunAllPendingInMessageLoop(BrowserThread::FILE);
1549 RunAllPendingInMessageLoop(); 1549 RunAllPendingInMessageLoop();
1550 EXPECT_FALSE(file_util::PathExists(intermediate_path)); 1550 EXPECT_FALSE(file_util::PathExists(intermediate_path));
1551 EXPECT_TRUE(download->GetFullPath().empty()); 1551 EXPECT_TRUE(download->GetFullPath().empty());
1552 1552
1553 // Start the second download and wait until it's done. The test server is 1553 // Start the second download and wait until it's done. The test server is
1554 // single threaded. The response to this download request should follow the 1554 // single threaded. The response to this download request should follow the
1555 // response to the previous resumption request. 1555 // response to the previous resumption request.
1556 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); 1556 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x"));
1557 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE); 1557 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE);
1558 1558
1559 EXPECT_TRUE(EnsureNoPendingDownloads()); 1559 EXPECT_TRUE(EnsureNoPendingDownloads());
1560 } 1560 }
1561 1561
1562 } // namespace content 1562 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698