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