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 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/download/download_history.h" | 23 #include "chrome/browser/download/download_history.h" |
24 #include "chrome/browser/download/download_prefs.h" | 24 #include "chrome/browser/download/download_prefs.h" |
25 #include "chrome/browser/download/download_request_limiter.h" | 25 #include "chrome/browser/download/download_request_limiter.h" |
26 #include "chrome/browser/download/download_service.h" | 26 #include "chrome/browser/download/download_service.h" |
27 #include "chrome/browser/download/download_service_factory.h" | 27 #include "chrome/browser/download/download_service_factory.h" |
28 #include "chrome/browser/download/download_shelf.h" | 28 #include "chrome/browser/download/download_shelf.h" |
29 #include "chrome/browser/download/download_test_file_chooser_observer.h" | 29 #include "chrome/browser/download/download_test_file_chooser_observer.h" |
30 #include "chrome/browser/download/download_util.h" | 30 #include "chrome/browser/download/download_util.h" |
31 #include "chrome/browser/extensions/extension_install_prompt.h" | 31 #include "chrome/browser/extensions/extension_install_prompt.h" |
32 #include "chrome/browser/extensions/extension_service.h" | 32 #include "chrome/browser/extensions/extension_service.h" |
| 33 #include "chrome/browser/extensions/extension_system.h" |
33 #include "chrome/browser/history/download_row.h" | 34 #include "chrome/browser/history/download_row.h" |
34 #include "chrome/browser/history/history.h" | 35 #include "chrome/browser/history/history.h" |
35 #include "chrome/browser/history/history_service_factory.h" | 36 #include "chrome/browser/history/history_service_factory.h" |
36 #include "chrome/browser/net/url_request_mock_util.h" | 37 #include "chrome/browser/net/url_request_mock_util.h" |
37 #include "chrome/browser/prefs/pref_service.h" | 38 #include "chrome/browser/prefs/pref_service.h" |
38 #include "chrome/browser/profiles/profile.h" | 39 #include "chrome/browser/profiles/profile.h" |
39 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 40 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
40 #include "chrome/browser/ui/browser.h" | 41 #include "chrome/browser/ui/browser.h" |
41 #include "chrome/browser/ui/browser_commands.h" | 42 #include "chrome/browser/ui/browser_commands.h" |
42 #include "chrome/browser/ui/browser_list.h" | 43 #include "chrome/browser/ui/browser_list.h" |
(...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 ui_test_utils::NavigateToURL(browser(), extension_url); | 1527 ui_test_utils::NavigateToURL(browser(), extension_url); |
1527 | 1528 |
1528 observer->WaitForFinished(); | 1529 observer->WaitForFinished(); |
1529 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); | 1530 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); |
1530 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1531 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1531 | 1532 |
1532 // Download shelf should close. | 1533 // Download shelf should close. |
1533 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1534 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1534 | 1535 |
1535 // Check that the CRX is not installed. | 1536 // Check that the CRX is not installed. |
1536 ExtensionService* extension_service = | 1537 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
1537 browser()->profile()->GetExtensionService(); | 1538 browser()->profile())->extension_service(); |
1538 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1539 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1539 } | 1540 } |
1540 | 1541 |
1541 // Download an extension. Expect a dangerous download warning. | 1542 // Download an extension. Expect a dangerous download warning. |
1542 // Allow the download, deny the install. | 1543 // Allow the download, deny the install. |
1543 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1544 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
1544 FeatureSwitch::ScopedOverride enable_easy_off_store_install( | 1545 FeatureSwitch::ScopedOverride enable_easy_off_store_install( |
1545 FeatureSwitch::easy_off_store_install(), true); | 1546 FeatureSwitch::easy_off_store_install(), true); |
1546 | 1547 |
1547 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1548 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
(...skipping 16 matching lines...) Expand all Loading... |
1564 | 1565 |
1565 // Download shelf should close from auto-open. | 1566 // Download shelf should close from auto-open. |
1566 content::DownloadManager::DownloadVector downloads; | 1567 content::DownloadManager::DownloadVector downloads; |
1567 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 1568 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
1568 ASSERT_EQ(1u, downloads.size()); | 1569 ASSERT_EQ(1u, downloads.size()); |
1569 content::DownloadUpdatedObserver( | 1570 content::DownloadUpdatedObserver( |
1570 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); | 1571 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
1571 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1572 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1572 | 1573 |
1573 // Check that the extension was not installed. | 1574 // Check that the extension was not installed. |
1574 ExtensionService* extension_service = | 1575 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
1575 browser()->profile()->GetExtensionService(); | 1576 browser()->profile())->extension_service(); |
1576 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1577 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1577 } | 1578 } |
1578 | 1579 |
1579 // Download an extension. Expect a dangerous download warning. | 1580 // Download an extension. Expect a dangerous download warning. |
1580 // Allow the download, and the install. | 1581 // Allow the download, and the install. |
1581 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1582 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
1582 FeatureSwitch::ScopedOverride enable_easy_off_store_install( | 1583 FeatureSwitch::ScopedOverride enable_easy_off_store_install( |
1583 FeatureSwitch::easy_off_store_install(), true); | 1584 FeatureSwitch::easy_off_store_install(), true); |
1584 | 1585 |
1585 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1586 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
(...skipping 15 matching lines...) Expand all Loading... |
1601 | 1602 |
1602 // Download shelf should close from auto-open. | 1603 // Download shelf should close from auto-open. |
1603 content::DownloadManager::DownloadVector downloads; | 1604 content::DownloadManager::DownloadVector downloads; |
1604 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 1605 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
1605 ASSERT_EQ(1u, downloads.size()); | 1606 ASSERT_EQ(1u, downloads.size()); |
1606 content::DownloadUpdatedObserver( | 1607 content::DownloadUpdatedObserver( |
1607 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); | 1608 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
1608 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1609 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1609 | 1610 |
1610 // Check that the extension was installed. | 1611 // Check that the extension was installed. |
1611 ExtensionService* extension_service = | 1612 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
1612 browser()->profile()->GetExtensionService(); | 1613 browser()->profile())->extension_service(); |
1613 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1614 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1614 } | 1615 } |
1615 | 1616 |
1616 // Test installing a CRX that fails integrity checks. | 1617 // Test installing a CRX that fails integrity checks. |
1617 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1618 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
1618 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1619 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
1619 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1620 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1620 | 1621 |
1621 // Install a mock install UI that simulates a user allowing permission to | 1622 // Install a mock install UI that simulates a user allowing permission to |
1622 // finish the install, and dismisses any error message. We check that the | 1623 // finish the install, and dismisses any error message. We check that the |
1623 // install failed below. | 1624 // install failed below. |
1624 SetAllowMockInstallPrompt(); | 1625 SetAllowMockInstallPrompt(); |
1625 | 1626 |
1626 scoped_ptr<content::DownloadTestObserver> observer( | 1627 scoped_ptr<content::DownloadTestObserver> observer( |
1627 DangerousDownloadWaiter( | 1628 DangerousDownloadWaiter( |
1628 browser(), 1, | 1629 browser(), 1, |
1629 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1630 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1630 ui_test_utils::NavigateToURL(browser(), extension_url); | 1631 ui_test_utils::NavigateToURL(browser(), extension_url); |
1631 | 1632 |
1632 observer->WaitForFinished(); | 1633 observer->WaitForFinished(); |
1633 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1634 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1634 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1635 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1635 | 1636 |
1636 // Check that the extension was not installed. | 1637 // Check that the extension was not installed. |
1637 ExtensionService* extension_service = | 1638 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
1638 browser()->profile()->GetExtensionService(); | 1639 browser()->profile())->extension_service(); |
1639 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1640 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1640 } | 1641 } |
1641 | 1642 |
1642 // Install a large (100kb) theme. | 1643 // Install a large (100kb) theme. |
1643 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1644 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
1644 FeatureSwitch::ScopedOverride enable_easy_off_store_install( | 1645 FeatureSwitch::ScopedOverride enable_easy_off_store_install( |
1645 FeatureSwitch::easy_off_store_install(), true); | 1646 FeatureSwitch::easy_off_store_install(), true); |
1646 | 1647 |
1647 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1648 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
1648 | 1649 |
(...skipping 14 matching lines...) Expand all Loading... |
1663 | 1664 |
1664 // Download shelf should close from auto-open. | 1665 // Download shelf should close from auto-open. |
1665 content::DownloadManager::DownloadVector downloads; | 1666 content::DownloadManager::DownloadVector downloads; |
1666 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 1667 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
1667 ASSERT_EQ(1u, downloads.size()); | 1668 ASSERT_EQ(1u, downloads.size()); |
1668 content::DownloadUpdatedObserver( | 1669 content::DownloadUpdatedObserver( |
1669 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); | 1670 downloads[0], base::Bind(&WasAutoOpened)).WaitForEvent(); |
1670 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1671 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1671 | 1672 |
1672 // Check that the extension was installed. | 1673 // Check that the extension was installed. |
1673 ExtensionService* extension_service = | 1674 ExtensionService* extension_service = extensions::ExtensionSystem::Get( |
1674 browser()->profile()->GetExtensionService(); | 1675 browser()->profile())->extension_service(); |
1675 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1676 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
1676 } | 1677 } |
1677 | 1678 |
1678 // Tests for download initiation functions. | 1679 // Tests for download initiation functions. |
1679 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 1680 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
1680 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1681 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1681 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1682 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1682 | 1683 |
1683 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1684 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
1684 EnableFileChooser(true); | 1685 EnableFileChooser(true); |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2225 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 2226 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
2226 scoped_ptr<DownloadUrlParameters> params( | 2227 scoped_ptr<DownloadUrlParameters> params( |
2227 DownloadUrlParameters::FromWebContents(web_contents, url)); | 2228 DownloadUrlParameters::FromWebContents(web_contents, url)); |
2228 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); | 2229 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); |
2229 download_manager->DownloadUrl(params.Pass()); | 2230 download_manager->DownloadUrl(params.Pass()); |
2230 observer->WaitForFinished(); | 2231 observer->WaitForFinished(); |
2231 | 2232 |
2232 // Verify that download shelf is not shown. | 2233 // Verify that download shelf is not shown. |
2233 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 2234 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
2234 } | 2235 } |
OLD | NEW |