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

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

Issue 1527043002: [Extensions] Don't use ExtensionInstallPrompt subclasses for auto-confirmation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years 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
« no previous file with comments | « no previous file | chrome/browser/extensions/crx_installer_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 19 matching lines...) Expand all
30 #include "chrome/browser/download/download_crx_util.h" 30 #include "chrome/browser/download/download_crx_util.h"
31 #include "chrome/browser/download/download_history.h" 31 #include "chrome/browser/download/download_history.h"
32 #include "chrome/browser/download/download_item_model.h" 32 #include "chrome/browser/download/download_item_model.h"
33 #include "chrome/browser/download/download_prefs.h" 33 #include "chrome/browser/download/download_prefs.h"
34 #include "chrome/browser/download/download_request_limiter.h" 34 #include "chrome/browser/download/download_request_limiter.h"
35 #include "chrome/browser/download/download_service.h" 35 #include "chrome/browser/download/download_service.h"
36 #include "chrome/browser/download/download_service_factory.h" 36 #include "chrome/browser/download/download_service_factory.h"
37 #include "chrome/browser/download/download_shelf.h" 37 #include "chrome/browser/download/download_shelf.h"
38 #include "chrome/browser/download/download_target_determiner.h" 38 #include "chrome/browser/download/download_target_determiner.h"
39 #include "chrome/browser/download/download_test_file_activity_observer.h" 39 #include "chrome/browser/download/download_test_file_activity_observer.h"
40 #include "chrome/browser/extensions/extension_install_prompt.h"
41 #include "chrome/browser/extensions/extension_install_prompt_show_params.h"
42 #include "chrome/browser/extensions/extension_service.h" 40 #include "chrome/browser/extensions/extension_service.h"
43 #include "chrome/browser/history/history_service_factory.h" 41 #include "chrome/browser/history/history_service_factory.h"
44 #include "chrome/browser/infobars/infobar_service.h" 42 #include "chrome/browser/infobars/infobar_service.h"
45 #include "chrome/browser/net/url_request_mock_util.h" 43 #include "chrome/browser/net/url_request_mock_util.h"
46 #include "chrome/browser/profiles/profile.h" 44 #include "chrome/browser/profiles/profile.h"
47 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" 45 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
48 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 46 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
49 #include "chrome/browser/ui/browser.h" 47 #include "chrome/browser/ui/browser.h"
50 #include "chrome/browser/ui/browser_commands.h" 48 #include "chrome/browser/ui/browser_commands.h"
51 #include "chrome/browser/ui/browser_finder.h" 49 #include "chrome/browser/ui/browser_finder.h"
(...skipping 29 matching lines...) Expand all
81 #include "content/public/browser/render_view_host.h" 79 #include "content/public/browser/render_view_host.h"
82 #include "content/public/browser/render_widget_host.h" 80 #include "content/public/browser/render_widget_host.h"
83 #include "content/public/browser/resource_context.h" 81 #include "content/public/browser/resource_context.h"
84 #include "content/public/browser/web_contents.h" 82 #include "content/public/browser/web_contents.h"
85 #include "content/public/common/content_switches.h" 83 #include "content/public/common/content_switches.h"
86 #include "content/public/common/context_menu_params.h" 84 #include "content/public/common/context_menu_params.h"
87 #include "content/public/test/browser_test_utils.h" 85 #include "content/public/test/browser_test_utils.h"
88 #include "content/public/test/download_test_observer.h" 86 #include "content/public/test/download_test_observer.h"
89 #include "content/public/test/test_file_error_injector.h" 87 #include "content/public/test/test_file_error_injector.h"
90 #include "content/public/test/test_navigation_observer.h" 88 #include "content/public/test/test_navigation_observer.h"
89 #include "extensions/browser/extension_dialog_auto_confirm.h"
91 #include "extensions/browser/extension_system.h" 90 #include "extensions/browser/extension_system.h"
92 #include "extensions/common/feature_switch.h" 91 #include "extensions/common/feature_switch.h"
93 #include "net/base/filename_util.h" 92 #include "net/base/filename_util.h"
94 #include "net/test/embedded_test_server/embedded_test_server.h" 93 #include "net/test/embedded_test_server/embedded_test_server.h"
95 #include "net/test/embedded_test_server/http_request.h" 94 #include "net/test/embedded_test_server/http_request.h"
96 #include "net/test/embedded_test_server/http_response.h" 95 #include "net/test/embedded_test_server/http_response.h"
97 #include "net/test/url_request/url_request_mock_http_job.h" 96 #include "net/test/url_request/url_request_mock_http_job.h"
98 #include "net/test/url_request/url_request_slow_download_job.h" 97 #include "net/test/url_request/url_request_slow_download_job.h"
99 #include "testing/gtest/include/gtest/gtest.h" 98 #include "testing/gtest/include/gtest/gtest.h"
100 #include "ui/base/l10n/l10n_util.h" 99 #include "ui/base/l10n/l10n_util.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 base::MessageLoopForUI::current()->QuitWhenIdle(); 278 base::MessageLoopForUI::current()->QuitWhenIdle();
280 } 279 }
281 280
282 Profile* profile_; 281 Profile* profile_;
283 scoped_ptr<std::vector<history::DownloadRow> > results_; 282 scoped_ptr<std::vector<history::DownloadRow> > results_;
284 bool result_valid_; 283 bool result_valid_;
285 284
286 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); 285 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector);
287 }; 286 };
288 287
289 // Mock that simulates a permissions dialog where the user denies
290 // permission to install. TODO(skerner): This could be shared with
291 // extensions tests. Find a common place for this class.
292 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt {
293 public:
294 MockAbortExtensionInstallPrompt() :
295 ExtensionInstallPrompt(NULL) {
296 }
297
298 // Simulate a user abort on an extension installation.
299 void ShowDialog(Delegate* delegate,
300 const Extension* extension,
301 const SkBitmap* icon,
302 const ShowDialogCallback& show_dialog_callback) override {
303 delegate->InstallUIAbort(true);
304 base::MessageLoopForUI::current()->QuitWhenIdle();
305 }
306
307 void OnInstallSuccess(const Extension* extension, SkBitmap* icon) override {}
308 void OnInstallFailure(const extensions::CrxInstallError& error) override {}
309 };
310
311 // Mock that simulates a permissions dialog where the user allows
312 // installation.
313 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt {
314 public:
315 explicit MockAutoConfirmExtensionInstallPrompt(
316 content::WebContents* web_contents)
317 : ExtensionInstallPrompt(web_contents) {}
318
319 // Proceed without confirmation prompt.
320 void ShowDialog(Delegate* delegate,
321 const Extension* extension,
322 const SkBitmap* icon,
323 const ShowDialogCallback& show_dialog_callback) override {
324 delegate->InstallUIProceed();
325 }
326
327 void OnInstallSuccess(const Extension* extension, SkBitmap* icon) override {}
328 void OnInstallFailure(const extensions::CrxInstallError& error) override {}
329 };
330
331 static DownloadManager* DownloadManagerForBrowser(Browser* browser) { 288 static DownloadManager* DownloadManagerForBrowser(Browser* browser) {
332 return BrowserContext::GetDownloadManager(browser->profile()); 289 return BrowserContext::GetDownloadManager(browser->profile());
333 } 290 }
334 291
335 bool WasAutoOpened(DownloadItem* item) { 292 bool WasAutoOpened(DownloadItem* item) {
336 return item->GetAutoOpened(); 293 return item->GetAutoOpened();
337 } 294 }
338 295
339 // Called when a download starts. Marks the download as hidden. 296 // Called when a download starts. Marks the download as hidden.
340 void SetHiddenDownloadCallback(DownloadItem* item, 297 void SetHiddenDownloadCallback(DownloadItem* item,
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 DVLOG(1) << " " << __FUNCTION__ << "()" 1008 DVLOG(1) << " " << __FUNCTION__ << "()"
1052 << " folder = '" << destination_folder.value() << "'"; 1009 << " folder = '" << destination_folder.value() << "'";
1053 base::FilePermissionRestorer permission_restorer(destination_folder); 1010 base::FilePermissionRestorer permission_restorer(destination_folder);
1054 EXPECT_TRUE(base::MakeFileUnwritable(destination_folder)); 1011 EXPECT_TRUE(base::MakeFileUnwritable(destination_folder));
1055 1012
1056 for (size_t i = 0; i < count; ++i) { 1013 for (size_t i = 0; i < count; ++i) {
1057 DownloadFilesCheckErrorsLoopBody(download_info[i], i); 1014 DownloadFilesCheckErrorsLoopBody(download_info[i], i);
1058 } 1015 }
1059 } 1016 }
1060 1017
1061 // A mock install prompt that simulates the user allowing an install request.
1062 void SetAllowMockInstallPrompt() {
1063 download_crx_util::SetMockInstallPromptForTesting(
1064 scoped_ptr<ExtensionInstallPrompt>(
1065 new MockAutoConfirmExtensionInstallPrompt(
1066 browser()->tab_strip_model()->GetActiveWebContents())));
1067 }
1068
1069 // This method: 1018 // This method:
1070 // * Starts a mock download by navigating browser() to a URLRequestMockHTTPJob 1019 // * Starts a mock download by navigating browser() to a URLRequestMockHTTPJob
1071 // mock URL. 1020 // mock URL.
1072 // * Injects |error| on the first write using |error_injector|. 1021 // * Injects |error| on the first write using |error_injector|.
1073 // * Waits for the download to be interrupted. 1022 // * Waits for the download to be interrupted.
1074 // * Clears the errors on |error_injector|. 1023 // * Clears the errors on |error_injector|.
1075 // * Returns the resulting interrupted download. 1024 // * Returns the resulting interrupted download.
1076 DownloadItem* StartMockDownloadAndInjectError( 1025 DownloadItem* StartMockDownloadAndInjectError(
1077 content::TestFileErrorInjector* error_injector, 1026 content::TestFileErrorInjector* error_injector,
1078 content::DownloadInterruptReason error) { 1027 content::DownloadInterruptReason error) {
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 ExtensionService* extension_service = extensions::ExtensionSystem::Get( 1915 ExtensionService* extension_service = extensions::ExtensionSystem::Get(
1967 browser()->profile())->extension_service(); 1916 browser()->profile())->extension_service();
1968 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1917 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1969 } 1918 }
1970 1919
1971 // Download an extension. Expect a dangerous download warning. 1920 // Download an extension. Expect a dangerous download warning.
1972 // Allow the download, deny the install. 1921 // Allow the download, deny the install.
1973 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { 1922 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) {
1974 FeatureSwitch::ScopedOverride enable_easy_off_store_install( 1923 FeatureSwitch::ScopedOverride enable_easy_off_store_install(
1975 FeatureSwitch::easy_off_store_install(), true); 1924 FeatureSwitch::easy_off_store_install(), true);
1925 extensions::ScopedTestDialogAutoConfirm auto_confirm_install_prompt(
1926 extensions::ScopedTestDialogAutoConfirm::CANCEL);
1976 1927
1977 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1928 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1978 1929
1979 // Install a mock install UI that simulates a user denying permission to
1980 // finish the install.
1981 download_crx_util::SetMockInstallPromptForTesting(
1982 scoped_ptr<ExtensionInstallPrompt>(
1983 new MockAbortExtensionInstallPrompt()));
1984
1985 scoped_ptr<content::DownloadTestObserver> observer( 1930 scoped_ptr<content::DownloadTestObserver> observer(
1986 DangerousDownloadWaiter( 1931 DangerousDownloadWaiter(
1987 browser(), 1, 1932 browser(), 1,
1988 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1933 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1989 ui_test_utils::NavigateToURL(browser(), extension_url); 1934 ui_test_utils::NavigateToURL(browser(), extension_url);
1990 1935
1991 observer->WaitForFinished(); 1936 observer->WaitForFinished();
1992 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1937 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1993 CheckDownloadStates(1, DownloadItem::COMPLETE); 1938 CheckDownloadStates(1, DownloadItem::COMPLETE);
1994 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1939 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
(...skipping 11 matching lines...) Expand all
2006 } 1951 }
2007 1952
2008 // Download an extension. Expect a dangerous download warning. 1953 // Download an extension. Expect a dangerous download warning.
2009 // Allow the download, and the install. 1954 // Allow the download, and the install.
2010 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { 1955 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) {
2011 FeatureSwitch::ScopedOverride enable_easy_off_store_install( 1956 FeatureSwitch::ScopedOverride enable_easy_off_store_install(
2012 FeatureSwitch::easy_off_store_install(), true); 1957 FeatureSwitch::easy_off_store_install(), true);
2013 1958
2014 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1959 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
2015 1960
2016 // Install a mock install UI that simulates a user allowing permission to 1961 // Simulate the user allowing permission to finish the install.
2017 // finish the install. 1962 extensions::ScopedTestDialogAutoConfirm auto_confirm_install_prompt(
2018 SetAllowMockInstallPrompt(); 1963 extensions::ScopedTestDialogAutoConfirm::ACCEPT);
2019 1964
2020 scoped_ptr<content::DownloadTestObserver> observer( 1965 scoped_ptr<content::DownloadTestObserver> observer(
2021 DangerousDownloadWaiter( 1966 DangerousDownloadWaiter(
2022 browser(), 1, 1967 browser(), 1,
2023 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1968 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
2024 ui_test_utils::NavigateToURL(browser(), extension_url); 1969 ui_test_utils::NavigateToURL(browser(), extension_url);
2025 1970
2026 observer->WaitForFinished(); 1971 observer->WaitForFinished();
2027 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1972 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2028 CheckDownloadStates(1, DownloadItem::COMPLETE); 1973 CheckDownloadStates(1, DownloadItem::COMPLETE);
(...skipping 10 matching lines...) Expand all
2039 ExtensionService* extension_service = extensions::ExtensionSystem::Get( 1984 ExtensionService* extension_service = extensions::ExtensionSystem::Get(
2040 browser()->profile())->extension_service(); 1985 browser()->profile())->extension_service();
2041 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); 1986 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false));
2042 } 1987 }
2043 1988
2044 // Test installing a CRX that fails integrity checks. 1989 // Test installing a CRX that fails integrity checks.
2045 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { 1990 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) {
2046 GURL extension_url( 1991 GURL extension_url(
2047 URLRequestMockHTTPJob::GetMockUrl("extensions/bad_signature.crx")); 1992 URLRequestMockHTTPJob::GetMockUrl("extensions/bad_signature.crx"));
2048 1993
2049 // Install a mock install UI that simulates a user allowing permission to 1994 // Simulate the user allowing permission to finish the install.
2050 // finish the install, and dismisses any error message. We check that the 1995 extensions::ScopedTestDialogAutoConfirm auto_confirm_install_prompt(
2051 // install failed below. 1996 extensions::ScopedTestDialogAutoConfirm::ACCEPT);
2052 SetAllowMockInstallPrompt();
2053 1997
2054 scoped_ptr<content::DownloadTestObserver> observer( 1998 scoped_ptr<content::DownloadTestObserver> observer(
2055 DangerousDownloadWaiter( 1999 DangerousDownloadWaiter(
2056 browser(), 1, 2000 browser(), 1,
2057 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 2001 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
2058 ui_test_utils::NavigateToURL(browser(), extension_url); 2002 ui_test_utils::NavigateToURL(browser(), extension_url);
2059 2003
2060 observer->WaitForFinished(); 2004 observer->WaitForFinished();
2061 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2005 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2062 CheckDownloadStates(1, DownloadItem::COMPLETE); 2006 CheckDownloadStates(1, DownloadItem::COMPLETE);
2063 2007
2064 // Check that the extension was not installed. 2008 // Check that the extension was not installed.
2065 ExtensionService* extension_service = extensions::ExtensionSystem::Get( 2009 ExtensionService* extension_service = extensions::ExtensionSystem::Get(
2066 browser()->profile())->extension_service(); 2010 browser()->profile())->extension_service();
2067 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 2011 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
2068 } 2012 }
2069 2013
2070 // Install a large (100kb) theme. 2014 // Install a large (100kb) theme.
2071 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { 2015 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) {
2072 FeatureSwitch::ScopedOverride enable_easy_off_store_install( 2016 FeatureSwitch::ScopedOverride enable_easy_off_store_install(
2073 FeatureSwitch::easy_off_store_install(), true); 2017 FeatureSwitch::easy_off_store_install(), true);
2074 2018
2075 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); 2019 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath));
2076 2020
2077 // Install a mock install UI that simulates a user allowing permission to 2021 // Simulate the user allowing permission to finish the install.
2078 // finish the install. 2022 extensions::ScopedTestDialogAutoConfirm auto_confirm_install_prompt(
2079 SetAllowMockInstallPrompt(); 2023 extensions::ScopedTestDialogAutoConfirm::ACCEPT);
2080 2024
2081 scoped_ptr<content::DownloadTestObserver> observer( 2025 scoped_ptr<content::DownloadTestObserver> observer(
2082 DangerousDownloadWaiter( 2026 DangerousDownloadWaiter(
2083 browser(), 1, 2027 browser(), 1,
2084 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 2028 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
2085 ui_test_utils::NavigateToURL(browser(), extension_url); 2029 ui_test_utils::NavigateToURL(browser(), extension_url);
2086 2030
2087 observer->WaitForFinished(); 2031 observer->WaitForFinished();
2088 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2032 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2089 CheckDownloadStates(1, DownloadItem::COMPLETE); 2033 CheckDownloadStates(1, DownloadItem::COMPLETE);
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after
3675 3619
3676 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( 3620 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter(
3677 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3621 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3678 ui_test_utils::NavigateToURL(browser(), extension_url); 3622 ui_test_utils::NavigateToURL(browser(), extension_url);
3679 3623
3680 observer->WaitForFinished(); 3624 observer->WaitForFinished();
3681 3625
3682 // Download shelf should close. 3626 // Download shelf should close.
3683 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3627 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3684 } 3628 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/crx_installer_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698