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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 return true; | 676 return true; |
677 } | 677 } |
678 | 678 |
679 // Attempts to download a file, based on information in |download_info|. | 679 // Attempts to download a file, based on information in |download_info|. |
680 void DownloadFileCheckErrors(const DownloadInfo& download_info) { | 680 void DownloadFileCheckErrors(const DownloadInfo& download_info) { |
681 ASSERT_TRUE(test_server()->Start()); | 681 ASSERT_TRUE(test_server()->Start()); |
682 std::vector<DownloadItem*> download_items; | 682 std::vector<DownloadItem*> download_items; |
683 GetDownloads(browser(), &download_items); | 683 GetDownloads(browser(), &download_items); |
684 ASSERT_TRUE(download_items.empty()); | 684 ASSERT_TRUE(download_items.empty()); |
685 | 685 |
686 NullSelectFile(browser()); | |
687 | |
686 std::string server_path = "files/downloads/"; | 688 std::string server_path = "files/downloads/"; |
687 server_path += download_info.url_name; | 689 server_path += download_info.url_name; |
688 GURL url = test_server()->GetURL(server_path); | 690 GURL url = test_server()->GetURL(server_path); |
689 ASSERT_TRUE(url.is_valid()); | 691 ASSERT_TRUE(url.is_valid()); |
690 | 692 |
691 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 693 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
692 scoped_ptr<DownloadTestObserverTerminal> observer( | 694 scoped_ptr<DownloadTestObserverTerminal> observer( |
693 new DownloadTestObserverTerminal( | 695 new DownloadTestObserverTerminal( |
694 download_manager, | 696 download_manager, |
695 1, | 697 1, |
696 true, // Bail on select file | 698 false, // Don't bail on select file. |
697 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); | 699 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); |
698 | 700 |
699 if (download_info.download_method == DOWNLOAD_DIRECT) { | 701 if (download_info.download_method == DOWNLOAD_DIRECT) { |
700 // Go directly to download. | 702 // Go directly to download. |
701 WebContents* web_contents = browser()->GetSelectedWebContents(); | 703 WebContents* web_contents = browser()->GetSelectedWebContents(); |
702 ASSERT_TRUE(web_contents); | 704 ASSERT_TRUE(web_contents); |
703 DownloadSaveInfo save_info; | 705 DownloadSaveInfo save_info; |
704 save_info.prompt_for_save_location = false; | 706 save_info.prompt_for_save_location = false; |
705 | 707 |
708 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( | |
709 new DownloadTestItemCreationObserver); | |
710 | |
706 DownloadManagerForBrowser(browser())->DownloadUrl( | 711 DownloadManagerForBrowser(browser())->DownloadUrl( |
707 url, GURL(""), "", false, -1, save_info, web_contents); | 712 url, GURL(""), "", false, -1, save_info, web_contents, |
713 creation_observer->callback()); | |
714 | |
715 // Wait until the item is created, or we have determined that it | |
716 // won't be. | |
717 creation_observer->WaitForDownloadItemCreation(); | |
718 | |
719 int32 invalid_id = content::DownloadId::Invalid().local(); | |
720 EXPECT_EQ(download_info.show_download_item, creation_observer->started()); | |
Randy Smith (Not in Mondays)
2012/03/07 21:16:57
Don't use mean ->succeeded() here? started() will
ahendrickson
2012/03/08 21:33:07
Done.
| |
721 if (download_info.show_download_item) { | |
722 EXPECT_EQ(net::OK, creation_observer->error()); | |
723 EXPECT_NE(invalid_id, creation_observer->download_id().local()); | |
724 } else { | |
725 EXPECT_NE(net::OK, creation_observer->error()); | |
726 EXPECT_EQ(invalid_id, creation_observer->download_id().local()); | |
727 } | |
708 } else { | 728 } else { |
709 // Navigate to URL normally, wait until done. | 729 // Navigate to URL normally, wait until done. |
710 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), | 730 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), |
711 url, | 731 url, |
712 1); | 732 1); |
713 } | 733 } |
714 | 734 |
715 if (download_info.show_download_item) | 735 if (download_info.show_download_item) |
716 observer->WaitForFinished(); | 736 observer->WaitForFinished(); |
717 | 737 |
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1818 ASSERT_TRUE(web_contents); | 1838 ASSERT_TRUE(web_contents); |
1819 | 1839 |
1820 DownloadTestObserverTerminal* observer( | 1840 DownloadTestObserverTerminal* observer( |
1821 new DownloadTestObserverTerminal( | 1841 new DownloadTestObserverTerminal( |
1822 DownloadManagerForBrowser(browser()), 1, | 1842 DownloadManagerForBrowser(browser()), 1, |
1823 false, // Ignore select file. | 1843 false, // Ignore select file. |
1824 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1844 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL)); |
1825 DownloadSaveInfo save_info; | 1845 DownloadSaveInfo save_info; |
1826 save_info.prompt_for_save_location = true; | 1846 save_info.prompt_for_save_location = true; |
1827 DownloadManagerForBrowser(browser())->DownloadUrl( | 1847 DownloadManagerForBrowser(browser())->DownloadUrl( |
1828 url, GURL(""), "", false, -1, save_info, web_contents); | 1848 url, GURL(""), "", false, -1, save_info, web_contents, |
1849 DownloadManager::OnStartedCallback()); | |
1829 observer->WaitForFinished(); | 1850 observer->WaitForFinished(); |
1830 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1851 EXPECT_TRUE(observer->select_file_dialog_seen()); |
1831 | 1852 |
1832 // Check state. | 1853 // Check state. |
1833 EXPECT_EQ(1, browser()->tab_count()); | 1854 EXPECT_EQ(1, browser()->tab_count()); |
1834 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1855 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
1835 CheckDownloadUI(browser(), true, true, file); | 1856 CheckDownloadUI(browser(), true, true, file); |
1836 } | 1857 } |
1837 | 1858 |
1838 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1859 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
1839 ASSERT_TRUE(InitialSetup(false)); | 1860 ASSERT_TRUE(InitialSetup(false)); |
1840 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1861 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1841 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1862 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1842 | 1863 |
1843 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1864 WebContents* web_contents = browser()->GetSelectedWebContents(); |
1844 ASSERT_TRUE(web_contents); | 1865 ASSERT_TRUE(web_contents); |
1845 | 1866 |
1846 ScopedTempDir other_directory; | 1867 ScopedTempDir other_directory; |
1847 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1868 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
1848 FilePath target_file_full_path | 1869 FilePath target_file_full_path |
1849 = other_directory.path().Append(file.BaseName()); | 1870 = other_directory.path().Append(file.BaseName()); |
1850 DownloadSaveInfo save_info; | 1871 DownloadSaveInfo save_info; |
1851 save_info.file_path = target_file_full_path; | 1872 save_info.file_path = target_file_full_path; |
1852 | 1873 |
1853 DownloadTestObserverTerminal* observer(CreateWaiter(browser(), 1)); | 1874 DownloadTestObserverTerminal* observer(CreateWaiter(browser(), 1)); |
1854 DownloadManagerForBrowser(browser())->DownloadUrl( | 1875 DownloadManagerForBrowser(browser())->DownloadUrl( |
1855 url, GURL(""), "", false, -1, save_info, web_contents); | 1876 url, GURL(""), "", false, -1, save_info, web_contents, |
1877 DownloadManager::OnStartedCallback()); | |
1856 observer->WaitForFinished(); | 1878 observer->WaitForFinished(); |
1857 | 1879 |
1858 // Check state. | 1880 // Check state. |
1859 EXPECT_EQ(1, browser()->tab_count()); | 1881 EXPECT_EQ(1, browser()->tab_count()); |
1860 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1882 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
1861 target_file_full_path, | 1883 target_file_full_path, |
1862 OriginFile(file))); | 1884 OriginFile(file))); |
1863 | 1885 |
1864 // Temporary downloads won't be visible. | 1886 // Temporary downloads won't be visible. |
1865 CheckDownloadUI(browser(), false, false, file); | 1887 CheckDownloadUI(browser(), false, false, file); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2069 "zip_file_not_found.zip", | 2091 "zip_file_not_found.zip", |
2070 DOWNLOAD_NAVIGATE, | 2092 DOWNLOAD_NAVIGATE, |
2071 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 2093 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
2072 false | 2094 false |
2073 }; | 2095 }; |
2074 | 2096 |
2075 // Do initial setup. | 2097 // Do initial setup. |
2076 ASSERT_TRUE(InitialSetup(false)); | 2098 ASSERT_TRUE(InitialSetup(false)); |
2077 DownloadFileCheckErrors(download_info); | 2099 DownloadFileCheckErrors(download_info); |
2078 } | 2100 } |
OLD | NEW |