Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 10905215: Kill DownloadManager::SearchDownloads, DownloadItem::MatchesQuery (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/download/download_query.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 content::DownloadUpdatedObserver( 1705 content::DownloadUpdatedObserver(
1706 downloads[0], base::Bind(WasAutoOpened)).WaitForEvent(); 1706 downloads[0], base::Bind(WasAutoOpened)).WaitForEvent();
1707 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1707 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1708 1708
1709 // Check that the extension was installed. 1709 // Check that the extension was installed.
1710 ExtensionService* extension_service = 1710 ExtensionService* extension_service =
1711 browser()->profile()->GetExtensionService(); 1711 browser()->profile()->GetExtensionService();
1712 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); 1712 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
1713 } 1713 }
1714 1714
1715 // Sort download items by db_handle.
1716 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) {
1717 return d1->GetDbHandle() < d2->GetDbHandle();
1718 }
1719
1720 // Confirm that searching through the history works properly
1721 IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) {
1722 // Downloads to populate history with.
1723 base::Time current(base::Time::Now());
1724 DownloadPersistentStoreInfo population_entries[] = {
1725 DownloadPersistentStoreInfo(
1726 FilePath(FILE_PATH_LITERAL("/path/to/file")),
1727 GURL("http://www.google.com/fantasy_download"),
1728 GURL(""),
1729 current - base::TimeDelta::FromMinutes(5),
1730 current,
1731 128,
1732 128,
1733 DownloadItem::COMPLETE,
1734 1,
1735 false),
1736 DownloadPersistentStoreInfo(
1737 FilePath(FILE_PATH_LITERAL("/path/to/another_file")),
1738 GURL("http://www.google.com/reality_download"),
1739 GURL(""),
1740 current - base::TimeDelta::FromMinutes(10),
1741 current,
1742 256,
1743 256,
1744 DownloadItem::COMPLETE,
1745 2,
1746 false),
1747 DownloadPersistentStoreInfo(
1748 FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")),
1749 GURL("http://www.izzle.com/not_really_a_download"),
1750 GURL(""),
1751 current - base::TimeDelta::FromMinutes(15),
1752 current,
1753 512,
1754 512,
1755 DownloadItem::COMPLETE,
1756 3,
1757 true)
1758 };
1759 std::vector<DownloadPersistentStoreInfo> entries(
1760 population_entries, population_entries + arraysize(population_entries));
1761
1762 // Populate the manager.
1763 DownloadManager* manager = DownloadManagerForBrowser(browser());
1764 manager->OnPersistentStoreQueryComplete(&entries);
1765
1766 // Do some searches and check the results.
1767 std::vector<DownloadItem*> search_results;
1768
1769 manager->GetAllDownloads(&search_results);
1770 ASSERT_EQ(3u, search_results.size());
1771 std::sort(search_results.begin(), search_results.end(),
1772 DownloadItemSorter);
1773 // We do a full check only once to protect against the data
1774 // somehow getting scrambled on its way into the DownloadItems.
1775 {
1776 DownloadItem* d1 = search_results[0];
1777 DownloadItem* d2 = search_results[1];
1778 DownloadItem* d3 = search_results[2];
1779 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath());
1780 EXPECT_EQ(GURL("http://www.google.com/fantasy_download"),
1781 d1->GetOriginalUrl());
1782 EXPECT_EQ(current - base::TimeDelta::FromMinutes(5),
1783 d1->GetStartTime());
1784 EXPECT_EQ(current, d1->GetEndTime());
1785 EXPECT_EQ(128, d1->GetReceivedBytes());
1786 EXPECT_EQ(128, d1->GetTotalBytes());
1787 EXPECT_EQ(DownloadItem::COMPLETE, d1->GetState());
1788 EXPECT_EQ(1, d1->GetDbHandle());
1789 EXPECT_FALSE(d1->GetOpened());
1790
1791 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/another_file")),
1792 d2->GetFullPath());
1793 EXPECT_EQ(GURL("http://www.google.com/reality_download"),
1794 d2->GetOriginalUrl());
1795 EXPECT_EQ(current - base::TimeDelta::FromMinutes(10),
1796 d2->GetStartTime());
1797 EXPECT_EQ(current, d2->GetEndTime());
1798 EXPECT_EQ(256, d2->GetReceivedBytes());
1799 EXPECT_EQ(256, d2->GetTotalBytes());
1800 EXPECT_EQ(DownloadItem::COMPLETE, d2->GetState());
1801 EXPECT_EQ(2, d2->GetDbHandle());
1802 EXPECT_FALSE(d2->GetOpened());
1803
1804 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")),
1805 d3->GetFullPath());
1806 EXPECT_EQ(GURL("http://www.izzle.com/not_really_a_download"),
1807 d3->GetOriginalUrl());
1808 EXPECT_EQ(current - base::TimeDelta::FromMinutes(15),
1809 d3->GetStartTime());
1810 EXPECT_EQ(current, d3->GetEndTime());
1811 EXPECT_EQ(512, d3->GetReceivedBytes());
1812 EXPECT_EQ(512, d3->GetTotalBytes());
1813 EXPECT_EQ(DownloadItem::COMPLETE, d3->GetState());
1814 EXPECT_EQ(3, d3->GetDbHandle());
1815 EXPECT_TRUE(d3->GetOpened());
1816 }
1817 search_results.clear();
1818
1819 string16 search_input;
1820 manager->SearchDownloads(UTF8ToUTF16("www.google.com"), &search_results);
1821 ASSERT_EQ(2u, search_results.size());
1822 std::sort(search_results.begin(), search_results.end(),
1823 DownloadItemSorter);
1824 EXPECT_EQ(1, search_results[0]->GetDbHandle());
1825 EXPECT_EQ(2, search_results[1]->GetDbHandle());
1826 search_results.clear();
1827
1828 manager->SearchDownloads(UTF8ToUTF16("real"), &search_results);
1829 ASSERT_EQ(2u, search_results.size());
1830 std::sort(search_results.begin(), search_results.end(),
1831 DownloadItemSorter);
1832 EXPECT_EQ(2, search_results[0]->GetDbHandle());
1833 EXPECT_EQ(3, search_results[1]->GetDbHandle());
1834 search_results.clear();
1835
1836 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results);
1837 ASSERT_EQ(2u, search_results.size());
1838 std::sort(search_results.begin(), search_results.end(),
1839 DownloadItemSorter);
1840 EXPECT_EQ(2, search_results[0]->GetDbHandle());
1841 EXPECT_EQ(3, search_results[1]->GetDbHandle());
1842 search_results.clear();
1843 }
1844
1845 // Tests for download initiation functions. 1715 // Tests for download initiation functions.
1846 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { 1716 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) {
1847 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1717 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1848 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1718 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1849 1719
1850 // DownloadUrl always prompts; return acceptance of whatever it prompts. 1720 // DownloadUrl always prompts; return acceptance of whatever it prompts.
1851 EnableFileChooser(true); 1721 EnableFileChooser(true);
1852 1722
1853 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 1723 WebContents* web_contents = chrome::GetActiveWebContents(browser());
1854 ASSERT_TRUE(web_contents); 1724 ASSERT_TRUE(web_contents);
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 GetDownloads(browser(), &download_items); 2235 GetDownloads(browser(), &download_items);
2366 ASSERT_EQ(1u, download_items.size()); 2236 ASSERT_EQ(1u, download_items.size());
2367 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), 2237 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"),
2368 download_items[0]->GetOriginalUrl()); 2238 download_items[0]->GetOriginalUrl());
2369 2239
2370 // Check that the file contains the expected referrer. 2240 // Check that the file contains the expected referrer.
2371 FilePath file(download_items[0]->GetFullPath()); 2241 FilePath file(download_items[0]->GetFullPath());
2372 std::string expected_contents = test_server()->GetURL("").spec(); 2242 std::string expected_contents = test_server()->GetURL("").spec();
2373 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); 2243 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length()));
2374 } 2244 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_query.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698