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

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

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

Powered by Google App Engine
This is Rietveld 408576698