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/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 void DownloadFileWithDelayFactory::WaitForSomeCallback() { | 263 void DownloadFileWithDelayFactory::WaitForSomeCallback() { |
264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
265 | 265 |
266 if (rename_callbacks_.empty() && detach_callbacks_.empty()) { | 266 if (rename_callbacks_.empty() && detach_callbacks_.empty()) { |
267 waiting_ = true; | 267 waiting_ = true; |
268 RunMessageLoop(); | 268 RunMessageLoop(); |
269 waiting_ = false; | 269 waiting_ = false; |
270 } | 270 } |
271 } | 271 } |
272 | 272 |
273 bool WasPersisted(DownloadItem* item) { | |
274 return item->IsPersisted(); | |
275 } | |
276 | |
277 class CountingDownloadFile : public DownloadFileImpl { | 273 class CountingDownloadFile : public DownloadFileImpl { |
278 public: | 274 public: |
279 CountingDownloadFile( | 275 CountingDownloadFile( |
280 scoped_ptr<DownloadSaveInfo> save_info, | 276 scoped_ptr<DownloadSaveInfo> save_info, |
281 const FilePath& default_downloads_directory, | 277 const FilePath& default_downloads_directory, |
282 const GURL& url, | 278 const GURL& url, |
283 const GURL& referrer_url, | 279 const GURL& referrer_url, |
284 bool calculate_hash, | 280 bool calculate_hash, |
285 scoped_ptr<ByteStreamReader> stream, | 281 scoped_ptr<ByteStreamReader> stream, |
286 const net::BoundNetLog& bound_net_log, | 282 const net::BoundNetLog& bound_net_log, |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1)); | 663 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1)); |
668 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 664 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
669 observer->WaitForFinished(); | 665 observer->WaitForFinished(); |
670 | 666 |
671 // Get the item. | 667 // Get the item. |
672 std::vector<DownloadItem*> items; | 668 std::vector<DownloadItem*> items; |
673 DownloadManagerForShell(shell())->GetAllDownloads(&items); | 669 DownloadManagerForShell(shell())->GetAllDownloads(&items); |
674 ASSERT_EQ(1u, items.size()); | 670 ASSERT_EQ(1u, items.size()); |
675 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); | 671 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); |
676 | 672 |
677 // Wait for it to be persisted. | |
678 DownloadUpdatedObserver(items[0], base::Bind(&WasPersisted)).WaitForEvent(); | |
679 | |
680 // Shutdown the download manager and make sure we get the right | 673 // Shutdown the download manager and make sure we get the right |
681 // notifications in the right order. | 674 // notifications in the right order. |
682 StrictMock<MockDownloadItemObserver> item_observer; | 675 StrictMock<MockDownloadItemObserver> item_observer; |
683 items[0]->AddObserver(&item_observer); | 676 items[0]->AddObserver(&item_observer); |
684 MockDownloadManagerObserver manager_observer; | 677 MockDownloadManagerObserver manager_observer; |
685 // Don't care about ModelChanged() events. | 678 // Don't care about ModelChanged() events. |
686 EXPECT_CALL(manager_observer, ModelChanged(_)) | 679 EXPECT_CALL(manager_observer, ModelChanged(_)) |
687 .WillRepeatedly(Return()); | 680 .WillRepeatedly(Return()); |
688 DownloadManagerForShell(shell())->AddObserver(&manager_observer); | 681 DownloadManagerForShell(shell())->AddObserver(&manager_observer); |
689 { | 682 { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 // Shutdown the download manager. Mostly this is confirming a lack of | 752 // Shutdown the download manager. Mostly this is confirming a lack of |
760 // crashes. | 753 // crashes. |
761 DownloadManagerForShell(shell())->Shutdown(); | 754 DownloadManagerForShell(shell())->Shutdown(); |
762 | 755 |
763 // Run the detach callback; shouldn't cause any problems. | 756 // Run the detach callback; shouldn't cause any problems. |
764 callbacks[0].Run(); | 757 callbacks[0].Run(); |
765 callbacks.clear(); | 758 callbacks.clear(); |
766 } | 759 } |
767 | 760 |
768 } // namespace content | 761 } // namespace content |
OLD | NEW |