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