OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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_URL download undecided. | |
627 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, | |
628 TestWithDangerousUrlDownload) { | |
629 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
630 | |
631 // Run a dangerous download, but the user doesn't make a decision. | |
632 // This test uses a .swf because it will trigger a dangerous download | |
633 // warning on every platform. | |
634 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); | |
635 GURL download_url(content::URLRequestMockHTTPJob::GetMockUrl(file)); | |
636 content::DownloadTestObserverInterrupted observer( | |
637 content::BrowserContext::GetDownloadManager(browser()->profile()), | |
638 1, | |
639 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT); | |
640 ui_test_utils::NavigateToURLWithDisposition( | |
641 browser(), | |
642 GURL(download_url), | |
643 NEW_BACKGROUND_TAB, | |
644 ui_test_utils::BROWSER_TEST_NONE); | |
645 observer.WaitForFinished(); | |
646 | |
647 // Change the type of the dangerous download to DANGEROUS_URL, since the | |
648 // browser still prompts for DANGEROUS_FILE. | |
649 std::vector<content::DownloadItem*> download_vector; | |
650 content::BrowserContext::GetDownloadManager(browser()->profile())-> | |
651 GetAllDownloads(&download_vector); | |
652 EXPECT_EQ(1u, download_vector.size()); | |
653 download_vector.at(0)->SetDangerType( | |
654 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); | |
asanka
2013/10/15 21:39:08
It would be great if we didn't add a public interf
| |
655 | |
656 // Check that the download manager has the expected state. | |
657 EXPECT_EQ(1, content::BrowserContext::GetDownloadManager( | |
658 browser()->profile())->InProgressCount()); | |
659 EXPECT_EQ(0, content::BrowserContext::GetDownloadManager( | |
660 browser()->profile())->NonDangerousInProgressCount()); | |
661 | |
662 // Close the browser with no user action. | |
663 RepeatedNotificationObserver close_observer( | |
664 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | |
665 TestBrowserCloseManager::AttemptClose( | |
666 TestBrowserCloseManager::NO_USER_CHOICE); | |
667 close_observer.Wait(); | |
668 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | |
669 EXPECT_TRUE(chrome::BrowserIterator().done()); | |
670 } | |
671 | |
622 // Test shutdown with a download in progress. | 672 // Test shutdown with a download in progress. |
623 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestWithDownloads) { | 673 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestWithDownloads) { |
624 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 674 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
625 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); | 675 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
626 content::TestNavigationObserver navigation_observer( | 676 content::TestNavigationObserver navigation_observer( |
627 browser()->tab_strip_model()->GetActiveWebContents(), 1); | 677 browser()->tab_strip_model()->GetActiveWebContents(), 1); |
628 TestBrowserCloseManager::AttemptClose( | 678 TestBrowserCloseManager::AttemptClose( |
629 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); | 679 TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); |
630 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 680 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
631 navigation_observer.Wait(); | 681 navigation_observer.Wait(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 TestBrowserCloseManager::AttemptClose( | 761 TestBrowserCloseManager::AttemptClose( |
712 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); | 762 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
713 close_observer.Wait(); | 763 close_observer.Wait(); |
714 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 764 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
715 EXPECT_TRUE(chrome::BrowserIterator().done()); | 765 EXPECT_TRUE(chrome::BrowserIterator().done()); |
716 } | 766 } |
717 | 767 |
718 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerBrowserTest, | 768 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerBrowserTest, |
719 BrowserCloseManagerBrowserTest, | 769 BrowserCloseManagerBrowserTest, |
720 testing::Bool()); | 770 testing::Bool()); |
OLD | NEW |