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 26 matching lines...) Expand all Loading... |
37 #include "chrome/common/chrome_notification_types.h" | 37 #include "chrome/common/chrome_notification_types.h" |
38 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
39 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
40 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
41 #include "chrome/test/base/in_process_browser_test.h" | 41 #include "chrome/test/base/in_process_browser_test.h" |
42 #include "chrome/test/base/ui_test_utils.h" | 42 #include "chrome/test/base/ui_test_utils.h" |
43 #include "content/browser/download/download_file_manager.h" | 43 #include "content/browser/download/download_file_manager.h" |
44 #include "content/browser/download/download_persistent_store_info.h" | 44 #include "content/browser/download/download_persistent_store_info.h" |
45 #include "content/browser/net/url_request_mock_http_job.h" | 45 #include "content/browser/net/url_request_mock_http_job.h" |
46 #include "content/browser/net/url_request_slow_download_job.h" | 46 #include "content/browser/net/url_request_slow_download_job.h" |
| 47 #include "content/browser/renderer_host/render_view_host.h" |
47 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 48 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
48 #include "content/public/browser/download_item.h" | 49 #include "content/public/browser/download_item.h" |
49 #include "content/public/browser/download_manager.h" | 50 #include "content/public/browser/download_manager.h" |
| 51 #include "content/public/browser/notification_source.h" |
50 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
51 #include "content/public/common/page_transition_types.h" | 53 #include "content/public/common/page_transition_types.h" |
52 #include "net/base/net_util.h" | 54 #include "net/base/net_util.h" |
53 #include "testing/gtest/include/gtest/gtest.h" | 55 #include "testing/gtest/include/gtest/gtest.h" |
54 | 56 |
55 using content::BrowserThread; | 57 using content::BrowserThread; |
56 using content::DownloadItem; | 58 using content::DownloadItem; |
57 using content::DownloadManager; | 59 using content::DownloadManager; |
58 using content::WebContents; | 60 using content::WebContents; |
59 | 61 |
(...skipping 1633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 | 1695 |
1694 DownloadTestObserver* observer( | 1696 DownloadTestObserver* observer( |
1695 new DownloadTestObserver( | 1697 new DownloadTestObserver( |
1696 DownloadManagerForBrowser(browser()), 1, | 1698 DownloadManagerForBrowser(browser()), 1, |
1697 DownloadItem::COMPLETE, // Really done | 1699 DownloadItem::COMPLETE, // Really done |
1698 false, // Ignore select file. | 1700 false, // Ignore select file. |
1699 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1701 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
1700 DownloadSaveInfo save_info; | 1702 DownloadSaveInfo save_info; |
1701 save_info.prompt_for_save_location = true; | 1703 save_info.prompt_for_save_location = true; |
1702 DownloadManagerForBrowser(browser())->DownloadUrl( | 1704 DownloadManagerForBrowser(browser())->DownloadUrl( |
1703 url, GURL(""), "", false, save_info, web_contents); | 1705 url, GURL(""), "", false, -1, save_info, web_contents); |
1704 observer->WaitForFinished(); | 1706 observer->WaitForFinished(); |
1705 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1707 EXPECT_TRUE(observer->select_file_dialog_seen()); |
1706 | 1708 |
1707 // Check state. | 1709 // Check state. |
1708 EXPECT_EQ(1, browser()->tab_count()); | 1710 EXPECT_EQ(1, browser()->tab_count()); |
1709 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1711 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
1710 CheckDownloadUI(browser(), true, true, file); | 1712 CheckDownloadUI(browser(), true, true, file); |
1711 } | 1713 } |
1712 | 1714 |
1713 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1715 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
1714 ASSERT_TRUE(InitialSetup(false)); | 1716 ASSERT_TRUE(InitialSetup(false)); |
1715 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1717 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1716 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1718 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1717 | 1719 |
1718 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1720 WebContents* web_contents = browser()->GetSelectedWebContents(); |
1719 ASSERT_TRUE(web_contents); | 1721 ASSERT_TRUE(web_contents); |
1720 | 1722 |
1721 ScopedTempDir other_directory; | 1723 ScopedTempDir other_directory; |
1722 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1724 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
1723 FilePath target_file_full_path | 1725 FilePath target_file_full_path |
1724 = other_directory.path().Append(file.BaseName()); | 1726 = other_directory.path().Append(file.BaseName()); |
1725 DownloadSaveInfo save_info; | 1727 DownloadSaveInfo save_info; |
1726 save_info.file_path = target_file_full_path; | 1728 save_info.file_path = target_file_full_path; |
1727 | 1729 |
1728 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 1730 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
1729 DownloadManagerForBrowser(browser())->DownloadUrl( | 1731 DownloadManagerForBrowser(browser())->DownloadUrl( |
1730 url, GURL(""), "", false, save_info, web_contents); | 1732 url, GURL(""), "", false, -1, save_info, web_contents); |
1731 observer->WaitForFinished(); | 1733 observer->WaitForFinished(); |
1732 | 1734 |
1733 // Check state. | 1735 // Check state. |
1734 EXPECT_EQ(1, browser()->tab_count()); | 1736 EXPECT_EQ(1, browser()->tab_count()); |
1735 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1737 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
1736 target_file_full_path, | 1738 target_file_full_path, |
1737 OriginFile(file))); | 1739 OriginFile(file))); |
1738 | 1740 |
1739 // Temporary downloads won't be visible. | 1741 // Temporary downloads won't be visible. |
1740 CheckDownloadUI(browser(), false, false, file); | 1742 CheckDownloadUI(browser(), false, false, file); |
(...skipping 25 matching lines...) Expand all Loading... |
1766 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1768 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
1767 browser()->SavePage(); | 1769 browser()->SavePage(); |
1768 waiter->WaitForFinished(); | 1770 waiter->WaitForFinished(); |
1769 | 1771 |
1770 // Validate that the correct file was downloaded. | 1772 // Validate that the correct file was downloaded. |
1771 GetDownloads(browser(), &download_items); | 1773 GetDownloads(browser(), &download_items); |
1772 EXPECT_TRUE(waiter->select_file_dialog_seen()); | 1774 EXPECT_TRUE(waiter->select_file_dialog_seen()); |
1773 ASSERT_EQ(1u, download_items.size()); | 1775 ASSERT_EQ(1u, download_items.size()); |
1774 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 1776 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
1775 } | 1777 } |
| 1778 |
| 1779 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) { |
| 1780 // Do initial setup. |
| 1781 ASSERT_TRUE(InitialSetup(false)); |
| 1782 ASSERT_TRUE(test_server()->Start()); |
| 1783 NullSelectFile(browser()); |
| 1784 std::vector<DownloadItem*> download_items; |
| 1785 GetDownloads(browser(), &download_items); |
| 1786 ASSERT_TRUE(download_items.empty()); |
| 1787 |
| 1788 // Navigate to a form page. |
| 1789 GURL form_url = test_server()->GetURL( |
| 1790 "files/downloads/form_page_to_post.html"); |
| 1791 ASSERT_TRUE(form_url.is_valid()); |
| 1792 ui_test_utils::NavigateToURL(browser(), form_url); |
| 1793 |
| 1794 // Submit the form. This will send a POST reqeuest, and the response is a |
| 1795 // JPEG image. The resource also has Cache-Control: no-cache set, |
| 1796 // which normally requires revalidation each time. |
| 1797 GURL jpeg_url = test_server()->GetURL("files/post/downloads/image.jpg"); |
| 1798 ASSERT_TRUE(jpeg_url.is_valid()); |
| 1799 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 1800 ASSERT_TRUE(web_contents != NULL); |
| 1801 ui_test_utils::WindowedNotificationObserver observer( |
| 1802 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 1803 content::Source<content::NavigationController>( |
| 1804 &web_contents->GetController())); |
| 1805 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); |
| 1806 ASSERT_TRUE(render_view_host != NULL); |
| 1807 render_view_host->ExecuteJavascriptInWebFrame( |
| 1808 string16(), ASCIIToUTF16("SubmitForm()")); |
| 1809 observer.Wait(); |
| 1810 EXPECT_EQ(jpeg_url, web_contents->GetURL()); |
| 1811 |
| 1812 // Stop the test server, and then try to save the page. If cache validation |
| 1813 // is not bypassed then this will fail since the server is no longer |
| 1814 // reachable. This will also fail if it tries to be retrieved via "GET" |
| 1815 // rather than "POST". |
| 1816 ASSERT_TRUE(test_server()->Stop()); |
| 1817 scoped_ptr<DownloadTestObserver> waiter( |
| 1818 new DownloadTestObserver( |
| 1819 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, |
| 1820 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1821 browser()->SavePage(); |
| 1822 waiter->WaitForFinished(); |
| 1823 |
| 1824 // Validate that the correct file was downloaded. |
| 1825 GetDownloads(browser(), &download_items); |
| 1826 EXPECT_TRUE(waiter->select_file_dialog_seen()); |
| 1827 ASSERT_EQ(1u, download_items.size()); |
| 1828 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
| 1829 } |
OLD | NEW |