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

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

Issue 10912173: Replace the DownloadFileManager with direct ownership of DownloadFileImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to LKGR (r156083) Created 8 years, 3 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
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 private: 190 private:
191 virtual void PlatformInit() {} 191 virtual void PlatformInit() {}
192 virtual void PlatformCancel() {} 192 virtual void PlatformCancel() {}
193 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) { 193 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) {
194 return false; 194 return false;
195 } 195 }
196 196
197 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); 197 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu);
198 }; 198 };
199 199
200 bool WasAutoOpened(DownloadItem* item) {
201 return item->GetAutoOpened();
202 }
203
200 } // namespace 204 } // namespace
201 205
202 // While an object of this class exists, it will mock out download 206 // While an object of this class exists, it will mock out download
203 // opening for all downloads created on the specified download manager. 207 // opening for all downloads created on the specified download manager.
204 class MockDownloadOpeningObserver : public DownloadManager::Observer { 208 class MockDownloadOpeningObserver : public DownloadManager::Observer {
205 public: 209 public:
206 explicit MockDownloadOpeningObserver(DownloadManager* manager) 210 explicit MockDownloadOpeningObserver(DownloadManager* manager)
207 : download_manager_(manager) { 211 : download_manager_(manager) {
208 download_manager_->AddObserver(this); 212 download_manager_->AddObserver(this);
209 } 213 }
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 if (info.download_info.show_download_item) 775 if (info.download_info.show_download_item)
772 EXPECT_TRUE(injector->HadFile(GURL(info.error_info.url))) << s.str(); 776 EXPECT_TRUE(injector->HadFile(GURL(info.error_info.url))) << s.str();
773 } 777 }
774 778
775 void DownloadInsertFilesErrorCheckErrors(size_t count, 779 void DownloadInsertFilesErrorCheckErrors(size_t count,
776 FileErrorInjectInfo* info) { 780 FileErrorInjectInfo* info) {
777 DownloadFilesCheckErrorsSetup(); 781 DownloadFilesCheckErrorsSetup();
778 782
779 // Set up file failures. 783 // Set up file failures.
780 scoped_refptr<content::TestFileErrorInjector> injector( 784 scoped_refptr<content::TestFileErrorInjector> injector(
781 content::TestFileErrorInjector::Create()); 785 content::TestFileErrorInjector::Create(
786 DownloadManagerForBrowser(browser())));
782 787
783 for (size_t i = 0; i < count; ++i) { 788 for (size_t i = 0; i < count; ++i) {
784 // Set up the full URL, for download file tracking. 789 // Set up the full URL, for download file tracking.
785 std::string server_path = "files/downloads/"; 790 std::string server_path = "files/downloads/";
786 server_path += info[i].download_info.url_name; 791 server_path += info[i].download_info.url_name;
787 GURL url = test_server()->GetURL(server_path); 792 GURL url = test_server()->GetURL(server_path);
788 info[i].error_info.url = url.spec(); 793 info[i].error_info.url = url.spec();
789 794
790 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i); 795 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i);
791 } 796 }
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 scoped_ptr<content::DownloadTestObserver> observer( 1560 scoped_ptr<content::DownloadTestObserver> observer(
1556 DangerousDownloadWaiter( 1561 DangerousDownloadWaiter(
1557 browser(), 1, 1562 browser(), 1,
1558 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 1563 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
1559 ui_test_utils::NavigateToURL(browser(), extension_url); 1564 ui_test_utils::NavigateToURL(browser(), extension_url);
1560 1565
1561 observer->WaitForFinished(); 1566 observer->WaitForFinished();
1562 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); 1567 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED));
1563 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1568 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1564 1569
1565 // Download shelf should close. Download panel stays open on ChromeOS. 1570 // Download shelf should close.
1566 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1571 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1567 1572
1568 // Check that the CRX is not installed. 1573 // Check that the CRX is not installed.
1569 ExtensionService* extension_service = 1574 ExtensionService* extension_service =
1570 browser()->profile()->GetExtensionService(); 1575 browser()->profile()->GetExtensionService();
1571 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1576 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1572 } 1577 }
1573 1578
1574 // Download an extension. Expect a dangerous download warning. 1579 // Download an extension. Expect a dangerous download warning.
1575 // Allow the download, deny the install. 1580 // Allow the download, deny the install.
(...skipping 12 matching lines...) Expand all
1588 DangerousDownloadWaiter( 1593 DangerousDownloadWaiter(
1589 browser(), 1, 1594 browser(), 1,
1590 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1595 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1591 ui_test_utils::NavigateToURL(browser(), extension_url); 1596 ui_test_utils::NavigateToURL(browser(), extension_url);
1592 1597
1593 observer->WaitForFinished(); 1598 observer->WaitForFinished();
1594 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1599 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1595 CheckDownloadStates(1, DownloadItem::COMPLETE); 1600 CheckDownloadStates(1, DownloadItem::COMPLETE);
1596 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1601 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1597 1602
1598 // Download shelf should close. Download panel stays open on ChromeOS. 1603 // Download shelf should close from auto-open.
1604 content::DownloadManager::DownloadVector downloads;
1605 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
1606 ASSERT_EQ(1u, downloads.size());
1607 content::DownloadUpdatedObserver(
1608 downloads[0], base::Bind(WasAutoOpened)).WaitForEvent();
benjhayden 2012/09/12 21:01:01 Why don't you need/want the address-of '&' operato
Randy Smith (Not in Mondays) 2012/09/13 20:15:12 Done.
1599 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1609 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1600 1610
1601 // Check that the extension was not installed. 1611 // Check that the extension was not installed.
1602 ExtensionService* extension_service = 1612 ExtensionService* extension_service =
1603 browser()->profile()->GetExtensionService(); 1613 browser()->profile()->GetExtensionService();
1604 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1614 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1605 } 1615 }
1606 1616
1607 // Download an extension. Expect a dangerous download warning. 1617 // Download an extension. Expect a dangerous download warning.
1608 // Allow the download, and the install. 1618 // Allow the download, and the install.
(...skipping 11 matching lines...) Expand all
1620 DangerousDownloadWaiter( 1630 DangerousDownloadWaiter(
1621 browser(), 1, 1631 browser(), 1,
1622 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1632 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1623 ui_test_utils::NavigateToURL(browser(), extension_url); 1633 ui_test_utils::NavigateToURL(browser(), extension_url);
1624 1634
1625 observer->WaitForFinished(); 1635 observer->WaitForFinished();
1626 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1636 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1627 CheckDownloadStates(1, DownloadItem::COMPLETE); 1637 CheckDownloadStates(1, DownloadItem::COMPLETE);
1628 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1638 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1629 1639
1630 // Download shelf should close. Download panel stays open on ChromeOS. 1640 // Download shelf should close from auto-open.
1641 content::DownloadManager::DownloadVector downloads;
1642 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
1643 ASSERT_EQ(1u, downloads.size());
1644 content::DownloadUpdatedObserver(
1645 downloads[0], base::Bind(WasAutoOpened)).WaitForEvent();
1631 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1646 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1632 1647
1633 // Check that the extension was installed. 1648 // Check that the extension was installed.
1634 ExtensionService* extension_service = 1649 ExtensionService* extension_service =
1635 browser()->profile()->GetExtensionService(); 1650 browser()->profile()->GetExtensionService();
1636 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); 1651 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false));
1637 } 1652 }
1638 1653
1639 // Test installing a CRX that fails integrity checks. 1654 // Test installing a CRX that fails integrity checks.
1640 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { 1655 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 DangerousDownloadWaiter( 1692 DangerousDownloadWaiter(
1678 browser(), 1, 1693 browser(), 1,
1679 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1694 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1680 ui_test_utils::NavigateToURL(browser(), extension_url); 1695 ui_test_utils::NavigateToURL(browser(), extension_url);
1681 1696
1682 observer->WaitForFinished(); 1697 observer->WaitForFinished();
1683 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1698 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1684 CheckDownloadStates(1, DownloadItem::COMPLETE); 1699 CheckDownloadStates(1, DownloadItem::COMPLETE);
1685 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1700 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1686 1701
1687 // Download shelf should close. Download panel stays open on ChromeOS. 1702 // Download shelf should close from auto-open.
1703 content::DownloadManager::DownloadVector downloads;
1704 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
1705 ASSERT_EQ(1u, downloads.size());
1706 content::DownloadUpdatedObserver(
1707 downloads[0], base::Bind(WasAutoOpened)).WaitForEvent();
1688 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1708 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1689 1709
1690 // Check that the extension was installed. 1710 // Check that the extension was installed.
1691 ExtensionService* extension_service = 1711 ExtensionService* extension_service =
1692 browser()->profile()->GetExtensionService(); 1712 browser()->profile()->GetExtensionService();
1693 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); 1713 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
1694 } 1714 }
1695 1715
1696 // Sort download items by db_handle. 1716 // Sort download items by db_handle.
1697 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { 1717 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) {
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
2346 GetDownloads(browser(), &download_items); 2366 GetDownloads(browser(), &download_items);
2347 ASSERT_EQ(1u, download_items.size()); 2367 ASSERT_EQ(1u, download_items.size());
2348 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), 2368 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"),
2349 download_items[0]->GetOriginalUrl()); 2369 download_items[0]->GetOriginalUrl());
2350 2370
2351 // Check that the file contains the expected referrer. 2371 // Check that the file contains the expected referrer.
2352 FilePath file(download_items[0]->GetFullPath()); 2372 FilePath file(download_items[0]->GetFullPath());
2353 std::string expected_contents = test_server()->GetURL("").spec(); 2373 std::string expected_contents = test_server()->GetURL("").spec();
2354 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); 2374 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length()));
2355 } 2375 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698