| 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 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/browser/history/history.h" | 33 #include "chrome/browser/history/history.h" |
| 34 #include "chrome/browser/net/url_request_mock_util.h" | 34 #include "chrome/browser/net/url_request_mock_util.h" |
| 35 #include "chrome/browser/prefs/pref_service.h" | 35 #include "chrome/browser/prefs/pref_service.h" |
| 36 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 37 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 38 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
| 39 #include "chrome/browser/ui/browser_list.h" | 39 #include "chrome/browser/ui/browser_list.h" |
| 40 #include "chrome/browser/ui/browser_window.h" | 40 #include "chrome/browser/ui/browser_window.h" |
| 41 #include "chrome/common/chrome_notification_types.h" | 41 #include "chrome/common/chrome_notification_types.h" |
| 42 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
| 43 #include "chrome/common/extensions/extension_switch_utils.h" |
| 43 #include "chrome/common/pref_names.h" | 44 #include "chrome/common/pref_names.h" |
| 44 #include "chrome/common/url_constants.h" | 45 #include "chrome/common/url_constants.h" |
| 45 #include "chrome/test/base/in_process_browser_test.h" | 46 #include "chrome/test/base/in_process_browser_test.h" |
| 46 #include "chrome/test/base/ui_test_utils.h" | 47 #include "chrome/test/base/ui_test_utils.h" |
| 47 #include "content/public/browser/download_item.h" | 48 #include "content/public/browser/download_item.h" |
| 48 #include "content/public/browser/download_manager.h" | 49 #include "content/public/browser/download_manager.h" |
| 49 #include "content/public/browser/download_persistent_store_info.h" | 50 #include "content/public/browser/download_persistent_store_info.h" |
| 50 #include "content/public/browser/download_save_info.h" | 51 #include "content/public/browser/download_save_info.h" |
| 51 #include "content/public/browser/download_url_parameters.h" | 52 #include "content/public/browser/download_url_parameters.h" |
| 52 #include "content/public/browser/notification_source.h" | 53 #include "content/public/browser/notification_source.h" |
| (...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 // As long as we're here, confirmed everything else is good. | 1647 // As long as we're here, confirmed everything else is good. |
| 1647 EXPECT_EQ(1, browser()->tab_count()); | 1648 EXPECT_EQ(1, browser()->tab_count()); |
| 1648 CheckDownload(browser(), file, file); | 1649 CheckDownload(browser(), file, file); |
| 1649 // Download shelf should close. Download panel stays open on ChromeOS. | 1650 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1650 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1651 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1651 } | 1652 } |
| 1652 | 1653 |
| 1653 // Download an extension. Expect a dangerous download warning. | 1654 // Download an extension. Expect a dangerous download warning. |
| 1654 // Deny the download. | 1655 // Deny the download. |
| 1655 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { | 1656 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { |
| 1657 if (!extensions::switch_utils::IsOffStoreInstallEnabled()) |
| 1658 return; |
| 1659 |
| 1656 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1660 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1657 | 1661 |
| 1658 scoped_ptr<DownloadTestObserver> observer( | 1662 scoped_ptr<DownloadTestObserver> observer( |
| 1659 DangerousDownloadWaiter( | 1663 DangerousDownloadWaiter( |
| 1660 browser(), 1, | 1664 browser(), 1, |
| 1661 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 1665 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 1662 ui_test_utils::NavigateToURL(browser(), extension_url); | 1666 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1663 | 1667 |
| 1664 observer->WaitForFinished(); | 1668 observer->WaitForFinished(); |
| 1665 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); | 1669 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); |
| 1666 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1670 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1667 | 1671 |
| 1668 // Download shelf should close. Download panel stays open on ChromeOS. | 1672 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1669 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1673 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1670 | 1674 |
| 1671 // Check that the CRX is not installed. | 1675 // Check that the CRX is not installed. |
| 1672 ExtensionService* extension_service = | 1676 ExtensionService* extension_service = |
| 1673 browser()->profile()->GetExtensionService(); | 1677 browser()->profile()->GetExtensionService(); |
| 1674 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1678 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1675 } | 1679 } |
| 1676 | 1680 |
| 1677 // Download an extension. Expect a dangerous download warning. | 1681 // Download an extension. Expect a dangerous download warning. |
| 1678 // Allow the download, deny the install. | 1682 // Allow the download, deny the install. |
| 1679 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1683 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
| 1684 if (!extensions::switch_utils::IsOffStoreInstallEnabled()) |
| 1685 return; |
| 1686 |
| 1680 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1687 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1681 | 1688 |
| 1682 // Install a mock install UI that simulates a user denying permission to | 1689 // Install a mock install UI that simulates a user denying permission to |
| 1683 // finish the install. | 1690 // finish the install. |
| 1684 download_crx_util::SetMockInstallUIForTesting( | 1691 download_crx_util::SetMockInstallUIForTesting( |
| 1685 new MockAbortExtensionInstallUI()); | 1692 new MockAbortExtensionInstallUI()); |
| 1686 | 1693 |
| 1687 scoped_ptr<DownloadTestObserver> observer( | 1694 scoped_ptr<DownloadTestObserver> observer( |
| 1688 DangerousDownloadWaiter( | 1695 DangerousDownloadWaiter( |
| 1689 browser(), 1, | 1696 browser(), 1, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1700 | 1707 |
| 1701 // Check that the extension was not installed. | 1708 // Check that the extension was not installed. |
| 1702 ExtensionService* extension_service = | 1709 ExtensionService* extension_service = |
| 1703 browser()->profile()->GetExtensionService(); | 1710 browser()->profile()->GetExtensionService(); |
| 1704 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1711 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1705 } | 1712 } |
| 1706 | 1713 |
| 1707 // Download an extension. Expect a dangerous download warning. | 1714 // Download an extension. Expect a dangerous download warning. |
| 1708 // Allow the download, and the install. | 1715 // Allow the download, and the install. |
| 1709 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1716 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
| 1717 if (!extensions::switch_utils::IsOffStoreInstallEnabled()) |
| 1718 return; |
| 1719 |
| 1710 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1720 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1711 | 1721 |
| 1712 // Install a mock install UI that simulates a user allowing permission to | 1722 // Install a mock install UI that simulates a user allowing permission to |
| 1713 // finish the install. | 1723 // finish the install. |
| 1714 download_crx_util::SetMockInstallUIForTesting( | 1724 download_crx_util::SetMockInstallUIForTesting( |
| 1715 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1725 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1716 | 1726 |
| 1717 scoped_ptr<DownloadTestObserver> observer( | 1727 scoped_ptr<DownloadTestObserver> observer( |
| 1718 DangerousDownloadWaiter( | 1728 DangerousDownloadWaiter( |
| 1719 browser(), 1, | 1729 browser(), 1, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1756 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1766 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1757 | 1767 |
| 1758 // Check that the extension was not installed. | 1768 // Check that the extension was not installed. |
| 1759 ExtensionService* extension_service = | 1769 ExtensionService* extension_service = |
| 1760 browser()->profile()->GetExtensionService(); | 1770 browser()->profile()->GetExtensionService(); |
| 1761 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1771 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1762 } | 1772 } |
| 1763 | 1773 |
| 1764 // Install a large (100kb) theme. | 1774 // Install a large (100kb) theme. |
| 1765 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1775 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
| 1776 if (!extensions::switch_utils::IsOffStoreInstallEnabled()) |
| 1777 return; |
| 1778 |
| 1766 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1779 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
| 1767 | 1780 |
| 1768 // Install a mock install UI that simulates a user allowing permission to | 1781 // Install a mock install UI that simulates a user allowing permission to |
| 1769 // finish the install. | 1782 // finish the install. |
| 1770 download_crx_util::SetMockInstallUIForTesting( | 1783 download_crx_util::SetMockInstallUIForTesting( |
| 1771 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1784 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1772 | 1785 |
| 1773 scoped_ptr<DownloadTestObserver> observer( | 1786 scoped_ptr<DownloadTestObserver> observer( |
| 1774 DangerousDownloadWaiter( | 1787 DangerousDownloadWaiter( |
| 1775 browser(), 1, | 1788 browser(), 1, |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2443 GetDownloads(browser(), &download_items); | 2456 GetDownloads(browser(), &download_items); |
| 2444 ASSERT_EQ(1u, download_items.size()); | 2457 ASSERT_EQ(1u, download_items.size()); |
| 2445 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2458 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
| 2446 download_items[0]->GetOriginalUrl()); | 2459 download_items[0]->GetOriginalUrl()); |
| 2447 | 2460 |
| 2448 // Check that the file contains the expected referrer. | 2461 // Check that the file contains the expected referrer. |
| 2449 FilePath file(download_items[0]->GetFullPath()); | 2462 FilePath file(download_items[0]->GetFullPath()); |
| 2450 std::string expected_contents = test_server()->GetURL("").spec(); | 2463 std::string expected_contents = test_server()->GetURL("").spec(); |
| 2451 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2464 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
| 2452 } | 2465 } |
| OLD | NEW |