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 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 return true; | 640 return true; |
641 } | 641 } |
642 | 642 |
643 // Attempts to download a file, based on information in |download_info|. | 643 // Attempts to download a file, based on information in |download_info|. |
644 void DownloadFileCheckErrors(const DownloadInfo& download_info) { | 644 void DownloadFileCheckErrors(const DownloadInfo& download_info) { |
645 ASSERT_TRUE(test_server()->Start()); | 645 ASSERT_TRUE(test_server()->Start()); |
646 std::vector<DownloadItem*> download_items; | 646 std::vector<DownloadItem*> download_items; |
647 GetDownloads(browser(), &download_items); | 647 GetDownloads(browser(), &download_items); |
648 ASSERT_TRUE(download_items.empty()); | 648 ASSERT_TRUE(download_items.empty()); |
649 | 649 |
| 650 NullSelectFile(browser()); |
| 651 |
650 std::string server_path = "files/downloads/"; | 652 std::string server_path = "files/downloads/"; |
651 server_path += download_info.url_name; | 653 server_path += download_info.url_name; |
652 GURL url = test_server()->GetURL(server_path); | 654 GURL url = test_server()->GetURL(server_path); |
653 ASSERT_TRUE(url.is_valid()); | 655 ASSERT_TRUE(url.is_valid()); |
654 | 656 |
655 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 657 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
656 scoped_ptr<DownloadTestObserver> observer( | 658 scoped_ptr<DownloadTestObserver> observer( |
657 new DownloadTestObserverTerminal( | 659 new DownloadTestObserverTerminal( |
658 download_manager, | 660 download_manager, |
659 1, | 661 1, |
660 true, // Bail on select file | 662 false, // Don't bail on select file. |
661 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 663 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
662 | 664 |
663 if (download_info.download_method == DOWNLOAD_DIRECT) { | 665 if (download_info.download_method == DOWNLOAD_DIRECT) { |
664 // Go directly to download. | 666 // Go directly to download. |
665 WebContents* web_contents = browser()->GetSelectedWebContents(); | 667 WebContents* web_contents = browser()->GetSelectedWebContents(); |
666 ASSERT_TRUE(web_contents); | 668 ASSERT_TRUE(web_contents); |
667 DownloadSaveInfo save_info; | 669 DownloadSaveInfo save_info; |
668 save_info.prompt_for_save_location = false; | 670 save_info.prompt_for_save_location = false; |
669 | 671 |
| 672 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( |
| 673 new DownloadTestItemCreationObserver); |
| 674 |
670 DownloadManagerForBrowser(browser())->DownloadUrl( | 675 DownloadManagerForBrowser(browser())->DownloadUrl( |
671 url, GURL(""), "", false, -1, save_info, web_contents); | 676 url, GURL(""), "", false, -1, save_info, web_contents, |
| 677 creation_observer->callback()); |
| 678 |
| 679 // Wait until the item is created, or we have determined that it |
| 680 // won't be. |
| 681 creation_observer->WaitForDownloadItemCreation(); |
| 682 |
| 683 int32 invalid_id = content::DownloadId::Invalid().local(); |
| 684 EXPECT_EQ(download_info.show_download_item, |
| 685 creation_observer->succeeded()); |
| 686 if (download_info.show_download_item) { |
| 687 EXPECT_EQ(net::OK, creation_observer->error()); |
| 688 EXPECT_NE(invalid_id, creation_observer->download_id().local()); |
| 689 } else { |
| 690 EXPECT_NE(net::OK, creation_observer->error()); |
| 691 EXPECT_EQ(invalid_id, creation_observer->download_id().local()); |
| 692 } |
672 } else { | 693 } else { |
673 // Navigate to URL normally, wait until done. | 694 // Navigate to URL normally, wait until done. |
674 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), | 695 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), |
675 url, | 696 url, |
676 1); | 697 1); |
677 } | 698 } |
678 | 699 |
679 if (download_info.show_download_item) { | 700 if (download_info.show_download_item) { |
680 observer->WaitForFinished(); | 701 observer->WaitForFinished(); |
681 DownloadItem::DownloadState final_state = | 702 DownloadItem::DownloadState final_state = |
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1793 ASSERT_TRUE(web_contents); | 1814 ASSERT_TRUE(web_contents); |
1794 | 1815 |
1795 DownloadTestObserver* observer( | 1816 DownloadTestObserver* observer( |
1796 new DownloadTestObserverTerminal( | 1817 new DownloadTestObserverTerminal( |
1797 DownloadManagerForBrowser(browser()), 1, | 1818 DownloadManagerForBrowser(browser()), 1, |
1798 false, // Ignore select file. | 1819 false, // Ignore select file. |
1799 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1820 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
1800 DownloadSaveInfo save_info; | 1821 DownloadSaveInfo save_info; |
1801 save_info.prompt_for_save_location = true; | 1822 save_info.prompt_for_save_location = true; |
1802 DownloadManagerForBrowser(browser())->DownloadUrl( | 1823 DownloadManagerForBrowser(browser())->DownloadUrl( |
1803 url, GURL(""), "", false, -1, save_info, web_contents); | 1824 url, GURL(""), "", false, -1, save_info, web_contents, |
| 1825 DownloadManager::OnStartedCallback()); |
1804 observer->WaitForFinished(); | 1826 observer->WaitForFinished(); |
1805 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1827 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1806 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1828 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1807 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1829 EXPECT_TRUE(observer->select_file_dialog_seen()); |
1808 | 1830 |
1809 // Check state. | 1831 // Check state. |
1810 EXPECT_EQ(1, browser()->tab_count()); | 1832 EXPECT_EQ(1, browser()->tab_count()); |
1811 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1833 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
1812 CheckDownloadUI(browser(), true, true, file); | 1834 CheckDownloadUI(browser(), true, true, file); |
1813 } | 1835 } |
1814 | 1836 |
1815 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1837 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
1816 ASSERT_TRUE(InitialSetup(false)); | 1838 ASSERT_TRUE(InitialSetup(false)); |
1817 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1839 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1818 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1840 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1819 | 1841 |
1820 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1842 WebContents* web_contents = browser()->GetSelectedWebContents(); |
1821 ASSERT_TRUE(web_contents); | 1843 ASSERT_TRUE(web_contents); |
1822 | 1844 |
1823 ScopedTempDir other_directory; | 1845 ScopedTempDir other_directory; |
1824 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1846 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
1825 FilePath target_file_full_path | 1847 FilePath target_file_full_path |
1826 = other_directory.path().Append(file.BaseName()); | 1848 = other_directory.path().Append(file.BaseName()); |
1827 DownloadSaveInfo save_info; | 1849 DownloadSaveInfo save_info; |
1828 save_info.file_path = target_file_full_path; | 1850 save_info.file_path = target_file_full_path; |
1829 | 1851 |
1830 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 1852 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
1831 DownloadManagerForBrowser(browser())->DownloadUrl( | 1853 DownloadManagerForBrowser(browser())->DownloadUrl( |
1832 url, GURL(""), "", false, -1, save_info, web_contents); | 1854 url, GURL(""), "", false, -1, save_info, web_contents, |
| 1855 DownloadManager::OnStartedCallback()); |
1833 observer->WaitForFinished(); | 1856 observer->WaitForFinished(); |
1834 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1857 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1835 | 1858 |
1836 // Check state. | 1859 // Check state. |
1837 EXPECT_EQ(1, browser()->tab_count()); | 1860 EXPECT_EQ(1, browser()->tab_count()); |
1838 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1861 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
1839 target_file_full_path, | 1862 target_file_full_path, |
1840 OriginFile(file))); | 1863 OriginFile(file))); |
1841 | 1864 |
1842 // Temporary downloads won't be visible. | 1865 // Temporary downloads won't be visible. |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2054 "zip_file_not_found.zip", | 2077 "zip_file_not_found.zip", |
2055 DOWNLOAD_NAVIGATE, | 2078 DOWNLOAD_NAVIGATE, |
2056 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 2079 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
2057 false | 2080 false |
2058 }; | 2081 }; |
2059 | 2082 |
2060 // Do initial setup. | 2083 // Do initial setup. |
2061 ASSERT_TRUE(InitialSetup(false)); | 2084 ASSERT_TRUE(InitialSetup(false)); |
2062 DownloadFileCheckErrors(download_info); | 2085 DownloadFileCheckErrors(download_info); |
2063 } | 2086 } |
OLD | NEW |