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

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

Issue 10918136: Make web store resilient against download completion happening before opening. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 scoped_ptr<content::DownloadTestObserver> observer( 1559 scoped_ptr<content::DownloadTestObserver> observer(
1556 DangerousDownloadWaiter( 1560 DangerousDownloadWaiter(
1557 browser(), 1, 1561 browser(), 1,
1558 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 1562 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
1559 ui_test_utils::NavigateToURL(browser(), extension_url); 1563 ui_test_utils::NavigateToURL(browser(), extension_url);
1560 1564
1561 observer->WaitForFinished(); 1565 observer->WaitForFinished();
1562 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); 1566 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED));
1563 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1567 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1564 1568
1565 // Download shelf should close. Download panel stays open on ChromeOS. 1569 // Download shelf should close.
1566 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1570 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1567 1571
1568 // Check that the CRX is not installed. 1572 // Check that the CRX is not installed.
1569 ExtensionService* extension_service = 1573 ExtensionService* extension_service =
1570 browser()->profile()->GetExtensionService(); 1574 browser()->profile()->GetExtensionService();
1571 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1575 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1572 } 1576 }
1573 1577
1574 // Download an extension. Expect a dangerous download warning. 1578 // Download an extension. Expect a dangerous download warning.
1575 // Allow the download, deny the install. 1579 // Allow the download, deny the install.
(...skipping 12 matching lines...) Expand all
1588 DangerousDownloadWaiter( 1592 DangerousDownloadWaiter(
1589 browser(), 1, 1593 browser(), 1,
1590 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1594 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1591 ui_test_utils::NavigateToURL(browser(), extension_url); 1595 ui_test_utils::NavigateToURL(browser(), extension_url);
1592 1596
1593 observer->WaitForFinished(); 1597 observer->WaitForFinished();
1594 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1598 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1595 CheckDownloadStates(1, DownloadItem::COMPLETE); 1599 CheckDownloadStates(1, DownloadItem::COMPLETE);
1596 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1600 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1597 1601
1598 // Download shelf should close. Download panel stays open on ChromeOS. 1602 // Download shelf should close from auto-open.
1603 content::DownloadManager::DownloadVector downloads;
1604 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
1605 ASSERT_EQ(1u, downloads.size());
1606 content::DownloadUpdatedObserver(
1607 downloads[0], base::Bind(WasAutoOpened)).WaitForEvent();
1599 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1608 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1600 1609
1601 // Check that the extension was not installed. 1610 // Check that the extension was not installed.
1602 ExtensionService* extension_service = 1611 ExtensionService* extension_service =
1603 browser()->profile()->GetExtensionService(); 1612 browser()->profile()->GetExtensionService();
1604 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1613 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1605 } 1614 }
1606 1615
1607 // Download an extension. Expect a dangerous download warning. 1616 // Download an extension. Expect a dangerous download warning.
1608 // Allow the download, and the install. 1617 // Allow the download, and the install.
(...skipping 11 matching lines...) Expand all
1620 DangerousDownloadWaiter( 1629 DangerousDownloadWaiter(
1621 browser(), 1, 1630 browser(), 1,
1622 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1631 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1623 ui_test_utils::NavigateToURL(browser(), extension_url); 1632 ui_test_utils::NavigateToURL(browser(), extension_url);
1624 1633
1625 observer->WaitForFinished(); 1634 observer->WaitForFinished();
1626 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1635 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1627 CheckDownloadStates(1, DownloadItem::COMPLETE); 1636 CheckDownloadStates(1, DownloadItem::COMPLETE);
1628 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1637 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1629 1638
1630 // Download shelf should close. Download panel stays open on ChromeOS. 1639 // Download shelf should close from auto-open.
1640 content::DownloadManager::DownloadVector downloads;
1641 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
1642 ASSERT_EQ(1u, downloads.size());
1643 content::DownloadUpdatedObserver(
1644 downloads[0], base::Bind(WasAutoOpened)).WaitForEvent();
1631 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1645 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1632 1646
1633 // Check that the extension was installed. 1647 // Check that the extension was installed.
1634 ExtensionService* extension_service = 1648 ExtensionService* extension_service =
1635 browser()->profile()->GetExtensionService(); 1649 browser()->profile()->GetExtensionService();
1636 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); 1650 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false));
1637 } 1651 }
1638 1652
1639 // Test installing a CRX that fails integrity checks. 1653 // Test installing a CRX that fails integrity checks.
1640 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { 1654 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 DangerousDownloadWaiter( 1691 DangerousDownloadWaiter(
1678 browser(), 1, 1692 browser(), 1,
1679 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1693 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1680 ui_test_utils::NavigateToURL(browser(), extension_url); 1694 ui_test_utils::NavigateToURL(browser(), extension_url);
1681 1695
1682 observer->WaitForFinished(); 1696 observer->WaitForFinished();
1683 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1697 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1684 CheckDownloadStates(1, DownloadItem::COMPLETE); 1698 CheckDownloadStates(1, DownloadItem::COMPLETE);
1685 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1699 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1686 1700
1687 // Download shelf should close. Download panel stays open on ChromeOS. 1701 // Download shelf should close from auto-open.
1702 content::DownloadManager::DownloadVector downloads;
1703 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
1704 ASSERT_EQ(1u, downloads.size());
1705 content::DownloadUpdatedObserver(
1706 downloads[0], base::Bind(WasAutoOpened)).WaitForEvent();
1688 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1707 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1689 1708
1690 // Check that the extension was installed. 1709 // Check that the extension was installed.
1691 ExtensionService* extension_service = 1710 ExtensionService* extension_service =
1692 browser()->profile()->GetExtensionService(); 1711 browser()->profile()->GetExtensionService();
1693 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); 1712 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
1694 } 1713 }
1695 1714
1696 // Sort download items by db_handle. 1715 // Sort download items by db_handle.
1697 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { 1716 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) {
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
2346 GetDownloads(browser(), &download_items); 2365 GetDownloads(browser(), &download_items);
2347 ASSERT_EQ(1u, download_items.size()); 2366 ASSERT_EQ(1u, download_items.size());
2348 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), 2367 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"),
2349 download_items[0]->GetOriginalUrl()); 2368 download_items[0]->GetOriginalUrl());
2350 2369
2351 // Check that the file contains the expected referrer. 2370 // Check that the file contains the expected referrer.
2352 FilePath file(download_items[0]->GetFullPath()); 2371 FilePath file(download_items[0]->GetFullPath());
2353 std::string expected_contents = test_server()->GetURL("").spec(); 2372 std::string expected_contents = test_server()->GetURL("").spec();
2354 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); 2373 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length()));
2355 } 2374 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698