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

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

Issue 11028131: Shift passage of FileStream in downloads system to be by scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Al's comments. Created 8 years, 2 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 | Annotate | Revision Log
« 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 <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
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(DownloadItem* item, net::Error error) {
208 DownloadItem* item,
209 net::Error error) {
210 download_util::SetShouldShowInShelf(item, false); 208 download_util::SetShouldShowInShelf(item, false);
211 } 209 }
212 210
213 } // namespace 211 } // namespace
214 212
215 // While an object of this class exists, it will mock out download 213 // While an object of this class exists, it will mock out download
216 // opening for all downloads created on the specified download manager. 214 // opening for all downloads created on the specified download manager.
217 class MockDownloadOpeningObserver : public DownloadManager::Observer { 215 class MockDownloadOpeningObserver : public DownloadManager::Observer {
218 public: 216 public:
219 explicit MockDownloadOpeningObserver(DownloadManager* manager) 217 explicit MockDownloadOpeningObserver(DownloadManager* manager)
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 ASSERT_TRUE(web_contents) << s.str(); 646 ASSERT_TRUE(web_contents) << s.str();
649 647
650 scoped_ptr<content::DownloadTestObserver> observer( 648 scoped_ptr<content::DownloadTestObserver> observer(
651 new content::DownloadTestObserverTerminal( 649 new content::DownloadTestObserverTerminal(
652 download_manager, 650 download_manager,
653 1, 651 1,
654 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 652 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
655 653
656 if (download_info.download_method == DOWNLOAD_DIRECT) { 654 if (download_info.download_method == DOWNLOAD_DIRECT) {
657 // Go directly to download. Don't wait for navigation. 655 // Go directly to download. Don't wait for navigation.
658 content::DownloadSaveInfo save_info; 656 scoped_ptr<content::DownloadSaveInfo> save_info(
657 new content::DownloadSaveInfo());
659 // NOTE: |prompt_for_save_location| may change during the download. 658 // NOTE: |prompt_for_save_location| may change during the download.
660 save_info.prompt_for_save_location = false; 659 save_info->prompt_for_save_location = false;
661 660
662 scoped_refptr<content::DownloadTestItemCreationObserver> 661 scoped_refptr<content::DownloadTestItemCreationObserver>
663 creation_observer(new content::DownloadTestItemCreationObserver); 662 creation_observer(new content::DownloadTestItemCreationObserver);
664 663
665 scoped_ptr<DownloadUrlParameters> params( 664 scoped_ptr<DownloadUrlParameters> params(
666 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); 665 DownloadUrlParameters::FromWebContents(
666 web_contents, url, save_info.Pass()));
667 params->set_callback(creation_observer->callback()); 667 params->set_callback(creation_observer->callback());
668 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); 668 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
669 669
670 // Wait until the item is created, or we have determined that it 670 // Wait until the item is created, or we have determined that it
671 // won't be. 671 // won't be.
672 creation_observer->WaitForDownloadItemCreation(); 672 creation_observer->WaitForDownloadItemCreation();
673 673
674 int32 invalid_id = content::DownloadId::Invalid().local(); 674 int32 invalid_id = content::DownloadId::Invalid().local();
675 EXPECT_EQ(download_info.show_download_item, 675 EXPECT_EQ(download_info.show_download_item,
676 creation_observer->succeeded()); 676 creation_observer->succeeded());
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 // DownloadUrl always prompts; return acceptance of whatever it prompts. 1725 // DownloadUrl always prompts; return acceptance of whatever it prompts.
1726 EnableFileChooser(true); 1726 EnableFileChooser(true);
1727 1727
1728 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 1728 WebContents* web_contents = chrome::GetActiveWebContents(browser());
1729 ASSERT_TRUE(web_contents); 1729 ASSERT_TRUE(web_contents);
1730 1730
1731 content::DownloadTestObserver* observer( 1731 content::DownloadTestObserver* observer(
1732 new content::DownloadTestObserverTerminal( 1732 new content::DownloadTestObserverTerminal(
1733 DownloadManagerForBrowser(browser()), 1, 1733 DownloadManagerForBrowser(browser()), 1,
1734 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1734 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1735 content::DownloadSaveInfo save_info; 1735 scoped_ptr<content::DownloadSaveInfo> save_info(
1736 save_info.prompt_for_save_location = true; 1736 new content::DownloadSaveInfo());
1737 save_info->prompt_for_save_location = true;
1737 scoped_ptr<DownloadUrlParameters> params( 1738 scoped_ptr<DownloadUrlParameters> params(
1738 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); 1739 DownloadUrlParameters::FromWebContents(
1740 web_contents, url, save_info.Pass()));
1739 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); 1741 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
1740 observer->WaitForFinished(); 1742 observer->WaitForFinished();
1741 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1743 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1742 CheckDownloadStates(1, DownloadItem::COMPLETE); 1744 CheckDownloadStates(1, DownloadItem::COMPLETE);
1743 EXPECT_TRUE(DidShowFileChooser()); 1745 EXPECT_TRUE(DidShowFileChooser());
1744 1746
1745 // Check state. 1747 // Check state.
1746 EXPECT_EQ(1, browser()->tab_count()); 1748 EXPECT_EQ(1, browser()->tab_count());
1747 ASSERT_TRUE(CheckDownload(browser(), file, file)); 1749 ASSERT_TRUE(CheckDownload(browser(), file, file));
1748 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1750 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1749 } 1751 }
1750 1752
1751 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 1753 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
1752 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1754 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1753 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1755 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1754 1756
1755 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 1757 WebContents* web_contents = chrome::GetActiveWebContents(browser());
1756 ASSERT_TRUE(web_contents); 1758 ASSERT_TRUE(web_contents);
1757 1759
1758 ScopedTempDir other_directory; 1760 ScopedTempDir other_directory;
1759 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 1761 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
1760 FilePath target_file_full_path 1762 FilePath target_file_full_path
1761 = other_directory.path().Append(file.BaseName()); 1763 = other_directory.path().Append(file.BaseName());
1762 content::DownloadSaveInfo save_info; 1764 scoped_ptr<content::DownloadSaveInfo> save_info(
1763 save_info.file_path = target_file_full_path; 1765 new content::DownloadSaveInfo());
1766 save_info->file_path = target_file_full_path;
1764 1767
1765 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 1768 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1));
1766 scoped_ptr<DownloadUrlParameters> params( 1769 scoped_ptr<DownloadUrlParameters> params(
1767 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); 1770 DownloadUrlParameters::FromWebContents(
1771 web_contents, url, save_info.Pass()));
1768 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); 1772 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
1769 observer->WaitForFinished(); 1773 observer->WaitForFinished();
1770 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1774 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1771 1775
1772 // Check state. 1776 // Check state.
1773 EXPECT_EQ(1, browser()->tab_count()); 1777 EXPECT_EQ(1, browser()->tab_count());
1774 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 1778 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
1775 target_file_full_path, 1779 target_file_full_path,
1776 OriginFile(file))); 1780 OriginFile(file)));
1777 1781
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 2256 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2253 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 2257 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
2254 2258
2255 scoped_refptr<DownloadManager> download_manager = 2259 scoped_refptr<DownloadManager> download_manager =
2256 DownloadManagerForBrowser(browser()); 2260 DownloadManagerForBrowser(browser());
2257 scoped_ptr<content::DownloadTestObserver> observer( 2261 scoped_ptr<content::DownloadTestObserver> observer(
2258 new content::DownloadTestObserverTerminal( 2262 new content::DownloadTestObserverTerminal(
2259 download_manager, 2263 download_manager,
2260 1, 2264 1,
2261 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2265 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2262 content::DownloadSaveInfo save_info; 2266 scoped_ptr<content::DownloadSaveInfo> save_info(
2263 save_info.prompt_for_save_location = false; 2267 new content::DownloadSaveInfo());
2268 save_info->prompt_for_save_location = false;
2264 2269
2265 // Download and set IsHiddenDownload to true. 2270 // Download and set IsHiddenDownload to true.
2266 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 2271 WebContents* web_contents = chrome::GetActiveWebContents(browser());
2267 scoped_ptr<DownloadUrlParameters> params( 2272 scoped_ptr<DownloadUrlParameters> params(
2268 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); 2273 DownloadUrlParameters::FromWebContents(
2269 params->set_callback( 2274 web_contents, url, save_info.Pass()));
2270 base::Bind(&SetHiddenDownloadCallback, download_manager)); 2275 params->set_callback(base::Bind(&SetHiddenDownloadCallback));
2271 download_manager->DownloadUrl(params.Pass()); 2276 download_manager->DownloadUrl(params.Pass());
2272 observer->WaitForFinished(); 2277 observer->WaitForFinished();
2273 2278
2274 // Verify that download shelf is not shown. 2279 // Verify that download shelf is not shown.
2275 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 2280 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
2276 } 2281 }
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