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

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: fix 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
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 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 download_manager, 1, 875 download_manager, 1,
876 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 876 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
877 } 877 }
878 878
879 if (download_info.download_method == DOWNLOAD_DIRECT) { 879 if (download_info.download_method == DOWNLOAD_DIRECT) {
880 // Go directly to download. Don't wait for navigation. 880 // Go directly to download. Don't wait for navigation.
881 scoped_refptr<content::DownloadTestItemCreationObserver> 881 scoped_refptr<content::DownloadTestItemCreationObserver>
882 creation_observer(new content::DownloadTestItemCreationObserver); 882 creation_observer(new content::DownloadTestItemCreationObserver);
883 883
884 std::unique_ptr<DownloadUrlParameters> params( 884 std::unique_ptr<DownloadUrlParameters> params(
885 DownloadUrlParameters::FromWebContents(web_contents, starting_url)); 885 DownloadUrlParameters::CreateForWebContentsMainFrame(
886 web_contents, starting_url));
886 params->set_callback(creation_observer->callback()); 887 params->set_callback(creation_observer->callback());
887 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 888 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params));
888 889
889 // Wait until the item is created, or we have determined that it 890 // Wait until the item is created, or we have determined that it
890 // won't be. 891 // won't be.
891 creation_observer->WaitForDownloadItemCreation(); 892 creation_observer->WaitForDownloadItemCreation();
892 893
893 EXPECT_NE(content::DownloadItem::kInvalidId, 894 EXPECT_NE(content::DownloadItem::kInvalidId,
894 creation_observer->download_id()); 895 creation_observer->download_id());
895 } else { 896 } else {
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 browser()->tab_strip_model()->GetActiveWebContents(); 1682 browser()->tab_strip_model()->GetActiveWebContents();
1682 content::WebContents* new_tab = content::WebContents::Create( 1683 content::WebContents* new_tab = content::WebContents::Create(
1683 content::WebContents::CreateParams(tab->GetBrowserContext())); 1684 content::WebContents::CreateParams(tab->GetBrowserContext()));
1684 ASSERT_TRUE(new_tab); 1685 ASSERT_TRUE(new_tab);
1685 ASSERT_TRUE(new_tab->GetController().IsInitialNavigation()); 1686 ASSERT_TRUE(new_tab->GetController().IsInitialNavigation());
1686 browser()->tab_strip_model()->AppendWebContents(new_tab, true); 1687 browser()->tab_strip_model()->AppendWebContents(new_tab, true);
1687 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 1688 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1688 1689
1689 // Download a file in that new tab, having it open a file picker 1690 // Download a file in that new tab, having it open a file picker
1690 std::unique_ptr<DownloadUrlParameters> params( 1691 std::unique_ptr<DownloadUrlParameters> params(
1691 DownloadUrlParameters::FromWebContents(new_tab, slow_download_url)); 1692 DownloadUrlParameters::CreateForWebContentsMainFrame(
1693 new_tab, slow_download_url));
1692 params->set_prompt(true); 1694 params->set_prompt(true);
1693 manager->DownloadUrl(std::move(params)); 1695 manager->DownloadUrl(std::move(params));
1694 observer->WaitForFinished(); 1696 observer->WaitForFinished();
1695 1697
1696 DownloadManager::DownloadVector items; 1698 DownloadManager::DownloadVector items;
1697 manager->GetAllDownloads(&items); 1699 manager->GetAllDownloads(&items);
1698 ASSERT_NE(0u, items.size()); 1700 ASSERT_NE(0u, items.size());
1699 DownloadItem* item = items[0]; 1701 DownloadItem* item = items[0];
1700 EXPECT_TRUE(item != nullptr); 1702 EXPECT_TRUE(item != nullptr);
1701 1703
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
2148 2150
2149 WebContents* web_contents = 2151 WebContents* web_contents =
2150 browser()->tab_strip_model()->GetActiveWebContents(); 2152 browser()->tab_strip_model()->GetActiveWebContents();
2151 ASSERT_TRUE(web_contents); 2153 ASSERT_TRUE(web_contents);
2152 2154
2153 content::DownloadTestObserver* observer( 2155 content::DownloadTestObserver* observer(
2154 new content::DownloadTestObserverTerminal( 2156 new content::DownloadTestObserverTerminal(
2155 DownloadManagerForBrowser(browser()), 1, 2157 DownloadManagerForBrowser(browser()), 1,
2156 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2158 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2157 std::unique_ptr<DownloadUrlParameters> params( 2159 std::unique_ptr<DownloadUrlParameters> params(
2158 DownloadUrlParameters::FromWebContents(web_contents, url)); 2160 DownloadUrlParameters::CreateForWebContentsMainFrame(
2161 web_contents, url));
2159 params->set_prompt(true); 2162 params->set_prompt(true);
2160 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 2163 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params));
2161 observer->WaitForFinished(); 2164 observer->WaitForFinished();
2162 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2165 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2163 CheckDownloadStates(1, DownloadItem::COMPLETE); 2166 CheckDownloadStates(1, DownloadItem::COMPLETE);
2164 EXPECT_TRUE(DidShowFileChooser()); 2167 EXPECT_TRUE(DidShowFileChooser());
2165 2168
2166 // Check state. 2169 // Check state.
2167 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2170 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2168 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2171 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2169 ASSERT_TRUE(CheckDownload(browser(), file, file)); 2172 ASSERT_TRUE(CheckDownload(browser(), file, file));
2170 } 2173 }
2171 2174
2172 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 2175 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
2173 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); 2176 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path));
2174 2177
2175 WebContents* web_contents = 2178 WebContents* web_contents =
2176 browser()->tab_strip_model()->GetActiveWebContents(); 2179 browser()->tab_strip_model()->GetActiveWebContents();
2177 ASSERT_TRUE(web_contents); 2180 ASSERT_TRUE(web_contents);
2178 2181
2179 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2182 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2180 base::ScopedTempDir other_directory; 2183 base::ScopedTempDir other_directory;
2181 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 2184 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
2182 base::FilePath target_file_full_path 2185 base::FilePath target_file_full_path
2183 = other_directory.path().Append(file.BaseName()); 2186 = other_directory.path().Append(file.BaseName());
2184 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 2187 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1));
2185 std::unique_ptr<DownloadUrlParameters> params( 2188 std::unique_ptr<DownloadUrlParameters> params(
2186 DownloadUrlParameters::FromWebContents(web_contents, url)); 2189 DownloadUrlParameters::CreateForWebContentsMainFrame(
2190 web_contents, url));
2187 params->set_file_path(target_file_full_path); 2191 params->set_file_path(target_file_full_path);
2188 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); 2192 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params));
2189 observer->WaitForFinished(); 2193 observer->WaitForFinished();
2190 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2194 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2191 2195
2192 // Check state. 2196 // Check state.
2193 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2197 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2194 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 2198 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
2195 target_file_full_path, 2199 target_file_full_path,
2196 OriginFile(file))); 2200 OriginFile(file)));
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after
3631 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 3635 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
3632 std::unique_ptr<content::DownloadTestObserver> observer( 3636 std::unique_ptr<content::DownloadTestObserver> observer(
3633 new content::DownloadTestObserverTerminal( 3637 new content::DownloadTestObserverTerminal(
3634 download_manager, 1, 3638 download_manager, 1,
3635 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 3639 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
3636 3640
3637 // Download and set IsHiddenDownload to true. 3641 // Download and set IsHiddenDownload to true.
3638 WebContents* web_contents = 3642 WebContents* web_contents =
3639 browser()->tab_strip_model()->GetActiveWebContents(); 3643 browser()->tab_strip_model()->GetActiveWebContents();
3640 std::unique_ptr<DownloadUrlParameters> params( 3644 std::unique_ptr<DownloadUrlParameters> params(
3641 DownloadUrlParameters::FromWebContents(web_contents, url)); 3645 DownloadUrlParameters::CreateForWebContentsMainFrame(
3646 web_contents, url));
3642 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); 3647 params->set_callback(base::Bind(&SetHiddenDownloadCallback));
3643 download_manager->DownloadUrl(std::move(params)); 3648 download_manager->DownloadUrl(std::move(params));
3644 observer->WaitForFinished(); 3649 observer->WaitForFinished();
3645 3650
3646 // Verify that download shelf is not shown. 3651 // Verify that download shelf is not shown.
3647 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3652 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3648 } 3653 }
3649 3654
3650 // Test to make sure auto-open works. 3655 // Test to make sure auto-open works.
3651 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, AutoOpen) { 3656 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, AutoOpen) {
(...skipping 21 matching lines...) Expand all
3673 DangerousDownloadWaiter( 3678 DangerousDownloadWaiter(
3674 browser(), 1, 3679 browser(), 1,
3675 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3680 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3676 ui_test_utils::NavigateToURL(browser(), extension_url); 3681 ui_test_utils::NavigateToURL(browser(), extension_url);
3677 3682
3678 observer->WaitForFinished(); 3683 observer->WaitForFinished();
3679 3684
3680 // Download shelf should close. 3685 // Download shelf should close.
3681 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3686 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3682 } 3687 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698