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 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 return true; | 680 return true; |
681 } | 681 } |
682 | 682 |
683 // Attempts to download a file, based on information in |download_info|. | 683 // Attempts to download a file, based on information in |download_info|. |
684 void DownloadFileCheckErrors(const DownloadInfo& download_info) { | 684 void DownloadFileCheckErrors(const DownloadInfo& download_info) { |
685 ASSERT_TRUE(test_server()->Start()); | 685 ASSERT_TRUE(test_server()->Start()); |
686 std::vector<DownloadItem*> download_items; | 686 std::vector<DownloadItem*> download_items; |
687 GetDownloads(browser(), &download_items); | 687 GetDownloads(browser(), &download_items); |
688 ASSERT_TRUE(download_items.empty()); | 688 ASSERT_TRUE(download_items.empty()); |
689 | 689 |
690 NullSelectFile(browser()); | |
691 | |
690 std::string server_path = "files/downloads/"; | 692 std::string server_path = "files/downloads/"; |
691 server_path += download_info.url_name; | 693 server_path += download_info.url_name; |
692 GURL url = test_server()->GetURL(server_path); | 694 GURL url = test_server()->GetURL(server_path); |
693 ASSERT_TRUE(url.is_valid()); | 695 ASSERT_TRUE(url.is_valid()); |
694 | 696 |
695 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 697 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
696 scoped_ptr<DownloadTestObserver> observer( | 698 scoped_ptr<DownloadTestObserver> observer( |
697 new DownloadTestObserver( | 699 new DownloadTestObserver( |
698 download_manager, | 700 download_manager, |
699 1, | 701 1, |
700 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ? | 702 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ? |
701 DownloadItem::COMPLETE : // Really done | 703 DownloadItem::COMPLETE : // Really done |
702 DownloadItem::INTERRUPTED, | 704 DownloadItem::INTERRUPTED, |
703 true, // Bail on select file | 705 false, // Don't bail on select file. |
704 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 706 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
705 | 707 |
706 if (download_info.download_method == DOWNLOAD_DIRECT) { | 708 if (download_info.download_method == DOWNLOAD_DIRECT) { |
707 // Go directly to download. | 709 // Go directly to download. |
708 WebContents* web_contents = browser()->GetSelectedWebContents(); | 710 WebContents* web_contents = browser()->GetSelectedWebContents(); |
709 ASSERT_TRUE(web_contents); | 711 ASSERT_TRUE(web_contents); |
710 DownloadSaveInfo save_info; | 712 DownloadSaveInfo save_info; |
711 save_info.prompt_for_save_location = false; | 713 save_info.prompt_for_save_location = false; |
712 | 714 |
715 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( | |
716 new DownloadTestItemCreationObserver); | |
717 | |
713 DownloadManagerForBrowser(browser())->DownloadUrl( | 718 DownloadManagerForBrowser(browser())->DownloadUrl( |
714 url, GURL(""), "", false, -1, save_info, web_contents); | 719 url, GURL(""), "", false, -1, save_info, web_contents, |
720 creation_observer->callback()); | |
721 | |
722 // Wait until the item is created, or we have determined that it | |
723 // won't be. | |
724 creation_observer->WaitForDownloadItemCreation(); | |
725 | |
726 EXPECT_EQ(download_info.show_download_item, creation_observer->started()); | |
Randy Smith (Not in Mondays)
2012/03/06 21:29:14
As I understand the DownloadTestItemCreationObserv
ahendrickson
2012/03/07 02:58:12
Done.
| |
715 } else { | 727 } else { |
716 // Navigate to URL normally, wait until done. | 728 // Navigate to URL normally, wait until done. |
717 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), | 729 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), |
718 url, | 730 url, |
719 1); | 731 1); |
720 } | 732 } |
721 | 733 |
722 if (download_info.show_download_item) { | 734 if (download_info.show_download_item) { |
723 observer->WaitForFinished(); | 735 observer->WaitForFinished(); |
724 DCHECK_EQ(0u, observer->NumOtherDownloadsSeen()); | 736 DCHECK_EQ(0u, observer->NumOtherDownloadsSeen()); |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1828 | 1840 |
1829 DownloadTestObserver* observer( | 1841 DownloadTestObserver* observer( |
1830 new DownloadTestObserver( | 1842 new DownloadTestObserver( |
1831 DownloadManagerForBrowser(browser()), 1, | 1843 DownloadManagerForBrowser(browser()), 1, |
1832 DownloadItem::COMPLETE, // Really done | 1844 DownloadItem::COMPLETE, // Really done |
1833 false, // Ignore select file. | 1845 false, // Ignore select file. |
1834 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1846 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
1835 DownloadSaveInfo save_info; | 1847 DownloadSaveInfo save_info; |
1836 save_info.prompt_for_save_location = true; | 1848 save_info.prompt_for_save_location = true; |
1837 DownloadManagerForBrowser(browser())->DownloadUrl( | 1849 DownloadManagerForBrowser(browser())->DownloadUrl( |
1838 url, GURL(""), "", false, -1, save_info, web_contents); | 1850 url, GURL(""), "", false, -1, save_info, web_contents, |
1851 DownloadManager::OnStartedCallback()); | |
1839 observer->WaitForFinished(); | 1852 observer->WaitForFinished(); |
1840 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1853 EXPECT_TRUE(observer->select_file_dialog_seen()); |
1841 | 1854 |
1842 // Check state. | 1855 // Check state. |
1843 EXPECT_EQ(1, browser()->tab_count()); | 1856 EXPECT_EQ(1, browser()->tab_count()); |
1844 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1857 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
1845 CheckDownloadUI(browser(), true, true, file); | 1858 CheckDownloadUI(browser(), true, true, file); |
1846 } | 1859 } |
1847 | 1860 |
1848 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1861 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
1849 ASSERT_TRUE(InitialSetup(false)); | 1862 ASSERT_TRUE(InitialSetup(false)); |
1850 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1863 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1851 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1864 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1852 | 1865 |
1853 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1866 WebContents* web_contents = browser()->GetSelectedWebContents(); |
1854 ASSERT_TRUE(web_contents); | 1867 ASSERT_TRUE(web_contents); |
1855 | 1868 |
1856 ScopedTempDir other_directory; | 1869 ScopedTempDir other_directory; |
1857 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1870 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
1858 FilePath target_file_full_path | 1871 FilePath target_file_full_path |
1859 = other_directory.path().Append(file.BaseName()); | 1872 = other_directory.path().Append(file.BaseName()); |
1860 DownloadSaveInfo save_info; | 1873 DownloadSaveInfo save_info; |
1861 save_info.file_path = target_file_full_path; | 1874 save_info.file_path = target_file_full_path; |
1862 | 1875 |
1863 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 1876 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
1864 DownloadManagerForBrowser(browser())->DownloadUrl( | 1877 DownloadManagerForBrowser(browser())->DownloadUrl( |
1865 url, GURL(""), "", false, -1, save_info, web_contents); | 1878 url, GURL(""), "", false, -1, save_info, web_contents, |
1879 DownloadManager::OnStartedCallback()); | |
1866 observer->WaitForFinished(); | 1880 observer->WaitForFinished(); |
1867 | 1881 |
1868 // Check state. | 1882 // Check state. |
1869 EXPECT_EQ(1, browser()->tab_count()); | 1883 EXPECT_EQ(1, browser()->tab_count()); |
1870 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1884 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
1871 target_file_full_path, | 1885 target_file_full_path, |
1872 OriginFile(file))); | 1886 OriginFile(file))); |
1873 | 1887 |
1874 // Temporary downloads won't be visible. | 1888 // Temporary downloads won't be visible. |
1875 CheckDownloadUI(browser(), false, false, file); | 1889 CheckDownloadUI(browser(), false, false, file); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2076 "zip_file_not_found.zip", | 2090 "zip_file_not_found.zip", |
2077 DOWNLOAD_NAVIGATE, | 2091 DOWNLOAD_NAVIGATE, |
2078 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 2092 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
2079 false | 2093 false |
2080 }; | 2094 }; |
2081 | 2095 |
2082 // Do initial setup. | 2096 // Do initial setup. |
2083 ASSERT_TRUE(InitialSetup(false)); | 2097 ASSERT_TRUE(InitialSetup(false)); |
2084 DownloadFileCheckErrors(download_info); | 2098 DownloadFileCheckErrors(download_info); |
2085 } | 2099 } |
OLD | NEW |