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

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

Issue 2860593003: Refactoring DownloadManager::DownloadURL to add proper annotation. (Closed)
Patch Set: Annotation moved to DownloadManager::DownloadUrl. 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 #include "content/public/test/test_navigation_observer.h" 106 #include "content/public/test/test_navigation_observer.h"
107 #include "extensions/browser/extension_dialog_auto_confirm.h" 107 #include "extensions/browser/extension_dialog_auto_confirm.h"
108 #include "extensions/browser/extension_system.h" 108 #include "extensions/browser/extension_system.h"
109 #include "net/base/filename_util.h" 109 #include "net/base/filename_util.h"
110 #include "net/dns/mock_host_resolver.h" 110 #include "net/dns/mock_host_resolver.h"
111 #include "net/test/embedded_test_server/embedded_test_server.h" 111 #include "net/test/embedded_test_server/embedded_test_server.h"
112 #include "net/test/embedded_test_server/http_request.h" 112 #include "net/test/embedded_test_server/http_request.h"
113 #include "net/test/embedded_test_server/http_response.h" 113 #include "net/test/embedded_test_server/http_response.h"
114 #include "net/test/url_request/url_request_mock_http_job.h" 114 #include "net/test/url_request/url_request_mock_http_job.h"
115 #include "net/test/url_request/url_request_slow_download_job.h" 115 #include "net/test/url_request/url_request_slow_download_job.h"
116 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
116 #include "testing/gtest/include/gtest/gtest.h" 117 #include "testing/gtest/include/gtest/gtest.h"
117 #include "ui/base/l10n/l10n_util.h" 118 #include "ui/base/l10n/l10n_util.h"
118 #include "ui/base/page_transition_types.h" 119 #include "ui/base/page_transition_types.h"
119 120
120 #if defined(FULL_SAFE_BROWSING) 121 #if defined(FULL_SAFE_BROWSING)
121 #include "chrome/browser/safe_browsing/download_feedback_service.h" 122 #include "chrome/browser/safe_browsing/download_feedback_service.h"
122 #include "chrome/browser/safe_browsing/download_protection_service.h" 123 #include "chrome/browser/safe_browsing/download_protection_service.h"
123 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" 124 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
124 #endif 125 #endif
125 126
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 892
892 if (download_info.download_method == DOWNLOAD_DIRECT) { 893 if (download_info.download_method == DOWNLOAD_DIRECT) {
893 // Go directly to download. Don't wait for navigation. 894 // Go directly to download. Don't wait for navigation.
894 scoped_refptr<content::DownloadTestItemCreationObserver> 895 scoped_refptr<content::DownloadTestItemCreationObserver>
895 creation_observer(new content::DownloadTestItemCreationObserver); 896 creation_observer(new content::DownloadTestItemCreationObserver);
896 897
897 std::unique_ptr<DownloadUrlParameters> params( 898 std::unique_ptr<DownloadUrlParameters> params(
898 DownloadUrlParameters::CreateForWebContentsMainFrame( 899 DownloadUrlParameters::CreateForWebContentsMainFrame(
899 web_contents, starting_url)); 900 web_contents, starting_url));
900 params->set_callback(creation_observer->callback()); 901 params->set_callback(creation_observer->callback());
901 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 902 DownloadManagerForBrowser(browser())->DownloadUrl(
903 std::move(params), TRAFFIC_ANNOTATION_FOR_TESTS);
902 904
903 // Wait until the item is created, or we have determined that it 905 // Wait until the item is created, or we have determined that it
904 // won't be. 906 // won't be.
905 creation_observer->WaitForDownloadItemCreation(); 907 creation_observer->WaitForDownloadItemCreation();
906 908
907 EXPECT_NE(content::DownloadItem::kInvalidId, 909 EXPECT_NE(content::DownloadItem::kInvalidId,
908 creation_observer->download_id()); 910 creation_observer->download_id());
909 } else { 911 } else {
910 // Navigate to URL normally, wait until done. 912 // Navigate to URL normally, wait until done.
911 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 913 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 ASSERT_TRUE(new_tab); 1730 ASSERT_TRUE(new_tab);
1729 ASSERT_TRUE(new_tab->GetController().IsInitialNavigation()); 1731 ASSERT_TRUE(new_tab->GetController().IsInitialNavigation());
1730 browser()->tab_strip_model()->AppendWebContents(new_tab, true); 1732 browser()->tab_strip_model()->AppendWebContents(new_tab, true);
1731 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 1733 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1732 1734
1733 // Download a file in that new tab, having it open a file picker 1735 // Download a file in that new tab, having it open a file picker
1734 std::unique_ptr<DownloadUrlParameters> params( 1736 std::unique_ptr<DownloadUrlParameters> params(
1735 DownloadUrlParameters::CreateForWebContentsMainFrame( 1737 DownloadUrlParameters::CreateForWebContentsMainFrame(
1736 new_tab, slow_download_url)); 1738 new_tab, slow_download_url));
1737 params->set_prompt(true); 1739 params->set_prompt(true);
1738 manager->DownloadUrl(std::move(params)); 1740 manager->DownloadUrl(std::move(params), TRAFFIC_ANNOTATION_FOR_TESTS);
1739 observer->WaitForFinished(); 1741 observer->WaitForFinished();
1740 1742
1741 DownloadManager::DownloadVector items; 1743 DownloadManager::DownloadVector items;
1742 manager->GetAllDownloads(&items); 1744 manager->GetAllDownloads(&items);
1743 ASSERT_NE(0u, items.size()); 1745 ASSERT_NE(0u, items.size());
1744 DownloadItem* item = items[0]; 1746 DownloadItem* item = items[0];
1745 EXPECT_TRUE(item != nullptr); 1747 EXPECT_TRUE(item != nullptr);
1746 1748
1747 // When the download is canceled, the second tab should close. 1749 // When the download is canceled, the second tab should close.
1748 EXPECT_EQ(item->GetState(), DownloadItem::CANCELLED); 1750 EXPECT_EQ(item->GetState(), DownloadItem::CANCELLED);
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 ASSERT_TRUE(web_contents); 2216 ASSERT_TRUE(web_contents);
2215 2217
2216 content::DownloadTestObserver* observer( 2218 content::DownloadTestObserver* observer(
2217 new content::DownloadTestObserverTerminal( 2219 new content::DownloadTestObserverTerminal(
2218 DownloadManagerForBrowser(browser()), 1, 2220 DownloadManagerForBrowser(browser()), 1,
2219 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2221 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2220 std::unique_ptr<DownloadUrlParameters> params( 2222 std::unique_ptr<DownloadUrlParameters> params(
2221 DownloadUrlParameters::CreateForWebContentsMainFrame( 2223 DownloadUrlParameters::CreateForWebContentsMainFrame(
2222 web_contents, url)); 2224 web_contents, url));
2223 params->set_prompt(true); 2225 params->set_prompt(true);
2224 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 2226 DownloadManagerForBrowser(browser())->DownloadUrl(
2227 std::move(params), TRAFFIC_ANNOTATION_FOR_TESTS);
2225 observer->WaitForFinished(); 2228 observer->WaitForFinished();
2226 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2229 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2227 CheckDownloadStates(1, DownloadItem::COMPLETE); 2230 CheckDownloadStates(1, DownloadItem::COMPLETE);
2228 EXPECT_TRUE(DidShowFileChooser()); 2231 EXPECT_TRUE(DidShowFileChooser());
2229 2232
2230 // Check state. 2233 // Check state.
2231 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2234 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2232 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2235 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2233 ASSERT_TRUE(CheckDownload(browser(), file, file)); 2236 ASSERT_TRUE(CheckDownload(browser(), file, file));
2234 } 2237 }
2235 2238
2236 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 2239 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
2237 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); 2240 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path));
2238 2241
2239 WebContents* web_contents = 2242 WebContents* web_contents =
2240 browser()->tab_strip_model()->GetActiveWebContents(); 2243 browser()->tab_strip_model()->GetActiveWebContents();
2241 ASSERT_TRUE(web_contents); 2244 ASSERT_TRUE(web_contents);
2242 2245
2243 base::ThreadRestrictions::ScopedAllowIO allow_io; 2246 base::ThreadRestrictions::ScopedAllowIO allow_io;
2244 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2247 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2245 base::ScopedTempDir other_directory; 2248 base::ScopedTempDir other_directory;
2246 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 2249 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
2247 base::FilePath target_file_full_path = 2250 base::FilePath target_file_full_path =
2248 other_directory.GetPath().Append(file.BaseName()); 2251 other_directory.GetPath().Append(file.BaseName());
2249 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 2252 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1));
2250 std::unique_ptr<DownloadUrlParameters> params( 2253 std::unique_ptr<DownloadUrlParameters> params(
2251 DownloadUrlParameters::CreateForWebContentsMainFrame( 2254 DownloadUrlParameters::CreateForWebContentsMainFrame(
2252 web_contents, url)); 2255 web_contents, url));
2253 params->set_file_path(target_file_full_path); 2256 params->set_file_path(target_file_full_path);
2254 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 2257 DownloadManagerForBrowser(browser())->DownloadUrl(
2258 std::move(params), TRAFFIC_ANNOTATION_FOR_TESTS);
2255 observer->WaitForFinished(); 2259 observer->WaitForFinished();
2256 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2260 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2257 2261
2258 // Check state. 2262 // Check state.
2259 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2263 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2260 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 2264 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
2261 target_file_full_path, 2265 target_file_full_path,
2262 OriginFile(file))); 2266 OriginFile(file)));
2263 2267
2264 // Temporary are treated as auto-opened, and after that open won't be 2268 // Temporary are treated as auto-opened, and after that open won't be
(...skipping 16 matching lines...) Expand all
2281 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2285 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2282 base::ScopedTempDir other_directory; 2286 base::ScopedTempDir other_directory;
2283 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 2287 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
2284 base::FilePath target_file_full_path = 2288 base::FilePath target_file_full_path =
2285 other_directory.GetPath().Append(file.BaseName()); 2289 other_directory.GetPath().Append(file.BaseName());
2286 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 2290 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1));
2287 std::unique_ptr<DownloadUrlParameters> params( 2291 std::unique_ptr<DownloadUrlParameters> params(
2288 DownloadUrlParameters::CreateForWebContentsMainFrame(web_contents, url)); 2292 DownloadUrlParameters::CreateForWebContentsMainFrame(web_contents, url));
2289 params->set_file_path(target_file_full_path); 2293 params->set_file_path(target_file_full_path);
2290 params->set_transient(true); 2294 params->set_transient(true);
2291 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 2295 DownloadManagerForBrowser(browser())->DownloadUrl(
2296 std::move(params), TRAFFIC_ANNOTATION_FOR_TESTS);
2292 observer->WaitForFinished(); 2297 observer->WaitForFinished();
2293 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2298 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2294 2299
2295 // Check state. 2300 // Check state.
2296 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2301 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2297 ASSERT_TRUE(CheckDownloadFullPaths(browser(), target_file_full_path, 2302 ASSERT_TRUE(CheckDownloadFullPaths(browser(), target_file_full_path,
2298 OriginFile(file))); 2303 OriginFile(file)));
2299 2304
2300 std::vector<DownloadItem*> downloads; 2305 std::vector<DownloadItem*> downloads;
2301 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); 2306 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
(...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after
3854 download_manager, 1, 3859 download_manager, 1,
3855 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 3860 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
3856 3861
3857 // Download and set IsHiddenDownload to true. 3862 // Download and set IsHiddenDownload to true.
3858 WebContents* web_contents = 3863 WebContents* web_contents =
3859 browser()->tab_strip_model()->GetActiveWebContents(); 3864 browser()->tab_strip_model()->GetActiveWebContents();
3860 std::unique_ptr<DownloadUrlParameters> params( 3865 std::unique_ptr<DownloadUrlParameters> params(
3861 DownloadUrlParameters::CreateForWebContentsMainFrame( 3866 DownloadUrlParameters::CreateForWebContentsMainFrame(
3862 web_contents, url)); 3867 web_contents, url));
3863 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); 3868 params->set_callback(base::Bind(&SetHiddenDownloadCallback));
3864 download_manager->DownloadUrl(std::move(params)); 3869 download_manager->DownloadUrl(std::move(params),
3870 TRAFFIC_ANNOTATION_FOR_TESTS);
3865 observer->WaitForFinished(); 3871 observer->WaitForFinished();
3866 3872
3867 // Verify that download shelf is not shown. 3873 // Verify that download shelf is not shown.
3868 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3874 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3869 } 3875 }
3870 3876
3871 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpenClosesShelf) { 3877 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpenClosesShelf) {
3872 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); 3878 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt"));
3873 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-autoopen.txt")); 3879 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-autoopen.txt"));
3874 3880
(...skipping 17 matching lines...) Expand all
3892 browser(), 1, 3898 browser(), 1,
3893 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3899 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3894 ui_test_utils::NavigateToURL(browser(), extension_url); 3900 ui_test_utils::NavigateToURL(browser(), extension_url);
3895 3901
3896 observer->WaitForFinished(); 3902 observer->WaitForFinished();
3897 3903
3898 // Download shelf should close. 3904 // Download shelf should close.
3899 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3905 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3900 } 3906 }
3901 #endif // defined(OS_CHROMEOS) 3907 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698