[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 5 | #include "chrome/browser/lifetime/browser_close_manager.h" |
| 6 | |
| 7 | #include <utility> |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Sebastien Marchand | f1349f5 | 2019-01-25 03:16:41 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 12 | #include "base/files/scoped_temp_dir.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 13 | #include "base/macros.h" |
Gabriel Charette | 078e366 | 2017-08-28 22:59:04 | [diff] [blame] | 14 | #include "base/run_loop.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 15 | #include "base/task/post_task.h" |
jam | 3f2d393 | 2017-04-26 20:28:51 | [diff] [blame] | 16 | #include "base/threading/thread_restrictions.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 17 | #include "build/build_config.h" |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 18 | #include "chrome/browser/background/background_mode_manager.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 19 | #include "chrome/browser/browser_process.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 20 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 5fec470 | 2013-11-20 04:37:38 | [diff] [blame] | 21 | #include "chrome/browser/defaults.h" |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 22 | #include "chrome/browser/download/chrome_download_manager_delegate.h" |
peter | ccb33e8 | 2017-05-02 19:00:44 | [diff] [blame] | 23 | #include "chrome/browser/download/download_core_service.h" |
| 24 | #include "chrome/browser/download/download_core_service_factory.h" |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 25 | #include "chrome/browser/download/download_prefs.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 26 | #include "chrome/browser/lifetime/application_lifetime.h" |
Avi Drissman | d3092734 | 2018-05-22 15:04:27 | [diff] [blame] | 27 | #include "chrome/browser/lifetime/browser_shutdown.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 28 | #include "chrome/browser/prefs/session_startup_pref.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 29 | #include "chrome/browser/profiles/profile.h" |
| 30 | #include "chrome/browser/profiles/profile_manager.h" |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 31 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 32 | #include "chrome/browser/ui/browser.h" |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 33 | #include "chrome/browser/ui/browser_commands.h" |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 34 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 35 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 36 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 37 | #include "chrome/common/buildflags.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 38 | #include "chrome/common/chrome_switches.h" |
| 39 | #include "chrome/common/url_constants.h" |
| 40 | #include "chrome/test/base/in_process_browser_test.h" |
| 41 | #include "chrome/test/base/ui_test_utils.h" |
oshima | f6539842 | 2014-11-18 23:30:42 | [diff] [blame] | 42 | #include "components/app_modal/javascript_app_modal_dialog.h" |
| 43 | #include "components/app_modal/native_app_modal_dialog.h" |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 44 | #include "components/download/public/common/download_item.h" |
Michael Giuffrida | 2dbce0d1 | 2017-09-02 03:30:59 | [diff] [blame] | 45 | #include "components/keep_alive_registry/keep_alive_types.h" |
| 46 | #include "components/keep_alive_registry/scoped_keep_alive.h" |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 47 | #include "components/sessions/core/tab_restore_service.h" |
| 48 | #include "components/sessions/core/tab_restore_service_observer.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 49 | #include "content/public/browser/browser_context.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 50 | #include "content/public/browser/browser_task_traits.h" |
Gabriel Charette | 790754c | 2018-03-16 21:32:59 | [diff] [blame] | 51 | #include "content/public/browser/browser_thread.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 52 | #include "content/public/browser/download_manager.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 53 | #include "content/public/browser/notification_service.h" |
avi | 64b8b65b | 2017-03-29 18:50:34 | [diff] [blame] | 54 | #include "content/public/browser/render_frame_host.h" |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 55 | #include "content/public/browser/render_widget_host.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 56 | #include "content/public/browser/web_contents.h" |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 57 | #include "content/public/test/browser_test_utils.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 58 | #include "content/public/test/download_test_observer.h" |
Colin Blundell | fb2cfb2b | 2018-01-18 18:50:09 | [diff] [blame] | 59 | #include "content/public/test/slow_download_http_response.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 60 | #include "content/public/test/test_navigation_observer.h" |
| 61 | #include "net/test/embedded_test_server/embedded_test_server.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 62 | |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 63 | #if defined(OS_CHROMEOS) |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 64 | #include "chromeos/constants/chromeos_switches.h" |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 65 | #endif |
| 66 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 67 | namespace { |
| 68 | |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 69 | app_modal::NativeAppModalDialog* GetNextDialog() { |
avi | 373e72a | 2017-05-26 20:33:52 | [diff] [blame] | 70 | app_modal::JavaScriptAppModalDialog* dialog = |
| 71 | ui_test_utils::WaitForAppModalDialog(); |
| 72 | CHECK(dialog->native_dialog()); |
| 73 | return dialog->native_dialog(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 74 | } |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 75 | |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 76 | // Note: call |PrepareForDialog| on the relevant WebContents or Browser before |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 77 | // trying to close it, to avoid flakiness. https://crbug.com/519646 |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 78 | void AcceptClose() { |
| 79 | GetNextDialog()->AcceptAppModalDialog(); |
| 80 | } |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 81 | |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 82 | // Note: call |PrepareForDialog| on the relevant WebContents or Browser before |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 83 | // trying to close it, to avoid flakiness. https://crbug.com/519646 |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 84 | void CancelClose() { |
| 85 | GetNextDialog()->CancelAppModalDialog(); |
| 86 | } |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 87 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 88 | class RepeatedNotificationObserver : public content::NotificationObserver { |
| 89 | public: |
| 90 | explicit RepeatedNotificationObserver(int type, int count) |
| 91 | : num_outstanding_(count), running_(false) { |
| 92 | registrar_.Add(this, type, content::NotificationService::AllSources()); |
| 93 | } |
| 94 | |
| 95 | void Observe(int type, |
| 96 | const content::NotificationSource& source, |
| 97 | const content::NotificationDetails& details) override { |
| 98 | ASSERT_GT(num_outstanding_, 0); |
| 99 | if (!--num_outstanding_ && running_) { |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 100 | base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI}, |
| 101 | run_loop_.QuitClosure()); |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
| 105 | void Wait() { |
| 106 | if (num_outstanding_ <= 0) |
| 107 | return; |
| 108 | |
| 109 | running_ = true; |
| 110 | run_loop_.Run(); |
| 111 | running_ = false; |
Wez | a78944d | 2018-05-17 16:56:29 | [diff] [blame] | 112 | |
| 113 | EXPECT_LE(num_outstanding_, 0); |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | private: |
| 117 | int num_outstanding_; |
| 118 | content::NotificationRegistrar registrar_; |
| 119 | bool running_; |
| 120 | base::RunLoop run_loop_; |
| 121 | |
| 122 | DISALLOW_COPY_AND_ASSIGN(RepeatedNotificationObserver); |
| 123 | }; |
| 124 | |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 125 | class TabRestoreServiceChangesObserver |
| 126 | : public sessions::TabRestoreServiceObserver { |
| 127 | public: |
| 128 | explicit TabRestoreServiceChangesObserver(Profile* profile) |
| 129 | : service_(TabRestoreServiceFactory::GetForProfile(profile)) { |
| 130 | if (service_) |
| 131 | service_->AddObserver(this); |
| 132 | } |
| 133 | |
| 134 | ~TabRestoreServiceChangesObserver() override { |
| 135 | if (service_) |
| 136 | service_->RemoveObserver(this); |
| 137 | } |
| 138 | |
| 139 | size_t changes_count() const { return changes_count_; } |
| 140 | |
| 141 | private: |
| 142 | // sessions::TabRestoreServiceObserver: |
| 143 | void TabRestoreServiceChanged(sessions::TabRestoreService*) override { |
| 144 | changes_count_++; |
| 145 | } |
| 146 | |
| 147 | // sessions::TabRestoreServiceObserver: |
| 148 | void TabRestoreServiceDestroyed(sessions::TabRestoreService*) override { |
| 149 | service_ = nullptr; |
| 150 | } |
| 151 | |
| 152 | sessions::TabRestoreService* service_ = nullptr; |
| 153 | size_t changes_count_ = 0; |
| 154 | |
| 155 | DISALLOW_COPY_AND_ASSIGN(TabRestoreServiceChangesObserver); |
| 156 | }; |
| 157 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 158 | class TestBrowserCloseManager : public BrowserCloseManager { |
| 159 | public: |
| 160 | enum UserChoice { |
| 161 | USER_CHOICE_USER_CANCELS_CLOSE, |
| 162 | USER_CHOICE_USER_ALLOWS_CLOSE, |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 163 | NO_USER_CHOICE |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | static void AttemptClose(UserChoice user_choice) { |
| 167 | scoped_refptr<BrowserCloseManager> browser_close_manager = |
| 168 | new TestBrowserCloseManager(user_choice); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 169 | browser_shutdown::SetTryingToQuit(true); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 170 | browser_close_manager->StartClosingBrowsers(); |
| 171 | } |
| 172 | |
| 173 | protected: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 174 | ~TestBrowserCloseManager() override {} |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 175 | |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 176 | void ConfirmCloseWithPendingDownloads( |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 177 | int download_count, |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame] | 178 | const base::Callback<void(bool)>& callback) override { |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 179 | EXPECT_NE(NO_USER_CHOICE, user_choice_); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 180 | switch (user_choice_) { |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 181 | case NO_USER_CHOICE: |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 182 | case USER_CHOICE_USER_CANCELS_CLOSE: { |
| 183 | callback.Run(false); |
| 184 | break; |
| 185 | } |
| 186 | case USER_CHOICE_USER_ALLOWS_CLOSE: { |
| 187 | callback.Run(true); |
| 188 | break; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | private: |
| 194 | explicit TestBrowserCloseManager(UserChoice user_choice) |
| 195 | : user_choice_(user_choice) {} |
| 196 | |
| 197 | UserChoice user_choice_; |
| 198 | |
| 199 | DISALLOW_COPY_AND_ASSIGN(TestBrowserCloseManager); |
| 200 | }; |
| 201 | |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 202 | class TestDownloadManagerDelegate : public ChromeDownloadManagerDelegate { |
| 203 | public: |
| 204 | explicit TestDownloadManagerDelegate(Profile* profile) |
| 205 | : ChromeDownloadManagerDelegate(profile) { |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 206 | GetDownloadIdReceiverCallback().Run(download::DownloadItem::kInvalidId + 1); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 207 | } |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 208 | ~TestDownloadManagerDelegate() override {} |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 209 | |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 210 | bool DetermineDownloadTarget( |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 211 | download::DownloadItem* item, |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame] | 212 | const content::DownloadTargetCallback& callback) override { |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 213 | content::DownloadTargetCallback dangerous_callback = |
[email protected] | 861b4d0a | 2013-12-13 20:10:41 | [diff] [blame] | 214 | base::Bind(&TestDownloadManagerDelegate::SetDangerous, callback); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 215 | return ChromeDownloadManagerDelegate::DetermineDownloadTarget( |
| 216 | item, dangerous_callback); |
| 217 | } |
| 218 | |
Asanka Herath | 1ba0e9f | 2017-04-03 18:48:53 | [diff] [blame] | 219 | static void SetDangerous(const content::DownloadTargetCallback& callback, |
| 220 | const base::FilePath& target_path, |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 221 | download::DownloadItem::TargetDisposition disp, |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 222 | download::DownloadDangerType danger_type, |
Asanka Herath | 1ba0e9f | 2017-04-03 18:48:53 | [diff] [blame] | 223 | const base::FilePath& intermediate_path, |
Min Qin | eb78b7a | 2018-02-03 00:43:16 | [diff] [blame] | 224 | download::DownloadInterruptReason reason) { |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 225 | callback.Run(target_path, disp, |
| 226 | download::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, |
Asanka Herath | 1ba0e9f | 2017-04-03 18:48:53 | [diff] [blame] | 227 | intermediate_path, reason); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 228 | } |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 229 | }; |
| 230 | |
Denis Kuznetsov | 32099f3 | 2017-12-15 14:04:57 | [diff] [blame] | 231 | #if BUILDFLAG(ENABLE_BACKGROUND_MODE) |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 232 | class FakeBackgroundModeManager : public BackgroundModeManager { |
| 233 | public: |
| 234 | FakeBackgroundModeManager() |
lwchkg | 9c18394 | 2016-03-13 06:29:54 | [diff] [blame] | 235 | : BackgroundModeManager(*base::CommandLine::ForCurrentProcess(), |
| 236 | &g_browser_process->profile_manager() |
| 237 | ->GetProfileAttributesStorage()), |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 238 | suspended_(false) {} |
| 239 | |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 240 | void SuspendBackgroundMode() override { |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 241 | BackgroundModeManager::SuspendBackgroundMode(); |
| 242 | suspended_ = true; |
| 243 | } |
| 244 | |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 245 | void ResumeBackgroundMode() override { |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 246 | BackgroundModeManager::ResumeBackgroundMode(); |
| 247 | suspended_ = false; |
| 248 | } |
| 249 | |
| 250 | bool IsBackgroundModeSuspended() { |
| 251 | return suspended_; |
| 252 | } |
| 253 | |
| 254 | private: |
| 255 | bool suspended_; |
| 256 | |
| 257 | DISALLOW_COPY_AND_ASSIGN(FakeBackgroundModeManager); |
| 258 | }; |
Denis Kuznetsov | 32099f3 | 2017-12-15 14:04:57 | [diff] [blame] | 259 | #endif // BUILDFLAG(ENABLE_BACKGROUND_MODE) |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 260 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 261 | } // namespace |
| 262 | |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 263 | class BrowserCloseManagerBrowserTest : public InProcessBrowserTest { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 264 | protected: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 265 | void SetUpOnMainThread() override { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 266 | SessionStartupPref::SetStartupPref( |
| 267 | browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); |
| 268 | browsers_.push_back(browser()); |
Colin Blundell | fb2cfb2b | 2018-01-18 18:50:09 | [diff] [blame] | 269 | embedded_test_server()->RegisterRequestHandler(base::BindRepeating( |
| 270 | &content::SlowDownloadHttpResponse::HandleSlowDownloadRequest)); |
| 271 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 272 | } |
| 273 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 274 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 275 | #if defined(OS_CHROMEOS) |
| 276 | command_line->AppendSwitch( |
| 277 | chromeos::switches::kIgnoreUserProfileMappingForTests); |
| 278 | #endif |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 279 | } |
| 280 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 281 | void CreateStalledDownload(Browser* browser) { |
Colin Blundell | fb2cfb2b | 2018-01-18 18:50:09 | [diff] [blame] | 282 | ASSERT_TRUE(embedded_test_server()->Started()); |
| 283 | |
| 284 | GURL slow_download_url = embedded_test_server()->GetURL( |
| 285 | content::SlowDownloadHttpResponse::kKnownSizeUrl); |
| 286 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 287 | content::DownloadTestObserverInProgress observer( |
| 288 | content::BrowserContext::GetDownloadManager(browser->profile()), 1); |
| 289 | ui_test_utils::NavigateToURLWithDisposition( |
Colin Blundell | fb2cfb2b | 2018-01-18 18:50:09 | [diff] [blame] | 290 | browser, slow_download_url, WindowOpenDisposition::NEW_BACKGROUND_TAB, |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 291 | ui_test_utils::BROWSER_TEST_NONE); |
| 292 | observer.WaitForFinished(); |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 293 | EXPECT_EQ(1UL, observer.NumDownloadsSeenInState( |
| 294 | download::DownloadItem::IN_PROGRESS)); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 295 | } |
| 296 | |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 297 | void PrepareForDialog(content::WebContents* web_contents) { |
| 298 | content::PrepContentsForBeforeUnloadTest(web_contents); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 299 | } |
| 300 | |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 301 | void PrepareForDialog(Browser* browser) { |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 302 | for (int i = 0; i < browser->tab_strip_model()->count(); i++) |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 303 | PrepareForDialog(browser->tab_strip_model()->GetWebContentsAt(i)); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 304 | } |
| 305 | |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 306 | void WaitForAllBrowsersToClose() { |
| 307 | for (size_t i = 0U; i < browsers_.size(); ++i) |
| 308 | ui_test_utils::WaitForBrowserToClose(); |
| 309 | } |
| 310 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 311 | std::vector<Browser*> browsers_; |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 312 | }; |
| 313 | |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 314 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, TestSingleTabShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 315 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 316 | browser(), embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 317 | PrepareForDialog(browser()); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 318 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 319 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 320 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 321 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 322 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 323 | cancel_observer.Wait(); |
| 324 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 325 | EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 326 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 327 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 328 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 329 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 330 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 331 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 332 | } |
| 333 | |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 334 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 335 | TestShutdownMoreThanOnce) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 336 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 337 | browser(), embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 338 | PrepareForDialog(browser()); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 339 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 340 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 341 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 342 | chrome::CloseAllBrowsersAndQuit(); |
| 343 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 344 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 345 | cancel_observer.Wait(); |
| 346 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 347 | EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 348 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 349 | chrome::CloseAllBrowsersAndQuit(); |
| 350 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 351 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 352 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 353 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 354 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 355 | } |
| 356 | |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 357 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, PRE_TestSessionRestore) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 358 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 359 | browser(), embedded_test_server()->GetURL("/beforeunload.html"))); |
| 360 | AddBlankTabAndShow(browser()); |
| 361 | ASSERT_NO_FATAL_FAILURE( |
| 362 | ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 363 | PrepareForDialog(browser()); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 364 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 365 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 366 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 367 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 368 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 369 | cancel_observer.Wait(); |
| 370 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 371 | |
| 372 | browser()->tab_strip_model() |
| 373 | ->CloseWebContentsAt(1, TabStripModel::CLOSE_USER_GESTURE); |
| 374 | content::TestNavigationObserver navigation_observer( |
| 375 | browser()->tab_strip_model()->GetActiveWebContents(), 1); |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 376 | ASSERT_NO_FATAL_FAILURE(NavigateToURLWithDisposition( |
| 377 | browser(), GURL(chrome::kChromeUIVersionURL), |
| 378 | WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE)); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 379 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 380 | navigation_observer.Wait(); |
| 381 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 382 | chrome::CloseAllBrowsersAndQuit(); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 383 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 384 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 385 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | // Test that the tab closed after the aborted shutdown attempt is not re-opened |
| 389 | // when restoring the session. |
benwells | 70cc9322 | 2017-06-29 05:42:36 | [diff] [blame] | 390 | // Flaky on Windows trybots, see https://crbug.com/737860. |
| 391 | #if defined(OS_WIN) |
| 392 | #define MAYBE_TestSessionRestore DISABLED_TestSessionRestore |
| 393 | #else |
| 394 | #define MAYBE_TestSessionRestore TestSessionRestore |
| 395 | #endif |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 396 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
benwells | 70cc9322 | 2017-06-29 05:42:36 | [diff] [blame] | 397 | MAYBE_TestSessionRestore) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 398 | // The testing framework launches Chrome with about:blank as args. |
| 399 | EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 400 | EXPECT_EQ(GURL(chrome::kChromeUIVersionURL), |
| 401 | browser()->tab_strip_model()->GetWebContentsAt(0)->GetURL()); |
| 402 | EXPECT_EQ(GURL("about:blank"), |
| 403 | browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL()); |
| 404 | } |
| 405 | |
| 406 | // Test that browser windows are only closed if all browsers are ready to close |
| 407 | // and that all beforeunload dialogs are shown again after a cancel. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 408 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, TestMultipleWindows) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 409 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 410 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 411 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 412 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 413 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 414 | PrepareForDialog(browsers_[0]); |
| 415 | PrepareForDialog(browsers_[1]); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 416 | |
| 417 | // Cancel shutdown on the first beforeunload event. |
| 418 | { |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 419 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 420 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 421 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 422 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 423 | cancel_observer.Wait(); |
| 424 | } |
| 425 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 426 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 427 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 428 | |
| 429 | // Cancel shutdown on the second beforeunload event. |
| 430 | { |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 431 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 432 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 433 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 434 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 435 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 436 | cancel_observer.Wait(); |
| 437 | } |
| 438 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 439 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 440 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 441 | |
| 442 | // Allow shutdown for both beforeunload events. |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 443 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 444 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 445 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 446 | WaitForAllBrowsersToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 447 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 448 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | // Test that tabs in the same window with a beforeunload event that hangs are |
| 452 | // treated the same as the user accepting the close, but do not close the tab |
| 453 | // early. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 454 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 455 | TestHangInBeforeUnloadMultipleTabs) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 456 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 457 | browsers_[0], embedded_test_server()->GetURL("/beforeunload_hang.html"))); |
| 458 | AddBlankTabAndShow(browsers_[0]); |
| 459 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 460 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 461 | AddBlankTabAndShow(browsers_[0]); |
| 462 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 463 | browsers_[0], embedded_test_server()->GetURL("/beforeunload_hang.html"))); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 464 | // Disable the hang monitor in the tab that is not expected to hang, so that |
| 465 | // the dialog is guaranteed to show. |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 466 | PrepareForDialog(browsers_[0]->tab_strip_model()->GetWebContentsAt(1)); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 467 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 468 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 469 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 470 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 471 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 472 | cancel_observer.Wait(); |
| 473 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 474 | // All tabs should still be open. |
| 475 | EXPECT_EQ(3, browsers_[0]->tab_strip_model()->count()); |
| 476 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 477 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 478 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 479 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 480 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 481 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | // Test that tabs in different windows with a beforeunload event that hangs are |
| 485 | // treated the same as the user accepting the close, but do not close the tab |
| 486 | // early. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 487 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 488 | TestHangInBeforeUnloadMultipleWindows) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 489 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 490 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 491 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 492 | browsers_[0], embedded_test_server()->GetURL("/beforeunload_hang.html"))); |
| 493 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 494 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 495 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 496 | browsers_[2], embedded_test_server()->GetURL("/beforeunload_hang.html"))); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 497 | // Disable the hang monitor in the tab that is not expected to hang, so that |
| 498 | // the dialog is guaranteed to show. |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 499 | PrepareForDialog(browsers_[1]); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 500 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 501 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 502 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 503 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 504 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 505 | cancel_observer.Wait(); |
| 506 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 507 | // All windows should still be open. |
| 508 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 509 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 510 | EXPECT_EQ(1, browsers_[2]->tab_strip_model()->count()); |
| 511 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 512 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 513 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 514 | |
| 515 | WaitForAllBrowsersToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 516 | } |
| 517 | |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 518 | // Test that tabs that are slow to respond are not closed prematurely. |
| 519 | // Regression for crbug.com/365052 caused some of tabs to be closed even if |
| 520 | // user chose to cancel browser close. |
Kevin McNee | 98ba00f | 2018-02-09 19:19:36 | [diff] [blame] | 521 | // Flaky on ChromeOS ASan. https://crbug.com/805457 |
| 522 | #if defined(OS_CHROMEOS) && defined(ADDRESS_SANITIZER) |
| 523 | #define MAYBE_TestUnloadMultipleSlowTabs DISABLED_TestUnloadMultipleSlowTabs |
| 524 | #else |
| 525 | #define MAYBE_TestUnloadMultipleSlowTabs TestUnloadMultipleSlowTabs |
| 526 | #endif |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 527 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
Kevin McNee | 98ba00f | 2018-02-09 19:19:36 | [diff] [blame] | 528 | MAYBE_TestUnloadMultipleSlowTabs) { |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 529 | const int kTabCount = 5; |
| 530 | const int kResposiveTabIndex = 2; |
| 531 | // Create tab strip with all tabs except one responding after |
| 532 | // RenderViewHostImpl::kUnloadTimeoutMS. |
| 533 | // Minimum configuration is two slow tabs and then responsive tab. |
| 534 | // But we also want to check how slow tabs behave in tail. |
| 535 | for (int i = 0; i < kTabCount; i++) { |
| 536 | if (i) |
| 537 | AddBlankTabAndShow(browsers_[0]); |
| 538 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 539 | browsers_[0], |
| 540 | embedded_test_server()->GetURL((i == kResposiveTabIndex) |
| 541 | ? "/beforeunload.html" |
| 542 | : "/beforeunload_slow.html"))); |
| 543 | } |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 544 | // Disable the hang monitor in the tab that is not expected to hang, so that |
| 545 | // the dialog is guaranteed to show. |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 546 | PrepareForDialog( |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 547 | browsers_[0]->tab_strip_model()->GetWebContentsAt(kResposiveTabIndex)); |
| 548 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 549 | RepeatedNotificationObserver cancel_observer( |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 550 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
| 551 | chrome::CloseAllBrowsersAndQuit(); |
| 552 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
| 553 | cancel_observer.Wait(); |
| 554 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 555 | |
| 556 | // All tabs should still be open. |
| 557 | EXPECT_EQ(kTabCount, browsers_[0]->tab_strip_model()->count()); |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 558 | |
| 559 | // Quit, this time accepting close confirmation dialog. |
| 560 | chrome::CloseAllBrowsersAndQuit(); |
| 561 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 562 | ui_test_utils::WaitForBrowserToClose(); |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 563 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 564 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
| 565 | } |
| 566 | |
| 567 | // Test that tabs in different windows with a slow beforeunload event response |
| 568 | // are treated the same as the user accepting the close, but do not close the |
| 569 | // tab early. |
| 570 | // Regression for crbug.com/365052 caused CHECK in tabstrip. |
jdoerrie | 6cc3bd8 | 2018-03-07 16:42:56 | [diff] [blame] | 571 | // Flaky on Mac and Linux: https://crbug.com/819541 |
| 572 | #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 573 | #define MAYBE_TestBeforeUnloadMultipleSlowWindows \ |
| 574 | DISABLED_TestBeforeUnloadMultipleSlowWindows |
| 575 | #else |
| 576 | #define MAYBE_TestBeforeUnloadMultipleSlowWindows \ |
| 577 | TestBeforeUnloadMultipleSlowWindows |
| 578 | #endif |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 579 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
jdoerrie | 6cc3bd8 | 2018-03-07 16:42:56 | [diff] [blame] | 580 | MAYBE_TestBeforeUnloadMultipleSlowWindows) { |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 581 | const int kBrowserCount = 5; |
| 582 | const int kResposiveBrowserIndex = 2; |
| 583 | // Create multiple browsers with all tabs except one responding after |
| 584 | // RenderViewHostImpl::kUnloadTimeoutMS . |
| 585 | // Minimum configuration is just one browser with slow tab and then |
| 586 | // browser with responsive tab. |
| 587 | // But we also want to check how slow tabs behave in tail and make test |
| 588 | // more robust. |
| 589 | for (int i = 0; i < kBrowserCount; i++) { |
| 590 | if (i) |
| 591 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 592 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 593 | browsers_[i], |
| 594 | embedded_test_server()->GetURL((i == kResposiveBrowserIndex) |
| 595 | ? "/beforeunload.html" |
| 596 | : "/beforeunload_slow.html"))); |
| 597 | } |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 598 | // Disable the hang monitor in the tab that is not expected to hang, so that |
| 599 | // the dialog is guaranteed to show. |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 600 | PrepareForDialog(browsers_[kResposiveBrowserIndex]); |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 601 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 602 | RepeatedNotificationObserver cancel_observer( |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 603 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, kResposiveBrowserIndex + 1); |
| 604 | chrome::CloseAllBrowsersAndQuit(); |
| 605 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
| 606 | cancel_observer.Wait(); |
| 607 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 608 | |
| 609 | // All windows should still be open. |
| 610 | for (int i = 0; i < kBrowserCount; i++) |
| 611 | EXPECT_EQ(1, browsers_[i]->tab_strip_model()->count()); |
| 612 | |
| 613 | // Quit, this time accepting close confirmation dialog. |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 614 | chrome::CloseAllBrowsersAndQuit(); |
| 615 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 616 | WaitForAllBrowsersToClose(); |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 617 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 618 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
| 619 | } |
| 620 | |
Jan Krcal | 9a23f22 | 2017-08-01 14:13:07 | [diff] [blame] | 621 | // Flaky on Windows 7 (dbg) trybot, see https://crbug.com/751081. |
| 622 | #if defined(OS_WIN) && !defined(NDEBUG) |
| 623 | #define MAYBE_TestAddWindowDuringShutdown DISABLED_TestAddWindowDuringShutdown |
| 624 | #else |
| 625 | #define MAYBE_TestAddWindowDuringShutdown TestAddWindowDuringShutdown |
| 626 | #endif |
| 627 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 628 | // Test that a window created during shutdown is closed. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 629 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
Jan Krcal | 9a23f22 | 2017-08-01 14:13:07 | [diff] [blame] | 630 | MAYBE_TestAddWindowDuringShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 631 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 632 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 633 | PrepareForDialog(browsers_[0]); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 634 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 635 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 636 | browsers_.push_back(CreateBrowser(browser()->profile())); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 637 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 638 | WaitForAllBrowsersToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 639 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 640 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | // Test that a window created during shutdown with a beforeunload handler can |
| 644 | // cancel the shutdown. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 645 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
[email protected] | 40cd13a | 2013-10-24 13:42:01 | [diff] [blame] | 646 | TestAddWindowWithBeforeUnloadDuringShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 647 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 648 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 649 | PrepareForDialog(browsers_[0]); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 650 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 651 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 652 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 653 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 654 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 655 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 656 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 657 | PrepareForDialog(browsers_[1]); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 658 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 659 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 660 | cancel_observer.Wait(); |
| 661 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 662 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 663 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 664 | |
| 665 | // Allow shutdown for both beforeunload dialogs. |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 666 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 667 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 668 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 669 | WaitForAllBrowsersToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 670 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 671 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | // Test that tabs added during shutdown are closed. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 675 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 676 | TestAddTabDuringShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 677 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 678 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 679 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 680 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 681 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 682 | PrepareForDialog(browsers_[0]); |
| 683 | PrepareForDialog(browsers_[1]); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 684 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 685 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 686 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 687 | AddBlankTabAndShow(browsers_[0]); |
| 688 | AddBlankTabAndShow(browsers_[1]); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 689 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 690 | WaitForAllBrowsersToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 691 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 692 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | // Test that tabs created during shutdown with beforeunload handlers can cancel |
| 696 | // the shutdown. |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 697 | |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 698 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 699 | TestAddTabWithBeforeUnloadDuringShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 700 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 701 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 702 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 703 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 704 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 705 | PrepareForDialog(browsers_[0]); |
| 706 | PrepareForDialog(browsers_[1]); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 707 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 708 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 709 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 710 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 711 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 712 | AddBlankTabAndShow(browsers_[0]); |
| 713 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 714 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 715 | AddBlankTabAndShow(browsers_[1]); |
| 716 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 717 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 718 | PrepareForDialog(browsers_[0]); |
| 719 | PrepareForDialog(browsers_[1]); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 720 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 721 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 722 | cancel_observer.Wait(); |
| 723 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 724 | EXPECT_EQ(2, browsers_[0]->tab_strip_model()->count()); |
| 725 | EXPECT_EQ(2, browsers_[1]->tab_strip_model()->count()); |
| 726 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 727 | chrome::CloseAllBrowsersAndQuit(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 728 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 729 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 730 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 731 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 732 | |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 733 | WaitForAllBrowsersToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 734 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 735 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 736 | } |
| 737 | |
rogerm | f18929c | 2017-04-19 19:59:33 | [diff] [blame] | 738 | // TODO(crbug/713201): |
| 739 | // BrowserCloseManagerBrowserTest.AddBeforeUnloadDuringClosing flaky on Mac. |
| 740 | #if defined(OS_MACOSX) |
| 741 | #define MAYBE_AddBeforeUnloadDuringClosing DISABLED_AddBeforeUnloadDuringClosing |
| 742 | #else |
| 743 | #define MAYBE_AddBeforeUnloadDuringClosing AddBeforeUnloadDuringClosing |
| 744 | #endif |
| 745 | |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 746 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
rogerm | f18929c | 2017-04-19 19:59:33 | [diff] [blame] | 747 | MAYBE_AddBeforeUnloadDuringClosing) { |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 748 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 749 | browser(), embedded_test_server()->GetURL("/title1.html"))); |
| 750 | |
| 751 | // Open second window. |
| 752 | ui_test_utils::NavigateToURLWithDisposition( |
| 753 | browser(), embedded_test_server()->GetURL("/beforeunload.html"), |
| 754 | WindowOpenDisposition::NEW_WINDOW, |
| 755 | ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
| 756 | EXPECT_EQ(2u, BrowserList::GetInstance()->size()); |
| 757 | auto* browser2 = BrowserList::GetInstance()->get(0) != browser() |
| 758 | ? BrowserList::GetInstance()->get(0) |
| 759 | : BrowserList::GetInstance()->get(1); |
| 760 | content::WaitForLoadStop(browser2->tab_strip_model()->GetWebContentsAt(0)); |
| 761 | |
| 762 | // Let's work with second window only. |
| 763 | // This page has beforeunload handler already. |
| 764 | EXPECT_TRUE(browser2->tab_strip_model() |
| 765 | ->GetWebContentsAt(0) |
| 766 | ->NeedToFireBeforeUnload()); |
| 767 | // This page doesn't have beforeunload handler. Yet. |
| 768 | ui_test_utils::NavigateToURLWithDisposition( |
| 769 | browser2, embedded_test_server()->GetURL("/title2.html"), |
| 770 | WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 771 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 772 | content::WaitForLoadStop(browser2->tab_strip_model()->GetWebContentsAt(1)); |
| 773 | EXPECT_FALSE(browser2->tab_strip_model() |
| 774 | ->GetWebContentsAt(1) |
| 775 | ->NeedToFireBeforeUnload()); |
| 776 | EXPECT_EQ(2, browser2->tab_strip_model()->count()); |
| 777 | |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 778 | PrepareForDialog(browser2); |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 779 | |
| 780 | // The test. |
| 781 | |
| 782 | TabRestoreServiceChangesObserver restore_observer(browser2->profile()); |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 783 | chrome::CloseWindow(browser2); |
| 784 | // Just to be sure CloseWindow doesn't have asynchronous tasks |
| 785 | // that could have an impact. |
| 786 | content::RunAllPendingInMessageLoop(); |
| 787 | |
| 788 | // Closing browser shouldn't happen because of beforeunload handler. |
| 789 | EXPECT_EQ(2u, BrowserList::GetInstance()->size()); |
| 790 | // Add beforeunload handler for the 2nd (title2.html) tab which haven't had it |
| 791 | // yet. |
| 792 | ASSERT_TRUE(content::ExecuteScript( |
David Benjamin | 5a79265 | 2018-06-08 02:15:42 | [diff] [blame] | 793 | browser2->tab_strip_model()->GetWebContentsAt(1), |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 794 | "window.addEventListener('beforeunload', " |
| 795 | "function(event) { event.returnValue = 'Foo'; });")); |
| 796 | EXPECT_TRUE(browser2->tab_strip_model() |
| 797 | ->GetWebContentsAt(1) |
| 798 | ->NeedToFireBeforeUnload()); |
| 799 | // Accept closing the first tab. |
| 800 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 801 | // Just to be sure accepting a dialog doesn't have asynchronous tasks |
| 802 | // that could have an impact. |
| 803 | content::RunAllPendingInMessageLoop(); |
| 804 | // It shouldn't close the whole window/browser. |
| 805 | EXPECT_EQ(2u, BrowserList::GetInstance()->size()); |
| 806 | EXPECT_EQ(2, browser2->tab_strip_model()->count()); |
| 807 | // Accept closing the second tab. |
| 808 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 809 | ui_test_utils::WaitForBrowserToClose(); |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 810 | // Now the second window/browser should be closed. |
| 811 | EXPECT_EQ(1u, BrowserList::GetInstance()->size()); |
| 812 | EXPECT_EQ(browser(), BrowserList::GetInstance()->get(0)); |
| 813 | EXPECT_EQ(1u, restore_observer.changes_count()); |
| 814 | |
| 815 | // Restore the closed browser. |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 816 | chrome::OpenWindowWithRestoredTabs(browser()->profile()); |
mkolom | 65a0b3c | 2017-03-02 06:11:40 | [diff] [blame] | 817 | EXPECT_EQ(2u, BrowserList::GetInstance()->size()); |
| 818 | browser2 = BrowserList::GetInstance()->get(0) != browser() |
| 819 | ? BrowserList::GetInstance()->get(0) |
| 820 | : BrowserList::GetInstance()->get(1); |
| 821 | |
| 822 | // Check the restored browser contents. |
| 823 | EXPECT_EQ(2, browser2->tab_strip_model()->count()); |
| 824 | EXPECT_EQ(embedded_test_server()->GetURL("/beforeunload.html"), |
| 825 | browser2->tab_strip_model()->GetWebContentsAt(0)->GetURL()); |
| 826 | EXPECT_EQ(embedded_test_server()->GetURL("/title2.html"), |
| 827 | browser2->tab_strip_model()->GetWebContentsAt(1)->GetURL()); |
| 828 | } |
| 829 | |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 830 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
avi | 8804091 | 2017-03-30 03:48:42 | [diff] [blame] | 831 | TestCloseTabDuringShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 832 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 833 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 834 | PrepareForDialog(browsers_[0]); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 835 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 836 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 837 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 838 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 839 | |
| 840 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 841 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 842 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 843 | PrepareForDialog(browsers_[1]); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 844 | browsers_[1]->tab_strip_model()->CloseAllTabs(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 845 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
| 846 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 847 | cancel_observer.Wait(); |
| 848 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 849 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 850 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 851 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 852 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 853 | browsers_[1]->tab_strip_model()->CloseAllTabs(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 854 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 855 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 856 | |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 857 | WaitForAllBrowsersToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 858 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 859 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 860 | } |
| 861 | |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 862 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 863 | TestOpenAndCloseWindowDuringShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 864 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 865 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 866 | PrepareForDialog(browsers_[0]); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 867 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 868 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 869 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 870 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 871 | |
| 872 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 873 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 874 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 875 | PrepareForDialog(browsers_[1]); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 876 | ASSERT_FALSE(browsers_[1]->ShouldCloseWindow()); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 877 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
| 878 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 879 | cancel_observer.Wait(); |
| 880 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 881 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 882 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 883 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 884 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 885 | ASSERT_FALSE(browsers_[1]->ShouldCloseWindow()); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 886 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 887 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 888 | |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 889 | WaitForAllBrowsersToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 890 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 891 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 892 | } |
| 893 | |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 894 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 895 | TestCloseWindowDuringShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 896 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 897 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 898 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 899 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 900 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 901 | PrepareForDialog(browsers_[0]); |
| 902 | PrepareForDialog(browsers_[1]); |
metaflow | 812bb854 | 2016-05-24 21:10:46 | [diff] [blame] | 903 | |
Scott Violet | 1f106b58 | 2017-07-12 15:49:58 | [diff] [blame] | 904 | RepeatedNotificationObserver cancel_observer( |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 905 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 906 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 907 | |
| 908 | ASSERT_FALSE(browsers_[0]->ShouldCloseWindow()); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 909 | ASSERT_NO_FATAL_FAILURE(CancelClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 910 | cancel_observer.Wait(); |
| 911 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 912 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 913 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 914 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 915 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 916 | ASSERT_FALSE(browsers_[0]->ShouldCloseWindow()); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 917 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 918 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 919 | |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 920 | WaitForAllBrowsersToClose(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 921 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 922 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 923 | } |
| 924 | |
jackhou | ae8e6e5 | 2015-05-29 06:36:46 | [diff] [blame] | 925 | // Mac has its own in-progress download prompt in app_controller_mac.mm, so |
| 926 | // BrowserCloseManager should simply close all browsers. If there are no |
| 927 | // browsers, it should not crash. |
| 928 | #if defined(OS_MACOSX) |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 929 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, TestWithDownloads) { |
jackhou | ae8e6e5 | 2015-05-29 06:36:46 | [diff] [blame] | 930 | ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
| 931 | |
jackhou | ae8e6e5 | 2015-05-29 06:36:46 | [diff] [blame] | 932 | TestBrowserCloseManager::AttemptClose( |
| 933 | TestBrowserCloseManager::NO_USER_CHOICE); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 934 | WaitForAllBrowsersToClose(); |
jackhou | ae8e6e5 | 2015-05-29 06:36:46 | [diff] [blame] | 935 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 936 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
peter | ccb33e8 | 2017-05-02 19:00:44 | [diff] [blame] | 937 | EXPECT_EQ(1, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
jackhou | ae8e6e5 | 2015-05-29 06:36:46 | [diff] [blame] | 938 | |
| 939 | // Attempting to close again should not crash. |
| 940 | TestBrowserCloseManager::AttemptClose( |
| 941 | TestBrowserCloseManager::NO_USER_CHOICE); |
| 942 | } |
| 943 | #else // defined(OS_MACOSX) |
| 944 | |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 945 | // Test shutdown with a DANGEROUS_URL download undecided. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 946 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
Mattias Nissler | 441cc65 | 2018-04-05 00:08:56 | [diff] [blame] | 947 | TestWithDangerousUrlDownload) { |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 948 | // Set up the fake delegate that forces the download to be malicious. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 949 | std::unique_ptr<TestDownloadManagerDelegate> test_delegate( |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 950 | new TestDownloadManagerDelegate(browser()->profile())); |
peter | ccb33e8 | 2017-05-02 19:00:44 | [diff] [blame] | 951 | DownloadCoreServiceFactory::GetForBrowserContext(browser()->profile()) |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 952 | ->SetDownloadManagerDelegateForTesting(std::move(test_delegate)); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 953 | |
| 954 | // Run a dangerous download, but the user doesn't make a decision. |
| 955 | // This .swf normally would be categorized as DANGEROUS_FILE, but |
| 956 | // TestDownloadManagerDelegate turns it into DANGEROUS_URL. |
Jun Cai | 3ec06a12 | 2017-11-07 21:01:43 | [diff] [blame] | 957 | GURL download_url( |
| 958 | embedded_test_server()->GetURL("/downloads/dangerous/dangerous.swf")); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 959 | content::DownloadTestObserverInterrupted observer( |
| 960 | content::BrowserContext::GetDownloadManager(browser()->profile()), |
| 961 | 1, |
| 962 | content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT); |
| 963 | ui_test_utils::NavigateToURLWithDisposition( |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 964 | browser(), GURL(download_url), WindowOpenDisposition::NEW_BACKGROUND_TAB, |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 965 | ui_test_utils::BROWSER_TEST_NONE); |
| 966 | observer.WaitForFinished(); |
| 967 | |
| 968 | // Check that the download manager has the expected state. |
| 969 | EXPECT_EQ(1, content::BrowserContext::GetDownloadManager( |
| 970 | browser()->profile())->InProgressCount()); |
| 971 | EXPECT_EQ(0, content::BrowserContext::GetDownloadManager( |
| 972 | browser()->profile())->NonMaliciousInProgressCount()); |
| 973 | |
| 974 | // Close the browser with no user action. |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 975 | TestBrowserCloseManager::AttemptClose( |
| 976 | TestBrowserCloseManager::NO_USER_CHOICE); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 977 | WaitForAllBrowsersToClose(); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 978 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 979 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 980 | } |
| 981 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 982 | // Test shutdown with a download in progress. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 983 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, TestWithDownloads) { |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 984 | ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
| 985 | content::TestNavigationObserver navigation_observer( |
| 986 | browser()->tab_strip_model()->GetActiveWebContents(), 1); |
| 987 | TestBrowserCloseManager::AttemptClose( |
| 988 | TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); |
| 989 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 990 | navigation_observer.Wait(); |
| 991 | EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL), |
| 992 | browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 993 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 994 | TestBrowserCloseManager::AttemptClose( |
| 995 | TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 996 | WaitForAllBrowsersToClose(); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 997 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 998 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 5fec470 | 2013-11-20 04:37:38 | [diff] [blame] | 999 | if (browser_defaults::kBrowserAliveWithNoWindows) |
peter | ccb33e8 | 2017-05-02 19:00:44 | [diff] [blame] | 1000 | EXPECT_EQ(1, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
[email protected] | 5fec470 | 2013-11-20 04:37:38 | [diff] [blame] | 1001 | else |
peter | ccb33e8 | 2017-05-02 19:00:44 | [diff] [blame] | 1002 | EXPECT_EQ(0, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1003 | } |
| 1004 | |
sammc | cd34771 | 2015-03-13 22:02:32 | [diff] [blame] | 1005 | // Test shutdown with a download in progress in an off-the-record profile. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 1006 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
sammc | cd34771 | 2015-03-13 22:02:32 | [diff] [blame] | 1007 | TestWithOffTheRecordDownloads) { |
sammc | cd34771 | 2015-03-13 22:02:32 | [diff] [blame] | 1008 | Profile* otr_profile = browser()->profile()->GetOffTheRecordProfile(); |
sammc | cd34771 | 2015-03-13 22:02:32 | [diff] [blame] | 1009 | Browser* otr_browser = CreateBrowser(otr_profile); |
| 1010 | { |
sammc | cd34771 | 2015-03-13 22:02:32 | [diff] [blame] | 1011 | browser()->window()->Close(); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1012 | ui_test_utils::WaitForBrowserToClose(); |
sammc | cd34771 | 2015-03-13 22:02:32 | [diff] [blame] | 1013 | } |
| 1014 | ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(otr_browser)); |
| 1015 | content::TestNavigationObserver navigation_observer( |
| 1016 | otr_browser->tab_strip_model()->GetActiveWebContents(), 1); |
| 1017 | TestBrowserCloseManager::AttemptClose( |
| 1018 | TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); |
| 1019 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 1020 | navigation_observer.Wait(); |
| 1021 | EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL), |
| 1022 | otr_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 1023 | |
sammc | cd34771 | 2015-03-13 22:02:32 | [diff] [blame] | 1024 | TestBrowserCloseManager::AttemptClose( |
| 1025 | TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1026 | ui_test_utils::WaitForBrowserToClose(); |
sammc | cd34771 | 2015-03-13 22:02:32 | [diff] [blame] | 1027 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 1028 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
peter | ccb33e8 | 2017-05-02 19:00:44 | [diff] [blame] | 1029 | EXPECT_EQ(0, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
sammc | cd34771 | 2015-03-13 22:02:32 | [diff] [blame] | 1030 | } |
| 1031 | |
Asanka Herath | d1341dc | 2017-04-19 18:28:39 | [diff] [blame] | 1032 | // Test shutdown with a download in progress in a regular profile an inconito |
| 1033 | // browser is opened and closed. While there are active downloads, closing the |
| 1034 | // incognito window shouldn't block on the active downloads which belong to the |
| 1035 | // parent profile. |
Wez | a78944d | 2018-05-17 16:56:29 | [diff] [blame] | 1036 | // TODO(https://crbug.com/844019): Fix the notification expectation around the |
| 1037 | // call to AttemptClose. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 1038 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
Wez | a78944d | 2018-05-17 16:56:29 | [diff] [blame] | 1039 | DISABLED_TestWithOffTheRecordWindowAndRegularDownload) { |
Asanka Herath | d1341dc | 2017-04-19 18:28:39 | [diff] [blame] | 1040 | Profile* otr_profile = browser()->profile()->GetOffTheRecordProfile(); |
Asanka Herath | d1341dc | 2017-04-19 18:28:39 | [diff] [blame] | 1041 | Browser* otr_browser = CreateBrowser(otr_profile); |
| 1042 | ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
| 1043 | |
| 1044 | content::TestNavigationObserver navigation_observer( |
| 1045 | otr_browser->tab_strip_model()->GetActiveWebContents(), 1); |
| 1046 | ui_test_utils::NavigateToURL(otr_browser, GURL("about:blank")); |
| 1047 | navigation_observer.Wait(); |
| 1048 | |
| 1049 | int num_downloads_blocking = 0; |
| 1050 | ASSERT_EQ( |
| 1051 | Browser::DOWNLOAD_CLOSE_OK, |
| 1052 | otr_browser->OkToCloseWithInProgressDownloads(&num_downloads_blocking)); |
| 1053 | ASSERT_EQ(0, num_downloads_blocking); |
| 1054 | |
| 1055 | { |
Asanka Herath | d1341dc | 2017-04-19 18:28:39 | [diff] [blame] | 1056 | otr_browser->window()->Close(); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1057 | ui_test_utils::WaitForBrowserToClose(); |
Asanka Herath | d1341dc | 2017-04-19 18:28:39 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | ASSERT_EQ( |
| 1061 | Browser::DOWNLOAD_CLOSE_BROWSER_SHUTDOWN, |
| 1062 | browser()->OkToCloseWithInProgressDownloads(&num_downloads_blocking)); |
| 1063 | ASSERT_EQ(1, num_downloads_blocking); |
| 1064 | |
| 1065 | { |
Asanka Herath | d1341dc | 2017-04-19 18:28:39 | [diff] [blame] | 1066 | TestBrowserCloseManager::AttemptClose( |
| 1067 | TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1068 | ui_test_utils::WaitForBrowserToClose(); |
Asanka Herath | d1341dc | 2017-04-19 18:28:39 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 1072 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
| 1073 | if (browser_defaults::kBrowserAliveWithNoWindows) |
peter | ccb33e8 | 2017-05-02 19:00:44 | [diff] [blame] | 1074 | EXPECT_EQ(1, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
Asanka Herath | d1341dc | 2017-04-19 18:28:39 | [diff] [blame] | 1075 | else |
peter | ccb33e8 | 2017-05-02 19:00:44 | [diff] [blame] | 1076 | EXPECT_EQ(0, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
Asanka Herath | d1341dc | 2017-04-19 18:28:39 | [diff] [blame] | 1077 | } |
| 1078 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1079 | // Test shutdown with a download in progress from one profile, where the only |
| 1080 | // open windows are for another profile. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 1081 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1082 | TestWithDownloadsFromDifferentProfiles) { |
| 1083 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
Hui Yingst | bfedafc | 2019-05-14 00:56:07 | [diff] [blame] | 1084 | std::unique_ptr<Profile> other_profile; |
jam | 3f2d393 | 2017-04-26 20:28:51 | [diff] [blame] | 1085 | { |
| 1086 | base::FilePath path = |
| 1087 | profile_manager->user_data_dir().AppendASCII("test_profile"); |
Francois Doray | e6fb2d0 | 2017-10-18 21:29:13 | [diff] [blame] | 1088 | base::ScopedAllowBlockingForTesting allow_blocking; |
jam | 3f2d393 | 2017-04-26 20:28:51 | [diff] [blame] | 1089 | if (!base::PathExists(path)) |
| 1090 | ASSERT_TRUE(base::CreateDirectory(path)); |
| 1091 | other_profile = |
| 1092 | Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); |
| 1093 | } |
Hui Yingst | bfedafc | 2019-05-14 00:56:07 | [diff] [blame] | 1094 | Profile* other_profile_ptr = other_profile.get(); |
Daniel Hosseinian | 8f0b748 | 2019-06-07 18:21:04 | [diff] [blame] | 1095 | profile_manager->RegisterTestingProfile(std::move(other_profile), true, |
| 1096 | false); |
Hui Yingst | bfedafc | 2019-05-14 00:56:07 | [diff] [blame] | 1097 | Browser* other_profile_browser = CreateBrowser(other_profile_ptr); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1098 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1099 | ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
| 1100 | { |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1101 | browser()->window()->Close(); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1102 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | // When the shutdown is cancelled, the downloads page should be opened in a |
| 1106 | // browser for that profile. Because there are no browsers for that profile, a |
| 1107 | // new browser should be opened. |
| 1108 | ui_test_utils::BrowserAddedObserver new_browser_observer; |
| 1109 | TestBrowserCloseManager::AttemptClose( |
| 1110 | TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); |
| 1111 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 1112 | Browser* opened_browser = new_browser_observer.WaitForSingleNewBrowser(); |
| 1113 | EXPECT_EQ( |
| 1114 | GURL(chrome::kChromeUIDownloadsURL), |
| 1115 | opened_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 1116 | EXPECT_EQ(GURL("about:blank"), |
| 1117 | other_profile_browser->tab_strip_model()->GetActiveWebContents() |
| 1118 | ->GetURL()); |
| 1119 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1120 | TestBrowserCloseManager::AttemptClose( |
| 1121 | TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1122 | ui_test_utils::WaitForBrowserToClose(); |
| 1123 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1124 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 1125 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 5fec470 | 2013-11-20 04:37:38 | [diff] [blame] | 1126 | if (browser_defaults::kBrowserAliveWithNoWindows) |
peter | ccb33e8 | 2017-05-02 19:00:44 | [diff] [blame] | 1127 | EXPECT_EQ(1, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
[email protected] | 5fec470 | 2013-11-20 04:37:38 | [diff] [blame] | 1128 | else |
peter | ccb33e8 | 2017-05-02 19:00:44 | [diff] [blame] | 1129 | EXPECT_EQ(0, DownloadCoreService::NonMaliciousDownloadCountAllProfiles()); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1130 | } |
| 1131 | |
Vasilii Sukhanov | 4a65b86 | 2017-08-04 10:01:37 | [diff] [blame] | 1132 | // Fails on ChromeOS and Linux, times out on Win. crbug.com/749098 |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1133 | // Test shutdown with downloads in progress and beforeunload handlers. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 1134 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerBrowserTest, |
Vasilii Sukhanov | 4a65b86 | 2017-08-04 10:01:37 | [diff] [blame] | 1135 | DISABLED_TestBeforeUnloadAndDownloads) { |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1136 | ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
| 1137 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 1138 | browser(), embedded_test_server()->GetURL("/beforeunload.html"))); |
avi | 336125f7 | 2017-05-06 22:25:40 | [diff] [blame] | 1139 | PrepareForDialog(browser()); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1140 | |
| 1141 | content::WindowedNotificationObserver cancel_observer( |
| 1142 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 1143 | content::NotificationService::AllSources()); |
| 1144 | TestBrowserCloseManager::AttemptClose( |
| 1145 | TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 1146 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1147 | cancel_observer.Wait(); |
| 1148 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 1149 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1150 | TestBrowserCloseManager::AttemptClose( |
| 1151 | TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 1152 | ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1153 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1154 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 1155 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 1156 | } |
| 1157 | |
jackhou | ae8e6e5 | 2015-05-29 06:36:46 | [diff] [blame] | 1158 | #endif // defined(OS_MACOSX) |
| 1159 | |
Denis Kuznetsov | 32099f3 | 2017-12-15 14:04:57 | [diff] [blame] | 1160 | #if BUILDFLAG(ENABLE_BACKGROUND_MODE) |
| 1161 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1162 | class BrowserCloseManagerWithBackgroundModeBrowserTest |
| 1163 | : public BrowserCloseManagerBrowserTest { |
| 1164 | public: |
| 1165 | BrowserCloseManagerWithBackgroundModeBrowserTest() {} |
| 1166 | |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 1167 | void SetUpOnMainThread() override { |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1168 | BrowserCloseManagerBrowserTest::SetUpOnMainThread(); |
| 1169 | g_browser_process->set_background_mode_manager_for_test( |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 1170 | std::unique_ptr<BackgroundModeManager>(new FakeBackgroundModeManager)); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | bool IsBackgroundModeSuspended() { |
| 1174 | return static_cast<FakeBackgroundModeManager*>( |
| 1175 | g_browser_process->background_mode_manager()) |
| 1176 | ->IsBackgroundModeSuspended(); |
| 1177 | } |
| 1178 | |
| 1179 | private: |
| 1180 | DISALLOW_COPY_AND_ASSIGN(BrowserCloseManagerWithBackgroundModeBrowserTest); |
| 1181 | }; |
| 1182 | |
| 1183 | // Check that background mode is suspended when closing all browsers unless we |
| 1184 | // are quitting and that background mode is resumed when a new browser window is |
| 1185 | // opened. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 1186 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerWithBackgroundModeBrowserTest, |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1187 | CloseAllBrowsersWithBackgroundMode) { |
| 1188 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 1189 | std::unique_ptr<ScopedKeepAlive> tmp_keep_alive; |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1190 | Profile* profile = browser()->profile(); |
| 1191 | { |
dgn | 0237778 | 2016-03-12 00:58:38 | [diff] [blame] | 1192 | tmp_keep_alive.reset(new ScopedKeepAlive(KeepAliveOrigin::PANEL_VIEW, |
| 1193 | KeepAliveRestartOption::DISABLED)); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1194 | chrome::CloseAllBrowsers(); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1195 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1196 | } |
| 1197 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 1198 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1199 | EXPECT_TRUE(IsBackgroundModeSuspended()); |
| 1200 | |
| 1201 | // Background mode should be resumed when a new browser window is opened. |
| 1202 | ui_test_utils::BrowserAddedObserver new_browser_observer; |
scottmg | 85194900 | 2016-02-09 20:09:44 | [diff] [blame] | 1203 | chrome::NewEmptyWindow(profile); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1204 | new_browser_observer.WaitForSingleNewBrowser(); |
dgn | 0237778 | 2016-03-12 00:58:38 | [diff] [blame] | 1205 | tmp_keep_alive.reset(); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1206 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1207 | |
| 1208 | // Background mode should not be suspended when quitting. |
| 1209 | chrome::CloseAllBrowsersAndQuit(); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1210 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1211 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 1212 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1213 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | // Check that closing the last browser window individually does not affect |
| 1217 | // background mode. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 1218 | IN_PROC_BROWSER_TEST_F(BrowserCloseManagerWithBackgroundModeBrowserTest, |
dimich | 981e50f | 2016-03-03 23:39:16 | [diff] [blame] | 1219 | DISABLED_CloseSingleBrowserWithBackgroundMode) { |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1220 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
| 1221 | browser()->window()->Close(); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1222 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1223 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 1224 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1225 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
| 1226 | } |
| 1227 | |
| 1228 | // Check that closing all browsers with no browser windows open suspends |
| 1229 | // background mode but does not cause Chrome to quit. |
Avi Drissman | 78267f5 | 2019-01-16 21:21:42 | [diff] [blame] | 1230 | IN_PROC_BROWSER_TEST_F( |
| 1231 | BrowserCloseManagerWithBackgroundModeBrowserTest, |
| 1232 | DISABLED_CloseAllBrowsersWithNoOpenBrowsersWithBackgroundMode) { |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1233 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
dgn | 0237778 | 2016-03-12 00:58:38 | [diff] [blame] | 1234 | ScopedKeepAlive tmp_keep_alive(KeepAliveOrigin::PANEL_VIEW, |
| 1235 | KeepAliveRestartOption::DISABLED); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1236 | browser()->window()->Close(); |
Evan Stade | 4487c45 | 2019-07-11 00:58:06 | [diff] [blame^] | 1237 | ui_test_utils::WaitForBrowserToClose(); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1238 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 1239 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1240 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
| 1241 | |
| 1242 | chrome::CloseAllBrowsers(); |
| 1243 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 1244 | EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 1245 | EXPECT_TRUE(IsBackgroundModeSuspended()); |
| 1246 | } |
| 1247 | |
Denis Kuznetsov | 32099f3 | 2017-12-15 14:04:57 | [diff] [blame] | 1248 | #endif // BUILDFLAG(ENABLE_BACKGROUND_MODE) |