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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 if (info.download_info.show_download_item) | 777 if (info.download_info.show_download_item) |
778 EXPECT_TRUE(injector->HadFile(GURL(info.error_info.url))) << s.str(); | 778 EXPECT_TRUE(injector->HadFile(GURL(info.error_info.url))) << s.str(); |
779 } | 779 } |
780 | 780 |
781 void DownloadInsertFilesErrorCheckErrors(size_t count, | 781 void DownloadInsertFilesErrorCheckErrors(size_t count, |
782 FileErrorInjectInfo* info) { | 782 FileErrorInjectInfo* info) { |
783 DownloadFilesCheckErrorsSetup(); | 783 DownloadFilesCheckErrorsSetup(); |
784 | 784 |
785 // Set up file failures. | 785 // Set up file failures. |
786 scoped_refptr<content::TestFileErrorInjector> injector( | 786 scoped_refptr<content::TestFileErrorInjector> injector( |
787 content::TestFileErrorInjector::Create()); | 787 content::TestFileErrorInjector::Create( |
| 788 DownloadManagerForBrowser(browser()))); |
788 | 789 |
789 for (size_t i = 0; i < count; ++i) { | 790 for (size_t i = 0; i < count; ++i) { |
790 // Set up the full URL, for download file tracking. | 791 // Set up the full URL, for download file tracking. |
791 std::string server_path = "files/downloads/"; | 792 std::string server_path = "files/downloads/"; |
792 server_path += info[i].download_info.url_name; | 793 server_path += info[i].download_info.url_name; |
793 GURL url = test_server()->GetURL(server_path); | 794 GURL url = test_server()->GetURL(server_path); |
794 info[i].error_info.url = url.spec(); | 795 info[i].error_info.url = url.spec(); |
795 | 796 |
796 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i); | 797 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i); |
797 } | 798 } |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1515 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1515 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1516 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1516 | 1517 |
1517 // Confirm the downloaded data exists. | 1518 // Confirm the downloaded data exists. |
1518 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1519 FilePath downloaded_file = GetDownloadDirectory(browser()); |
1519 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1520 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
1520 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1521 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
1521 } | 1522 } |
1522 | 1523 |
1523 // Test to make sure auto-open works. | 1524 // Test to make sure auto-open works. |
1524 // Feel free to re-disable this test if it starts failing again, but please see | |
1525 // if the failure looks like http://crbug.com/118159 and use that bug if so. | |
1526 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1525 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
1527 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1526 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
1528 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1527 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1529 | 1528 |
1530 ASSERT_TRUE( | 1529 ASSERT_TRUE( |
1531 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1530 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
1532 | 1531 |
1533 // Mock out external opening on all downloads until end of test. | 1532 // Mock out external opening on all downloads until end of test. |
1534 MockDownloadOpeningObserver observer( | 1533 MockDownloadOpeningObserver observer(DownloadManagerForBrowser(browser())); |
1535 DownloadManagerForBrowser(browser())); | |
1536 | 1534 |
1537 DownloadAndWait(browser(), url); | 1535 DownloadAndWait(browser(), url); |
1538 | 1536 |
1539 // Find the download and confirm it was opened. | 1537 // Find the download and confirm it was opened. |
1540 std::vector<DownloadItem*> downloads; | 1538 std::vector<DownloadItem*> downloads; |
1541 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 1539 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
1542 ASSERT_EQ(1u, downloads.size()); | 1540 ASSERT_EQ(1u, downloads.size()); |
1543 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); | 1541 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); |
1544 EXPECT_TRUE(downloads[0]->GetOpened()); | 1542 |
| 1543 // Unfortunately, this will block forever, causing a timeout, if |
| 1544 // the download is never opened. |
| 1545 content::DownloadUpdatedObserver( |
| 1546 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
| 1547 EXPECT_TRUE(downloads[0]->GetOpened()); // Confirm it anyway. |
1545 | 1548 |
1546 // As long as we're here, confirmed everything else is good. | 1549 // As long as we're here, confirmed everything else is good. |
1547 EXPECT_EQ(1, browser()->tab_count()); | 1550 EXPECT_EQ(1, browser()->tab_count()); |
1548 CheckDownload(browser(), file, file); | 1551 CheckDownload(browser(), file, file); |
1549 // Download shelf should close. Download panel stays open on ChromeOS. | 1552 // Download shelf should close. Download panel stays open on ChromeOS. |
1550 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1553 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1551 } | 1554 } |
1552 | 1555 |
1553 // Download an extension. Expect a dangerous download warning. | 1556 // Download an extension. Expect a dangerous download warning. |
1554 // Deny the download. | 1557 // Deny the download. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1636 observer->WaitForFinished(); | 1639 observer->WaitForFinished(); |
1637 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1640 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1638 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1641 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1639 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1642 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1640 | 1643 |
1641 // Download shelf should close from auto-open. | 1644 // Download shelf should close from auto-open. |
1642 content::DownloadManager::DownloadVector downloads; | 1645 content::DownloadManager::DownloadVector downloads; |
1643 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 1646 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
1644 ASSERT_EQ(1u, downloads.size()); | 1647 ASSERT_EQ(1u, downloads.size()); |
1645 content::DownloadUpdatedObserver( | 1648 content::DownloadUpdatedObserver( |
1646 downloads[0], base::Bind(WasAutoOpened)).WaitForEvent(); | 1649 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
1647 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1650 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1648 | 1651 |
1649 // Check that the extension was installed. | 1652 // Check that the extension was installed. |
1650 ExtensionService* extension_service = | 1653 ExtensionService* extension_service = |
1651 browser()->profile()->GetExtensionService(); | 1654 browser()->profile()->GetExtensionService(); |
1652 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1655 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1653 } | 1656 } |
1654 | 1657 |
1655 // Test installing a CRX that fails integrity checks. | 1658 // Test installing a CRX that fails integrity checks. |
1656 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1659 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1698 observer->WaitForFinished(); | 1701 observer->WaitForFinished(); |
1699 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1702 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1700 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1703 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1701 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1704 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1702 | 1705 |
1703 // Download shelf should close from auto-open. | 1706 // Download shelf should close from auto-open. |
1704 content::DownloadManager::DownloadVector downloads; | 1707 content::DownloadManager::DownloadVector downloads; |
1705 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 1708 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
1706 ASSERT_EQ(1u, downloads.size()); | 1709 ASSERT_EQ(1u, downloads.size()); |
1707 content::DownloadUpdatedObserver( | 1710 content::DownloadUpdatedObserver( |
1708 downloads[0], base::Bind(WasAutoOpened)).WaitForEvent(); | 1711 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
1709 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1712 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1710 | 1713 |
1711 // Check that the extension was installed. | 1714 // Check that the extension was installed. |
1712 ExtensionService* extension_service = | 1715 ExtensionService* extension_service = |
1713 browser()->profile()->GetExtensionService(); | 1716 browser()->profile()->GetExtensionService(); |
1714 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1717 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
1715 } | 1718 } |
1716 | 1719 |
1717 // Tests for download initiation functions. | 1720 // Tests for download initiation functions. |
1718 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 1721 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1765 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 1768 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
1766 observer->WaitForFinished(); | 1769 observer->WaitForFinished(); |
1767 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1770 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1768 | 1771 |
1769 // Check state. | 1772 // Check state. |
1770 EXPECT_EQ(1, browser()->tab_count()); | 1773 EXPECT_EQ(1, browser()->tab_count()); |
1771 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1774 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
1772 target_file_full_path, | 1775 target_file_full_path, |
1773 OriginFile(file))); | 1776 OriginFile(file))); |
1774 | 1777 |
1775 // Temporary downloads won't be visible. | 1778 // Temporary are treated as auto-opened, and after that open won't be |
| 1779 // visible; wait for auto-open and confirm not visible. |
| 1780 std::vector<DownloadItem*> downloads; |
| 1781 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
| 1782 ASSERT_EQ(1u, downloads.size()); |
| 1783 content::DownloadUpdatedObserver( |
| 1784 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
1776 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1785 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1777 } | 1786 } |
1778 | 1787 |
1779 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaGet) { | 1788 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaGet) { |
1780 // Do initial setup. | 1789 // Do initial setup. |
1781 ASSERT_TRUE(test_server()->Start()); | 1790 ASSERT_TRUE(test_server()->Start()); |
1782 EnableFileChooser(true); | 1791 EnableFileChooser(true); |
1783 std::vector<DownloadItem*> download_items; | 1792 std::vector<DownloadItem*> download_items; |
1784 GetDownloads(browser(), &download_items); | 1793 GetDownloads(browser(), &download_items); |
1785 ASSERT_TRUE(download_items.empty()); | 1794 ASSERT_TRUE(download_items.empty()); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2237 GetDownloads(browser(), &download_items); | 2246 GetDownloads(browser(), &download_items); |
2238 ASSERT_EQ(1u, download_items.size()); | 2247 ASSERT_EQ(1u, download_items.size()); |
2239 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2248 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
2240 download_items[0]->GetOriginalUrl()); | 2249 download_items[0]->GetOriginalUrl()); |
2241 | 2250 |
2242 // Check that the file contains the expected referrer. | 2251 // Check that the file contains the expected referrer. |
2243 FilePath file(download_items[0]->GetFullPath()); | 2252 FilePath file(download_items[0]->GetFullPath()); |
2244 std::string expected_contents = test_server()->GetURL("").spec(); | 2253 std::string expected_contents = test_server()->GetURL("").spec(); |
2245 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2254 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
2246 } | 2255 } |
OLD | NEW |