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 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 | 1686 |
1687 // Download shelf should close. Download panel stays open on ChromeOS. | 1687 // Download shelf should close. Download panel stays open on ChromeOS. |
1688 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1688 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1689 | 1689 |
1690 // Check that the extension was installed. | 1690 // Check that the extension was installed. |
1691 ExtensionService* extension_service = | 1691 ExtensionService* extension_service = |
1692 browser()->profile()->GetExtensionService(); | 1692 browser()->profile()->GetExtensionService(); |
1693 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1693 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
1694 } | 1694 } |
1695 | 1695 |
1696 // Sort download items by db_handle. | |
1697 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { | |
1698 return d1->GetDbHandle() < d2->GetDbHandle(); | |
1699 } | |
1700 | |
1701 // Confirm that searching through the history works properly | |
1702 IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { | |
1703 // Downloads to populate history with. | |
1704 base::Time current(base::Time::Now()); | |
1705 DownloadPersistentStoreInfo population_entries[] = { | |
1706 DownloadPersistentStoreInfo( | |
1707 FilePath(FILE_PATH_LITERAL("/path/to/file")), | |
1708 GURL("http://www.google.com/fantasy_download"), | |
1709 GURL(""), | |
1710 current - base::TimeDelta::FromMinutes(5), | |
1711 current, | |
1712 128, | |
1713 128, | |
1714 DownloadItem::COMPLETE, | |
1715 1, | |
1716 false), | |
1717 DownloadPersistentStoreInfo( | |
1718 FilePath(FILE_PATH_LITERAL("/path/to/another_file")), | |
1719 GURL("http://www.google.com/reality_download"), | |
1720 GURL(""), | |
1721 current - base::TimeDelta::FromMinutes(10), | |
1722 current, | |
1723 256, | |
1724 256, | |
1725 DownloadItem::COMPLETE, | |
1726 2, | |
1727 false), | |
1728 DownloadPersistentStoreInfo( | |
1729 FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), | |
1730 GURL("http://www.izzle.com/not_really_a_download"), | |
1731 GURL(""), | |
1732 current - base::TimeDelta::FromMinutes(15), | |
1733 current, | |
1734 512, | |
1735 512, | |
1736 DownloadItem::COMPLETE, | |
1737 3, | |
1738 true) | |
1739 }; | |
1740 std::vector<DownloadPersistentStoreInfo> entries( | |
1741 population_entries, population_entries + arraysize(population_entries)); | |
1742 | |
1743 // Populate the manager. | |
1744 DownloadManager* manager = DownloadManagerForBrowser(browser()); | |
1745 manager->OnPersistentStoreQueryComplete(&entries); | |
1746 | |
1747 // Do some searches and check the results. | |
1748 std::vector<DownloadItem*> search_results; | |
1749 | |
1750 manager->GetAllDownloads(&search_results); | |
1751 ASSERT_EQ(3u, search_results.size()); | |
1752 std::sort(search_results.begin(), search_results.end(), | |
1753 DownloadItemSorter); | |
1754 // We do a full check only once to protect against the data | |
1755 // somehow getting scrambled on its way into the DownloadItems. | |
1756 { | |
1757 DownloadItem* d1 = search_results[0]; | |
1758 DownloadItem* d2 = search_results[1]; | |
1759 DownloadItem* d3 = search_results[2]; | |
1760 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath()); | |
1761 EXPECT_EQ(GURL("http://www.google.com/fantasy_download"), | |
1762 d1->GetOriginalUrl()); | |
1763 EXPECT_EQ(current - base::TimeDelta::FromMinutes(5), | |
1764 d1->GetStartTime()); | |
1765 EXPECT_EQ(current, d1->GetEndTime()); | |
1766 EXPECT_EQ(128, d1->GetReceivedBytes()); | |
1767 EXPECT_EQ(128, d1->GetTotalBytes()); | |
1768 EXPECT_EQ(DownloadItem::COMPLETE, d1->GetState()); | |
1769 EXPECT_EQ(1, d1->GetDbHandle()); | |
1770 EXPECT_FALSE(d1->GetOpened()); | |
1771 | |
1772 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/another_file")), | |
1773 d2->GetFullPath()); | |
1774 EXPECT_EQ(GURL("http://www.google.com/reality_download"), | |
1775 d2->GetOriginalUrl()); | |
1776 EXPECT_EQ(current - base::TimeDelta::FromMinutes(10), | |
1777 d2->GetStartTime()); | |
1778 EXPECT_EQ(current, d2->GetEndTime()); | |
1779 EXPECT_EQ(256, d2->GetReceivedBytes()); | |
1780 EXPECT_EQ(256, d2->GetTotalBytes()); | |
1781 EXPECT_EQ(DownloadItem::COMPLETE, d2->GetState()); | |
1782 EXPECT_EQ(2, d2->GetDbHandle()); | |
1783 EXPECT_FALSE(d2->GetOpened()); | |
1784 | |
1785 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), | |
1786 d3->GetFullPath()); | |
1787 EXPECT_EQ(GURL("http://www.izzle.com/not_really_a_download"), | |
1788 d3->GetOriginalUrl()); | |
1789 EXPECT_EQ(current - base::TimeDelta::FromMinutes(15), | |
1790 d3->GetStartTime()); | |
1791 EXPECT_EQ(current, d3->GetEndTime()); | |
1792 EXPECT_EQ(512, d3->GetReceivedBytes()); | |
1793 EXPECT_EQ(512, d3->GetTotalBytes()); | |
1794 EXPECT_EQ(DownloadItem::COMPLETE, d3->GetState()); | |
1795 EXPECT_EQ(3, d3->GetDbHandle()); | |
1796 EXPECT_TRUE(d3->GetOpened()); | |
1797 } | |
1798 search_results.clear(); | |
1799 | |
1800 string16 search_input; | |
1801 manager->SearchDownloads(UTF8ToUTF16("www.google.com"), &search_results); | |
1802 ASSERT_EQ(2u, search_results.size()); | |
1803 std::sort(search_results.begin(), search_results.end(), | |
1804 DownloadItemSorter); | |
1805 EXPECT_EQ(1, search_results[0]->GetDbHandle()); | |
1806 EXPECT_EQ(2, search_results[1]->GetDbHandle()); | |
1807 search_results.clear(); | |
1808 | |
1809 manager->SearchDownloads(UTF8ToUTF16("real"), &search_results); | |
1810 ASSERT_EQ(2u, search_results.size()); | |
1811 std::sort(search_results.begin(), search_results.end(), | |
1812 DownloadItemSorter); | |
1813 EXPECT_EQ(2, search_results[0]->GetDbHandle()); | |
1814 EXPECT_EQ(3, search_results[1]->GetDbHandle()); | |
1815 search_results.clear(); | |
1816 | |
1817 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); | |
1818 ASSERT_EQ(2u, search_results.size()); | |
1819 std::sort(search_results.begin(), search_results.end(), | |
1820 DownloadItemSorter); | |
1821 EXPECT_EQ(2, search_results[0]->GetDbHandle()); | |
1822 EXPECT_EQ(3, search_results[1]->GetDbHandle()); | |
1823 search_results.clear(); | |
1824 } | |
1825 | |
1826 // Tests for download initiation functions. | 1696 // Tests for download initiation functions. |
1827 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 1697 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
1828 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1698 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1829 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1699 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1830 | 1700 |
1831 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1701 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
1832 EnableFileChooser(true); | 1702 EnableFileChooser(true); |
1833 | 1703 |
1834 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1704 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
1835 ASSERT_TRUE(web_contents); | 1705 ASSERT_TRUE(web_contents); |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2346 GetDownloads(browser(), &download_items); | 2216 GetDownloads(browser(), &download_items); |
2347 ASSERT_EQ(1u, download_items.size()); | 2217 ASSERT_EQ(1u, download_items.size()); |
2348 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2218 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
2349 download_items[0]->GetOriginalUrl()); | 2219 download_items[0]->GetOriginalUrl()); |
2350 | 2220 |
2351 // Check that the file contains the expected referrer. | 2221 // Check that the file contains the expected referrer. |
2352 FilePath file(download_items[0]->GetFullPath()); | 2222 FilePath file(download_items[0]->GetFullPath()); |
2353 std::string expected_contents = test_server()->GetURL("").spec(); | 2223 std::string expected_contents = test_server()->GetURL("").spec(); |
2354 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2224 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
2355 } | 2225 } |
OLD | NEW |