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

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

Issue 1977623002: Updates to DownloadUrlParameters in preparation for OOPIF changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 7 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 | « no previous file | chrome/browser/extensions/api/downloads/downloads_api.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 "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 #include <sstream> 8 #include <sstream>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 download_manager, 1, 876 download_manager, 1,
877 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 877 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
878 } 878 }
879 879
880 if (download_info.download_method == DOWNLOAD_DIRECT) { 880 if (download_info.download_method == DOWNLOAD_DIRECT) {
881 // Go directly to download. Don't wait for navigation. 881 // Go directly to download. Don't wait for navigation.
882 scoped_refptr<content::DownloadTestItemCreationObserver> 882 scoped_refptr<content::DownloadTestItemCreationObserver>
883 creation_observer(new content::DownloadTestItemCreationObserver); 883 creation_observer(new content::DownloadTestItemCreationObserver);
884 884
885 std::unique_ptr<DownloadUrlParameters> params( 885 std::unique_ptr<DownloadUrlParameters> params(
886 DownloadUrlParameters::FromWebContents(web_contents, starting_url)); 886 DownloadUrlParameters::CreateForWebContentsMainFrame(
887 web_contents, starting_url));
887 params->set_callback(creation_observer->callback()); 888 params->set_callback(creation_observer->callback());
888 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 889 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params));
889 890
890 // Wait until the item is created, or we have determined that it 891 // Wait until the item is created, or we have determined that it
891 // won't be. 892 // won't be.
892 creation_observer->WaitForDownloadItemCreation(); 893 creation_observer->WaitForDownloadItemCreation();
893 894
894 EXPECT_NE(content::DownloadItem::kInvalidId, 895 EXPECT_NE(content::DownloadItem::kInvalidId,
895 creation_observer->download_id()); 896 creation_observer->download_id());
896 } else { 897 } else {
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 browser()->tab_strip_model()->GetActiveWebContents(); 1674 browser()->tab_strip_model()->GetActiveWebContents();
1674 content::WebContents* new_tab = content::WebContents::Create( 1675 content::WebContents* new_tab = content::WebContents::Create(
1675 content::WebContents::CreateParams(tab->GetBrowserContext())); 1676 content::WebContents::CreateParams(tab->GetBrowserContext()));
1676 ASSERT_TRUE(new_tab); 1677 ASSERT_TRUE(new_tab);
1677 ASSERT_TRUE(new_tab->GetController().IsInitialNavigation()); 1678 ASSERT_TRUE(new_tab->GetController().IsInitialNavigation());
1678 browser()->tab_strip_model()->AppendWebContents(new_tab, true); 1679 browser()->tab_strip_model()->AppendWebContents(new_tab, true);
1679 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 1680 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1680 1681
1681 // Download a file in that new tab, having it open a file picker 1682 // Download a file in that new tab, having it open a file picker
1682 std::unique_ptr<DownloadUrlParameters> params( 1683 std::unique_ptr<DownloadUrlParameters> params(
1683 DownloadUrlParameters::FromWebContents(new_tab, slow_download_url)); 1684 DownloadUrlParameters::CreateForWebContentsMainFrame(
1685 new_tab, slow_download_url));
1684 params->set_prompt(true); 1686 params->set_prompt(true);
1685 manager->DownloadUrl(std::move(params)); 1687 manager->DownloadUrl(std::move(params));
1686 observer->WaitForFinished(); 1688 observer->WaitForFinished();
1687 1689
1688 DownloadManager::DownloadVector items; 1690 DownloadManager::DownloadVector items;
1689 manager->GetAllDownloads(&items); 1691 manager->GetAllDownloads(&items);
1690 ASSERT_NE(0u, items.size()); 1692 ASSERT_NE(0u, items.size());
1691 DownloadItem* item = items[0]; 1693 DownloadItem* item = items[0];
1692 EXPECT_TRUE(item != nullptr); 1694 EXPECT_TRUE(item != nullptr);
1693 1695
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 2145
2144 WebContents* web_contents = 2146 WebContents* web_contents =
2145 browser()->tab_strip_model()->GetActiveWebContents(); 2147 browser()->tab_strip_model()->GetActiveWebContents();
2146 ASSERT_TRUE(web_contents); 2148 ASSERT_TRUE(web_contents);
2147 2149
2148 content::DownloadTestObserver* observer( 2150 content::DownloadTestObserver* observer(
2149 new content::DownloadTestObserverTerminal( 2151 new content::DownloadTestObserverTerminal(
2150 DownloadManagerForBrowser(browser()), 1, 2152 DownloadManagerForBrowser(browser()), 1,
2151 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2153 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2152 std::unique_ptr<DownloadUrlParameters> params( 2154 std::unique_ptr<DownloadUrlParameters> params(
2153 DownloadUrlParameters::FromWebContents(web_contents, url)); 2155 DownloadUrlParameters::CreateForWebContentsMainFrame(
2156 web_contents, url));
2154 params->set_prompt(true); 2157 params->set_prompt(true);
2155 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 2158 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params));
2156 observer->WaitForFinished(); 2159 observer->WaitForFinished();
2157 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2160 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2158 CheckDownloadStates(1, DownloadItem::COMPLETE); 2161 CheckDownloadStates(1, DownloadItem::COMPLETE);
2159 EXPECT_TRUE(DidShowFileChooser()); 2162 EXPECT_TRUE(DidShowFileChooser());
2160 2163
2161 // Check state. 2164 // Check state.
2162 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2165 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2163 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2166 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2164 ASSERT_TRUE(CheckDownload(browser(), file, file)); 2167 ASSERT_TRUE(CheckDownload(browser(), file, file));
2165 } 2168 }
2166 2169
2167 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 2170 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
2168 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); 2171 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path));
2169 2172
2170 WebContents* web_contents = 2173 WebContents* web_contents =
2171 browser()->tab_strip_model()->GetActiveWebContents(); 2174 browser()->tab_strip_model()->GetActiveWebContents();
2172 ASSERT_TRUE(web_contents); 2175 ASSERT_TRUE(web_contents);
2173 2176
2174 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2177 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2175 base::ScopedTempDir other_directory; 2178 base::ScopedTempDir other_directory;
2176 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 2179 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
2177 base::FilePath target_file_full_path 2180 base::FilePath target_file_full_path
2178 = other_directory.path().Append(file.BaseName()); 2181 = other_directory.path().Append(file.BaseName());
2179 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 2182 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1));
2180 std::unique_ptr<DownloadUrlParameters> params( 2183 std::unique_ptr<DownloadUrlParameters> params(
2181 DownloadUrlParameters::FromWebContents(web_contents, url)); 2184 DownloadUrlParameters::CreateForWebContentsMainFrame(
2185 web_contents, url));
2182 params->set_file_path(target_file_full_path); 2186 params->set_file_path(target_file_full_path);
2183 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 2187 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params));
2184 observer->WaitForFinished(); 2188 observer->WaitForFinished();
2185 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2189 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2186 2190
2187 // Check state. 2191 // Check state.
2188 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2192 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2189 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 2193 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
2190 target_file_full_path, 2194 target_file_full_path,
2191 OriginFile(file))); 2195 OriginFile(file)));
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after
3627 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 3631 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
3628 std::unique_ptr<content::DownloadTestObserver> observer( 3632 std::unique_ptr<content::DownloadTestObserver> observer(
3629 new content::DownloadTestObserverTerminal( 3633 new content::DownloadTestObserverTerminal(
3630 download_manager, 1, 3634 download_manager, 1,
3631 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 3635 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
3632 3636
3633 // Download and set IsHiddenDownload to true. 3637 // Download and set IsHiddenDownload to true.
3634 WebContents* web_contents = 3638 WebContents* web_contents =
3635 browser()->tab_strip_model()->GetActiveWebContents(); 3639 browser()->tab_strip_model()->GetActiveWebContents();
3636 std::unique_ptr<DownloadUrlParameters> params( 3640 std::unique_ptr<DownloadUrlParameters> params(
3637 DownloadUrlParameters::FromWebContents(web_contents, url)); 3641 DownloadUrlParameters::CreateForWebContentsMainFrame(
3642 web_contents, url));
3638 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); 3643 params->set_callback(base::Bind(&SetHiddenDownloadCallback));
3639 download_manager->DownloadUrl(std::move(params)); 3644 download_manager->DownloadUrl(std::move(params));
3640 observer->WaitForFinished(); 3645 observer->WaitForFinished();
3641 3646
3642 // Verify that download shelf is not shown. 3647 // Verify that download shelf is not shown.
3643 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3648 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3644 } 3649 }
3645 3650
3646 // Test to make sure auto-open works. 3651 // Test to make sure auto-open works.
3647 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, AutoOpen) { 3652 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, AutoOpen) {
(...skipping 21 matching lines...) Expand all
3669 DangerousDownloadWaiter( 3674 DangerousDownloadWaiter(
3670 browser(), 1, 3675 browser(), 1,
3671 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3676 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3672 ui_test_utils::NavigateToURL(browser(), extension_url); 3677 ui_test_utils::NavigateToURL(browser(), extension_url);
3673 3678
3674 observer->WaitForFinished(); 3679 observer->WaitForFinished();
3675 3680
3676 // Download shelf should close. 3681 // Download shelf should close.
3677 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3682 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3678 } 3683 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/downloads/downloads_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698