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

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

Issue 2890853002: Downloads: replace BrowserThread::FILE with task scheduler. (Closed)
Patch Set: Add a missing mock expectation. Created 3 years, 6 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
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 <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
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
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 13 matching lines...) Expand all
268 weak_ptr_factory_(this) {} 269 weak_ptr_factory_(this) {}
269 270
270 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} 271 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {}
271 272
272 DownloadFile* DownloadFileWithDelayFactory::CreateFile( 273 DownloadFile* DownloadFileWithDelayFactory::CreateFile(
273 std::unique_ptr<DownloadSaveInfo> save_info, 274 std::unique_ptr<DownloadSaveInfo> save_info,
274 const base::FilePath& default_download_directory, 275 const base::FilePath& default_download_directory,
275 std::unique_ptr<ByteStreamReader> stream, 276 std::unique_ptr<ByteStreamReader> stream,
276 const net::NetLogWithSource& net_log, 277 const net::NetLogWithSource& net_log,
277 base::WeakPtr<DownloadDestinationObserver> observer) { 278 base::WeakPtr<DownloadDestinationObserver> observer) {
278 return new DownloadFileWithDelay(std::move(save_info), 279 return new DownloadFileWithDelay(
279 default_download_directory, 280 std::move(save_info), default_download_directory, std::move(stream),
280 std::move(stream), 281 net_log, observer, weak_ptr_factory_.GetWeakPtr());
281 net_log,
282 observer,
283 weak_ptr_factory_.GetWeakPtr());
284 } 282 }
285 283
286 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { 284 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) {
287 DCHECK_CURRENTLY_ON(BrowserThread::UI); 285 DCHECK_CURRENTLY_ON(BrowserThread::UI);
288 rename_callbacks_.push_back(callback); 286 rename_callbacks_.push_back(callback);
289 if (waiting_) 287 if (waiting_)
290 base::MessageLoopForUI::current()->QuitWhenIdle(); 288 base::MessageLoopForUI::current()->QuitWhenIdle();
291 } 289 }
292 290
293 void DownloadFileWithDelayFactory::GetAllRenameCallbacks( 291 void DownloadFileWithDelayFactory::GetAllRenameCallbacks(
(...skipping 20 matching lines...) Expand all
314 std::unique_ptr<ByteStreamReader> stream, 312 std::unique_ptr<ByteStreamReader> stream,
315 const net::NetLogWithSource& net_log, 313 const net::NetLogWithSource& net_log,
316 base::WeakPtr<DownloadDestinationObserver> observer) 314 base::WeakPtr<DownloadDestinationObserver> observer)
317 : DownloadFileImpl(std::move(save_info), 315 : DownloadFileImpl(std::move(save_info),
318 default_downloads_directory, 316 default_downloads_directory,
319 std::move(stream), 317 std::move(stream),
320 net_log, 318 net_log,
321 observer) {} 319 observer) {}
322 320
323 ~CountingDownloadFile() override { 321 ~CountingDownloadFile() override {
324 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 322 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
325 active_files_--; 323 active_files_--;
326 } 324 }
327 325
328 void Initialize( 326 void Initialize(
329 const InitializeCallback& callback, 327 const InitializeCallback& callback,
330 const CancelRequestCallback& cancel_request_callback, 328 const CancelRequestCallback& cancel_request_callback,
331 const DownloadItem::ReceivedSlices& received_slices, 329 const DownloadItem::ReceivedSlices& received_slices,
332 bool is_parallelizable) override { 330 bool is_parallelizable) override {
333 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 331 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
334 active_files_++; 332 active_files_++;
335 DownloadFileImpl::Initialize(callback, cancel_request_callback, 333 DownloadFileImpl::Initialize(callback, cancel_request_callback,
336 received_slices, is_parallelizable); 334 received_slices, is_parallelizable);
337 } 335 }
338 336
339 static void GetNumberActiveFiles(int* result) { 337 static void GetNumberActiveFiles(int* result) {
340 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 338 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
341 *result = active_files_; 339 *result = active_files_;
342 } 340 }
343 341
344 // Can be called on any thread, and will block (running message loop) 342 // Can be called on any thread, and will block (running message loop)
345 // until data is returned. 343 // until data is returned.
346 static int GetNumberActiveFilesFromFileThread() { 344 static int GetNumberActiveFilesFromFileThread() {
347 int result = -1; 345 int result = -1;
348 BrowserThread::PostTaskAndReply( 346 GetDownloadTaskRunner()->PostTaskAndReply(
349 BrowserThread::FILE, FROM_HERE, 347 FROM_HERE,
350 base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result), 348 base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result),
351 base::MessageLoop::current()->QuitWhenIdleClosure()); 349 base::MessageLoop::current()->QuitWhenIdleClosure());
352 base::RunLoop().Run(); 350 base::RunLoop().Run();
353 DCHECK_NE(-1, result); 351 DCHECK_NE(-1, result);
354 return result; 352 return result;
355 } 353 }
356 354
357 private: 355 private:
358 static int active_files_; 356 static int active_files_;
359 }; 357 };
360 358
361 int CountingDownloadFile::active_files_ = 0; 359 int CountingDownloadFile::active_files_ = 0;
362 360
363 class CountingDownloadFileFactory : public DownloadFileFactory { 361 class CountingDownloadFileFactory : public DownloadFileFactory {
364 public: 362 public:
365 CountingDownloadFileFactory() {} 363 CountingDownloadFileFactory() {}
366 ~CountingDownloadFileFactory() override {} 364 ~CountingDownloadFileFactory() override {}
367 365
368 // DownloadFileFactory interface. 366 // DownloadFileFactory interface.
369 DownloadFile* CreateFile( 367 DownloadFile* CreateFile(
370 std::unique_ptr<DownloadSaveInfo> save_info, 368 std::unique_ptr<DownloadSaveInfo> save_info,
371 const base::FilePath& default_downloads_directory, 369 const base::FilePath& default_downloads_directory,
372 std::unique_ptr<ByteStreamReader> stream, 370 std::unique_ptr<ByteStreamReader> stream,
373 const net::NetLogWithSource& net_log, 371 const net::NetLogWithSource& net_log,
374 base::WeakPtr<DownloadDestinationObserver> observer) override { 372 base::WeakPtr<DownloadDestinationObserver> observer) override {
375 return new CountingDownloadFile(std::move(save_info), 373 return new CountingDownloadFile(std::move(save_info),
376 default_downloads_directory, 374 default_downloads_directory,
377 std::move(stream), 375 std::move(stream), net_log, observer);
378 net_log,
379 observer);
380 } 376 }
381 }; 377 };
382 378
383 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { 379 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate {
384 public: 380 public:
385 TestShellDownloadManagerDelegate() 381 TestShellDownloadManagerDelegate()
386 : delay_download_open_(false) {} 382 : delay_download_open_(false) {}
387 ~TestShellDownloadManagerDelegate() override {} 383 ~TestShellDownloadManagerDelegate() override {}
388 384
389 bool ShouldOpenDownload( 385 bool ShouldOpenDownload(
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 // Wait until the second (final) rename callback is posted. 897 // Wait until the second (final) rename callback is posted.
902 file_factory->WaitForSomeCallback(); 898 file_factory->WaitForSomeCallback();
903 file_factory->GetAllRenameCallbacks(&callbacks); 899 file_factory->GetAllRenameCallbacks(&callbacks);
904 ASSERT_EQ(1u, callbacks.size()); 900 ASSERT_EQ(1u, callbacks.size());
905 901
906 // Cancel it. 902 // Cancel it.
907 std::vector<DownloadItem*> items; 903 std::vector<DownloadItem*> items;
908 download_manager->GetAllDownloads(&items); 904 download_manager->GetAllDownloads(&items);
909 ASSERT_EQ(1u, items.size()); 905 ASSERT_EQ(1u, items.size());
910 items[0]->Cancel(true); 906 items[0]->Cancel(true);
911 RunAllPendingInMessageLoop(); 907 RunAllBlockingPoolTasksUntilIdle();
912 908
913 // Check state. 909 // Check state.
914 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); 910 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState());
915 911
916 // Run final rename callback. 912 // Run final rename callback.
917 callbacks[0].Run(); 913 callbacks[0].Run();
918 callbacks.clear(); 914 callbacks.clear();
919 915
920 // Check state. 916 // Check state.
921 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); 917 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState());
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 1065
1070 // Confirm download isn't complete yet. 1066 // Confirm download isn't complete yet.
1071 std::vector<DownloadItem*> items; 1067 std::vector<DownloadItem*> items;
1072 DownloadManagerForShell(shell())->GetAllDownloads(&items); 1068 DownloadManagerForShell(shell())->GetAllDownloads(&items);
1073 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); 1069 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState());
1074 1070
1075 // Cancel the download; confirm cancel fails anyway. 1071 // Cancel the download; confirm cancel fails anyway.
1076 ASSERT_EQ(1u, items.size()); 1072 ASSERT_EQ(1u, items.size());
1077 items[0]->Cancel(true); 1073 items[0]->Cancel(true);
1078 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); 1074 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState());
1079 RunAllPendingInMessageLoop(); 1075 RunAllBlockingPoolTasksUntilIdle();
1080 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); 1076 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState());
1081 1077
1082 MockDownloadItemObserver observer; 1078 MockDownloadItemObserver observer;
1083 items[0]->AddObserver(&observer); 1079 items[0]->AddObserver(&observer);
1084 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); 1080 EXPECT_CALL(observer, OnDownloadDestroyed(items[0]));
1085 1081
1086 // Shutdown the download manager. Mostly this is confirming a lack of 1082 // Shutdown the download manager. Mostly this is confirming a lack of
1087 // crashes. 1083 // crashes.
1088 DownloadManagerForShell(shell())->Shutdown(); 1084 DownloadManagerForShell(shell())->Shutdown();
1089 } 1085 }
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 1486 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
1491 download->GetLastReason()); 1487 download->GetLastReason());
1492 EXPECT_EQ(0, download->GetReceivedBytes()); 1488 EXPECT_EQ(0, download->GetReceivedBytes());
1493 EXPECT_TRUE(download->GetFullPath().empty()); 1489 EXPECT_TRUE(download->GetFullPath().empty());
1494 EXPECT_FALSE(download->GetTargetFilePath().empty()); 1490 EXPECT_FALSE(download->GetTargetFilePath().empty());
1495 1491
1496 // We need to make sure that any cross-thread downloads communication has 1492 // We need to make sure that any cross-thread downloads communication has
1497 // quiesced before clearing and injecting the new errors, as the 1493 // quiesced before clearing and injecting the new errors, as the
1498 // InjectErrors() routine alters the currently in use download file 1494 // InjectErrors() routine alters the currently in use download file
1499 // factory, which is a file thread object. 1495 // factory, which is a file thread object.
1500 RunAllPendingInMessageLoop(BrowserThread::FILE); 1496 RunAllBlockingPoolTasksUntilIdle();
1501 RunAllPendingInMessageLoop();
1502 1497
1503 // Clear the old errors list. 1498 // Clear the old errors list.
1504 injector->ClearError(); 1499 injector->ClearError();
1505 1500
1506 // Resume and watch completion. 1501 // Resume and watch completion.
1507 download->Resume(); 1502 download->Resume();
1508 WaitForCompletion(download); 1503 WaitForCompletion(download);
1509 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); 1504 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE);
1510 } 1505 }
1511 1506
(...skipping 21 matching lines...) Expand all
1533 EXPECT_TRUE(download->GetFullPath().empty()); 1528 EXPECT_TRUE(download->GetFullPath().empty());
1534 // Target path will have been set after file name determination. GetFullPath() 1529 // Target path will have been set after file name determination. GetFullPath()
1535 // being empty is sufficient to signal that filename determination needs to be 1530 // being empty is sufficient to signal that filename determination needs to be
1536 // redone. 1531 // redone.
1537 EXPECT_FALSE(download->GetTargetFilePath().empty()); 1532 EXPECT_FALSE(download->GetTargetFilePath().empty());
1538 1533
1539 // We need to make sure that any cross-thread downloads communication has 1534 // We need to make sure that any cross-thread downloads communication has
1540 // quiesced before clearing and injecting the new errors, as the 1535 // quiesced before clearing and injecting the new errors, as the
1541 // InjectErrors() routine alters the currently in use download file 1536 // InjectErrors() routine alters the currently in use download file
1542 // factory, which is a file thread object. 1537 // factory, which is a file thread object.
1543 RunAllPendingInMessageLoop(BrowserThread::FILE); 1538 RunAllBlockingPoolTasksUntilIdle();
1544 RunAllPendingInMessageLoop();
1545 1539
1546 // Clear the old errors list. 1540 // Clear the old errors list.
1547 injector->ClearError(); 1541 injector->ClearError();
1548 1542
1549 download->Resume(); 1543 download->Resume();
1550 WaitForCompletion(download); 1544 WaitForCompletion(download);
1551 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); 1545 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE);
1552 } 1546 }
1553 1547
1554 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RecoverFromFinalRenameError) { 1548 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RecoverFromFinalRenameError) {
(...skipping 15 matching lines...) Expand all
1570 WaitForInterrupt(download); 1564 WaitForInterrupt(download);
1571 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); 1565 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState());
1572 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, download->GetLastReason()); 1566 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, download->GetLastReason());
1573 EXPECT_TRUE(download->GetFullPath().empty()); 1567 EXPECT_TRUE(download->GetFullPath().empty());
1574 // Target path should still be intact. 1568 // Target path should still be intact.
1575 EXPECT_FALSE(download->GetTargetFilePath().empty()); 1569 EXPECT_FALSE(download->GetTargetFilePath().empty());
1576 1570
1577 // We need to make sure that any cross-thread downloads communication has 1571 // We need to make sure that any cross-thread downloads communication has
1578 // quiesced before clearing and injecting the new errors, as the 1572 // quiesced before clearing and injecting the new errors, as the
1579 // InjectErrors() routine alters the currently in use download file 1573 // InjectErrors() routine alters the currently in use download file
1580 // factory, which is a file thread object. 1574 // factory, which is a file thread object.
gab 2017/06/21 19:42:24 update reference to "file thread"
Sigurður Ásgeirsson 2017/06/22 14:50:06 Done.
1581 RunAllPendingInMessageLoop(BrowserThread::FILE); 1575 RunAllBlockingPoolTasksUntilIdle();
1582 RunAllPendingInMessageLoop();
1583 1576
1584 // Clear the old errors list. 1577 // Clear the old errors list.
1585 injector->ClearError(); 1578 injector->ClearError();
1586 1579
1587 download->Resume(); 1580 download->Resume();
1588 WaitForCompletion(download); 1581 WaitForCompletion(download);
1589 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); 1582 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE);
1590 } 1583 }
1591 1584
1592 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Resume_Hash) { 1585 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Resume_Hash) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 1643
1651 DownloadItem* download = 1644 DownloadItem* download =
1652 StartDownloadAndReturnItem(shell(), request_handler.url()); 1645 StartDownloadAndReturnItem(shell(), request_handler.url());
1653 WaitForInterrupt(download); 1646 WaitForInterrupt(download);
1654 1647
1655 base::FilePath intermediate_path = download->GetFullPath(); 1648 base::FilePath intermediate_path = download->GetFullPath();
1656 ASSERT_FALSE(intermediate_path.empty()); 1649 ASSERT_FALSE(intermediate_path.empty());
1657 ASSERT_TRUE(PathExists(intermediate_path)); 1650 ASSERT_TRUE(PathExists(intermediate_path));
1658 1651
1659 download->Cancel(true /* user_cancel */); 1652 download->Cancel(true /* user_cancel */);
1660 RunAllPendingInMessageLoop(BrowserThread::FILE); 1653 RunAllBlockingPoolTasksUntilIdle();
1661 RunAllPendingInMessageLoop();
1662 1654
1663 // The intermediate file should now be gone. 1655 // The intermediate file should now be gone.
1664 EXPECT_FALSE(PathExists(intermediate_path)); 1656 EXPECT_FALSE(PathExists(intermediate_path));
1665 EXPECT_TRUE(download->GetFullPath().empty()); 1657 EXPECT_TRUE(download->GetFullPath().empty());
1666 } 1658 }
1667 1659
1668 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveInterruptedDownload) { 1660 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveInterruptedDownload) {
1669 TestDownloadRequestHandler request_handler; 1661 TestDownloadRequestHandler request_handler;
1670 request_handler.StartServing( 1662 request_handler.StartServing(
1671 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); 1663 TestDownloadRequestHandler::Parameters::WithSingleInterruption());
1672 1664
1673 DownloadItem* download = 1665 DownloadItem* download =
1674 StartDownloadAndReturnItem(shell(), request_handler.url()); 1666 StartDownloadAndReturnItem(shell(), request_handler.url());
1675 WaitForInterrupt(download); 1667 WaitForInterrupt(download);
1676 1668
1677 base::FilePath intermediate_path = download->GetFullPath(); 1669 base::FilePath intermediate_path = download->GetFullPath();
1678 ASSERT_FALSE(intermediate_path.empty()); 1670 ASSERT_FALSE(intermediate_path.empty());
1679 ASSERT_TRUE(PathExists(intermediate_path)); 1671 ASSERT_TRUE(PathExists(intermediate_path));
1680 1672
1681 download->Remove(); 1673 download->Remove();
1682 RunAllPendingInMessageLoop(BrowserThread::FILE); 1674 RunAllBlockingPoolTasksUntilIdle();
1683 RunAllPendingInMessageLoop();
1684 1675
1685 // The intermediate file should now be gone. 1676 // The intermediate file should now be gone.
1686 EXPECT_FALSE(PathExists(intermediate_path)); 1677 EXPECT_FALSE(PathExists(intermediate_path));
1687 } 1678 }
1688 1679
1689 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveCompletedDownload) { 1680 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveCompletedDownload) {
1690 // A completed download shouldn't delete the downloaded file when it is 1681 // A completed download shouldn't delete the downloaded file when it is
1691 // removed. 1682 // removed.
1692 TestDownloadRequestHandler request_handler; 1683 TestDownloadRequestHandler request_handler;
1693 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); 1684 request_handler.StartServing(TestDownloadRequestHandler::Parameters());
1694 std::unique_ptr<DownloadTestObserver> completion_observer( 1685 std::unique_ptr<DownloadTestObserver> completion_observer(
1695 CreateWaiter(shell(), 1)); 1686 CreateWaiter(shell(), 1));
1696 DownloadItem* download( 1687 DownloadItem* download(
1697 StartDownloadAndReturnItem(shell(), request_handler.url())); 1688 StartDownloadAndReturnItem(shell(), request_handler.url()));
1698 completion_observer->WaitForFinished(); 1689 completion_observer->WaitForFinished();
1699 1690
1700 // The target path should exist. 1691 // The target path should exist.
1701 base::FilePath target_path(download->GetTargetFilePath()); 1692 base::FilePath target_path(download->GetTargetFilePath());
1702 EXPECT_TRUE(PathExists(target_path)); 1693 EXPECT_TRUE(PathExists(target_path));
1703 download->Remove(); 1694 download->Remove();
1704 RunAllPendingInMessageLoop(BrowserThread::FILE); 1695 RunAllBlockingPoolTasksUntilIdle();
1705 RunAllPendingInMessageLoop();
1706 1696
1707 // The file should still exist. 1697 // The file should still exist.
1708 EXPECT_TRUE(PathExists(target_path)); 1698 EXPECT_TRUE(PathExists(target_path));
1709 } 1699 }
1710 1700
1711 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) { 1701 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) {
1712 TestDownloadRequestHandler::Parameters parameters = 1702 TestDownloadRequestHandler::Parameters parameters =
1713 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); 1703 TestDownloadRequestHandler::Parameters::WithSingleInterruption();
1714 TestDownloadRequestHandler request_handler; 1704 TestDownloadRequestHandler request_handler;
1715 request_handler.StartServing(parameters); 1705 request_handler.StartServing(parameters);
(...skipping 18 matching lines...) Expand all
1734 download->Resume(); 1724 download->Resume();
1735 request_start_handler.WaitForCallback(); 1725 request_start_handler.WaitForCallback();
1736 1726
1737 // At this point, the download resumption request has been sent out, but the 1727 // At this point, the download resumption request has been sent out, but the
1738 // reponse hasn't been received yet. 1728 // reponse hasn't been received yet.
1739 download->Remove(); 1729 download->Remove();
1740 1730
1741 request_start_handler.RespondWith(std::string(), net::OK); 1731 request_start_handler.RespondWith(std::string(), net::OK);
1742 1732
1743 // The intermediate file should now be gone. 1733 // The intermediate file should now be gone.
1744 RunAllPendingInMessageLoop(BrowserThread::FILE); 1734 RunAllBlockingPoolTasksUntilIdle();
1745 RunAllPendingInMessageLoop();
1746 EXPECT_FALSE(PathExists(intermediate_path)); 1735 EXPECT_FALSE(PathExists(intermediate_path));
1747 1736
1748 parameters.ClearInjectedErrors(); 1737 parameters.ClearInjectedErrors();
1749 parameters.on_start_handler.Reset(); 1738 parameters.on_start_handler.Reset();
1750 request_handler.StartServing(parameters); 1739 request_handler.StartServing(parameters);
1751 1740
1752 // Start the second download and wait until it's done. This exercises the 1741 // Start the second download and wait until it's done. This exercises the
1753 // entire downloads stack and effectively flushes all of our worker threads. 1742 // entire downloads stack and effectively flushes all of our worker threads.
1754 // We are testing whether the URL request created in the previous 1743 // We are testing whether the URL request created in the previous
1755 // DownloadItem::Resume() call reulted in a new download or not. 1744 // DownloadItem::Resume() call reulted in a new download or not.
(...skipping 28 matching lines...) Expand all
1784 download->Resume(); 1773 download->Resume();
1785 request_start_handler.WaitForCallback(); 1774 request_start_handler.WaitForCallback();
1786 1775
1787 // At this point, the download item has initiated a network request for the 1776 // At this point, the download item has initiated a network request for the
1788 // resumption attempt, but hasn't received a response yet. 1777 // resumption attempt, but hasn't received a response yet.
1789 download->Cancel(true /* user_cancel */); 1778 download->Cancel(true /* user_cancel */);
1790 1779
1791 request_start_handler.RespondWith(std::string(), net::OK); 1780 request_start_handler.RespondWith(std::string(), net::OK);
1792 1781
1793 // The intermediate file should now be gone. 1782 // The intermediate file should now be gone.
1794 RunAllPendingInMessageLoop(BrowserThread::IO); 1783 RunAllBlockingPoolTasksUntilIdle();
1795 RunAllPendingInMessageLoop(BrowserThread::FILE);
1796 RunAllPendingInMessageLoop();
1797 EXPECT_FALSE(PathExists(intermediate_path)); 1784 EXPECT_FALSE(PathExists(intermediate_path));
1798 1785
1799 parameters.ClearInjectedErrors(); 1786 parameters.ClearInjectedErrors();
1800 parameters.on_start_handler.Reset(); 1787 parameters.on_start_handler.Reset();
1801 request_handler.StartServing(parameters); 1788 request_handler.StartServing(parameters);
1802 1789
1803 // Start the second download and wait until it's done. This exercises the 1790 // Start the second download and wait until it's done. This exercises the
1804 // entire downloads stack and effectively flushes all of our worker threads. 1791 // entire downloads stack and effectively flushes all of our worker threads.
1805 // We are testing whether the URL request created in the previous 1792 // We are testing whether the URL request created in the previous
1806 // DownloadItem::Resume() call reulted in a new download or not. 1793 // DownloadItem::Resume() call reulted in a new download or not.
(...skipping 21 matching lines...) Expand all
1828 // Resume and remove download. We don't expect OnDownloadCreated() calls. 1815 // Resume and remove download. We don't expect OnDownloadCreated() calls.
1829 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); 1816 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell()));
1830 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0); 1817 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0);
1831 1818
1832 download->Resume(); 1819 download->Resume();
1833 WaitForInProgress(download); 1820 WaitForInProgress(download);
1834 1821
1835 download->Remove(); 1822 download->Remove();
1836 1823
1837 // The intermediate file should now be gone. 1824 // The intermediate file should now be gone.
1838 RunAllPendingInMessageLoop(BrowserThread::FILE); 1825 RunAllBlockingPoolTasksUntilIdle();
1839 RunAllPendingInMessageLoop();
1840 EXPECT_FALSE(PathExists(intermediate_path)); 1826 EXPECT_FALSE(PathExists(intermediate_path));
1841 EXPECT_FALSE(PathExists(target_path)); 1827 EXPECT_FALSE(PathExists(target_path));
1842 EXPECT_TRUE(EnsureNoPendingDownloads()); 1828 EXPECT_TRUE(EnsureNoPendingDownloads());
1843 } 1829 }
1844 1830
1845 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumedDownload) { 1831 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumedDownload) {
1846 TestDownloadRequestHandler::Parameters parameters = 1832 TestDownloadRequestHandler::Parameters parameters =
1847 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); 1833 TestDownloadRequestHandler::Parameters::WithSingleInterruption();
1848 TestDownloadRequestHandler request_handler; 1834 TestDownloadRequestHandler request_handler;
1849 request_handler.StartServing(parameters); 1835 request_handler.StartServing(parameters);
(...skipping 11 matching lines...) Expand all
1861 // Resume and remove download. We don't expect OnDownloadCreated() calls. 1847 // Resume and remove download. We don't expect OnDownloadCreated() calls.
1862 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); 1848 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell()));
1863 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0); 1849 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0);
1864 1850
1865 download->Resume(); 1851 download->Resume();
1866 WaitForInProgress(download); 1852 WaitForInProgress(download);
1867 1853
1868 download->Cancel(true); 1854 download->Cancel(true);
1869 1855
1870 // The intermediate file should now be gone. 1856 // The intermediate file should now be gone.
1871 RunAllPendingInMessageLoop(BrowserThread::FILE); 1857 RunAllBlockingPoolTasksUntilIdle();
1872 RunAllPendingInMessageLoop();
1873 EXPECT_FALSE(PathExists(intermediate_path)); 1858 EXPECT_FALSE(PathExists(intermediate_path));
1874 EXPECT_FALSE(PathExists(target_path)); 1859 EXPECT_FALSE(PathExists(target_path));
1875 EXPECT_TRUE(EnsureNoPendingDownloads()); 1860 EXPECT_TRUE(EnsureNoPendingDownloads());
1876 } 1861 }
1877 1862
1878 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoFile) { 1863 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoFile) {
1879 TestDownloadRequestHandler request_handler; 1864 TestDownloadRequestHandler request_handler;
1880 TestDownloadRequestHandler::Parameters parameters; 1865 TestDownloadRequestHandler::Parameters parameters;
1881 request_handler.StartServing(parameters); 1866 request_handler.StartServing(parameters);
1882 1867
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
2753 2738
2754 std::vector<DownloadItem*> downloads; 2739 std::vector<DownloadItem*> downloads;
2755 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 2740 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
2756 ASSERT_EQ(1u, downloads.size()); 2741 ASSERT_EQ(1u, downloads.size());
2757 2742
2758 EXPECT_EQ(FILE_PATH_LITERAL("foo"), 2743 EXPECT_EQ(FILE_PATH_LITERAL("foo"),
2759 downloads[0]->GetTargetFilePath().BaseName().value()); 2744 downloads[0]->GetTargetFilePath().BaseName().value());
2760 } 2745 }
2761 2746
2762 } // namespace content 2747 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698