Chromium Code Reviews| 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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 ASSERT_TRUE(web_contents) << s.str(); | 641 ASSERT_TRUE(web_contents) << s.str(); |
| 642 | 642 |
| 643 scoped_ptr<content::DownloadTestObserver> observer( | 643 scoped_ptr<content::DownloadTestObserver> observer( |
| 644 new content::DownloadTestObserverTerminal( | 644 new content::DownloadTestObserverTerminal( |
| 645 download_manager, | 645 download_manager, |
| 646 1, | 646 1, |
| 647 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 647 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 648 | 648 |
| 649 if (download_info.download_method == DOWNLOAD_DIRECT) { | 649 if (download_info.download_method == DOWNLOAD_DIRECT) { |
| 650 // Go directly to download. Don't wait for navigation. | 650 // Go directly to download. Don't wait for navigation. |
| 651 content::DownloadSaveInfo save_info; | 651 scoped_ptr<content::DownloadSaveInfo> save_info( |
| 652 new content::DownloadSaveInfo()); | |
| 652 // NOTE: |prompt_for_save_location| may change during the download. | 653 // NOTE: |prompt_for_save_location| may change during the download. |
| 653 save_info.prompt_for_save_location = false; | 654 save_info->prompt_for_save_location = false; |
| 654 | 655 |
| 655 scoped_refptr<content::DownloadTestItemCreationObserver> | 656 scoped_refptr<content::DownloadTestItemCreationObserver> |
| 656 creation_observer(new content::DownloadTestItemCreationObserver); | 657 creation_observer(new content::DownloadTestItemCreationObserver); |
| 657 | 658 |
| 658 scoped_ptr<DownloadUrlParameters> params( | 659 scoped_ptr<DownloadUrlParameters> params( |
| 659 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 660 DownloadUrlParameters::FromWebContents( |
| 661 web_contents, url, save_info.Pass())); | |
|
benjhayden
2012/10/11 19:41:12
While you're doing this, do you want to go ahead a
Randy Smith (Not in Mondays)
2012/10/15 18:56:32
That's a good idea, but I'd sorta like to keep it
| |
| 660 params->set_callback(creation_observer->callback()); | 662 params->set_callback(creation_observer->callback()); |
| 661 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 663 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
| 662 | 664 |
| 663 // Wait until the item is created, or we have determined that it | 665 // Wait until the item is created, or we have determined that it |
| 664 // won't be. | 666 // won't be. |
| 665 creation_observer->WaitForDownloadItemCreation(); | 667 creation_observer->WaitForDownloadItemCreation(); |
| 666 | 668 |
| 667 int32 invalid_id = content::DownloadId::Invalid().local(); | 669 int32 invalid_id = content::DownloadId::Invalid().local(); |
| 668 EXPECT_EQ(download_info.show_download_item, | 670 EXPECT_EQ(download_info.show_download_item, |
| 669 creation_observer->succeeded()); | 671 creation_observer->succeeded()); |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1722 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1724 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
| 1723 EnableFileChooser(true); | 1725 EnableFileChooser(true); |
| 1724 | 1726 |
| 1725 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1727 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 1726 ASSERT_TRUE(web_contents); | 1728 ASSERT_TRUE(web_contents); |
| 1727 | 1729 |
| 1728 content::DownloadTestObserver* observer( | 1730 content::DownloadTestObserver* observer( |
| 1729 new content::DownloadTestObserverTerminal( | 1731 new content::DownloadTestObserverTerminal( |
| 1730 DownloadManagerForBrowser(browser()), 1, | 1732 DownloadManagerForBrowser(browser()), 1, |
| 1731 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1733 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1732 content::DownloadSaveInfo save_info; | 1734 scoped_ptr<content::DownloadSaveInfo> save_info( |
| 1733 save_info.prompt_for_save_location = true; | 1735 new content::DownloadSaveInfo()); |
| 1736 save_info->prompt_for_save_location = true; | |
| 1734 scoped_ptr<DownloadUrlParameters> params( | 1737 scoped_ptr<DownloadUrlParameters> params( |
| 1735 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 1738 DownloadUrlParameters::FromWebContents( |
| 1739 web_contents, url, save_info.Pass())); | |
| 1736 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 1740 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
| 1737 observer->WaitForFinished(); | 1741 observer->WaitForFinished(); |
| 1738 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1742 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1739 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1743 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1740 EXPECT_TRUE(DidShowFileChooser()); | 1744 EXPECT_TRUE(DidShowFileChooser()); |
| 1741 | 1745 |
| 1742 // Check state. | 1746 // Check state. |
| 1743 EXPECT_EQ(1, browser()->tab_count()); | 1747 EXPECT_EQ(1, browser()->tab_count()); |
| 1744 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1748 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
| 1745 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1749 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1746 } | 1750 } |
| 1747 | 1751 |
| 1748 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1752 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
| 1749 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1753 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1750 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1754 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1751 | 1755 |
| 1752 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1756 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 1753 ASSERT_TRUE(web_contents); | 1757 ASSERT_TRUE(web_contents); |
| 1754 | 1758 |
| 1755 ScopedTempDir other_directory; | 1759 ScopedTempDir other_directory; |
| 1756 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1760 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
| 1757 FilePath target_file_full_path | 1761 FilePath target_file_full_path |
| 1758 = other_directory.path().Append(file.BaseName()); | 1762 = other_directory.path().Append(file.BaseName()); |
| 1759 content::DownloadSaveInfo save_info; | 1763 scoped_ptr<content::DownloadSaveInfo> save_info( |
| 1760 save_info.file_path = target_file_full_path; | 1764 new content::DownloadSaveInfo()); |
| 1765 save_info->file_path = target_file_full_path; | |
| 1761 | 1766 |
| 1762 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 1767 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
| 1763 scoped_ptr<DownloadUrlParameters> params( | 1768 scoped_ptr<DownloadUrlParameters> params( |
| 1764 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 1769 DownloadUrlParameters::FromWebContents( |
| 1770 web_contents, url, save_info.Pass())); | |
| 1765 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 1771 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
| 1766 observer->WaitForFinished(); | 1772 observer->WaitForFinished(); |
| 1767 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1773 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1768 | 1774 |
| 1769 // Check state. | 1775 // Check state. |
| 1770 EXPECT_EQ(1, browser()->tab_count()); | 1776 EXPECT_EQ(1, browser()->tab_count()); |
| 1771 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1777 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
| 1772 target_file_full_path, | 1778 target_file_full_path, |
| 1773 OriginFile(file))); | 1779 OriginFile(file))); |
| 1774 | 1780 |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2237 GetDownloads(browser(), &download_items); | 2243 GetDownloads(browser(), &download_items); |
| 2238 ASSERT_EQ(1u, download_items.size()); | 2244 ASSERT_EQ(1u, download_items.size()); |
| 2239 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2245 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
| 2240 download_items[0]->GetOriginalUrl()); | 2246 download_items[0]->GetOriginalUrl()); |
| 2241 | 2247 |
| 2242 // Check that the file contains the expected referrer. | 2248 // Check that the file contains the expected referrer. |
| 2243 FilePath file(download_items[0]->GetFullPath()); | 2249 FilePath file(download_items[0]->GetFullPath()); |
| 2244 std::string expected_contents = test_server()->GetURL("").spec(); | 2250 std::string expected_contents = test_server()->GetURL("").spec(); |
| 2245 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2251 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
| 2246 } | 2252 } |
| OLD | NEW |