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

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

Issue 833033002: Remove dependency on //content from history DownloadDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove obsolete #include Created 5 years, 11 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
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | chrome/browser/download/download_history.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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 22 matching lines...) Expand all
33 #include "chrome/browser/download/download_prefs.h" 33 #include "chrome/browser/download/download_prefs.h"
34 #include "chrome/browser/download/download_request_limiter.h" 34 #include "chrome/browser/download/download_request_limiter.h"
35 #include "chrome/browser/download/download_service.h" 35 #include "chrome/browser/download/download_service.h"
36 #include "chrome/browser/download/download_service_factory.h" 36 #include "chrome/browser/download/download_service_factory.h"
37 #include "chrome/browser/download/download_shelf.h" 37 #include "chrome/browser/download/download_shelf.h"
38 #include "chrome/browser/download/download_target_determiner.h" 38 #include "chrome/browser/download/download_target_determiner.h"
39 #include "chrome/browser/download/download_test_file_activity_observer.h" 39 #include "chrome/browser/download/download_test_file_activity_observer.h"
40 #include "chrome/browser/extensions/extension_install_prompt.h" 40 #include "chrome/browser/extensions/extension_install_prompt.h"
41 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" 41 #include "chrome/browser/extensions/extension_install_prompt_show_params.h"
42 #include "chrome/browser/extensions/extension_service.h" 42 #include "chrome/browser/extensions/extension_service.h"
43 #include "chrome/browser/history/download_row.h"
44 #include "chrome/browser/history/history_service.h" 43 #include "chrome/browser/history/history_service.h"
45 #include "chrome/browser/history/history_service_factory.h" 44 #include "chrome/browser/history/history_service_factory.h"
46 #include "chrome/browser/infobars/infobar_service.h" 45 #include "chrome/browser/infobars/infobar_service.h"
47 #include "chrome/browser/net/url_request_mock_util.h" 46 #include "chrome/browser/net/url_request_mock_util.h"
48 #include "chrome/browser/profiles/profile.h" 47 #include "chrome/browser/profiles/profile.h"
49 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" 48 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
50 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 49 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
51 #include "chrome/browser/ui/browser.h" 50 #include "chrome/browser/ui/browser.h"
52 #include "chrome/browser/ui/browser_commands.h" 51 #include "chrome/browser/ui/browser_commands.h"
53 #include "chrome/browser/ui/browser_finder.h" 52 #include "chrome/browser/ui/browser_finder.h"
54 #include "chrome/browser/ui/browser_list.h" 53 #include "chrome/browser/ui/browser_list.h"
55 #include "chrome/browser/ui/browser_tabstrip.h" 54 #include "chrome/browser/ui/browser_tabstrip.h"
56 #include "chrome/browser/ui/browser_window.h" 55 #include "chrome/browser/ui/browser_window.h"
57 #include "chrome/browser/ui/chrome_pages.h" 56 #include "chrome/browser/ui/chrome_pages.h"
58 #include "chrome/browser/ui/host_desktop.h" 57 #include "chrome/browser/ui/host_desktop.h"
59 #include "chrome/browser/ui/tabs/tab_strip_model.h" 58 #include "chrome/browser/ui/tabs/tab_strip_model.h"
60 #include "chrome/common/chrome_paths.h" 59 #include "chrome/common/chrome_paths.h"
61 #include "chrome/common/pref_names.h" 60 #include "chrome/common/pref_names.h"
62 #include "chrome/common/safe_browsing/csd.pb.h" 61 #include "chrome/common/safe_browsing/csd.pb.h"
63 #include "chrome/common/url_constants.h" 62 #include "chrome/common/url_constants.h"
64 #include "chrome/grit/generated_resources.h" 63 #include "chrome/grit/generated_resources.h"
65 #include "chrome/test/base/in_process_browser_test.h" 64 #include "chrome/test/base/in_process_browser_test.h"
66 #include "chrome/test/base/test_switches.h" 65 #include "chrome/test/base/test_switches.h"
67 #include "chrome/test/base/ui_test_utils.h" 66 #include "chrome/test/base/ui_test_utils.h"
67 #include "components/history/content/browser/download_constants_utils.h"
68 #include "components/history/core/browser/download_constants.h"
69 #include "components/history/core/browser/download_row.h"
68 #include "components/infobars/core/confirm_infobar_delegate.h" 70 #include "components/infobars/core/confirm_infobar_delegate.h"
69 #include "components/infobars/core/infobar.h" 71 #include "components/infobars/core/infobar.h"
70 #include "content/public/browser/download_interrupt_reasons.h" 72 #include "content/public/browser/download_interrupt_reasons.h"
71 #include "content/public/browser/download_item.h" 73 #include "content/public/browser/download_item.h"
72 #include "content/public/browser/download_manager.h" 74 #include "content/public/browser/download_manager.h"
73 #include "content/public/browser/download_save_info.h" 75 #include "content/public/browser/download_save_info.h"
74 #include "content/public/browser/download_url_parameters.h" 76 #include "content/public/browser/download_url_parameters.h"
75 #include "content/public/browser/notification_source.h" 77 #include "content/public/browser/notification_source.h"
76 #include "content/public/browser/render_frame_host.h" 78 #include "content/public/browser/render_frame_host.h"
77 #include "content/public/browser/render_view_host.h" 79 #include "content/public/browser/render_view_host.h"
(...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 // Confirm history storage is what you expect for a partially completed 1769 // Confirm history storage is what you expect for a partially completed
1768 // slow download job. 1770 // slow download job.
1769 history::DownloadRow& row(downloads_in_database->at(0)); 1771 history::DownloadRow& row(downloads_in_database->at(0));
1770 EXPECT_EQ(DestinationFile(browser(), file), row.target_path); 1772 EXPECT_EQ(DestinationFile(browser(), file), row.target_path);
1771 EXPECT_EQ(DownloadTargetDeterminer::GetCrDownloadPath( 1773 EXPECT_EQ(DownloadTargetDeterminer::GetCrDownloadPath(
1772 DestinationFile(browser(), file)), 1774 DestinationFile(browser(), file)),
1773 row.current_path); 1775 row.current_path);
1774 ASSERT_EQ(2u, row.url_chain.size()); 1776 ASSERT_EQ(2u, row.url_chain.size());
1775 EXPECT_EQ(redirect_url.spec(), row.url_chain[0].spec()); 1777 EXPECT_EQ(redirect_url.spec(), row.url_chain[0].spec());
1776 EXPECT_EQ(download_url.spec(), row.url_chain[1].spec()); 1778 EXPECT_EQ(download_url.spec(), row.url_chain[1].spec());
1777 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, row.danger_type); 1779 EXPECT_EQ(history::DownloadDangerType::NOT_DANGEROUS, row.danger_type);
1778 EXPECT_LE(start, row.start_time); 1780 EXPECT_LE(start, row.start_time);
1779 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize, row.received_bytes); 1781 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize, row.received_bytes);
1780 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize 1782 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize
1781 + URLRequestSlowDownloadJob::kSecondDownloadSize, row.total_bytes); 1783 + URLRequestSlowDownloadJob::kSecondDownloadSize, row.total_bytes);
1782 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, row.state); 1784 EXPECT_EQ(history::DownloadState::IN_PROGRESS, row.state);
1783 EXPECT_FALSE(row.opened); 1785 EXPECT_FALSE(row.opened);
1784 1786
1785 // Finish the download. We're ok relying on the history to be flushed 1787 // Finish the download. We're ok relying on the history to be flushed
1786 // at this point as our queries will be behind the history updates 1788 // at this point as our queries will be behind the history updates
1787 // invoked by completion. 1789 // invoked by completion.
1788 scoped_ptr<content::DownloadTestObserver> download_observer( 1790 scoped_ptr<content::DownloadTestObserver> download_observer(
1789 CreateWaiter(browser(), 1)); 1791 CreateWaiter(browser(), 1));
1790 ui_test_utils::NavigateToURL(browser(), 1792 ui_test_utils::NavigateToURL(browser(),
1791 GURL(URLRequestSlowDownloadJob::kErrorDownloadUrl)); 1793 GURL(URLRequestSlowDownloadJob::kErrorDownloadUrl));
1792 download_observer->WaitForFinished(); 1794 download_observer->WaitForFinished();
1793 EXPECT_EQ(1u, download_observer->NumDownloadsSeenInState( 1795 EXPECT_EQ(1u, download_observer->NumDownloadsSeenInState(
1794 DownloadItem::INTERRUPTED)); 1796 DownloadItem::INTERRUPTED));
1795 base::Time end(base::Time::Now()); 1797 base::Time end(base::Time::Now());
1796 1798
1797 // Get what was stored in the history. 1799 // Get what was stored in the history.
1798 ASSERT_TRUE(DownloadsHistoryDataCollector( 1800 ASSERT_TRUE(DownloadsHistoryDataCollector(
1799 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); 1801 browser()->profile()).WaitForDownloadInfo(&downloads_in_database));
1800 ASSERT_EQ(1u, downloads_in_database->size()); 1802 ASSERT_EQ(1u, downloads_in_database->size());
1801 1803
1802 // Confirm history storage is what you expect for an interrupted slow download 1804 // Confirm history storage is what you expect for an interrupted slow download
1803 // job. The download isn't continuable, so there's no intermediate file. 1805 // job. The download isn't continuable, so there's no intermediate file.
1804 history::DownloadRow& row1(downloads_in_database->at(0)); 1806 history::DownloadRow& row1(downloads_in_database->at(0));
1805 EXPECT_EQ(DestinationFile(browser(), file), row1.target_path); 1807 EXPECT_EQ(DestinationFile(browser(), file), row1.target_path);
1806 EXPECT_TRUE(row1.current_path.empty()); 1808 EXPECT_TRUE(row1.current_path.empty());
1807 ASSERT_EQ(2u, row1.url_chain.size()); 1809 ASSERT_EQ(2u, row1.url_chain.size());
1808 EXPECT_EQ(redirect_url.spec(), row1.url_chain[0].spec()); 1810 EXPECT_EQ(redirect_url.spec(), row1.url_chain[0].spec());
1809 EXPECT_EQ(download_url.spec(), row1.url_chain[1].spec()); 1811 EXPECT_EQ(download_url.spec(), row1.url_chain[1].spec());
1810 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, row1.danger_type); 1812 EXPECT_EQ(history::DownloadDangerType::NOT_DANGEROUS, row1.danger_type);
1811 EXPECT_LE(start, row1.start_time); 1813 EXPECT_LE(start, row1.start_time);
1812 EXPECT_GE(end, row1.end_time); 1814 EXPECT_GE(end, row1.end_time);
1813 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize, 1815 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize,
1814 row1.received_bytes); 1816 row1.received_bytes);
1815 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize 1817 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize
1816 + URLRequestSlowDownloadJob::kSecondDownloadSize, row1.total_bytes); 1818 + URLRequestSlowDownloadJob::kSecondDownloadSize, row1.total_bytes);
1817 EXPECT_EQ(content::DownloadItem::INTERRUPTED, row1.state); 1819 EXPECT_EQ(history::DownloadState::INTERRUPTED, row1.state);
1818 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, 1820 EXPECT_EQ(history::ToHistoryDownloadInterruptReason(
1821 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED),
1819 row1.interrupt_reason); 1822 row1.interrupt_reason);
1820 EXPECT_FALSE(row1.opened); 1823 EXPECT_FALSE(row1.opened);
1821 } 1824 }
1822 1825
1823 // Make sure a dangerous file shows up properly in the history. 1826 // Make sure a dangerous file shows up properly in the history.
1824 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryDangerCheck) { 1827 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryDangerCheck) {
1825 #if defined(OS_WIN) && defined(USE_ASH) 1828 #if defined(OS_WIN) && defined(USE_ASH)
1826 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 1829 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
1827 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1830 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1828 switches::kAshBrowserTests)) 1831 switches::kAshBrowserTests))
(...skipping 21 matching lines...) Expand all
1850 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); 1853 browser()->profile()).WaitForDownloadInfo(&downloads_in_database));
1851 ASSERT_EQ(1u, downloads_in_database->size()); 1854 ASSERT_EQ(1u, downloads_in_database->size());
1852 1855
1853 // Confirm history storage is what you expect for an unvalidated 1856 // Confirm history storage is what you expect for an unvalidated
1854 // dangerous file. 1857 // dangerous file.
1855 history::DownloadRow& row(downloads_in_database->at(0)); 1858 history::DownloadRow& row(downloads_in_database->at(0));
1856 EXPECT_EQ(DestinationFile(browser(), file), row.target_path); 1859 EXPECT_EQ(DestinationFile(browser(), file), row.target_path);
1857 EXPECT_NE(DownloadTargetDeterminer::GetCrDownloadPath( 1860 EXPECT_NE(DownloadTargetDeterminer::GetCrDownloadPath(
1858 DestinationFile(browser(), file)), 1861 DestinationFile(browser(), file)),
1859 row.current_path); 1862 row.current_path);
1860 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, row.danger_type); 1863 EXPECT_EQ(history::DownloadDangerType::DANGEROUS_FILE, row.danger_type);
1861 EXPECT_LE(start, row.start_time); 1864 EXPECT_LE(start, row.start_time);
1862 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, row.state); 1865 EXPECT_EQ(history::DownloadState::IN_PROGRESS, row.state);
1863 EXPECT_FALSE(row.opened); 1866 EXPECT_FALSE(row.opened);
1864 1867
1865 // Validate the download and wait for it to finish. 1868 // Validate the download and wait for it to finish.
1866 std::vector<DownloadItem*> downloads; 1869 std::vector<DownloadItem*> downloads;
1867 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); 1870 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
1868 ASSERT_EQ(1u, downloads.size()); 1871 ASSERT_EQ(1u, downloads.size());
1869 downloads[0]->ValidateDangerousDownload(); 1872 downloads[0]->ValidateDangerousDownload();
1870 download_observer->WaitForFinished(); 1873 download_observer->WaitForFinished();
1871 1874
1872 // Get history details and confirm it's what you expect. 1875 // Get history details and confirm it's what you expect.
1873 downloads_in_database->clear(); 1876 downloads_in_database->clear();
1874 ASSERT_TRUE(DownloadsHistoryDataCollector( 1877 ASSERT_TRUE(DownloadsHistoryDataCollector(
1875 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); 1878 browser()->profile()).WaitForDownloadInfo(&downloads_in_database));
1876 ASSERT_EQ(1u, downloads_in_database->size()); 1879 ASSERT_EQ(1u, downloads_in_database->size());
1877 history::DownloadRow& row1(downloads_in_database->at(0)); 1880 history::DownloadRow& row1(downloads_in_database->at(0));
1878 EXPECT_EQ(DestinationFile(browser(), file), row1.target_path); 1881 EXPECT_EQ(DestinationFile(browser(), file), row1.target_path);
1879 EXPECT_EQ(DestinationFile(browser(), file), row1.current_path); 1882 EXPECT_EQ(DestinationFile(browser(), file), row1.current_path);
1880 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED, row1.danger_type); 1883 EXPECT_EQ(history::DownloadDangerType::USER_VALIDATED, row1.danger_type);
1881 EXPECT_LE(start, row1.start_time); 1884 EXPECT_LE(start, row1.start_time);
1882 EXPECT_EQ(content::DownloadItem::COMPLETE, row1.state); 1885 EXPECT_EQ(history::DownloadState::COMPLETE, row1.state);
1883 EXPECT_FALSE(row1.opened); 1886 EXPECT_FALSE(row1.opened);
1884 // Not checking file size--not relevant to the point of the test, and 1887 // Not checking file size--not relevant to the point of the test, and
1885 // the file size is actually different on Windows and other platforms, 1888 // the file size is actually different on Windows and other platforms,
1886 // because for source control simplicity it's actually a text file, and 1889 // because for source control simplicity it's actually a text file, and
1887 // there are CRLF transformations for those files. 1890 // there are CRLF transformations for those files.
1888 } 1891 }
1889 1892
1890 IN_PROC_BROWSER_TEST_F(DownloadTest, PRE_DownloadTest_History) { 1893 IN_PROC_BROWSER_TEST_F(DownloadTest, PRE_DownloadTest_History) {
1891 // Download a file and wait for it to be stored. 1894 // Download a file and wait for it to be stored.
1892 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1895 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
(...skipping 1626 matching lines...) Expand 10 before | Expand all | Expand 10 after
3519 *(downloads[0]))); 3522 *(downloads[0])));
3520 3523
3521 // Begin feedback and check that the file is "stolen". 3524 // Begin feedback and check that the file is "stolen".
3522 download_protection_service->feedback_service()->BeginFeedbackForDownload( 3525 download_protection_service->feedback_service()->BeginFeedbackForDownload(
3523 downloads[0]); 3526 downloads[0]);
3524 std::vector<DownloadItem*> updated_downloads; 3527 std::vector<DownloadItem*> updated_downloads;
3525 GetDownloads(browser(), &updated_downloads); 3528 GetDownloads(browser(), &updated_downloads);
3526 ASSERT_TRUE(updated_downloads.empty()); 3529 ASSERT_TRUE(updated_downloads.empty());
3527 } 3530 }
3528 #endif 3531 #endif
OLDNEW
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | chrome/browser/download/download_history.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698