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

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

Issue 10699057: Move application creation and extension install prompt showing off Browser and onto ExtensionTabHel… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 CancelableRequestConsumer callback_consumer_; 151 CancelableRequestConsumer callback_consumer_;
152 152
153 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); 153 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector);
154 }; 154 };
155 155
156 // Mock that simulates a permissions dialog where the user denies 156 // Mock that simulates a permissions dialog where the user denies
157 // permission to install. TODO(skerner): This could be shared with 157 // permission to install. TODO(skerner): This could be shared with
158 // extensions tests. Find a common place for this class. 158 // extensions tests. Find a common place for this class.
159 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt { 159 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt {
160 public: 160 public:
161 MockAbortExtensionInstallPrompt() : ExtensionInstallPrompt(NULL) {} 161 MockAbortExtensionInstallPrompt() : ExtensionInstallPrompt(NULL, NULL, NULL) {
162 }
162 163
163 // Simulate a user abort on an extension installation. 164 // Simulate a user abort on an extension installation.
164 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { 165 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) {
165 delegate->InstallUIAbort(true); 166 delegate->InstallUIAbort(true);
166 MessageLoopForUI::current()->Quit(); 167 MessageLoopForUI::current()->Quit();
167 } 168 }
168 169
169 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} 170 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {}
170 virtual void OnInstallFailure(const CrxInstallerError& error) {} 171 virtual void OnInstallFailure(const CrxInstallerError& error) {}
171 }; 172 };
172 173
173 // Mock that simulates a permissions dialog where the user allows 174 // Mock that simulates a permissions dialog where the user allows
174 // installation. 175 // installation.
175 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { 176 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt {
176 public: 177 public:
177 explicit MockAutoConfirmExtensionInstallPrompt(Browser* browser) 178 explicit MockAutoConfirmExtensionInstallPrompt(
178 : ExtensionInstallPrompt(browser) {} 179 gfx::NativeWindow parent,
180 content::PageNavigator* navigator,
181 Profile* profile)
182 : ExtensionInstallPrompt(parent, navigator, profile) {}
179 183
180 // Proceed without confirmation prompt. 184 // Proceed without confirmation prompt.
181 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { 185 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) {
182 delegate->InstallUIProceed(); 186 delegate->InstallUIProceed();
183 } 187 }
184 188
185 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} 189 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {}
186 virtual void OnInstallFailure(const CrxInstallerError& error) {} 190 virtual void OnInstallFailure(const CrxInstallerError& error) {}
187 }; 191 };
188 192
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 837
834 bool EnsureNoPendingDownloads() { 838 bool EnsureNoPendingDownloads() {
835 bool result = true; 839 bool result = true;
836 BrowserThread::PostTask( 840 BrowserThread::PostTask(
837 BrowserThread::IO, FROM_HERE, 841 BrowserThread::IO, FROM_HERE,
838 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result)); 842 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result));
839 MessageLoop::current()->Run(); 843 MessageLoop::current()->Run();
840 return result && DownloadManager::EnsureNoPendingDownloadsForTesting(); 844 return result && DownloadManager::EnsureNoPendingDownloadsForTesting();
841 } 845 }
842 846
847 // A mock install prompt that simulates the user allowing an install request.
848 void SetAllowMockInstallPrompt() {
849 gfx::NativeWindow parent =
850 browser()->window() ? browser()->window()->GetNativeWindow() : NULL;
851 download_crx_util::SetMockInstallPromptForTesting(
852 new MockAutoConfirmExtensionInstallPrompt(parent,
853 browser(),
854 browser()->profile()));
855 }
856
843 private: 857 private:
844 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { 858 static void EnsureNoPendingDownloadJobsOnIO(bool* result) {
845 if (URLRequestSlowDownloadJob::NumberOutstandingRequests()) 859 if (URLRequestSlowDownloadJob::NumberOutstandingRequests())
846 *result = false; 860 *result = false;
847 BrowserThread::PostTask( 861 BrowserThread::PostTask(
848 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); 862 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure());
849 } 863 }
850 864
851 // Location of the test data. 865 // Location of the test data.
852 FilePath test_dir_; 866 FilePath test_dir_;
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 // Download an extension. Expect a dangerous download warning. 1722 // Download an extension. Expect a dangerous download warning.
1709 // Allow the download, and the install. 1723 // Allow the download, and the install.
1710 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { 1724 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) {
1711 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) 1725 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled())
1712 return; 1726 return;
1713 1727
1714 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1728 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1715 1729
1716 // Install a mock install UI that simulates a user allowing permission to 1730 // Install a mock install UI that simulates a user allowing permission to
1717 // finish the install. 1731 // finish the install.
1718 download_crx_util::SetMockInstallPromptForTesting( 1732 SetAllowMockInstallPrompt();
1719 new MockAutoConfirmExtensionInstallPrompt(browser()));
1720 1733
1721 scoped_ptr<DownloadTestObserver> observer( 1734 scoped_ptr<DownloadTestObserver> observer(
1722 DangerousDownloadWaiter( 1735 DangerousDownloadWaiter(
1723 browser(), 1, 1736 browser(), 1,
1724 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1737 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1725 ui_test_utils::NavigateToURL(browser(), extension_url); 1738 ui_test_utils::NavigateToURL(browser(), extension_url);
1726 1739
1727 observer->WaitForFinished(); 1740 observer->WaitForFinished();
1728 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1741 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1729 CheckDownloadStates(1, DownloadItem::COMPLETE); 1742 CheckDownloadStates(1, DownloadItem::COMPLETE);
1730 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1743 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1731 1744
1732 // Download shelf should close. Download panel stays open on ChromeOS. 1745 // Download shelf should close. Download panel stays open on ChromeOS.
1733 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1746 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1734 1747
1735 // Check that the extension was installed. 1748 // Check that the extension was installed.
1736 ExtensionService* extension_service = 1749 ExtensionService* extension_service =
1737 browser()->profile()->GetExtensionService(); 1750 browser()->profile()->GetExtensionService();
1738 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); 1751 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false));
1739 } 1752 }
1740 1753
1741 // Test installing a CRX that fails integrity checks. 1754 // Test installing a CRX that fails integrity checks.
1742 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { 1755 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) {
1743 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); 1756 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx"));
1744 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1757 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file));
1745 1758
1746 // Install a mock install UI that simulates a user allowing permission to 1759 // Install a mock install UI that simulates a user allowing permission to
1747 // finish the install, and dismisses any error message. We check that the 1760 // finish the install, and dismisses any error message. We check that the
1748 // install failed below. 1761 // install failed below.
1749 download_crx_util::SetMockInstallPromptForTesting( 1762 SetAllowMockInstallPrompt();
1750 new MockAutoConfirmExtensionInstallPrompt(browser()));
1751 1763
1752 scoped_ptr<DownloadTestObserver> observer( 1764 scoped_ptr<DownloadTestObserver> observer(
1753 DangerousDownloadWaiter( 1765 DangerousDownloadWaiter(
1754 browser(), 1, 1766 browser(), 1,
1755 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1767 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1756 ui_test_utils::NavigateToURL(browser(), extension_url); 1768 ui_test_utils::NavigateToURL(browser(), extension_url);
1757 1769
1758 observer->WaitForFinished(); 1770 observer->WaitForFinished();
1759 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1771 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1760 CheckDownloadStates(1, DownloadItem::COMPLETE); 1772 CheckDownloadStates(1, DownloadItem::COMPLETE);
1761 1773
1762 // Check that the extension was not installed. 1774 // Check that the extension was not installed.
1763 ExtensionService* extension_service = 1775 ExtensionService* extension_service =
1764 browser()->profile()->GetExtensionService(); 1776 browser()->profile()->GetExtensionService();
1765 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1777 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1766 } 1778 }
1767 1779
1768 // Install a large (100kb) theme. 1780 // Install a large (100kb) theme.
1769 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { 1781 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) {
1770 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) 1782 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled())
1771 return; 1783 return;
1772 1784
1773 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); 1785 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath));
1774 1786
1775 // Install a mock install UI that simulates a user allowing permission to 1787 // Install a mock install UI that simulates a user allowing permission to
1776 // finish the install. 1788 // finish the install.
1777 download_crx_util::SetMockInstallPromptForTesting( 1789 SetAllowMockInstallPrompt();
1778 new MockAutoConfirmExtensionInstallPrompt(browser()));
1779 1790
1780 scoped_ptr<DownloadTestObserver> observer( 1791 scoped_ptr<DownloadTestObserver> observer(
1781 DangerousDownloadWaiter( 1792 DangerousDownloadWaiter(
1782 browser(), 1, 1793 browser(), 1,
1783 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1794 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1784 ui_test_utils::NavigateToURL(browser(), extension_url); 1795 ui_test_utils::NavigateToURL(browser(), extension_url);
1785 1796
1786 observer->WaitForFinished(); 1797 observer->WaitForFinished();
1787 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1798 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1788 CheckDownloadStates(1, DownloadItem::COMPLETE); 1799 CheckDownloadStates(1, DownloadItem::COMPLETE);
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 GetDownloads(browser(), &download_items); 2461 GetDownloads(browser(), &download_items);
2451 ASSERT_EQ(1u, download_items.size()); 2462 ASSERT_EQ(1u, download_items.size());
2452 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), 2463 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"),
2453 download_items[0]->GetOriginalUrl()); 2464 download_items[0]->GetOriginalUrl());
2454 2465
2455 // Check that the file contains the expected referrer. 2466 // Check that the file contains the expected referrer.
2456 FilePath file(download_items[0]->GetFullPath()); 2467 FilePath file(download_items[0]->GetFullPath());
2457 std::string expected_contents = test_server()->GetURL("").spec(); 2468 std::string expected_contents = test_server()->GetURL("").spec();
2458 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); 2469 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length()));
2459 } 2470 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager_util.cc ('k') | chrome/browser/download/download_crx_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698