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

Side by Side Diff: chrome/browser/lifetime/browser_close_manager_browsertest.cc

Issue 1376063005: Cleanup: Pull some browser keep alive functions into its own file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more fixes Created 5 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
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 "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "chrome/browser/background/background_mode_manager.h" 9 #include "chrome/browser/background/background_mode_manager.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/browser_shutdown.h" 11 #include "chrome/browser/browser_shutdown.h"
12 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/defaults.h" 13 #include "chrome/browser/defaults.h"
14 #include "chrome/browser/download/chrome_download_manager_delegate.h" 14 #include "chrome/browser/download/chrome_download_manager_delegate.h"
15 #include "chrome/browser/download/download_prefs.h" 15 #include "chrome/browser/download/download_prefs.h"
16 #include "chrome/browser/download/download_service.h" 16 #include "chrome/browser/download/download_service.h"
17 #include "chrome/browser/download/download_service_factory.h" 17 #include "chrome/browser/download/download_service_factory.h"
18 #include "chrome/browser/lifetime/application_lifetime.h" 18 #include "chrome/browser/lifetime/application_lifetime.h"
19 #include "chrome/browser/lifetime/browser_close_manager.h" 19 #include "chrome/browser/lifetime/browser_close_manager.h"
20 #include "chrome/browser/lifetime/browser_keep_alive.h"
20 #include "chrome/browser/net/url_request_mock_util.h" 21 #include "chrome/browser/net/url_request_mock_util.h"
21 #include "chrome/browser/prefs/session_startup_pref.h" 22 #include "chrome/browser/prefs/session_startup_pref.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/profiles/profile_manager.h" 24 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/browser_commands.h" 26 #include "chrome/browser/ui/browser_commands.h"
26 #include "chrome/browser/ui/browser_iterator.h" 27 #include "chrome/browser/ui/browser_iterator.h"
27 #include "chrome/browser/ui/browser_window.h" 28 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h" 29 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 // Check that background mode is suspended when closing all browsers unless we 970 // Check that background mode is suspended when closing all browsers unless we
970 // are quitting and that background mode is resumed when a new browser window is 971 // are quitting and that background mode is resumed when a new browser window is
971 // opened. 972 // opened.
972 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, 973 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest,
973 CloseAllBrowsersWithBackgroundMode) { 974 CloseAllBrowsersWithBackgroundMode) {
974 EXPECT_FALSE(IsBackgroundModeSuspended()); 975 EXPECT_FALSE(IsBackgroundModeSuspended());
975 Profile* profile = browser()->profile(); 976 Profile* profile = browser()->profile();
976 { 977 {
977 RepeatedNotificationObserver close_observer( 978 RepeatedNotificationObserver close_observer(
978 chrome::NOTIFICATION_BROWSER_CLOSED, 1); 979 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
979 chrome::IncrementKeepAliveCount(); 980 browser_lifetime::IncrementKeepAliveCount();
sky 2015/10/07 17:27:24 And a scopedkeepalive here that is reset on 992ish
980 chrome::CloseAllBrowsers(); 981 chrome::CloseAllBrowsers();
981 close_observer.Wait(); 982 close_observer.Wait();
982 } 983 }
983 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 984 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
984 EXPECT_TRUE(chrome::BrowserIterator().done()); 985 EXPECT_TRUE(chrome::BrowserIterator().done());
985 EXPECT_TRUE(IsBackgroundModeSuspended()); 986 EXPECT_TRUE(IsBackgroundModeSuspended());
986 987
987 // 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.
988 ui_test_utils::BrowserAddedObserver new_browser_observer; 989 ui_test_utils::BrowserAddedObserver new_browser_observer;
989 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); 990 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
990 new_browser_observer.WaitForSingleNewBrowser(); 991 new_browser_observer.WaitForSingleNewBrowser();
991 chrome::DecrementKeepAliveCount(); 992 browser_lifetime::DecrementKeepAliveCount();
992 EXPECT_FALSE(IsBackgroundModeSuspended()); 993 EXPECT_FALSE(IsBackgroundModeSuspended());
993 RepeatedNotificationObserver close_observer( 994 RepeatedNotificationObserver close_observer(
994 chrome::NOTIFICATION_BROWSER_CLOSED, 1); 995 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
995 996
996 // Background mode should not be suspended when quitting. 997 // Background mode should not be suspended when quitting.
997 chrome::CloseAllBrowsersAndQuit(); 998 chrome::CloseAllBrowsersAndQuit();
998 close_observer.Wait(); 999 close_observer.Wait();
999 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); 1000 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
1000 EXPECT_TRUE(chrome::BrowserIterator().done()); 1001 EXPECT_TRUE(chrome::BrowserIterator().done());
1001 EXPECT_FALSE(IsBackgroundModeSuspended()); 1002 EXPECT_FALSE(IsBackgroundModeSuspended());
1002
1003 } 1003 }
1004 1004
1005 // Check that closing the last browser window individually does not affect 1005 // Check that closing the last browser window individually does not affect
1006 // background mode. 1006 // background mode.
1007 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, 1007 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest,
1008 CloseSingleBrowserWithBackgroundMode) { 1008 CloseSingleBrowserWithBackgroundMode) {
1009 RepeatedNotificationObserver close_observer( 1009 RepeatedNotificationObserver close_observer(
1010 chrome::NOTIFICATION_BROWSER_CLOSED, 1); 1010 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
1011 EXPECT_FALSE(IsBackgroundModeSuspended()); 1011 EXPECT_FALSE(IsBackgroundModeSuspended());
1012 browser()->window()->Close(); 1012 browser()->window()->Close();
1013 close_observer.Wait(); 1013 close_observer.Wait();
1014 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 1014 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
1015 EXPECT_TRUE(chrome::BrowserIterator().done()); 1015 EXPECT_TRUE(chrome::BrowserIterator().done());
1016 EXPECT_FALSE(IsBackgroundModeSuspended()); 1016 EXPECT_FALSE(IsBackgroundModeSuspended());
1017 } 1017 }
1018 1018
1019 // Check that closing all browsers with no browser windows open suspends 1019 // Check that closing all browsers with no browser windows open suspends
1020 // background mode but does not cause Chrome to quit. 1020 // background mode but does not cause Chrome to quit.
1021 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, 1021 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest,
1022 CloseAllBrowsersWithNoOpenBrowsersWithBackgroundMode) { 1022 CloseAllBrowsersWithNoOpenBrowsersWithBackgroundMode) {
1023 RepeatedNotificationObserver close_observer( 1023 RepeatedNotificationObserver close_observer(
1024 chrome::NOTIFICATION_BROWSER_CLOSED, 1); 1024 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
1025 EXPECT_FALSE(IsBackgroundModeSuspended()); 1025 EXPECT_FALSE(IsBackgroundModeSuspended());
1026 chrome::IncrementKeepAliveCount(); 1026 browser_lifetime::IncrementKeepAliveCount();
sky 2015/10/07 17:27:24 And a scopedkeepalive that is reset on 1037 ish?
1027 browser()->window()->Close(); 1027 browser()->window()->Close();
1028 close_observer.Wait(); 1028 close_observer.Wait();
1029 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 1029 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
1030 EXPECT_TRUE(chrome::BrowserIterator().done()); 1030 EXPECT_TRUE(chrome::BrowserIterator().done());
1031 EXPECT_FALSE(IsBackgroundModeSuspended()); 1031 EXPECT_FALSE(IsBackgroundModeSuspended());
1032 1032
1033 chrome::CloseAllBrowsers(); 1033 chrome::CloseAllBrowsers();
1034 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 1034 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
1035 EXPECT_TRUE(chrome::BrowserIterator().done()); 1035 EXPECT_TRUE(chrome::BrowserIterator().done());
1036 EXPECT_TRUE(IsBackgroundModeSuspended()); 1036 EXPECT_TRUE(IsBackgroundModeSuspended());
1037 } 1037 }
1038 1038
1039 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, 1039 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest,
1040 BrowserCloseManagerWithBackgroundModeBrowserTest, 1040 BrowserCloseManagerWithBackgroundModeBrowserTest,
1041 testing::Bool()); 1041 testing::Bool());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698