OLD | NEW |
---|---|
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/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 } | 197 } |
198 | 198 |
199 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); | 199 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); |
200 }; | 200 }; |
201 | 201 |
202 bool WasAutoOpened(DownloadItem* item) { | 202 bool WasAutoOpened(DownloadItem* item) { |
203 return item->GetAutoOpened(); | 203 return item->GetAutoOpened(); |
204 } | 204 } |
205 | 205 |
206 // Called when a download starts. Marks the download as hidden. | 206 // Called when a download starts. Marks the download as hidden. |
207 void SetHiddenDownloadCallback(scoped_refptr<DownloadManager> download_manager, | 207 void SetHiddenDownloadCallback(scoped_refptr<DownloadManager> download_manager, |
benjhayden
2012/10/11 19:41:12
This scoped_refptr appears unnecessary, even when
Randy Smith (Not in Mondays)
2012/10/15 18:56:33
Agreed, but I think the code would be uglier with
awong
2012/10/15 19:02:33
drive-by nits: this should probably take "const sc
Randy Smith (Not in Mondays)
2012/10/16 17:24:35
So this may well be due to my lack of understandin
awong
2012/10/16 19:14:33
Oh, sorry. Your'e right. I misread the code. Yes,
| |
208 DownloadItem* item, | 208 DownloadItem* item, |
209 net::Error error) { | 209 net::Error error) { |
210 download_util::SetShouldShowInShelf(item, false); | 210 download_util::SetShouldShowInShelf(item, false); |
211 } | 211 } |
212 | 212 |
213 } // namespace | 213 } // namespace |
214 | 214 |
215 // While an object of this class exists, it will mock out download | 215 // While an object of this class exists, it will mock out download |
216 // opening for all downloads created on the specified download manager. | 216 // opening for all downloads created on the specified download manager. |
217 class MockDownloadOpeningObserver : public DownloadManager::Observer { | 217 class MockDownloadOpeningObserver : public DownloadManager::Observer { |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 ASSERT_TRUE(web_contents) << s.str(); | 648 ASSERT_TRUE(web_contents) << s.str(); |
649 | 649 |
650 scoped_ptr<content::DownloadTestObserver> observer( | 650 scoped_ptr<content::DownloadTestObserver> observer( |
651 new content::DownloadTestObserverTerminal( | 651 new content::DownloadTestObserverTerminal( |
652 download_manager, | 652 download_manager, |
653 1, | 653 1, |
654 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 654 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
655 | 655 |
656 if (download_info.download_method == DOWNLOAD_DIRECT) { | 656 if (download_info.download_method == DOWNLOAD_DIRECT) { |
657 // Go directly to download. Don't wait for navigation. | 657 // Go directly to download. Don't wait for navigation. |
658 content::DownloadSaveInfo save_info; | 658 scoped_ptr<content::DownloadSaveInfo> save_info( |
659 new content::DownloadSaveInfo()); | |
659 // NOTE: |prompt_for_save_location| may change during the download. | 660 // NOTE: |prompt_for_save_location| may change during the download. |
660 save_info.prompt_for_save_location = false; | 661 save_info->prompt_for_save_location = false; |
661 | 662 |
662 scoped_refptr<content::DownloadTestItemCreationObserver> | 663 scoped_refptr<content::DownloadTestItemCreationObserver> |
663 creation_observer(new content::DownloadTestItemCreationObserver); | 664 creation_observer(new content::DownloadTestItemCreationObserver); |
664 | 665 |
665 scoped_ptr<DownloadUrlParameters> params( | 666 scoped_ptr<DownloadUrlParameters> params( |
666 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 667 DownloadUrlParameters::FromWebContents( |
668 web_contents, url, save_info.Pass())); | |
667 params->set_callback(creation_observer->callback()); | 669 params->set_callback(creation_observer->callback()); |
668 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 670 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
669 | 671 |
670 // Wait until the item is created, or we have determined that it | 672 // Wait until the item is created, or we have determined that it |
671 // won't be. | 673 // won't be. |
672 creation_observer->WaitForDownloadItemCreation(); | 674 creation_observer->WaitForDownloadItemCreation(); |
673 | 675 |
674 int32 invalid_id = content::DownloadId::Invalid().local(); | 676 int32 invalid_id = content::DownloadId::Invalid().local(); |
675 EXPECT_EQ(download_info.show_download_item, | 677 EXPECT_EQ(download_info.show_download_item, |
676 creation_observer->succeeded()); | 678 creation_observer->succeeded()); |
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1725 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1727 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
1726 EnableFileChooser(true); | 1728 EnableFileChooser(true); |
1727 | 1729 |
1728 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1730 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
1729 ASSERT_TRUE(web_contents); | 1731 ASSERT_TRUE(web_contents); |
1730 | 1732 |
1731 content::DownloadTestObserver* observer( | 1733 content::DownloadTestObserver* observer( |
1732 new content::DownloadTestObserverTerminal( | 1734 new content::DownloadTestObserverTerminal( |
1733 DownloadManagerForBrowser(browser()), 1, | 1735 DownloadManagerForBrowser(browser()), 1, |
1734 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1736 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
1735 content::DownloadSaveInfo save_info; | 1737 scoped_ptr<content::DownloadSaveInfo> save_info( |
1736 save_info.prompt_for_save_location = true; | 1738 new content::DownloadSaveInfo()); |
1739 save_info->prompt_for_save_location = true; | |
1737 scoped_ptr<DownloadUrlParameters> params( | 1740 scoped_ptr<DownloadUrlParameters> params( |
1738 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 1741 DownloadUrlParameters::FromWebContents( |
1742 web_contents, url, save_info.Pass())); | |
1739 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 1743 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
1740 observer->WaitForFinished(); | 1744 observer->WaitForFinished(); |
1741 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1745 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1742 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1746 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1743 EXPECT_TRUE(DidShowFileChooser()); | 1747 EXPECT_TRUE(DidShowFileChooser()); |
1744 | 1748 |
1745 // Check state. | 1749 // Check state. |
1746 EXPECT_EQ(1, browser()->tab_count()); | 1750 EXPECT_EQ(1, browser()->tab_count()); |
1747 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1751 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
1748 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1752 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
1749 } | 1753 } |
1750 | 1754 |
1751 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1755 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
1752 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1756 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1753 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1757 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1754 | 1758 |
1755 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1759 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
1756 ASSERT_TRUE(web_contents); | 1760 ASSERT_TRUE(web_contents); |
1757 | 1761 |
1758 ScopedTempDir other_directory; | 1762 ScopedTempDir other_directory; |
1759 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1763 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
1760 FilePath target_file_full_path | 1764 FilePath target_file_full_path |
1761 = other_directory.path().Append(file.BaseName()); | 1765 = other_directory.path().Append(file.BaseName()); |
1762 content::DownloadSaveInfo save_info; | 1766 scoped_ptr<content::DownloadSaveInfo> save_info( |
1763 save_info.file_path = target_file_full_path; | 1767 new content::DownloadSaveInfo()); |
1768 save_info->file_path = target_file_full_path; | |
1764 | 1769 |
1765 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 1770 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
1766 scoped_ptr<DownloadUrlParameters> params( | 1771 scoped_ptr<DownloadUrlParameters> params( |
1767 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 1772 DownloadUrlParameters::FromWebContents( |
1773 web_contents, url, save_info.Pass())); | |
1768 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 1774 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
1769 observer->WaitForFinished(); | 1775 observer->WaitForFinished(); |
1770 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1776 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1771 | 1777 |
1772 // Check state. | 1778 // Check state. |
1773 EXPECT_EQ(1, browser()->tab_count()); | 1779 EXPECT_EQ(1, browser()->tab_count()); |
1774 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1780 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
1775 target_file_full_path, | 1781 target_file_full_path, |
1776 OriginFile(file))); | 1782 OriginFile(file))); |
1777 | 1783 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2252 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 2258 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
2253 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 2259 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
2254 | 2260 |
2255 scoped_refptr<DownloadManager> download_manager = | 2261 scoped_refptr<DownloadManager> download_manager = |
2256 DownloadManagerForBrowser(browser()); | 2262 DownloadManagerForBrowser(browser()); |
2257 scoped_ptr<content::DownloadTestObserver> observer( | 2263 scoped_ptr<content::DownloadTestObserver> observer( |
2258 new content::DownloadTestObserverTerminal( | 2264 new content::DownloadTestObserverTerminal( |
2259 download_manager, | 2265 download_manager, |
2260 1, | 2266 1, |
2261 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2267 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
2262 content::DownloadSaveInfo save_info; | 2268 scoped_ptr<content::DownloadSaveInfo> save_info( |
2263 save_info.prompt_for_save_location = false; | 2269 new content::DownloadSaveInfo()); |
2270 save_info->prompt_for_save_location = false; | |
2264 | 2271 |
2265 // Download and set IsHiddenDownload to true. | 2272 // Download and set IsHiddenDownload to true. |
2266 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 2273 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
2267 scoped_ptr<DownloadUrlParameters> params( | 2274 scoped_ptr<DownloadUrlParameters> params( |
2268 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 2275 DownloadUrlParameters::FromWebContents( |
2276 web_contents, url, save_info.Pass())); | |
2269 params->set_callback( | 2277 params->set_callback( |
2270 base::Bind(&SetHiddenDownloadCallback, download_manager)); | 2278 base::Bind(&SetHiddenDownloadCallback, download_manager)); |
2271 download_manager->DownloadUrl(params.Pass()); | 2279 download_manager->DownloadUrl(params.Pass()); |
2272 observer->WaitForFinished(); | 2280 observer->WaitForFinished(); |
2273 | 2281 |
2274 // Verify that download shelf is not shown. | 2282 // Verify that download shelf is not shown. |
2275 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 2283 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
2276 } | 2284 } |
OLD | NEW |