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

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

Issue 1778873002: Replace Increment/DecrementKeepAliveCount by ScopedKeepAlives (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@KAObserver
Patch Set: Created 4 years, 9 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 "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_options.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
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));
977 chrome::CloseAllBrowsers(); 980 chrome::CloseAllBrowsers();
978 close_observer.Wait(); 981 close_observer.Wait();
979 } 982 }
980 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 983 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
981 EXPECT_TRUE(BrowserList::GetInstance()->empty()); 984 EXPECT_TRUE(BrowserList::GetInstance()->empty());
982 EXPECT_TRUE(IsBackgroundModeSuspended()); 985 EXPECT_TRUE(IsBackgroundModeSuspended());
983 986
984 // Background mode should be resumed when a new browser window is opened. 987 // Background mode should be resumed when a new browser window is opened.
985 ui_test_utils::BrowserAddedObserver new_browser_observer; 988 ui_test_utils::BrowserAddedObserver new_browser_observer;
986 chrome::NewEmptyWindow(profile); 989 chrome::NewEmptyWindow(profile);
987 new_browser_observer.WaitForSingleNewBrowser(); 990 new_browser_observer.WaitForSingleNewBrowser();
988 chrome::DecrementKeepAliveCount(); 991 tmp_keep_alive.reset();
989 EXPECT_FALSE(IsBackgroundModeSuspended()); 992 EXPECT_FALSE(IsBackgroundModeSuspended());
990 RepeatedNotificationObserver close_observer( 993 RepeatedNotificationObserver close_observer(
991 chrome::NOTIFICATION_BROWSER_CLOSED, 1); 994 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
992 995
993 // Background mode should not be suspended when quitting. 996 // Background mode should not be suspended when quitting.
994 chrome::CloseAllBrowsersAndQuit(); 997 chrome::CloseAllBrowsersAndQuit();
995 close_observer.Wait(); 998 close_observer.Wait();
996 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); 999 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
997 EXPECT_TRUE(BrowserList::GetInstance()->empty()); 1000 EXPECT_TRUE(BrowserList::GetInstance()->empty());
998 EXPECT_FALSE(IsBackgroundModeSuspended()); 1001 EXPECT_FALSE(IsBackgroundModeSuspended());
(...skipping 14 matching lines...) Expand all
1013 EXPECT_FALSE(IsBackgroundModeSuspended()); 1016 EXPECT_FALSE(IsBackgroundModeSuspended());
1014 } 1017 }
1015 1018
1016 // Check that closing all browsers with no browser windows open suspends 1019 // Check that closing all browsers with no browser windows open suspends
1017 // background mode but does not cause Chrome to quit. 1020 // background mode but does not cause Chrome to quit.
1018 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, 1021 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest,
1019 DISABLED_CloseAllBrowsersWithNoOpenBrowsersWithBackground Mode) { 1022 DISABLED_CloseAllBrowsersWithNoOpenBrowsersWithBackground Mode) {
1020 RepeatedNotificationObserver close_observer( 1023 RepeatedNotificationObserver close_observer(
1021 chrome::NOTIFICATION_BROWSER_CLOSED, 1); 1024 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
1022 EXPECT_FALSE(IsBackgroundModeSuspended()); 1025 EXPECT_FALSE(IsBackgroundModeSuspended());
1023 chrome::IncrementKeepAliveCount(); 1026 ScopedKeepAlive tmp_keep_alive(&kKeepAliveOptions);
1024 browser()->window()->Close(); 1027 browser()->window()->Close();
1025 close_observer.Wait(); 1028 close_observer.Wait();
1026 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 1029 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
1027 EXPECT_TRUE(BrowserList::GetInstance()->empty()); 1030 EXPECT_TRUE(BrowserList::GetInstance()->empty());
1028 EXPECT_FALSE(IsBackgroundModeSuspended()); 1031 EXPECT_FALSE(IsBackgroundModeSuspended());
1029 1032
1030 chrome::CloseAllBrowsers(); 1033 chrome::CloseAllBrowsers();
1031 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 1034 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
1032 EXPECT_TRUE(BrowserList::GetInstance()->empty()); 1035 EXPECT_TRUE(BrowserList::GetInstance()->empty());
1033 EXPECT_TRUE(IsBackgroundModeSuspended()); 1036 EXPECT_TRUE(IsBackgroundModeSuspended());
1034 } 1037 }
1035 1038
1036 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, 1039 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest,
1037 BrowserCloseManagerWithBackgroundModeBrowserTest, 1040 BrowserCloseManagerWithBackgroundModeBrowserTest,
1038 testing::Bool()); 1041 testing::Bool());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698