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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/browser_shutdown.h" 9 #include "chrome/browser/browser_shutdown.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "chrome/test/base/in_process_browser_test.h" 25 #include "chrome/test/base/in_process_browser_test.h"
26 #include "chrome/test/base/ui_test_utils.h" 26 #include "chrome/test/base/ui_test_utils.h"
27 #include "content/public/browser/browser_context.h" 27 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/download_item.h" 28 #include "content/public/browser/download_item.h"
29 #include "content/public/browser/download_manager.h" 29 #include "content/public/browser/download_manager.h"
30 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
32 #include "content/public/test/download_test_observer.h" 32 #include "content/public/test/download_test_observer.h"
33 #include "content/public/test/test_navigation_observer.h" 33 #include "content/public/test/test_navigation_observer.h"
34 #include "content/test/net/url_request_mock_http_job.h"
34 #include "content/test/net/url_request_slow_download_job.h" 35 #include "content/test/net/url_request_slow_download_job.h"
35 #include "net/test/embedded_test_server/embedded_test_server.h" 36 #include "net/test/embedded_test_server/embedded_test_server.h"
36 37
37 namespace { 38 namespace {
38 39
39 class AppModalDialogObserver { 40 class AppModalDialogObserver {
40 public: 41 public:
41 AppModalDialogObserver() {} 42 AppModalDialogObserver() {}
42 43
43 void Start() { 44 void Start() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 base::RunLoop run_loop_; 115 base::RunLoop run_loop_;
115 116
116 DISALLOW_COPY_AND_ASSIGN(RepeatedNotificationObserver); 117 DISALLOW_COPY_AND_ASSIGN(RepeatedNotificationObserver);
117 }; 118 };
118 119
119 class TestBrowserCloseManager : public BrowserCloseManager { 120 class TestBrowserCloseManager : public BrowserCloseManager {
120 public: 121 public:
121 enum UserChoice { 122 enum UserChoice {
122 USER_CHOICE_USER_CANCELS_CLOSE, 123 USER_CHOICE_USER_CANCELS_CLOSE,
123 USER_CHOICE_USER_ALLOWS_CLOSE, 124 USER_CHOICE_USER_ALLOWS_CLOSE,
125 NO_USER_CHOICE
124 }; 126 };
125 127
126 static void AttemptClose(UserChoice user_choice) { 128 static void AttemptClose(UserChoice user_choice) {
127 scoped_refptr<BrowserCloseManager> browser_close_manager = 129 scoped_refptr<BrowserCloseManager> browser_close_manager =
128 new TestBrowserCloseManager(user_choice); 130 new TestBrowserCloseManager(user_choice);
129 browser_close_manager->StartClosingBrowsers(); 131 browser_close_manager->StartClosingBrowsers();
130 } 132 }
131 133
132 protected: 134 protected:
133 virtual ~TestBrowserCloseManager() {} 135 virtual ~TestBrowserCloseManager() {}
134 136
135 virtual void ConfirmCloseWithPendingDownloads( 137 virtual void ConfirmCloseWithPendingDownloads(
136 int download_count, 138 int download_count,
137 const base::Callback<void(bool)>& callback) OVERRIDE { 139 const base::Callback<void(bool)>& callback) OVERRIDE {
140 EXPECT_NE(NO_USER_CHOICE, user_choice_);
138 switch (user_choice_) { 141 switch (user_choice_) {
142 case NO_USER_CHOICE:
139 case USER_CHOICE_USER_CANCELS_CLOSE: { 143 case USER_CHOICE_USER_CANCELS_CLOSE: {
140 callback.Run(false); 144 callback.Run(false);
141 break; 145 break;
142 } 146 }
143 case USER_CHOICE_USER_ALLOWS_CLOSE: { 147 case USER_CHOICE_USER_ALLOWS_CLOSE: {
144 callback.Run(true); 148 callback.Run(true);
145 break; 149 break;
146 } 150 }
147 } 151 }
148 } 152 }
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 chrome::CloseAllBrowsers(); 616 chrome::CloseAllBrowsers();
613 ASSERT_FALSE(browsers_[0]->ShouldCloseWindow()); 617 ASSERT_FALSE(browsers_[0]->ShouldCloseWindow());
614 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); 618 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
615 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); 619 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
616 620
617 close_observer.Wait(); 621 close_observer.Wait();
618 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); 622 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
619 EXPECT_TRUE(chrome::BrowserIterator().done()); 623 EXPECT_TRUE(chrome::BrowserIterator().done());
620 } 624 }
621 625
626 // Test shutdown with a dangerous download undecided.
627 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest,
628 TestWithDangerousDownload) {
629 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
630
631 // Run a dangerous download, but the user doesn't make a decision.
632 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf"));
633 GURL download_url(content::URLRequestMockHTTPJob::GetMockUrl(file));
634 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
635 content::BrowserContext::GetDownloadManager(browser()->profile()),
636 1,
637 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT);
638 ui_test_utils::NavigateToURLWithDisposition(
639 browser(),
640 GURL(download_url),
641 NEW_BACKGROUND_TAB,
642 ui_test_utils::BROWSER_TEST_NONE);
643 observer.WaitForFinished();
644
645 // Check that the download manager has the expected state.
646 EXPECT_EQ(1UL, observer.NumDangerousDownloadsSeen());
647 EXPECT_EQ(1, content::BrowserContext::GetDownloadManager(
648 browser()->profile())->InProgressCount());
649 EXPECT_EQ(0, content::BrowserContext::GetDownloadManager(
650 browser()->profile())->NonDangerousInProgressCount());
651
652 // Close the browser with no user action.
653 RepeatedNotificationObserver close_observer(
654 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
655 TestBrowserCloseManager::AttemptClose(
656 TestBrowserCloseManager::NO_USER_CHOICE);
657 close_observer.Wait();
658 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
659 EXPECT_TRUE(chrome::BrowserIterator().done());
660 }
661
622 // Test shutdown with a download in progress. 662 // Test shutdown with a download in progress.
623 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestWithDownloads) { 663 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestWithDownloads) {
624 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 664 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
625 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); 665 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser()));
626 content::TestNavigationObserver navigation_observer( 666 content::TestNavigationObserver navigation_observer(
627 browser()->tab_strip_model()->GetActiveWebContents(), 1); 667 browser()->tab_strip_model()->GetActiveWebContents(), 1);
628 TestBrowserCloseManager::AttemptClose( 668 TestBrowserCloseManager::AttemptClose(
629 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); 669 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE);
630 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 670 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
631 navigation_observer.Wait(); 671 navigation_observer.Wait();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 TestBrowserCloseManager::AttemptClose( 751 TestBrowserCloseManager::AttemptClose(
712 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); 752 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE);
713 close_observer.Wait(); 753 close_observer.Wait();
714 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); 754 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
715 EXPECT_TRUE(chrome::BrowserIterator().done()); 755 EXPECT_TRUE(chrome::BrowserIterator().done());
716 } 756 }
717 757
718 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerBrowserTest, 758 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerBrowserTest,
719 BrowserCloseManagerBrowserTest, 759 BrowserCloseManagerBrowserTest,
720 testing::Bool()); 760 testing::Bool());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698