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 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 | 1516 |
1517 // Get the important info from other threads and check it. | 1517 // Get the important info from other threads and check it. |
1518 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1518 EXPECT_TRUE(EnsureNoPendingDownloads()); |
1519 | 1519 |
1520 // Using "DownloadItem::Remove" follows the discard dangerous download path, | 1520 // Using "DownloadItem::Remove" follows the discard dangerous download path, |
1521 // which completely removes the browser from the shelf and closes the shelf | 1521 // which completely removes the browser from the shelf and closes the shelf |
1522 // if it was there. Download panel stays open on ChromeOS. | 1522 // if it was there. Download panel stays open on ChromeOS. |
1523 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1523 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1524 } | 1524 } |
1525 | 1525 |
1526 // Confirm a download makes it into the history properly. | |
1527 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | |
1528 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
1529 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
1530 FilePath origin_file(OriginFile(file)); | |
1531 int64 origin_size; | |
1532 file_util::GetFileSize(origin_file, &origin_size); | |
1533 | |
1534 // Download the file and wait. We do not expect the Select File dialog. | |
1535 DownloadAndWait(browser(), url); | |
1536 | |
1537 // Get details of what downloads have just happened. | |
1538 std::vector<DownloadItem*> downloads; | |
1539 GetDownloads(browser(), &downloads); | |
1540 ASSERT_EQ(1u, downloads.size()); | |
1541 int64 db_handle = downloads[0]->GetDbHandle(); | |
1542 | |
1543 // Check state. | |
1544 EXPECT_EQ(1, browser()->tab_count()); | |
1545 CheckDownload(browser(), file, file); | |
1546 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
1547 | |
1548 // Check history results. | |
1549 DownloadsHistoryDataCollector history_collector( | |
1550 db_handle, | |
1551 DownloadManagerForBrowser(browser())); | |
1552 DownloadPersistentStoreInfo info; | |
1553 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; | |
1554 EXPECT_EQ(file, info.path.BaseName()); | |
1555 EXPECT_EQ(url, info.url); | |
1556 // Ignore start_time. | |
1557 EXPECT_EQ(origin_size, info.received_bytes); | |
1558 EXPECT_EQ(origin_size, info.total_bytes); | |
1559 EXPECT_EQ(DownloadItem::COMPLETE, info.state); | |
1560 } | |
1561 | |
1562 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1526 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
1563 // after download of a file while viewing another chrome://. | 1527 // after download of a file while viewing another chrome://. |
1564 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1528 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
1565 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1529 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1566 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1530 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1567 GURL flags_url(chrome::kChromeUIFlagsURL); | 1531 GURL flags_url(chrome::kChromeUIFlagsURL); |
1568 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); | 1532 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); |
1569 | 1533 |
1570 ui_test_utils::NavigateToURL(browser(), flags_url); | 1534 ui_test_utils::NavigateToURL(browser(), flags_url); |
1571 DownloadAndWait(browser(), download_url); | 1535 DownloadAndWait(browser(), download_url); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1802 | 1766 |
1803 // Download shelf should close. Download panel stays open on ChromeOS. | 1767 // Download shelf should close. Download panel stays open on ChromeOS. |
1804 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1768 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1805 | 1769 |
1806 // Check that the extension was installed. | 1770 // Check that the extension was installed. |
1807 ExtensionService* extension_service = | 1771 ExtensionService* extension_service = |
1808 browser()->profile()->GetExtensionService(); | 1772 browser()->profile()->GetExtensionService(); |
1809 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1773 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
1810 } | 1774 } |
1811 | 1775 |
1812 // Sort download items by db_handle. | 1776 // Sort download items by id. |
1813 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { | 1777 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { |
1814 return d1->GetDbHandle() < d2->GetDbHandle(); | 1778 return d1->GetId() < d2->GetId(); |
1815 } | 1779 } |
1816 | 1780 |
1817 // Confirm that searching through the history works properly | 1781 // Confirm that searching through the history works properly |
1818 IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { | 1782 IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { |
1819 // Downloads to populate history with. | 1783 // Downloads to populate history with. |
1820 base::Time current(base::Time::Now()); | 1784 base::Time current(base::Time::Now()); |
1821 DownloadPersistentStoreInfo population_entries[] = { | 1785 DownloadPersistentStoreInfo population_entries[] = { |
1822 DownloadPersistentStoreInfo( | 1786 DownloadPersistentStoreInfo( |
1823 FilePath(FILE_PATH_LITERAL("/path/to/file")), | 1787 FilePath(FILE_PATH_LITERAL("/path/to/file")), |
1824 GURL("http://www.google.com/fantasy_download"), | 1788 GURL("http://www.google.com/fantasy_download"), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1875 DownloadItem* d3 = search_results[2]; | 1839 DownloadItem* d3 = search_results[2]; |
1876 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath()); | 1840 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath()); |
1877 EXPECT_EQ(GURL("http://www.google.com/fantasy_download"), | 1841 EXPECT_EQ(GURL("http://www.google.com/fantasy_download"), |
1878 d1->GetOriginalUrl()); | 1842 d1->GetOriginalUrl()); |
1879 EXPECT_EQ(current - base::TimeDelta::FromMinutes(5), | 1843 EXPECT_EQ(current - base::TimeDelta::FromMinutes(5), |
1880 d1->GetStartTime()); | 1844 d1->GetStartTime()); |
1881 EXPECT_EQ(current, d1->GetEndTime()); | 1845 EXPECT_EQ(current, d1->GetEndTime()); |
1882 EXPECT_EQ(128, d1->GetReceivedBytes()); | 1846 EXPECT_EQ(128, d1->GetReceivedBytes()); |
1883 EXPECT_EQ(128, d1->GetTotalBytes()); | 1847 EXPECT_EQ(128, d1->GetTotalBytes()); |
1884 EXPECT_EQ(DownloadItem::COMPLETE, d1->GetState()); | 1848 EXPECT_EQ(DownloadItem::COMPLETE, d1->GetState()); |
1885 EXPECT_EQ(1, d1->GetDbHandle()); | |
1886 EXPECT_FALSE(d1->GetOpened()); | 1849 EXPECT_FALSE(d1->GetOpened()); |
1887 | 1850 |
1888 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/another_file")), | 1851 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/another_file")), |
1889 d2->GetFullPath()); | 1852 d2->GetFullPath()); |
1890 EXPECT_EQ(GURL("http://www.google.com/reality_download"), | 1853 EXPECT_EQ(GURL("http://www.google.com/reality_download"), |
1891 d2->GetOriginalUrl()); | 1854 d2->GetOriginalUrl()); |
1892 EXPECT_EQ(current - base::TimeDelta::FromMinutes(10), | 1855 EXPECT_EQ(current - base::TimeDelta::FromMinutes(10), |
1893 d2->GetStartTime()); | 1856 d2->GetStartTime()); |
1894 EXPECT_EQ(current, d2->GetEndTime()); | 1857 EXPECT_EQ(current, d2->GetEndTime()); |
1895 EXPECT_EQ(256, d2->GetReceivedBytes()); | 1858 EXPECT_EQ(256, d2->GetReceivedBytes()); |
1896 EXPECT_EQ(256, d2->GetTotalBytes()); | 1859 EXPECT_EQ(256, d2->GetTotalBytes()); |
1897 EXPECT_EQ(DownloadItem::COMPLETE, d2->GetState()); | 1860 EXPECT_EQ(DownloadItem::COMPLETE, d2->GetState()); |
1898 EXPECT_EQ(2, d2->GetDbHandle()); | |
1899 EXPECT_FALSE(d2->GetOpened()); | 1861 EXPECT_FALSE(d2->GetOpened()); |
1900 | 1862 |
1901 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), | 1863 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), |
1902 d3->GetFullPath()); | 1864 d3->GetFullPath()); |
1903 EXPECT_EQ(GURL("http://www.izzle.com/not_really_a_download"), | 1865 EXPECT_EQ(GURL("http://www.izzle.com/not_really_a_download"), |
1904 d3->GetOriginalUrl()); | 1866 d3->GetOriginalUrl()); |
1905 EXPECT_EQ(current - base::TimeDelta::FromMinutes(15), | 1867 EXPECT_EQ(current - base::TimeDelta::FromMinutes(15), |
1906 d3->GetStartTime()); | 1868 d3->GetStartTime()); |
1907 EXPECT_EQ(current, d3->GetEndTime()); | 1869 EXPECT_EQ(current, d3->GetEndTime()); |
1908 EXPECT_EQ(512, d3->GetReceivedBytes()); | 1870 EXPECT_EQ(512, d3->GetReceivedBytes()); |
1909 EXPECT_EQ(512, d3->GetTotalBytes()); | 1871 EXPECT_EQ(512, d3->GetTotalBytes()); |
1910 EXPECT_EQ(DownloadItem::COMPLETE, d3->GetState()); | 1872 EXPECT_EQ(DownloadItem::COMPLETE, d3->GetState()); |
1911 EXPECT_EQ(3, d3->GetDbHandle()); | |
1912 EXPECT_TRUE(d3->GetOpened()); | 1873 EXPECT_TRUE(d3->GetOpened()); |
1913 } | 1874 } |
1914 search_results.clear(); | 1875 search_results.clear(); |
1915 | 1876 |
1916 string16 search_input; | 1877 string16 search_input; |
1917 manager->SearchDownloads(UTF8ToUTF16("www.google.com"), &search_results); | 1878 manager->SearchDownloads(UTF8ToUTF16("www.google.com"), &search_results); |
1918 ASSERT_EQ(2u, search_results.size()); | 1879 ASSERT_EQ(2u, search_results.size()); |
1919 std::sort(search_results.begin(), search_results.end(), | 1880 std::sort(search_results.begin(), search_results.end(), |
1920 DownloadItemSorter); | 1881 DownloadItemSorter); |
1921 EXPECT_EQ(1, search_results[0]->GetDbHandle()); | |
1922 EXPECT_EQ(2, search_results[1]->GetDbHandle()); | |
1923 search_results.clear(); | 1882 search_results.clear(); |
1924 | 1883 |
1925 manager->SearchDownloads(UTF8ToUTF16("real"), &search_results); | 1884 manager->SearchDownloads(UTF8ToUTF16("real"), &search_results); |
1926 ASSERT_EQ(2u, search_results.size()); | 1885 ASSERT_EQ(2u, search_results.size()); |
1927 std::sort(search_results.begin(), search_results.end(), | 1886 std::sort(search_results.begin(), search_results.end(), |
1928 DownloadItemSorter); | 1887 DownloadItemSorter); |
1929 EXPECT_EQ(2, search_results[0]->GetDbHandle()); | |
1930 EXPECT_EQ(3, search_results[1]->GetDbHandle()); | |
1931 search_results.clear(); | 1888 search_results.clear(); |
1932 | 1889 |
1933 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); | 1890 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); |
1934 ASSERT_EQ(2u, search_results.size()); | 1891 ASSERT_EQ(2u, search_results.size()); |
1935 std::sort(search_results.begin(), search_results.end(), | 1892 std::sort(search_results.begin(), search_results.end(), |
1936 DownloadItemSorter); | 1893 DownloadItemSorter); |
1937 EXPECT_EQ(2, search_results[0]->GetDbHandle()); | |
1938 EXPECT_EQ(3, search_results[1]->GetDbHandle()); | |
1939 search_results.clear(); | 1894 search_results.clear(); |
1940 } | 1895 } |
1941 | 1896 |
1942 // Tests for download initiation functions. | 1897 // Tests for download initiation functions. |
1943 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 1898 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
1944 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1899 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1945 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1900 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1946 | 1901 |
1947 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1902 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
1948 EnableFileChooser(true); | 1903 EnableFileChooser(true); |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2461 GetDownloads(browser(), &download_items); | 2416 GetDownloads(browser(), &download_items); |
2462 ASSERT_EQ(1u, download_items.size()); | 2417 ASSERT_EQ(1u, download_items.size()); |
2463 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2418 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
2464 download_items[0]->GetOriginalUrl()); | 2419 download_items[0]->GetOriginalUrl()); |
2465 | 2420 |
2466 // Check that the file contains the expected referrer. | 2421 // Check that the file contains the expected referrer. |
2467 FilePath file(download_items[0]->GetFullPath()); | 2422 FilePath file(download_items[0]->GetFullPath()); |
2468 std::string expected_contents = test_server()->GetURL("").spec(); | 2423 std::string expected_contents = test_server()->GetURL("").spec(); |
2469 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2424 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
2470 } | 2425 } |
OLD | NEW |