| 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 "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 void DownloadFileWithDelayFactory::WaitForSomeCallback() { | 229 void DownloadFileWithDelayFactory::WaitForSomeCallback() { |
| 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 231 | 231 |
| 232 if (rename_callbacks_.empty()) { | 232 if (rename_callbacks_.empty()) { |
| 233 waiting_ = true; | 233 waiting_ = true; |
| 234 RunMessageLoop(); | 234 RunMessageLoop(); |
| 235 waiting_ = false; | 235 waiting_ = false; |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 bool WasPersisted(DownloadItem* item) { | |
| 240 return item->IsPersisted(); | |
| 241 } | |
| 242 | |
| 243 class CountingDownloadFile : public DownloadFileImpl { | 239 class CountingDownloadFile : public DownloadFileImpl { |
| 244 public: | 240 public: |
| 245 CountingDownloadFile( | 241 CountingDownloadFile( |
| 246 scoped_ptr<DownloadSaveInfo> save_info, | 242 scoped_ptr<DownloadSaveInfo> save_info, |
| 247 const FilePath& default_downloads_directory, | 243 const FilePath& default_downloads_directory, |
| 248 const GURL& url, | 244 const GURL& url, |
| 249 const GURL& referrer_url, | 245 const GURL& referrer_url, |
| 250 bool calculate_hash, | 246 bool calculate_hash, |
| 251 scoped_ptr<ByteStreamReader> stream, | 247 scoped_ptr<ByteStreamReader> stream, |
| 252 const net::BoundNetLog& bound_net_log, | 248 const net::BoundNetLog& bound_net_log, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 // we're in the expected state. | 461 // we're in the expected state. |
| 466 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1)); | 462 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1)); |
| 467 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 463 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 468 observer->WaitForFinished(); | 464 observer->WaitForFinished(); |
| 469 | 465 |
| 470 std::vector<DownloadItem*> downloads; | 466 std::vector<DownloadItem*> downloads; |
| 471 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 467 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 472 ASSERT_EQ(1u, downloads.size()); | 468 ASSERT_EQ(1u, downloads.size()); |
| 473 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | 469 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
| 474 | 470 |
| 475 // Wait for it to be persisted. | |
| 476 DownloadUpdatedObserver( | |
| 477 downloads[0], base::Bind(&WasPersisted)).WaitForEvent(); | |
| 478 | |
| 479 // Cancel the download and wait for download system quiesce. | 471 // Cancel the download and wait for download system quiesce. |
| 480 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 472 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 481 scoped_refptr<DownloadTestFlushObserver> flush_observer( | 473 scoped_refptr<DownloadTestFlushObserver> flush_observer( |
| 482 new DownloadTestFlushObserver(DownloadManagerForShell(shell()))); | 474 new DownloadTestFlushObserver(DownloadManagerForShell(shell()))); |
| 483 flush_observer->WaitForFlush(); | 475 flush_observer->WaitForFlush(); |
| 484 | 476 |
| 485 // Get the important info from other threads and check it. | 477 // Get the important info from other threads and check it. |
| 486 EXPECT_TRUE(EnsureNoPendingDownloads()); | 478 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 487 } | 479 } |
| 488 | 480 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1)); | 644 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1)); |
| 653 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 645 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 654 observer->WaitForFinished(); | 646 observer->WaitForFinished(); |
| 655 | 647 |
| 656 // Get the item. | 648 // Get the item. |
| 657 std::vector<DownloadItem*> items; | 649 std::vector<DownloadItem*> items; |
| 658 DownloadManagerForShell(shell())->GetAllDownloads(&items); | 650 DownloadManagerForShell(shell())->GetAllDownloads(&items); |
| 659 ASSERT_EQ(1u, items.size()); | 651 ASSERT_EQ(1u, items.size()); |
| 660 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); | 652 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); |
| 661 | 653 |
| 662 // Wait for it to be persisted. | |
| 663 DownloadUpdatedObserver(items[0], base::Bind(&WasPersisted)).WaitForEvent(); | |
| 664 | |
| 665 // Shutdown the download manager and make sure we get the right | 654 // Shutdown the download manager and make sure we get the right |
| 666 // notifications in the right order. | 655 // notifications in the right order. |
| 667 StrictMock<MockDownloadItemObserver> item_observer; | 656 StrictMock<MockDownloadItemObserver> item_observer; |
| 668 items[0]->AddObserver(&item_observer); | 657 items[0]->AddObserver(&item_observer); |
| 669 MockDownloadManagerObserver manager_observer; | 658 MockDownloadManagerObserver manager_observer; |
| 670 // Don't care about ModelChanged() events. | 659 // Don't care about ModelChanged() events. |
| 671 EXPECT_CALL(manager_observer, ModelChanged(_)) | 660 EXPECT_CALL(manager_observer, ModelChanged(_)) |
| 672 .WillRepeatedly(Return()); | 661 .WillRepeatedly(Return()); |
| 673 DownloadManagerForShell(shell())->AddObserver(&manager_observer); | 662 DownloadManagerForShell(shell())->AddObserver(&manager_observer); |
| 674 { | 663 { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 MockDownloadItemObserver observer; | 727 MockDownloadItemObserver observer; |
| 739 items[0]->AddObserver(&observer); | 728 items[0]->AddObserver(&observer); |
| 740 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); | 729 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); |
| 741 | 730 |
| 742 // Shutdown the download manager. Mostly this is confirming a lack of | 731 // Shutdown the download manager. Mostly this is confirming a lack of |
| 743 // crashes. | 732 // crashes. |
| 744 DownloadManagerForShell(shell())->Shutdown(); | 733 DownloadManagerForShell(shell())->Shutdown(); |
| 745 } | 734 } |
| 746 | 735 |
| 747 } // namespace content | 736 } // namespace content |
| OLD | NEW |