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

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(gfx::NativeWindow parent,
178 : ExtensionInstallPrompt(browser) {} 179 content::PageNavigator* navigat or,
Aaron Boodman 2012/07/03 00:52:14 80 cols, 80 cols. 80 80 80 80 eight-y cols.
Ben Goodger (Google) 2012/07/03 19:17:00 Done.
180 Profile* profile)
181 : ExtensionInstallPrompt(parent, navigator, profile) {}
179 182
180 // Proceed without confirmation prompt. 183 // Proceed without confirmation prompt.
181 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { 184 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) {
182 delegate->InstallUIProceed(); 185 delegate->InstallUIProceed();
183 } 186 }
184 187
185 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} 188 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {}
186 virtual void OnInstallFailure(const CrxInstallerError& error) {} 189 virtual void OnInstallFailure(const CrxInstallerError& error) {}
187 }; 190 };
188 191
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 // Download an extension. Expect a dangerous download warning. 1711 // Download an extension. Expect a dangerous download warning.
1709 // Allow the download, and the install. 1712 // Allow the download, and the install.
1710 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { 1713 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) {
1711 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) 1714 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled())
1712 return; 1715 return;
1713 1716
1714 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1717 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1715 1718
1716 // 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
1717 // finish the install. 1720 // finish the install.
1721 gfx::NativeWindow parent =
Aaron Boodman 2012/07/03 00:52:14 These lines are repeated several times. Could you
Ben Goodger (Google) 2012/07/03 19:17:00 Done. I made it set the mock prompt, since all the
1722 browser()->window() ? browser()->window()->GetNativeWindow() : NULL;
1718 download_crx_util::SetMockInstallPromptForTesting( 1723 download_crx_util::SetMockInstallPromptForTesting(
1719 new MockAutoConfirmExtensionInstallPrompt(browser())); 1724 new MockAutoConfirmExtensionInstallPrompt(parent,
1725 browser(),
1726 browser()->profile()));
1720 1727
1721 scoped_ptr<DownloadTestObserver> observer( 1728 scoped_ptr<DownloadTestObserver> observer(
1722 DangerousDownloadWaiter( 1729 DangerousDownloadWaiter(
1723 browser(), 1, 1730 browser(), 1,
1724 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1731 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1725 ui_test_utils::NavigateToURL(browser(), extension_url); 1732 ui_test_utils::NavigateToURL(browser(), extension_url);
1726 1733
1727 observer->WaitForFinished(); 1734 observer->WaitForFinished();
1728 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1735 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1729 CheckDownloadStates(1, DownloadItem::COMPLETE); 1736 CheckDownloadStates(1, DownloadItem::COMPLETE);
1730 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1737 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1731 1738
1732 // Download shelf should close. Download panel stays open on ChromeOS. 1739 // Download shelf should close. Download panel stays open on ChromeOS.
1733 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1740 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1734 1741
1735 // Check that the extension was installed. 1742 // Check that the extension was installed.
1736 ExtensionService* extension_service = 1743 ExtensionService* extension_service =
1737 browser()->profile()->GetExtensionService(); 1744 browser()->profile()->GetExtensionService();
1738 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); 1745 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false));
1739 } 1746 }
1740 1747
1741 // Test installing a CRX that fails integrity checks. 1748 // Test installing a CRX that fails integrity checks.
1742 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { 1749 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) {
1743 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); 1750 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx"));
1744 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1751 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file));
1745 1752
1746 // 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
1747 // 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
1748 // install failed below. 1755 // install failed below.
1756 gfx::NativeWindow parent =
1757 browser()->window() ? browser()->window()->GetNativeWindow() : NULL;
1749 download_crx_util::SetMockInstallPromptForTesting( 1758 download_crx_util::SetMockInstallPromptForTesting(
1750 new MockAutoConfirmExtensionInstallPrompt(browser())); 1759 new MockAutoConfirmExtensionInstallPrompt(parent,
1760 browser(),
1761 browser()->profile()));
1751 1762
1752 scoped_ptr<DownloadTestObserver> observer( 1763 scoped_ptr<DownloadTestObserver> observer(
1753 DangerousDownloadWaiter( 1764 DangerousDownloadWaiter(
1754 browser(), 1, 1765 browser(), 1,
1755 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1766 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1756 ui_test_utils::NavigateToURL(browser(), extension_url); 1767 ui_test_utils::NavigateToURL(browser(), extension_url);
1757 1768
1758 observer->WaitForFinished(); 1769 observer->WaitForFinished();
1759 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1770 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1760 CheckDownloadStates(1, DownloadItem::COMPLETE); 1771 CheckDownloadStates(1, DownloadItem::COMPLETE);
1761 1772
1762 // Check that the extension was not installed. 1773 // Check that the extension was not installed.
1763 ExtensionService* extension_service = 1774 ExtensionService* extension_service =
1764 browser()->profile()->GetExtensionService(); 1775 browser()->profile()->GetExtensionService();
1765 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1776 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1766 } 1777 }
1767 1778
1768 // Install a large (100kb) theme. 1779 // Install a large (100kb) theme.
1769 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { 1780 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) {
1770 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) 1781 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled())
1771 return; 1782 return;
1772 1783
1773 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); 1784 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath));
1774 1785
1775 // Install a mock install UI that simulates a user allowing permission to 1786 // Install a mock install UI that simulates a user allowing permission to
1776 // finish the install. 1787 // finish the install.
1788 gfx::NativeWindow parent =
1789 browser()->window() ? browser()->window()->GetNativeWindow() : NULL;
1777 download_crx_util::SetMockInstallPromptForTesting( 1790 download_crx_util::SetMockInstallPromptForTesting(
1778 new MockAutoConfirmExtensionInstallPrompt(browser())); 1791 new MockAutoConfirmExtensionInstallPrompt(parent,
1792 browser(),
1793 browser()->profile()));
1779 1794
1780 scoped_ptr<DownloadTestObserver> observer( 1795 scoped_ptr<DownloadTestObserver> observer(
1781 DangerousDownloadWaiter( 1796 DangerousDownloadWaiter(
1782 browser(), 1, 1797 browser(), 1,
1783 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1798 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1784 ui_test_utils::NavigateToURL(browser(), extension_url); 1799 ui_test_utils::NavigateToURL(browser(), extension_url);
1785 1800
1786 observer->WaitForFinished(); 1801 observer->WaitForFinished();
1787 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1802 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1788 CheckDownloadStates(1, DownloadItem::COMPLETE); 1803 CheckDownloadStates(1, DownloadItem::COMPLETE);
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 GetDownloads(browser(), &download_items); 2465 GetDownloads(browser(), &download_items);
2451 ASSERT_EQ(1u, download_items.size()); 2466 ASSERT_EQ(1u, download_items.size());
2452 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), 2467 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"),
2453 download_items[0]->GetOriginalUrl()); 2468 download_items[0]->GetOriginalUrl());
2454 2469
2455 // Check that the file contains the expected referrer. 2470 // Check that the file contains the expected referrer.
2456 FilePath file(download_items[0]->GetFullPath()); 2471 FilePath file(download_items[0]->GetFullPath());
2457 std::string expected_contents = test_server()->GetURL("").spec(); 2472 std::string expected_contents = test_server()->GetURL("").spec();
2458 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); 2473 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length()));
2459 } 2474 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698