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 "chrome/browser/lifetime/browser_close_manager.h" | 5 #include "chrome/browser/lifetime/browser_close_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "chrome/browser/background/background_mode_manager.h" | 14 #include "chrome/browser/background/background_mode_manager.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
19 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 19 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
20 #include "chrome/browser/download/download_prefs.h" | 20 #include "chrome/browser/download/download_prefs.h" |
21 #include "chrome/browser/download/download_service.h" | 21 #include "chrome/browser/download/download_service.h" |
22 #include "chrome/browser/download/download_service_factory.h" | 22 #include "chrome/browser/download/download_service_factory.h" |
23 #include "chrome/browser/lifetime/application_lifetime.h" | 23 #include "chrome/browser/lifetime/application_lifetime.h" |
| 24 #include "chrome/browser/lifetime/keep_alive_types.h" |
| 25 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
24 #include "chrome/browser/net/url_request_mock_util.h" | 26 #include "chrome/browser/net/url_request_mock_util.h" |
25 #include "chrome/browser/prefs/session_startup_pref.h" | 27 #include "chrome/browser/prefs/session_startup_pref.h" |
26 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/profiles/profile_manager.h" | 29 #include "chrome/browser/profiles/profile_manager.h" |
28 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/browser_commands.h" | 31 #include "chrome/browser/ui/browser_commands.h" |
30 #include "chrome/browser/ui/browser_list.h" | 32 #include "chrome/browser/ui/browser_list.h" |
31 #include "chrome/browser/ui/browser_window.h" | 33 #include "chrome/browser/ui/browser_window.h" |
32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
33 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 private: | 964 private: |
963 DISALLOW_COPY_AND_ASSIGN(BrowserCloseManagerWithBackgroundModeBrowserTest); | 965 DISALLOW_COPY_AND_ASSIGN(BrowserCloseManagerWithBackgroundModeBrowserTest); |
964 }; | 966 }; |
965 | 967 |
966 // Check that background mode is suspended when closing all browsers unless we | 968 // Check that background mode is suspended when closing all browsers unless we |
967 // are quitting and that background mode is resumed when a new browser window is | 969 // are quitting and that background mode is resumed when a new browser window is |
968 // opened. | 970 // opened. |
969 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, | 971 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
970 CloseAllBrowsersWithBackgroundMode) { | 972 CloseAllBrowsersWithBackgroundMode) { |
971 EXPECT_FALSE(IsBackgroundModeSuspended()); | 973 EXPECT_FALSE(IsBackgroundModeSuspended()); |
| 974 scoped_ptr<ScopedKeepAlive> tmp_keep_alive; |
972 Profile* profile = browser()->profile(); | 975 Profile* profile = browser()->profile(); |
973 { | 976 { |
974 RepeatedNotificationObserver close_observer( | 977 RepeatedNotificationObserver close_observer( |
975 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | 978 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
976 chrome::IncrementKeepAliveCount(); | 979 tmp_keep_alive.reset(new ScopedKeepAlive(KeepAliveOrigin::PANEL_VIEW, |
| 980 KeepAliveRestartOption::DISABLED)); |
977 chrome::CloseAllBrowsers(); | 981 chrome::CloseAllBrowsers(); |
978 close_observer.Wait(); | 982 close_observer.Wait(); |
979 } | 983 } |
980 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 984 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
981 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 985 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
982 EXPECT_TRUE(IsBackgroundModeSuspended()); | 986 EXPECT_TRUE(IsBackgroundModeSuspended()); |
983 | 987 |
984 // Background mode should be resumed when a new browser window is opened. | 988 // Background mode should be resumed when a new browser window is opened. |
985 ui_test_utils::BrowserAddedObserver new_browser_observer; | 989 ui_test_utils::BrowserAddedObserver new_browser_observer; |
986 chrome::NewEmptyWindow(profile); | 990 chrome::NewEmptyWindow(profile); |
987 new_browser_observer.WaitForSingleNewBrowser(); | 991 new_browser_observer.WaitForSingleNewBrowser(); |
988 chrome::DecrementKeepAliveCount(); | 992 tmp_keep_alive.reset(); |
989 EXPECT_FALSE(IsBackgroundModeSuspended()); | 993 EXPECT_FALSE(IsBackgroundModeSuspended()); |
990 RepeatedNotificationObserver close_observer( | 994 RepeatedNotificationObserver close_observer( |
991 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | 995 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
992 | 996 |
993 // Background mode should not be suspended when quitting. | 997 // Background mode should not be suspended when quitting. |
994 chrome::CloseAllBrowsersAndQuit(); | 998 chrome::CloseAllBrowsersAndQuit(); |
995 close_observer.Wait(); | 999 close_observer.Wait(); |
996 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 1000 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
997 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 1001 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
998 EXPECT_FALSE(IsBackgroundModeSuspended()); | 1002 EXPECT_FALSE(IsBackgroundModeSuspended()); |
(...skipping 14 matching lines...) Expand all Loading... |
1013 EXPECT_FALSE(IsBackgroundModeSuspended()); | 1017 EXPECT_FALSE(IsBackgroundModeSuspended()); |
1014 } | 1018 } |
1015 | 1019 |
1016 // Check that closing all browsers with no browser windows open suspends | 1020 // Check that closing all browsers with no browser windows open suspends |
1017 // background mode but does not cause Chrome to quit. | 1021 // background mode but does not cause Chrome to quit. |
1018 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, | 1022 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
1019 DISABLED_CloseAllBrowsersWithNoOpenBrowsersWithBackground
Mode) { | 1023 DISABLED_CloseAllBrowsersWithNoOpenBrowsersWithBackground
Mode) { |
1020 RepeatedNotificationObserver close_observer( | 1024 RepeatedNotificationObserver close_observer( |
1021 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | 1025 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
1022 EXPECT_FALSE(IsBackgroundModeSuspended()); | 1026 EXPECT_FALSE(IsBackgroundModeSuspended()); |
1023 chrome::IncrementKeepAliveCount(); | 1027 ScopedKeepAlive tmp_keep_alive(KeepAliveOrigin::PANEL_VIEW, |
| 1028 KeepAliveRestartOption::DISABLED); |
1024 browser()->window()->Close(); | 1029 browser()->window()->Close(); |
1025 close_observer.Wait(); | 1030 close_observer.Wait(); |
1026 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 1031 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
1027 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 1032 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
1028 EXPECT_FALSE(IsBackgroundModeSuspended()); | 1033 EXPECT_FALSE(IsBackgroundModeSuspended()); |
1029 | 1034 |
1030 chrome::CloseAllBrowsers(); | 1035 chrome::CloseAllBrowsers(); |
1031 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 1036 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
1032 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 1037 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
1033 EXPECT_TRUE(IsBackgroundModeSuspended()); | 1038 EXPECT_TRUE(IsBackgroundModeSuspended()); |
1034 } | 1039 } |
1035 | 1040 |
1036 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, | 1041 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
1037 BrowserCloseManagerWithBackgroundModeBrowserTest, | 1042 BrowserCloseManagerWithBackgroundModeBrowserTest, |
1038 testing::Bool()); | 1043 testing::Bool()); |
OLD | NEW |