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

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

Issue 2860593003: Refactoring DownloadManager::DownloadURL to add proper annotation. (Closed)
Patch Set: Comment addressed. Created 3 years, 6 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
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 "chrome/browser/download/download_browsertest.h" 5 #include "chrome/browser/download/download_browsertest.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 #include "content/public/test/test_navigation_observer.h" 105 #include "content/public/test/test_navigation_observer.h"
106 #include "extensions/browser/extension_dialog_auto_confirm.h" 106 #include "extensions/browser/extension_dialog_auto_confirm.h"
107 #include "extensions/browser/extension_system.h" 107 #include "extensions/browser/extension_system.h"
108 #include "net/base/filename_util.h" 108 #include "net/base/filename_util.h"
109 #include "net/dns/mock_host_resolver.h" 109 #include "net/dns/mock_host_resolver.h"
110 #include "net/test/embedded_test_server/embedded_test_server.h" 110 #include "net/test/embedded_test_server/embedded_test_server.h"
111 #include "net/test/embedded_test_server/http_request.h" 111 #include "net/test/embedded_test_server/http_request.h"
112 #include "net/test/embedded_test_server/http_response.h" 112 #include "net/test/embedded_test_server/http_response.h"
113 #include "net/test/url_request/url_request_mock_http_job.h" 113 #include "net/test/url_request/url_request_mock_http_job.h"
114 #include "net/test/url_request/url_request_slow_download_job.h" 114 #include "net/test/url_request/url_request_slow_download_job.h"
115 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
115 #include "testing/gtest/include/gtest/gtest.h" 116 #include "testing/gtest/include/gtest/gtest.h"
116 #include "ui/base/l10n/l10n_util.h" 117 #include "ui/base/l10n/l10n_util.h"
117 #include "ui/base/page_transition_types.h" 118 #include "ui/base/page_transition_types.h"
118 119
119 #if defined(FULL_SAFE_BROWSING) 120 #if defined(FULL_SAFE_BROWSING)
120 #include "chrome/browser/safe_browsing/download_feedback_service.h" 121 #include "chrome/browser/safe_browsing/download_feedback_service.h"
121 #include "chrome/browser/safe_browsing/download_protection_service.h" 122 #include "chrome/browser/safe_browsing/download_protection_service.h"
122 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" 123 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
123 #endif 124 #endif
124 125
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 884
884 if (download_info.download_method == DOWNLOAD_DIRECT) { 885 if (download_info.download_method == DOWNLOAD_DIRECT) {
885 // Go directly to download. Don't wait for navigation. 886 // Go directly to download. Don't wait for navigation.
886 scoped_refptr<content::DownloadTestItemCreationObserver> 887 scoped_refptr<content::DownloadTestItemCreationObserver>
887 creation_observer(new content::DownloadTestItemCreationObserver); 888 creation_observer(new content::DownloadTestItemCreationObserver);
888 889
889 std::unique_ptr<DownloadUrlParameters> params( 890 std::unique_ptr<DownloadUrlParameters> params(
890 DownloadUrlParameters::CreateForWebContentsMainFrame( 891 DownloadUrlParameters::CreateForWebContentsMainFrame(
891 web_contents, starting_url)); 892 web_contents, starting_url));
892 params->set_callback(creation_observer->callback()); 893 params->set_callback(creation_observer->callback());
893 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 894 DownloadManagerForBrowser(browser())->DownloadUrl(
895 std::move(params), TRAFFIC_ANNOTATION_FOR_TESTS);
894 896
895 // Wait until the item is created, or we have determined that it 897 // Wait until the item is created, or we have determined that it
896 // won't be. 898 // won't be.
897 creation_observer->WaitForDownloadItemCreation(); 899 creation_observer->WaitForDownloadItemCreation();
898 900
899 EXPECT_NE(content::DownloadItem::kInvalidId, 901 EXPECT_NE(content::DownloadItem::kInvalidId,
900 creation_observer->download_id()); 902 creation_observer->download_id());
901 } else { 903 } else {
902 // Navigate to URL normally, wait until done. 904 // Navigate to URL normally, wait until done.
903 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 905 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 ASSERT_TRUE(new_tab); 1718 ASSERT_TRUE(new_tab);
1717 ASSERT_TRUE(new_tab->GetController().IsInitialNavigation()); 1719 ASSERT_TRUE(new_tab->GetController().IsInitialNavigation());
1718 browser()->tab_strip_model()->AppendWebContents(new_tab, true); 1720 browser()->tab_strip_model()->AppendWebContents(new_tab, true);
1719 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 1721 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1720 1722
1721 // Download a file in that new tab, having it open a file picker 1723 // Download a file in that new tab, having it open a file picker
1722 std::unique_ptr<DownloadUrlParameters> params( 1724 std::unique_ptr<DownloadUrlParameters> params(
1723 DownloadUrlParameters::CreateForWebContentsMainFrame( 1725 DownloadUrlParameters::CreateForWebContentsMainFrame(
1724 new_tab, slow_download_url)); 1726 new_tab, slow_download_url));
1725 params->set_prompt(true); 1727 params->set_prompt(true);
1726 manager->DownloadUrl(std::move(params)); 1728 manager->DownloadUrl(std::move(params), TRAFFIC_ANNOTATION_FOR_TESTS);
1727 observer->WaitForFinished(); 1729 observer->WaitForFinished();
1728 1730
1729 DownloadManager::DownloadVector items; 1731 DownloadManager::DownloadVector items;
1730 manager->GetAllDownloads(&items); 1732 manager->GetAllDownloads(&items);
1731 ASSERT_NE(0u, items.size()); 1733 ASSERT_NE(0u, items.size());
1732 DownloadItem* item = items[0]; 1734 DownloadItem* item = items[0];
1733 EXPECT_TRUE(item != nullptr); 1735 EXPECT_TRUE(item != nullptr);
1734 1736
1735 // When the download is canceled, the second tab should close. 1737 // When the download is canceled, the second tab should close.
1736 EXPECT_EQ(item->GetState(), DownloadItem::CANCELLED); 1738 EXPECT_EQ(item->GetState(), DownloadItem::CANCELLED);
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 ASSERT_TRUE(web_contents); 2195 ASSERT_TRUE(web_contents);
2194 2196
2195 content::DownloadTestObserver* observer( 2197 content::DownloadTestObserver* observer(
2196 new content::DownloadTestObserverTerminal( 2198 new content::DownloadTestObserverTerminal(
2197 DownloadManagerForBrowser(browser()), 1, 2199 DownloadManagerForBrowser(browser()), 1,
2198 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2200 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2199 std::unique_ptr<DownloadUrlParameters> params( 2201 std::unique_ptr<DownloadUrlParameters> params(
2200 DownloadUrlParameters::CreateForWebContentsMainFrame( 2202 DownloadUrlParameters::CreateForWebContentsMainFrame(
2201 web_contents, url)); 2203 web_contents, url));
2202 params->set_prompt(true); 2204 params->set_prompt(true);
2203 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 2205 DownloadManagerForBrowser(browser())->DownloadUrl(
2206 std::move(params), TRAFFIC_ANNOTATION_FOR_TESTS);
2204 observer->WaitForFinished(); 2207 observer->WaitForFinished();
2205 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2208 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2206 CheckDownloadStates(1, DownloadItem::COMPLETE); 2209 CheckDownloadStates(1, DownloadItem::COMPLETE);
2207 EXPECT_TRUE(DidShowFileChooser()); 2210 EXPECT_TRUE(DidShowFileChooser());
2208 2211
2209 // Check state. 2212 // Check state.
2210 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2213 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2211 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2214 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2212 ASSERT_TRUE(CheckDownload(browser(), file, file)); 2215 ASSERT_TRUE(CheckDownload(browser(), file, file));
2213 } 2216 }
2214 2217
2215 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 2218 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
2216 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); 2219 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path));
2217 2220
2218 WebContents* web_contents = 2221 WebContents* web_contents =
2219 browser()->tab_strip_model()->GetActiveWebContents(); 2222 browser()->tab_strip_model()->GetActiveWebContents();
2220 ASSERT_TRUE(web_contents); 2223 ASSERT_TRUE(web_contents);
2221 2224
2222 base::ThreadRestrictions::ScopedAllowIO allow_io; 2225 base::ThreadRestrictions::ScopedAllowIO allow_io;
2223 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2226 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2224 base::ScopedTempDir other_directory; 2227 base::ScopedTempDir other_directory;
2225 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 2228 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
2226 base::FilePath target_file_full_path = 2229 base::FilePath target_file_full_path =
2227 other_directory.GetPath().Append(file.BaseName()); 2230 other_directory.GetPath().Append(file.BaseName());
2228 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 2231 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1));
2229 std::unique_ptr<DownloadUrlParameters> params( 2232 std::unique_ptr<DownloadUrlParameters> params(
2230 DownloadUrlParameters::CreateForWebContentsMainFrame( 2233 DownloadUrlParameters::CreateForWebContentsMainFrame(
2231 web_contents, url)); 2234 web_contents, url));
2232 params->set_file_path(target_file_full_path); 2235 params->set_file_path(target_file_full_path);
2233 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 2236 DownloadManagerForBrowser(browser())->DownloadUrl(
2237 std::move(params), TRAFFIC_ANNOTATION_FOR_TESTS);
2234 observer->WaitForFinished(); 2238 observer->WaitForFinished();
2235 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2239 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2236 2240
2237 // Check state. 2241 // Check state.
2238 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2242 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2239 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 2243 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
2240 target_file_full_path, 2244 target_file_full_path,
2241 OriginFile(file))); 2245 OriginFile(file)));
2242 2246
2243 // Temporary are treated as auto-opened, and after that open won't be 2247 // Temporary are treated as auto-opened, and after that open won't be
(...skipping 16 matching lines...) Expand all
2260 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2264 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2261 base::ScopedTempDir other_directory; 2265 base::ScopedTempDir other_directory;
2262 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 2266 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
2263 base::FilePath target_file_full_path = 2267 base::FilePath target_file_full_path =
2264 other_directory.GetPath().Append(file.BaseName()); 2268 other_directory.GetPath().Append(file.BaseName());
2265 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 2269 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1));
2266 std::unique_ptr<DownloadUrlParameters> params( 2270 std::unique_ptr<DownloadUrlParameters> params(
2267 DownloadUrlParameters::CreateForWebContentsMainFrame(web_contents, url)); 2271 DownloadUrlParameters::CreateForWebContentsMainFrame(web_contents, url));
2268 params->set_file_path(target_file_full_path); 2272 params->set_file_path(target_file_full_path);
2269 params->set_transient(true); 2273 params->set_transient(true);
2270 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 2274 DownloadManagerForBrowser(browser())->DownloadUrl(
2275 std::move(params), TRAFFIC_ANNOTATION_FOR_TESTS);
2271 observer->WaitForFinished(); 2276 observer->WaitForFinished();
2272 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2277 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2273 2278
2274 // Check state. 2279 // Check state.
2275 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2280 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2276 ASSERT_TRUE(CheckDownloadFullPaths(browser(), target_file_full_path, 2281 ASSERT_TRUE(CheckDownloadFullPaths(browser(), target_file_full_path,
2277 OriginFile(file))); 2282 OriginFile(file)));
2278 2283
2279 std::vector<DownloadItem*> downloads; 2284 std::vector<DownloadItem*> downloads;
2280 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); 2285 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after
3830 download_manager, 1, 3835 download_manager, 1,
3831 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 3836 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
3832 3837
3833 // Download and set IsHiddenDownload to true. 3838 // Download and set IsHiddenDownload to true.
3834 WebContents* web_contents = 3839 WebContents* web_contents =
3835 browser()->tab_strip_model()->GetActiveWebContents(); 3840 browser()->tab_strip_model()->GetActiveWebContents();
3836 std::unique_ptr<DownloadUrlParameters> params( 3841 std::unique_ptr<DownloadUrlParameters> params(
3837 DownloadUrlParameters::CreateForWebContentsMainFrame( 3842 DownloadUrlParameters::CreateForWebContentsMainFrame(
3838 web_contents, url)); 3843 web_contents, url));
3839 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); 3844 params->set_callback(base::Bind(&SetHiddenDownloadCallback));
3840 download_manager->DownloadUrl(std::move(params)); 3845 download_manager->DownloadUrl(std::move(params),
3846 TRAFFIC_ANNOTATION_FOR_TESTS);
3841 observer->WaitForFinished(); 3847 observer->WaitForFinished();
3842 3848
3843 // Verify that download shelf is not shown. 3849 // Verify that download shelf is not shown.
3844 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3850 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3845 } 3851 }
3846 3852
3847 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpenClosesShelf) { 3853 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpenClosesShelf) {
3848 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); 3854 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt"));
3849 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-autoopen.txt")); 3855 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-autoopen.txt"));
3850 3856
(...skipping 17 matching lines...) Expand all
3868 browser(), 1, 3874 browser(), 1,
3869 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3875 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3870 ui_test_utils::NavigateToURL(browser(), extension_url); 3876 ui_test_utils::NavigateToURL(browser(), extension_url);
3871 3877
3872 observer->WaitForFinished(); 3878 observer->WaitForFinished();
3873 3879
3874 // Download shelf should close. 3880 // Download shelf should close.
3875 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3881 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3876 } 3882 }
3877 #endif // defined(OS_CHROMEOS) 3883 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698