Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include "base/threading/sequenced_worker_pool.h" | 30 #include "base/threading/sequenced_worker_pool.h" |
| 31 #include "base/threading/thread_restrictions.h" | 31 #include "base/threading/thread_restrictions.h" |
| 32 #include "base/time/time.h" | 32 #include "base/time/time.h" |
| 33 #include "build/build_config.h" | 33 #include "build/build_config.h" |
| 34 #include "content/browser/byte_stream.h" | 34 #include "content/browser/byte_stream.h" |
| 35 #include "content/browser/download/download_file_factory.h" | 35 #include "content/browser/download/download_file_factory.h" |
| 36 #include "content/browser/download/download_file_impl.h" | 36 #include "content/browser/download/download_file_impl.h" |
| 37 #include "content/browser/download/download_item_impl.h" | 37 #include "content/browser/download/download_item_impl.h" |
| 38 #include "content/browser/download/download_manager_impl.h" | 38 #include "content/browser/download/download_manager_impl.h" |
| 39 #include "content/browser/download/download_resource_handler.h" | 39 #include "content/browser/download/download_resource_handler.h" |
| 40 #include "content/browser/download/download_task_runner.h" | |
| 40 #include "content/browser/download/parallel_download_utils.h" | 41 #include "content/browser/download/parallel_download_utils.h" |
| 41 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 42 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 42 #include "content/browser/web_contents/web_contents_impl.h" | 43 #include "content/browser/web_contents/web_contents_impl.h" |
| 43 #include "content/public/browser/download_danger_type.h" | 44 #include "content/public/browser/download_danger_type.h" |
| 44 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 45 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 45 #include "content/public/browser/resource_throttle.h" | 46 #include "content/public/browser/resource_throttle.h" |
| 46 #include "content/public/common/content_features.h" | 47 #include "content/public/common/content_features.h" |
| 47 #include "content/public/common/webplugininfo.h" | 48 #include "content/public/common/webplugininfo.h" |
| 48 #include "content/public/test/browser_test_utils.h" | 49 #include "content/public/test/browser_test_utils.h" |
| 49 #include "content/public/test/content_browser_test.h" | 50 #include "content/public/test/content_browser_test.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 std::move(stream), | 223 std::move(stream), |
| 223 net_log, | 224 net_log, |
| 224 observer), | 225 observer), |
| 225 owner_(owner) {} | 226 owner_(owner) {} |
| 226 | 227 |
| 227 DownloadFileWithDelay::~DownloadFileWithDelay() {} | 228 DownloadFileWithDelay::~DownloadFileWithDelay() {} |
| 228 | 229 |
| 229 void DownloadFileWithDelay::RenameAndUniquify( | 230 void DownloadFileWithDelay::RenameAndUniquify( |
| 230 const base::FilePath& full_path, | 231 const base::FilePath& full_path, |
| 231 const RenameCompletionCallback& callback) { | 232 const RenameCompletionCallback& callback) { |
| 232 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 233 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
| 233 DownloadFileImpl::RenameAndUniquify( | 234 DownloadFileImpl::RenameAndUniquify( |
| 234 full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper, | 235 full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper, |
| 235 owner_, callback)); | 236 owner_, callback)); |
| 236 } | 237 } |
| 237 | 238 |
| 238 void DownloadFileWithDelay::RenameAndAnnotate( | 239 void DownloadFileWithDelay::RenameAndAnnotate( |
| 239 const base::FilePath& full_path, | 240 const base::FilePath& full_path, |
| 240 const std::string& client_guid, | 241 const std::string& client_guid, |
| 241 const GURL& source_url, | 242 const GURL& source_url, |
| 242 const GURL& referrer_url, | 243 const GURL& referrer_url, |
| 243 const RenameCompletionCallback& callback) { | 244 const RenameCompletionCallback& callback) { |
| 244 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 245 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
| 245 DownloadFileImpl::RenameAndAnnotate( | 246 DownloadFileImpl::RenameAndAnnotate( |
| 246 full_path, | 247 full_path, |
| 247 client_guid, | 248 client_guid, |
| 248 source_url, | 249 source_url, |
| 249 referrer_url, | 250 referrer_url, |
| 250 base::Bind( | 251 base::Bind( |
| 251 DownloadFileWithDelay::RenameCallbackWrapper, owner_, callback)); | 252 DownloadFileWithDelay::RenameCallbackWrapper, owner_, callback)); |
| 252 } | 253 } |
| 253 | 254 |
| 254 // static | 255 // static |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 std::unique_ptr<ByteStreamReader> stream, | 315 std::unique_ptr<ByteStreamReader> stream, |
| 315 const net::NetLogWithSource& net_log, | 316 const net::NetLogWithSource& net_log, |
| 316 base::WeakPtr<DownloadDestinationObserver> observer) | 317 base::WeakPtr<DownloadDestinationObserver> observer) |
| 317 : DownloadFileImpl(std::move(save_info), | 318 : DownloadFileImpl(std::move(save_info), |
| 318 default_downloads_directory, | 319 default_downloads_directory, |
| 319 std::move(stream), | 320 std::move(stream), |
| 320 net_log, | 321 net_log, |
| 321 observer) {} | 322 observer) {} |
| 322 | 323 |
| 323 ~CountingDownloadFile() override { | 324 ~CountingDownloadFile() override { |
| 324 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 325 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
| 325 active_files_--; | 326 active_files_--; |
| 326 } | 327 } |
| 327 | 328 |
| 328 void Initialize( | 329 void Initialize( |
| 329 const InitializeCallback& callback, | 330 const InitializeCallback& callback, |
| 330 const CancelRequestCallback& cancel_request_callback, | 331 const CancelRequestCallback& cancel_request_callback, |
| 331 const DownloadItem::ReceivedSlices& received_slices, | 332 const DownloadItem::ReceivedSlices& received_slices, |
| 332 bool is_parallelizable) override { | 333 bool is_parallelizable) override { |
| 333 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 334 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
| 334 active_files_++; | 335 active_files_++; |
| 335 DownloadFileImpl::Initialize(callback, cancel_request_callback, | 336 DownloadFileImpl::Initialize(callback, cancel_request_callback, |
| 336 received_slices, is_parallelizable); | 337 received_slices, is_parallelizable); |
| 337 } | 338 } |
| 338 | 339 |
| 339 static void GetNumberActiveFiles(int* result) { | 340 static void GetNumberActiveFiles(int* result) { |
| 340 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 341 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
| 341 *result = active_files_; | 342 *result = active_files_; |
| 342 } | 343 } |
| 343 | 344 |
| 344 // Can be called on any thread, and will block (running message loop) | 345 // Can be called on any thread, and will block (running message loop) |
| 345 // until data is returned. | 346 // until data is returned. |
| 346 static int GetNumberActiveFilesFromFileThread() { | 347 static int GetNumberActiveFilesFromFileThread() { |
| 347 int result = -1; | 348 int result = -1; |
| 348 BrowserThread::PostTaskAndReply( | 349 GetDownloadTaskRunner()->PostTaskAndReply( |
| 349 BrowserThread::FILE, FROM_HERE, | 350 FROM_HERE, |
| 350 base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result), | 351 base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result), |
| 351 base::MessageLoop::current()->QuitWhenIdleClosure()); | 352 base::MessageLoop::current()->QuitWhenIdleClosure()); |
| 352 base::RunLoop().Run(); | 353 base::RunLoop().Run(); |
| 353 DCHECK_NE(-1, result); | 354 DCHECK_NE(-1, result); |
| 354 return result; | 355 return result; |
| 355 } | 356 } |
| 356 | 357 |
| 357 private: | 358 private: |
| 358 static int active_files_; | 359 static int active_files_; |
| 359 }; | 360 }; |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 899 // Wait until the second (final) rename callback is posted. | 900 // Wait until the second (final) rename callback is posted. |
| 900 file_factory->WaitForSomeCallback(); | 901 file_factory->WaitForSomeCallback(); |
| 901 file_factory->GetAllRenameCallbacks(&callbacks); | 902 file_factory->GetAllRenameCallbacks(&callbacks); |
| 902 ASSERT_EQ(1u, callbacks.size()); | 903 ASSERT_EQ(1u, callbacks.size()); |
| 903 | 904 |
| 904 // Cancel it. | 905 // Cancel it. |
| 905 std::vector<DownloadItem*> items; | 906 std::vector<DownloadItem*> items; |
| 906 download_manager->GetAllDownloads(&items); | 907 download_manager->GetAllDownloads(&items); |
| 907 ASSERT_EQ(1u, items.size()); | 908 ASSERT_EQ(1u, items.size()); |
| 908 items[0]->Cancel(true); | 909 items[0]->Cancel(true); |
| 909 RunAllPendingInMessageLoop(); | 910 RunAllBlockingPoolTasksUntilIdle(); |
| 910 | 911 |
| 911 // Check state. | 912 // Check state. |
| 912 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); | 913 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); |
| 913 | 914 |
| 914 // Run final rename callback. | 915 // Run final rename callback. |
| 915 callbacks[0].Run(); | 916 callbacks[0].Run(); |
| 916 callbacks.clear(); | 917 callbacks.clear(); |
| 917 | 918 |
| 918 // Check state. | 919 // Check state. |
| 919 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); | 920 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1067 | 1068 |
| 1068 // Confirm download isn't complete yet. | 1069 // Confirm download isn't complete yet. |
| 1069 std::vector<DownloadItem*> items; | 1070 std::vector<DownloadItem*> items; |
| 1070 DownloadManagerForShell(shell())->GetAllDownloads(&items); | 1071 DownloadManagerForShell(shell())->GetAllDownloads(&items); |
| 1071 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); | 1072 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); |
| 1072 | 1073 |
| 1073 // Cancel the download; confirm cancel fails anyway. | 1074 // Cancel the download; confirm cancel fails anyway. |
| 1074 ASSERT_EQ(1u, items.size()); | 1075 ASSERT_EQ(1u, items.size()); |
| 1075 items[0]->Cancel(true); | 1076 items[0]->Cancel(true); |
| 1076 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); | 1077 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); |
| 1077 RunAllPendingInMessageLoop(); | 1078 RunAllBlockingPoolTasksUntilIdle(); |
| 1078 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); | 1079 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); |
| 1079 | 1080 |
| 1080 MockDownloadItemObserver observer; | 1081 MockDownloadItemObserver observer; |
| 1081 items[0]->AddObserver(&observer); | 1082 items[0]->AddObserver(&observer); |
| 1082 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); | 1083 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); |
| 1083 | 1084 |
| 1084 // Shutdown the download manager. Mostly this is confirming a lack of | 1085 // Shutdown the download manager. Mostly this is confirming a lack of |
| 1085 // crashes. | 1086 // crashes. |
| 1086 DownloadManagerForShell(shell())->Shutdown(); | 1087 DownloadManagerForShell(shell())->Shutdown(); |
| 1087 } | 1088 } |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1487 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 1488 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
| 1488 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 1489 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 1489 download->GetLastReason()); | 1490 download->GetLastReason()); |
| 1490 EXPECT_EQ(0, download->GetReceivedBytes()); | 1491 EXPECT_EQ(0, download->GetReceivedBytes()); |
| 1491 EXPECT_TRUE(download->GetFullPath().empty()); | 1492 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1492 EXPECT_FALSE(download->GetTargetFilePath().empty()); | 1493 EXPECT_FALSE(download->GetTargetFilePath().empty()); |
| 1493 | 1494 |
| 1494 // We need to make sure that any cross-thread downloads communication has | 1495 // We need to make sure that any cross-thread downloads communication has |
| 1495 // quiesced before clearing and injecting the new errors, as the | 1496 // quiesced before clearing and injecting the new errors, as the |
| 1496 // InjectErrors() routine alters the currently in use download file | 1497 // InjectErrors() routine alters the currently in use download file |
| 1497 // factory, which is a file thread object. | 1498 // factory, which is a file thread object. |
|
gab
2017/07/20 16:54:31
rm mention to "file thread"
Sigurður Ásgeirsson
2017/07/20 17:23:21
Done.
| |
| 1498 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1499 RunAllBlockingPoolTasksUntilIdle(); |
| 1499 RunAllPendingInMessageLoop(); | |
| 1500 | 1500 |
| 1501 // Clear the old errors list. | 1501 // Clear the old errors list. |
| 1502 injector->ClearError(); | 1502 injector->ClearError(); |
| 1503 | 1503 |
| 1504 // Resume and watch completion. | 1504 // Resume and watch completion. |
| 1505 download->Resume(); | 1505 download->Resume(); |
| 1506 WaitForCompletion(download); | 1506 WaitForCompletion(download); |
| 1507 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1507 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
| 1508 } | 1508 } |
| 1509 | 1509 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1530 download->GetLastReason()); | 1530 download->GetLastReason()); |
| 1531 EXPECT_TRUE(download->GetFullPath().empty()); | 1531 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1532 // Target path will have been set after file name determination. GetFullPath() | 1532 // Target path will have been set after file name determination. GetFullPath() |
| 1533 // being empty is sufficient to signal that filename determination needs to be | 1533 // being empty is sufficient to signal that filename determination needs to be |
| 1534 // redone. | 1534 // redone. |
| 1535 EXPECT_FALSE(download->GetTargetFilePath().empty()); | 1535 EXPECT_FALSE(download->GetTargetFilePath().empty()); |
| 1536 | 1536 |
| 1537 // We need to make sure that any cross-thread downloads communication has | 1537 // We need to make sure that any cross-thread downloads communication has |
| 1538 // quiesced before clearing and injecting the new errors, as the | 1538 // quiesced before clearing and injecting the new errors, as the |
| 1539 // InjectErrors() routine alters the currently in use download file | 1539 // InjectErrors() routine alters the currently in use download file |
| 1540 // factory, which is a file thread object. | 1540 // factory, which is a file thread object. |
|
gab
2017/07/20 16:54:31
ditto
Sigurður Ásgeirsson
2017/07/20 17:23:21
Done.
| |
| 1541 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1541 RunAllBlockingPoolTasksUntilIdle(); |
| 1542 RunAllPendingInMessageLoop(); | |
| 1543 | 1542 |
| 1544 // Clear the old errors list. | 1543 // Clear the old errors list. |
| 1545 injector->ClearError(); | 1544 injector->ClearError(); |
| 1546 | 1545 |
| 1547 download->Resume(); | 1546 download->Resume(); |
| 1548 WaitForCompletion(download); | 1547 WaitForCompletion(download); |
| 1549 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1548 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
| 1550 } | 1549 } |
| 1551 | 1550 |
| 1552 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RecoverFromFinalRenameError) { | 1551 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RecoverFromFinalRenameError) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1568 WaitForInterrupt(download); | 1567 WaitForInterrupt(download); |
| 1569 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 1568 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
| 1570 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, download->GetLastReason()); | 1569 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, download->GetLastReason()); |
| 1571 EXPECT_TRUE(download->GetFullPath().empty()); | 1570 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1572 // Target path should still be intact. | 1571 // Target path should still be intact. |
| 1573 EXPECT_FALSE(download->GetTargetFilePath().empty()); | 1572 EXPECT_FALSE(download->GetTargetFilePath().empty()); |
| 1574 | 1573 |
| 1575 // We need to make sure that any cross-thread downloads communication has | 1574 // We need to make sure that any cross-thread downloads communication has |
| 1576 // quiesced before clearing and injecting the new errors, as the | 1575 // quiesced before clearing and injecting the new errors, as the |
| 1577 // InjectErrors() routine alters the currently in use download file | 1576 // InjectErrors() routine alters the currently in use download file |
| 1578 // factory, which is a file thread object. | 1577 // factory, which is a download sequence object. |
| 1579 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1578 RunAllBlockingPoolTasksUntilIdle(); |
| 1580 RunAllPendingInMessageLoop(); | |
| 1581 | 1579 |
| 1582 // Clear the old errors list. | 1580 // Clear the old errors list. |
| 1583 injector->ClearError(); | 1581 injector->ClearError(); |
| 1584 | 1582 |
| 1585 download->Resume(); | 1583 download->Resume(); |
| 1586 WaitForCompletion(download); | 1584 WaitForCompletion(download); |
| 1587 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1585 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
| 1588 } | 1586 } |
| 1589 | 1587 |
| 1590 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Resume_Hash) { | 1588 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Resume_Hash) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1648 | 1646 |
| 1649 DownloadItem* download = | 1647 DownloadItem* download = |
| 1650 StartDownloadAndReturnItem(shell(), request_handler.url()); | 1648 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1651 WaitForInterrupt(download); | 1649 WaitForInterrupt(download); |
| 1652 | 1650 |
| 1653 base::FilePath intermediate_path = download->GetFullPath(); | 1651 base::FilePath intermediate_path = download->GetFullPath(); |
| 1654 ASSERT_FALSE(intermediate_path.empty()); | 1652 ASSERT_FALSE(intermediate_path.empty()); |
| 1655 ASSERT_TRUE(PathExists(intermediate_path)); | 1653 ASSERT_TRUE(PathExists(intermediate_path)); |
| 1656 | 1654 |
| 1657 download->Cancel(true /* user_cancel */); | 1655 download->Cancel(true /* user_cancel */); |
| 1658 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1656 RunAllBlockingPoolTasksUntilIdle(); |
| 1659 RunAllPendingInMessageLoop(); | |
| 1660 | 1657 |
| 1661 // The intermediate file should now be gone. | 1658 // The intermediate file should now be gone. |
| 1662 EXPECT_FALSE(PathExists(intermediate_path)); | 1659 EXPECT_FALSE(PathExists(intermediate_path)); |
| 1663 EXPECT_TRUE(download->GetFullPath().empty()); | 1660 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1664 } | 1661 } |
| 1665 | 1662 |
| 1666 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveInterruptedDownload) { | 1663 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveInterruptedDownload) { |
| 1667 TestDownloadRequestHandler request_handler; | 1664 TestDownloadRequestHandler request_handler; |
| 1668 request_handler.StartServing( | 1665 request_handler.StartServing( |
| 1669 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); | 1666 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); |
| 1670 | 1667 |
| 1671 DownloadItem* download = | 1668 DownloadItem* download = |
| 1672 StartDownloadAndReturnItem(shell(), request_handler.url()); | 1669 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1673 WaitForInterrupt(download); | 1670 WaitForInterrupt(download); |
| 1674 | 1671 |
| 1675 base::FilePath intermediate_path = download->GetFullPath(); | 1672 base::FilePath intermediate_path = download->GetFullPath(); |
| 1676 ASSERT_FALSE(intermediate_path.empty()); | 1673 ASSERT_FALSE(intermediate_path.empty()); |
| 1677 ASSERT_TRUE(PathExists(intermediate_path)); | 1674 ASSERT_TRUE(PathExists(intermediate_path)); |
| 1678 | 1675 |
| 1679 download->Remove(); | 1676 download->Remove(); |
| 1680 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1677 RunAllBlockingPoolTasksUntilIdle(); |
| 1681 RunAllPendingInMessageLoop(); | |
| 1682 | 1678 |
| 1683 // The intermediate file should now be gone. | 1679 // The intermediate file should now be gone. |
| 1684 EXPECT_FALSE(PathExists(intermediate_path)); | 1680 EXPECT_FALSE(PathExists(intermediate_path)); |
| 1685 } | 1681 } |
| 1686 | 1682 |
| 1687 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveCompletedDownload) { | 1683 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveCompletedDownload) { |
| 1688 // A completed download shouldn't delete the downloaded file when it is | 1684 // A completed download shouldn't delete the downloaded file when it is |
| 1689 // removed. | 1685 // removed. |
| 1690 TestDownloadRequestHandler request_handler; | 1686 TestDownloadRequestHandler request_handler; |
| 1691 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); | 1687 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); |
| 1692 std::unique_ptr<DownloadTestObserver> completion_observer( | 1688 std::unique_ptr<DownloadTestObserver> completion_observer( |
| 1693 CreateWaiter(shell(), 1)); | 1689 CreateWaiter(shell(), 1)); |
| 1694 DownloadItem* download( | 1690 DownloadItem* download( |
| 1695 StartDownloadAndReturnItem(shell(), request_handler.url())); | 1691 StartDownloadAndReturnItem(shell(), request_handler.url())); |
| 1696 completion_observer->WaitForFinished(); | 1692 completion_observer->WaitForFinished(); |
| 1697 | 1693 |
| 1698 // The target path should exist. | 1694 // The target path should exist. |
| 1699 base::FilePath target_path(download->GetTargetFilePath()); | 1695 base::FilePath target_path(download->GetTargetFilePath()); |
| 1700 EXPECT_TRUE(PathExists(target_path)); | 1696 EXPECT_TRUE(PathExists(target_path)); |
| 1701 download->Remove(); | 1697 download->Remove(); |
| 1702 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1698 RunAllBlockingPoolTasksUntilIdle(); |
| 1703 RunAllPendingInMessageLoop(); | |
| 1704 | 1699 |
| 1705 // The file should still exist. | 1700 // The file should still exist. |
| 1706 EXPECT_TRUE(PathExists(target_path)); | 1701 EXPECT_TRUE(PathExists(target_path)); |
| 1707 } | 1702 } |
| 1708 | 1703 |
| 1709 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) { | 1704 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) { |
| 1710 TestDownloadRequestHandler::Parameters parameters = | 1705 TestDownloadRequestHandler::Parameters parameters = |
| 1711 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1706 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1712 TestDownloadRequestHandler request_handler; | 1707 TestDownloadRequestHandler request_handler; |
| 1713 request_handler.StartServing(parameters); | 1708 request_handler.StartServing(parameters); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1732 download->Resume(); | 1727 download->Resume(); |
| 1733 request_start_handler.WaitForCallback(); | 1728 request_start_handler.WaitForCallback(); |
| 1734 | 1729 |
| 1735 // At this point, the download resumption request has been sent out, but the | 1730 // At this point, the download resumption request has been sent out, but the |
| 1736 // reponse hasn't been received yet. | 1731 // reponse hasn't been received yet. |
| 1737 download->Remove(); | 1732 download->Remove(); |
| 1738 | 1733 |
| 1739 request_start_handler.RespondWith(std::string(), net::OK); | 1734 request_start_handler.RespondWith(std::string(), net::OK); |
| 1740 | 1735 |
| 1741 // The intermediate file should now be gone. | 1736 // The intermediate file should now be gone. |
| 1742 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1737 RunAllBlockingPoolTasksUntilIdle(); |
| 1743 RunAllPendingInMessageLoop(); | |
| 1744 EXPECT_FALSE(PathExists(intermediate_path)); | 1738 EXPECT_FALSE(PathExists(intermediate_path)); |
| 1745 | 1739 |
| 1746 parameters.ClearInjectedErrors(); | 1740 parameters.ClearInjectedErrors(); |
| 1747 parameters.on_start_handler.Reset(); | 1741 parameters.on_start_handler.Reset(); |
| 1748 request_handler.StartServing(parameters); | 1742 request_handler.StartServing(parameters); |
| 1749 | 1743 |
| 1750 // Start the second download and wait until it's done. This exercises the | 1744 // Start the second download and wait until it's done. This exercises the |
| 1751 // entire downloads stack and effectively flushes all of our worker threads. | 1745 // entire downloads stack and effectively flushes all of our worker threads. |
| 1752 // We are testing whether the URL request created in the previous | 1746 // We are testing whether the URL request created in the previous |
| 1753 // DownloadItem::Resume() call reulted in a new download or not. | 1747 // DownloadItem::Resume() call reulted in a new download or not. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1783 request_start_handler.WaitForCallback(); | 1777 request_start_handler.WaitForCallback(); |
| 1784 | 1778 |
| 1785 // At this point, the download item has initiated a network request for the | 1779 // At this point, the download item has initiated a network request for the |
| 1786 // resumption attempt, but hasn't received a response yet. | 1780 // resumption attempt, but hasn't received a response yet. |
| 1787 download->Cancel(true /* user_cancel */); | 1781 download->Cancel(true /* user_cancel */); |
| 1788 | 1782 |
| 1789 request_start_handler.RespondWith(std::string(), net::OK); | 1783 request_start_handler.RespondWith(std::string(), net::OK); |
| 1790 | 1784 |
| 1791 // The intermediate file should now be gone. | 1785 // The intermediate file should now be gone. |
| 1792 RunAllPendingInMessageLoop(BrowserThread::IO); | 1786 RunAllPendingInMessageLoop(BrowserThread::IO); |
| 1793 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1787 RunAllBlockingPoolTasksUntilIdle(); |
| 1794 RunAllPendingInMessageLoop(); | |
| 1795 EXPECT_FALSE(PathExists(intermediate_path)); | 1788 EXPECT_FALSE(PathExists(intermediate_path)); |
| 1796 | 1789 |
| 1797 parameters.ClearInjectedErrors(); | 1790 parameters.ClearInjectedErrors(); |
| 1798 parameters.on_start_handler.Reset(); | 1791 parameters.on_start_handler.Reset(); |
| 1799 request_handler.StartServing(parameters); | 1792 request_handler.StartServing(parameters); |
| 1800 | 1793 |
| 1801 // Start the second download and wait until it's done. This exercises the | 1794 // Start the second download and wait until it's done. This exercises the |
| 1802 // entire downloads stack and effectively flushes all of our worker threads. | 1795 // entire downloads stack and effectively flushes all of our worker threads. |
| 1803 // We are testing whether the URL request created in the previous | 1796 // We are testing whether the URL request created in the previous |
| 1804 // DownloadItem::Resume() call reulted in a new download or not. | 1797 // DownloadItem::Resume() call reulted in a new download or not. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1826 // Resume and remove download. We don't expect OnDownloadCreated() calls. | 1819 // Resume and remove download. We don't expect OnDownloadCreated() calls. |
| 1827 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); | 1820 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); |
| 1828 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0); | 1821 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0); |
| 1829 | 1822 |
| 1830 download->Resume(); | 1823 download->Resume(); |
| 1831 WaitForInProgress(download); | 1824 WaitForInProgress(download); |
| 1832 | 1825 |
| 1833 download->Remove(); | 1826 download->Remove(); |
| 1834 | 1827 |
| 1835 // The intermediate file should now be gone. | 1828 // The intermediate file should now be gone. |
| 1836 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1829 RunAllBlockingPoolTasksUntilIdle(); |
| 1837 RunAllPendingInMessageLoop(); | |
| 1838 EXPECT_FALSE(PathExists(intermediate_path)); | 1830 EXPECT_FALSE(PathExists(intermediate_path)); |
| 1839 EXPECT_FALSE(PathExists(target_path)); | 1831 EXPECT_FALSE(PathExists(target_path)); |
| 1840 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1832 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1841 } | 1833 } |
| 1842 | 1834 |
| 1843 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumedDownload) { | 1835 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumedDownload) { |
| 1844 TestDownloadRequestHandler::Parameters parameters = | 1836 TestDownloadRequestHandler::Parameters parameters = |
| 1845 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1837 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1846 TestDownloadRequestHandler request_handler; | 1838 TestDownloadRequestHandler request_handler; |
| 1847 request_handler.StartServing(parameters); | 1839 request_handler.StartServing(parameters); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1859 // Resume and remove download. We don't expect OnDownloadCreated() calls. | 1851 // Resume and remove download. We don't expect OnDownloadCreated() calls. |
| 1860 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); | 1852 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); |
| 1861 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0); | 1853 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0); |
| 1862 | 1854 |
| 1863 download->Resume(); | 1855 download->Resume(); |
| 1864 WaitForInProgress(download); | 1856 WaitForInProgress(download); |
| 1865 | 1857 |
| 1866 download->Cancel(true); | 1858 download->Cancel(true); |
| 1867 | 1859 |
| 1868 // The intermediate file should now be gone. | 1860 // The intermediate file should now be gone. |
| 1869 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1861 RunAllBlockingPoolTasksUntilIdle(); |
| 1870 RunAllPendingInMessageLoop(); | |
| 1871 EXPECT_FALSE(PathExists(intermediate_path)); | 1862 EXPECT_FALSE(PathExists(intermediate_path)); |
| 1872 EXPECT_FALSE(PathExists(target_path)); | 1863 EXPECT_FALSE(PathExists(target_path)); |
| 1873 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1864 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1874 } | 1865 } |
| 1875 | 1866 |
| 1876 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoFile) { | 1867 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoFile) { |
| 1877 TestDownloadRequestHandler request_handler; | 1868 TestDownloadRequestHandler request_handler; |
| 1878 TestDownloadRequestHandler::Parameters parameters; | 1869 TestDownloadRequestHandler::Parameters parameters; |
| 1879 request_handler.StartServing(parameters); | 1870 request_handler.StartServing(parameters); |
| 1880 | 1871 |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2772 | 2763 |
| 2773 std::vector<DownloadItem*> downloads; | 2764 std::vector<DownloadItem*> downloads; |
| 2774 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 2765 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 2775 ASSERT_EQ(1u, downloads.size()); | 2766 ASSERT_EQ(1u, downloads.size()); |
| 2776 | 2767 |
| 2777 EXPECT_EQ(FILE_PATH_LITERAL("foo"), | 2768 EXPECT_EQ(FILE_PATH_LITERAL("foo"), |
| 2778 downloads[0]->GetTargetFilePath().BaseName().value()); | 2769 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 2779 } | 2770 } |
| 2780 | 2771 |
| 2781 } // namespace content | 2772 } // namespace content |
| OLD | NEW |