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 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 21 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
22 #include "chrome/browser/download/download_crx_util.h" | 22 #include "chrome/browser/download/download_crx_util.h" |
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_observer.h" | 29 #include "chrome/browser/download/download_test_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_ui.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/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" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 bool result_valid_; | 148 bool result_valid_; |
149 int64 download_db_handle_; | 149 int64 download_db_handle_; |
150 CancelableRequestConsumer callback_consumer_; | 150 CancelableRequestConsumer callback_consumer_; |
151 | 151 |
152 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); | 152 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); |
153 }; | 153 }; |
154 | 154 |
155 // Mock that simulates a permissions dialog where the user denies | 155 // Mock that simulates a permissions dialog where the user denies |
156 // permission to install. TODO(skerner): This could be shared with | 156 // permission to install. TODO(skerner): This could be shared with |
157 // extensions tests. Find a common place for this class. | 157 // extensions tests. Find a common place for this class. |
158 class MockAbortExtensionInstallUI : public ExtensionInstallUI { | 158 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt { |
159 public: | 159 public: |
160 MockAbortExtensionInstallUI() : ExtensionInstallUI(NULL) {} | 160 MockAbortExtensionInstallPrompt() : ExtensionInstallPrompt(NULL) {} |
161 | 161 |
162 // Simulate a user abort on an extension installation. | 162 // Simulate a user abort on an extension installation. |
163 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { | 163 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { |
164 delegate->InstallUIAbort(true); | 164 delegate->InstallUIAbort(true); |
165 MessageLoopForUI::current()->Quit(); | 165 MessageLoopForUI::current()->Quit(); |
166 } | 166 } |
167 | 167 |
168 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} | 168 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} |
169 virtual void OnInstallFailure(const string16& error) {} | 169 virtual void OnInstallFailure(const string16& error) {} |
170 }; | 170 }; |
171 | 171 |
172 // Mock that simulates a permissions dialog where the user allows | 172 // Mock that simulates a permissions dialog where the user allows |
173 // installation. | 173 // installation. |
174 class MockAutoConfirmExtensionInstallUI : public ExtensionInstallUI { | 174 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { |
175 public: | 175 public: |
176 explicit MockAutoConfirmExtensionInstallUI(Profile* profile) | 176 explicit MockAutoConfirmExtensionInstallPrompt(Profile* profile) |
177 : ExtensionInstallUI(profile) {} | 177 : ExtensionInstallPrompt(profile) {} |
178 | 178 |
179 // Proceed without confirmation prompt. | 179 // Proceed without confirmation prompt. |
180 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { | 180 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { |
181 delegate->InstallUIProceed(); | 181 delegate->InstallUIProceed(); |
182 } | 182 } |
183 | 183 |
184 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} | 184 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} |
185 virtual void OnInstallFailure(const string16& error) {} | 185 virtual void OnInstallFailure(const string16& error) {} |
186 }; | 186 }; |
187 | 187 |
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 // Download an extension. Expect a dangerous download warning. | 1682 // Download an extension. Expect a dangerous download warning. |
1683 // Allow the download, deny the install. | 1683 // Allow the download, deny the install. |
1684 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1684 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
1685 if (!extensions::switch_utils::IsOffStoreInstallEnabled()) | 1685 if (!extensions::switch_utils::IsOffStoreInstallEnabled()) |
1686 return; | 1686 return; |
1687 | 1687 |
1688 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1688 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1689 | 1689 |
1690 // Install a mock install UI that simulates a user denying permission to | 1690 // Install a mock install UI that simulates a user denying permission to |
1691 // finish the install. | 1691 // finish the install. |
1692 download_crx_util::SetMockInstallUIForTesting( | 1692 download_crx_util::SetMockInstallPromptForTesting( |
1693 new MockAbortExtensionInstallUI()); | 1693 new MockAbortExtensionInstallPrompt()); |
1694 | 1694 |
1695 scoped_ptr<DownloadTestObserver> observer( | 1695 scoped_ptr<DownloadTestObserver> observer( |
1696 DangerousDownloadWaiter( | 1696 DangerousDownloadWaiter( |
1697 browser(), 1, | 1697 browser(), 1, |
1698 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1698 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1699 ui_test_utils::NavigateToURL(browser(), extension_url); | 1699 ui_test_utils::NavigateToURL(browser(), extension_url); |
1700 | 1700 |
1701 observer->WaitForFinished(); | 1701 observer->WaitForFinished(); |
1702 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1702 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1703 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1703 CheckDownloadStates(1, DownloadItem::COMPLETE); |
(...skipping 11 matching lines...) Expand all Loading... |
1715 // Download an extension. Expect a dangerous download warning. | 1715 // Download an extension. Expect a dangerous download warning. |
1716 // Allow the download, and the install. | 1716 // Allow the download, and the install. |
1717 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1717 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
1718 if (!extensions::switch_utils::IsOffStoreInstallEnabled()) | 1718 if (!extensions::switch_utils::IsOffStoreInstallEnabled()) |
1719 return; | 1719 return; |
1720 | 1720 |
1721 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1721 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1722 | 1722 |
1723 // Install a mock install UI that simulates a user allowing permission to | 1723 // Install a mock install UI that simulates a user allowing permission to |
1724 // finish the install. | 1724 // finish the install. |
1725 download_crx_util::SetMockInstallUIForTesting( | 1725 download_crx_util::SetMockInstallPromptForTesting( |
1726 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1726 new MockAutoConfirmExtensionInstallPrompt(browser()->profile())); |
1727 | 1727 |
1728 scoped_ptr<DownloadTestObserver> observer( | 1728 scoped_ptr<DownloadTestObserver> observer( |
1729 DangerousDownloadWaiter( | 1729 DangerousDownloadWaiter( |
1730 browser(), 1, | 1730 browser(), 1, |
1731 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1731 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1732 ui_test_utils::NavigateToURL(browser(), extension_url); | 1732 ui_test_utils::NavigateToURL(browser(), extension_url); |
1733 | 1733 |
1734 observer->WaitForFinished(); | 1734 observer->WaitForFinished(); |
1735 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1735 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1736 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1736 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1737 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1737 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1738 | 1738 |
1739 // Download shelf should close. Download panel stays open on ChromeOS. | 1739 // Download shelf should close. Download panel stays open on ChromeOS. |
1740 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1740 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1741 | 1741 |
1742 // Check that the extension was installed. | 1742 // Check that the extension was installed. |
1743 ExtensionService* extension_service = | 1743 ExtensionService* extension_service = |
1744 browser()->profile()->GetExtensionService(); | 1744 browser()->profile()->GetExtensionService(); |
1745 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1745 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1746 } | 1746 } |
1747 | 1747 |
1748 // Test installing a CRX that fails integrity checks. | 1748 // Test installing a CRX that fails integrity checks. |
1749 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1749 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
1750 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1750 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
1751 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1751 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1752 | 1752 |
1753 // Install a mock install UI that simulates a user allowing permission to | 1753 // Install a mock install UI that simulates a user allowing permission to |
1754 // finish the install, and dismisses any error message. We check that the | 1754 // finish the install, and dismisses any error message. We check that the |
1755 // install failed below. | 1755 // install failed below. |
1756 download_crx_util::SetMockInstallUIForTesting( | 1756 download_crx_util::SetMockInstallPromptForTesting( |
1757 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1757 new MockAutoConfirmExtensionInstallPrompt(browser()->profile())); |
1758 | 1758 |
1759 scoped_ptr<DownloadTestObserver> observer( | 1759 scoped_ptr<DownloadTestObserver> observer( |
1760 DangerousDownloadWaiter( | 1760 DangerousDownloadWaiter( |
1761 browser(), 1, | 1761 browser(), 1, |
1762 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1762 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1763 ui_test_utils::NavigateToURL(browser(), extension_url); | 1763 ui_test_utils::NavigateToURL(browser(), extension_url); |
1764 | 1764 |
1765 observer->WaitForFinished(); | 1765 observer->WaitForFinished(); |
1766 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1766 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1767 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1767 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1768 | 1768 |
1769 // Check that the extension was not installed. | 1769 // Check that the extension was not installed. |
1770 ExtensionService* extension_service = | 1770 ExtensionService* extension_service = |
1771 browser()->profile()->GetExtensionService(); | 1771 browser()->profile()->GetExtensionService(); |
1772 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1772 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1773 } | 1773 } |
1774 | 1774 |
1775 // Install a large (100kb) theme. | 1775 // Install a large (100kb) theme. |
1776 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1776 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
1777 if (!extensions::switch_utils::IsOffStoreInstallEnabled()) | 1777 if (!extensions::switch_utils::IsOffStoreInstallEnabled()) |
1778 return; | 1778 return; |
1779 | 1779 |
1780 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1780 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
1781 | 1781 |
1782 // Install a mock install UI that simulates a user allowing permission to | 1782 // Install a mock install UI that simulates a user allowing permission to |
1783 // finish the install. | 1783 // finish the install. |
1784 download_crx_util::SetMockInstallUIForTesting( | 1784 download_crx_util::SetMockInstallPromptForTesting( |
1785 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1785 new MockAutoConfirmExtensionInstallPrompt(browser()->profile())); |
1786 | 1786 |
1787 scoped_ptr<DownloadTestObserver> observer( | 1787 scoped_ptr<DownloadTestObserver> observer( |
1788 DangerousDownloadWaiter( | 1788 DangerousDownloadWaiter( |
1789 browser(), 1, | 1789 browser(), 1, |
1790 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1790 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1791 ui_test_utils::NavigateToURL(browser(), extension_url); | 1791 ui_test_utils::NavigateToURL(browser(), extension_url); |
1792 | 1792 |
1793 observer->WaitForFinished(); | 1793 observer->WaitForFinished(); |
1794 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1794 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1795 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1795 CheckDownloadStates(1, DownloadItem::COMPLETE); |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2457 GetDownloads(browser(), &download_items); | 2457 GetDownloads(browser(), &download_items); |
2458 ASSERT_EQ(1u, download_items.size()); | 2458 ASSERT_EQ(1u, download_items.size()); |
2459 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2459 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
2460 download_items[0]->GetOriginalUrl()); | 2460 download_items[0]->GetOriginalUrl()); |
2461 | 2461 |
2462 // Check that the file contains the expected referrer. | 2462 // Check that the file contains the expected referrer. |
2463 FilePath file(download_items[0]->GetFullPath()); | 2463 FilePath file(download_items[0]->GetFullPath()); |
2464 std::string expected_contents = test_server()->GetURL("").spec(); | 2464 std::string expected_contents = test_server()->GetURL("").spec(); |
2465 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2465 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
2466 } | 2466 } |
OLD | NEW |