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