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

Unified Diff: chrome/browser/lifetime/browser_close_manager_browsertest.cc

Issue 26938003: Don't prompt to save malicious downloads on exit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit test compile error Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/lifetime/browser_close_manager_browsertest.cc
diff --git a/chrome/browser/lifetime/browser_close_manager_browsertest.cc b/chrome/browser/lifetime/browser_close_manager_browsertest.cc
index ce61b244028c4b7e4ea4a2f1fbdc7fe02d91fae3..1770039fdec4b8caaab63263afc6512e27eb50c3 100644
--- a/chrome/browser/lifetime/browser_close_manager_browsertest.cc
+++ b/chrome/browser/lifetime/browser_close_manager_browsertest.cc
@@ -31,6 +31,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/test/download_test_observer.h"
#include "content/public/test/test_navigation_observer.h"
+#include "content/test/net/url_request_mock_http_job.h"
#include "content/test/net/url_request_slow_download_job.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
@@ -121,6 +122,7 @@ class TestBrowserCloseManager : public BrowserCloseManager {
enum UserChoice {
USER_CHOICE_USER_CANCELS_CLOSE,
USER_CHOICE_USER_ALLOWS_CLOSE,
+ NO_USER_CHOICE
};
static void AttemptClose(UserChoice user_choice) {
@@ -135,7 +137,9 @@ class TestBrowserCloseManager : public BrowserCloseManager {
virtual void ConfirmCloseWithPendingDownloads(
int download_count,
const base::Callback<void(bool)>& callback) OVERRIDE {
+ EXPECT_NE(NO_USER_CHOICE, user_choice_);
switch (user_choice_) {
+ case NO_USER_CHOICE:
case USER_CHOICE_USER_CANCELS_CLOSE: {
callback.Run(false);
break;
@@ -619,6 +623,42 @@ IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest,
EXPECT_TRUE(chrome::BrowserIterator().done());
}
+// Test shutdown with a dangerous download undecided.
+IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest,
+ TestWithDangerousDownload) {
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+
+ // Run a dangerous download, but the user doesn't make a decision.
+ base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf"));
+ GURL download_url(content::URLRequestMockHTTPJob::GetMockUrl(file));
+ content::DownloadTestObserverInterrupted observer(
asanka 2013/10/11 16:02:35 You should be able to use DownloadTestObserverInPr
felt 2013/10/11 17:39:37 Missed this comment before. I tried this first, an
+ content::BrowserContext::GetDownloadManager(browser()->profile()),
+ 1,
+ content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT);
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL(download_url),
+ NEW_BACKGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_NONE);
+ observer.WaitForFinished();
+
+ // Check that the download manager has the expected state.
+ EXPECT_EQ(1UL, observer.NumDangerousDownloadsSeen());
+ EXPECT_EQ(1, content::BrowserContext::GetDownloadManager(
+ browser()->profile())->InProgressCount());
+ EXPECT_EQ(0, content::BrowserContext::GetDownloadManager(
+ browser()->profile())->NonDangerousInProgressCount());
+
+ // Close the browser with no user action.
+ RepeatedNotificationObserver close_observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED, 1);
+ TestBrowserCloseManager::AttemptClose(
+ TestBrowserCloseManager::NO_USER_CHOICE);
+ close_observer.Wait();
+ EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
+ EXPECT_TRUE(chrome::BrowserIterator().done());
+}
+
// Test shutdown with a download in progress.
IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestWithDownloads) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());

Powered by Google App Engine
This is Rietveld 408576698