[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 | |
| 5 | #include <vector> |
| 6 | |
| 7 | #include "base/command_line.h" |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 8 | #include "base/files/scoped_temp_dir.h" |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 9 | #include "chrome/browser/background/background_mode_manager.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 10 | #include "chrome/browser/browser_process.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 11 | #include "chrome/browser/browser_shutdown.h" |
| 12 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 5fec470 | 2013-11-20 04:37:38 | [diff] [blame] | 13 | #include "chrome/browser/defaults.h" |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 14 | #include "chrome/browser/download/chrome_download_manager_delegate.h" |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 15 | #include "chrome/browser/download/download_prefs.h" |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 16 | #include "chrome/browser/download/download_service.h" |
| 17 | #include "chrome/browser/download/download_service_factory.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 18 | #include "chrome/browser/lifetime/application_lifetime.h" |
| 19 | #include "chrome/browser/lifetime/browser_close_manager.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 20 | #include "chrome/browser/net/url_request_mock_util.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 21 | #include "chrome/browser/prefs/session_startup_pref.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 22 | #include "chrome/browser/profiles/profile.h" |
| 23 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 24 | #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
| 25 | #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
| 26 | #include "chrome/browser/ui/browser.h" |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 27 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 28 | #include "chrome/browser/ui/browser_iterator.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 29 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 30 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 31 | #include "chrome/common/chrome_switches.h" |
| 32 | #include "chrome/common/url_constants.h" |
| 33 | #include "chrome/test/base/in_process_browser_test.h" |
| 34 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 35 | #include "content/public/browser/browser_context.h" |
| 36 | #include "content/public/browser/download_item.h" |
| 37 | #include "content/public/browser/download_manager.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 38 | #include "content/public/browser/notification_service.h" |
| 39 | #include "content/public/browser/web_contents.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 40 | #include "content/public/test/download_test_observer.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 41 | #include "content/public/test/test_navigation_observer.h" |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 42 | #include "content/test/net/url_request_slow_download_job.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 43 | #include "net/test/embedded_test_server/embedded_test_server.h" |
xunjieli | 0332c19 | 2014-09-10 23:23:31 | [diff] [blame] | 44 | #include "net/test/url_request/url_request_mock_http_job.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 45 | |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 46 | #if defined(OS_CHROMEOS) |
| 47 | #include "chromeos/chromeos_switches.h" |
| 48 | #endif |
| 49 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 50 | namespace { |
| 51 | |
| 52 | class AppModalDialogObserver { |
| 53 | public: |
| 54 | AppModalDialogObserver() {} |
| 55 | |
| 56 | void Start() { |
| 57 | observer_.reset(new content::WindowedNotificationObserver( |
| 58 | chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, |
| 59 | content::NotificationService::AllSources())); |
| 60 | } |
| 61 | |
| 62 | void AcceptClose() { |
| 63 | NativeAppModalDialog* dialog = GetNextDialog(); |
| 64 | ASSERT_TRUE(dialog); |
| 65 | dialog->AcceptAppModalDialog(); |
| 66 | } |
| 67 | |
| 68 | void CancelClose() { |
| 69 | NativeAppModalDialog* dialog = GetNextDialog(); |
| 70 | ASSERT_TRUE(dialog); |
| 71 | dialog->CancelAppModalDialog(); |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | NativeAppModalDialog* GetNextDialog() { |
| 76 | DCHECK(observer_); |
| 77 | observer_->Wait(); |
| 78 | if (observer_->source() == content::NotificationService::AllSources()) |
| 79 | return NULL; |
| 80 | |
| 81 | AppModalDialog* dialog = |
| 82 | content::Source<AppModalDialog>(observer_->source()).ptr(); |
| 83 | EXPECT_TRUE(dialog->IsJavaScriptModalDialog()); |
| 84 | JavaScriptAppModalDialog* js_dialog = |
| 85 | static_cast<JavaScriptAppModalDialog*>(dialog); |
| 86 | observer_.reset(new content::WindowedNotificationObserver( |
| 87 | chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, |
| 88 | content::NotificationService::AllSources())); |
| 89 | return js_dialog->native_dialog(); |
| 90 | } |
| 91 | |
| 92 | scoped_ptr<content::WindowedNotificationObserver> observer_; |
| 93 | |
| 94 | DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver); |
| 95 | }; |
| 96 | |
| 97 | class RepeatedNotificationObserver : public content::NotificationObserver { |
| 98 | public: |
| 99 | explicit RepeatedNotificationObserver(int type, int count) |
| 100 | : num_outstanding_(count), running_(false) { |
| 101 | registrar_.Add(this, type, content::NotificationService::AllSources()); |
| 102 | } |
| 103 | |
| 104 | virtual void Observe(int type, |
| 105 | const content::NotificationSource& source, |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame^] | 106 | const content::NotificationDetails& details) override { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 107 | ASSERT_GT(num_outstanding_, 0); |
| 108 | if (!--num_outstanding_ && running_) { |
| 109 | content::BrowserThread::PostTask( |
| 110 | content::BrowserThread::UI, FROM_HERE, run_loop_.QuitClosure()); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void Wait() { |
| 115 | if (num_outstanding_ <= 0) |
| 116 | return; |
| 117 | |
| 118 | running_ = true; |
| 119 | run_loop_.Run(); |
| 120 | running_ = false; |
| 121 | } |
| 122 | |
| 123 | private: |
| 124 | int num_outstanding_; |
| 125 | content::NotificationRegistrar registrar_; |
| 126 | bool running_; |
| 127 | base::RunLoop run_loop_; |
| 128 | |
| 129 | DISALLOW_COPY_AND_ASSIGN(RepeatedNotificationObserver); |
| 130 | }; |
| 131 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 132 | class TestBrowserCloseManager : public BrowserCloseManager { |
| 133 | public: |
| 134 | enum UserChoice { |
| 135 | USER_CHOICE_USER_CANCELS_CLOSE, |
| 136 | USER_CHOICE_USER_ALLOWS_CLOSE, |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 137 | NO_USER_CHOICE |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static void AttemptClose(UserChoice user_choice) { |
| 141 | scoped_refptr<BrowserCloseManager> browser_close_manager = |
| 142 | new TestBrowserCloseManager(user_choice); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 143 | browser_shutdown::SetTryingToQuit(true); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 144 | browser_close_manager->StartClosingBrowsers(); |
| 145 | } |
| 146 | |
| 147 | protected: |
| 148 | virtual ~TestBrowserCloseManager() {} |
| 149 | |
| 150 | virtual void ConfirmCloseWithPendingDownloads( |
| 151 | int download_count, |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame^] | 152 | const base::Callback<void(bool)>& callback) override { |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 153 | EXPECT_NE(NO_USER_CHOICE, user_choice_); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 154 | switch (user_choice_) { |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 155 | case NO_USER_CHOICE: |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 156 | case USER_CHOICE_USER_CANCELS_CLOSE: { |
| 157 | callback.Run(false); |
| 158 | break; |
| 159 | } |
| 160 | case USER_CHOICE_USER_ALLOWS_CLOSE: { |
| 161 | callback.Run(true); |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | private: |
| 168 | explicit TestBrowserCloseManager(UserChoice user_choice) |
| 169 | : user_choice_(user_choice) {} |
| 170 | |
| 171 | UserChoice user_choice_; |
| 172 | |
| 173 | DISALLOW_COPY_AND_ASSIGN(TestBrowserCloseManager); |
| 174 | }; |
| 175 | |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 176 | class TestDownloadManagerDelegate : public ChromeDownloadManagerDelegate { |
| 177 | public: |
| 178 | explicit TestDownloadManagerDelegate(Profile* profile) |
| 179 | : ChromeDownloadManagerDelegate(profile) { |
[email protected] | 861b4d0a | 2013-12-13 20:10:41 | [diff] [blame] | 180 | GetDownloadIdReceiverCallback().Run(content::DownloadItem::kInvalidId + 1); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 181 | } |
[email protected] | 861b4d0a | 2013-12-13 20:10:41 | [diff] [blame] | 182 | virtual ~TestDownloadManagerDelegate() {} |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 183 | |
| 184 | virtual bool DetermineDownloadTarget( |
| 185 | content::DownloadItem* item, |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame^] | 186 | const content::DownloadTargetCallback& callback) override { |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 187 | content::DownloadTargetCallback dangerous_callback = |
[email protected] | 861b4d0a | 2013-12-13 20:10:41 | [diff] [blame] | 188 | base::Bind(&TestDownloadManagerDelegate::SetDangerous, callback); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 189 | return ChromeDownloadManagerDelegate::DetermineDownloadTarget( |
| 190 | item, dangerous_callback); |
| 191 | } |
| 192 | |
[email protected] | 861b4d0a | 2013-12-13 20:10:41 | [diff] [blame] | 193 | static void SetDangerous( |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 194 | const content::DownloadTargetCallback& callback, |
| 195 | const base::FilePath& target_path, |
| 196 | content::DownloadItem::TargetDisposition disp, |
| 197 | content::DownloadDangerType danger_type, |
| 198 | const base::FilePath& intermediate_path) { |
| 199 | callback.Run(target_path, |
| 200 | disp, |
| 201 | content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, |
| 202 | intermediate_path); |
| 203 | } |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 204 | }; |
| 205 | |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 206 | class FakeBackgroundModeManager : public BackgroundModeManager { |
| 207 | public: |
| 208 | FakeBackgroundModeManager() |
| 209 | : BackgroundModeManager( |
| 210 | CommandLine::ForCurrentProcess(), |
| 211 | &g_browser_process->profile_manager()->GetProfileInfoCache()), |
| 212 | suspended_(false) {} |
| 213 | |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame^] | 214 | virtual void SuspendBackgroundMode() override { |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 215 | BackgroundModeManager::SuspendBackgroundMode(); |
| 216 | suspended_ = true; |
| 217 | } |
| 218 | |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame^] | 219 | virtual void ResumeBackgroundMode() override { |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 220 | BackgroundModeManager::ResumeBackgroundMode(); |
| 221 | suspended_ = false; |
| 222 | } |
| 223 | |
| 224 | bool IsBackgroundModeSuspended() { |
| 225 | return suspended_; |
| 226 | } |
| 227 | |
| 228 | private: |
| 229 | bool suspended_; |
| 230 | |
| 231 | DISALLOW_COPY_AND_ASSIGN(FakeBackgroundModeManager); |
| 232 | }; |
| 233 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 234 | } // namespace |
| 235 | |
| 236 | class BrowserCloseManagerBrowserTest |
| 237 | : public InProcessBrowserTest, |
| 238 | public testing::WithParamInterface<bool> { |
| 239 | protected: |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame^] | 240 | virtual void SetUpOnMainThread() override { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 241 | InProcessBrowserTest::SetUpOnMainThread(); |
| 242 | SessionStartupPref::SetStartupPref( |
| 243 | browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); |
| 244 | browsers_.push_back(browser()); |
| 245 | dialogs_.Start(); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 246 | content::BrowserThread::PostTask( |
| 247 | content::BrowserThread::IO, |
| 248 | FROM_HERE, |
| 249 | base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 250 | } |
| 251 | |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame^] | 252 | virtual void SetUpCommandLine(CommandLine* command_line) override { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 253 | if (GetParam()) |
| 254 | command_line->AppendSwitch(switches::kEnableFastUnload); |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 255 | #if defined(OS_CHROMEOS) |
| 256 | command_line->AppendSwitch( |
| 257 | chromeos::switches::kIgnoreUserProfileMappingForTests); |
| 258 | #endif |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 261 | void CreateStalledDownload(Browser* browser) { |
| 262 | content::DownloadTestObserverInProgress observer( |
| 263 | content::BrowserContext::GetDownloadManager(browser->profile()), 1); |
| 264 | ui_test_utils::NavigateToURLWithDisposition( |
| 265 | browser, |
| 266 | GURL(content::URLRequestSlowDownloadJob::kKnownSizeUrl), |
| 267 | NEW_BACKGROUND_TAB, |
| 268 | ui_test_utils::BROWSER_TEST_NONE); |
| 269 | observer.WaitForFinished(); |
| 270 | EXPECT_EQ( |
| 271 | 1UL, |
| 272 | observer.NumDownloadsSeenInState(content::DownloadItem::IN_PROGRESS)); |
| 273 | } |
| 274 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 275 | std::vector<Browser*> browsers_; |
| 276 | AppModalDialogObserver dialogs_; |
| 277 | }; |
| 278 | |
| 279 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestSingleTabShutdown) { |
| 280 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 281 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 282 | browser(), embedded_test_server()->GetURL("/beforeunload.html"))); |
| 283 | RepeatedNotificationObserver cancel_observer( |
| 284 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 285 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 286 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 287 | cancel_observer.Wait(); |
| 288 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 289 | EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 290 | |
| 291 | RepeatedNotificationObserver close_observer( |
| 292 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 293 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 294 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 295 | close_observer.Wait(); |
| 296 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 297 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 298 | } |
| 299 | |
| 300 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
| 301 | TestShutdownMoreThanOnce) { |
| 302 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 303 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 304 | browser(), embedded_test_server()->GetURL("/beforeunload.html"))); |
| 305 | RepeatedNotificationObserver cancel_observer( |
| 306 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 307 | chrome::CloseAllBrowsersAndQuit(); |
| 308 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 309 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 310 | cancel_observer.Wait(); |
| 311 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 312 | EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 313 | |
| 314 | RepeatedNotificationObserver close_observer( |
| 315 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 316 | chrome::CloseAllBrowsersAndQuit(); |
| 317 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 318 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 319 | close_observer.Wait(); |
| 320 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 321 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 322 | } |
| 323 | |
| 324 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, PRE_TestSessionRestore) { |
| 325 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 326 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 327 | browser(), embedded_test_server()->GetURL("/beforeunload.html"))); |
| 328 | AddBlankTabAndShow(browser()); |
| 329 | ASSERT_NO_FATAL_FAILURE( |
| 330 | ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL))); |
| 331 | RepeatedNotificationObserver cancel_observer( |
| 332 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 333 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 334 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 335 | cancel_observer.Wait(); |
| 336 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 337 | |
| 338 | browser()->tab_strip_model() |
| 339 | ->CloseWebContentsAt(1, TabStripModel::CLOSE_USER_GESTURE); |
| 340 | content::TestNavigationObserver navigation_observer( |
| 341 | browser()->tab_strip_model()->GetActiveWebContents(), 1); |
| 342 | ASSERT_NO_FATAL_FAILURE( |
| 343 | NavigateToURLWithDisposition(browser(), |
| 344 | GURL(chrome::kChromeUIVersionURL), |
| 345 | CURRENT_TAB, |
| 346 | ui_test_utils::BROWSER_TEST_NONE)); |
| 347 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 348 | navigation_observer.Wait(); |
| 349 | |
| 350 | RepeatedNotificationObserver close_observer( |
| 351 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 352 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 353 | close_observer.Wait(); |
| 354 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 355 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 356 | } |
| 357 | |
| 358 | // Test that the tab closed after the aborted shutdown attempt is not re-opened |
| 359 | // when restoring the session. |
| 360 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestSessionRestore) { |
| 361 | // The testing framework launches Chrome with about:blank as args. |
| 362 | EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 363 | EXPECT_EQ(GURL(chrome::kChromeUIVersionURL), |
| 364 | browser()->tab_strip_model()->GetWebContentsAt(0)->GetURL()); |
| 365 | EXPECT_EQ(GURL("about:blank"), |
| 366 | browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL()); |
| 367 | } |
| 368 | |
| 369 | // Test that browser windows are only closed if all browsers are ready to close |
| 370 | // and that all beforeunload dialogs are shown again after a cancel. |
[email protected] | 40cd13a | 2013-10-24 13:42:01 | [diff] [blame] | 371 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestMultipleWindows) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 372 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 373 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 374 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 375 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 376 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 377 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 378 | |
| 379 | // Cancel shutdown on the first beforeunload event. |
| 380 | { |
| 381 | RepeatedNotificationObserver cancel_observer( |
| 382 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 383 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 384 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 385 | cancel_observer.Wait(); |
| 386 | } |
| 387 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 388 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 389 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 390 | |
| 391 | // Cancel shutdown on the second beforeunload event. |
| 392 | { |
| 393 | RepeatedNotificationObserver cancel_observer( |
| 394 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 395 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 396 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 397 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 398 | cancel_observer.Wait(); |
| 399 | } |
| 400 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 401 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 402 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 403 | |
| 404 | // Allow shutdown for both beforeunload events. |
| 405 | RepeatedNotificationObserver close_observer( |
| 406 | chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 407 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 408 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
[email protected] | 40cd13a | 2013-10-24 13:42:01 | [diff] [blame] | 409 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 410 | close_observer.Wait(); |
| 411 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 412 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 413 | } |
| 414 | |
| 415 | // Test that tabs in the same window with a beforeunload event that hangs are |
| 416 | // treated the same as the user accepting the close, but do not close the tab |
| 417 | // early. |
[email protected] | 52656e0 | 2013-08-20 15:50:13 | [diff] [blame] | 418 | // Test is flaky on windows, disabled. See http://crbug.com/276366 |
| 419 | #if defined(OS_WIN) |
| 420 | #define MAYBE_TestHangInBeforeUnloadMultipleTabs \ |
| 421 | DISABLED_TestHangInBeforeUnloadMultipleTabs |
| 422 | #else |
| 423 | #define MAYBE_TestHangInBeforeUnloadMultipleTabs \ |
| 424 | TestHangInBeforeUnloadMultipleTabs |
| 425 | #endif |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 426 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
[email protected] | 52656e0 | 2013-08-20 15:50:13 | [diff] [blame] | 427 | MAYBE_TestHangInBeforeUnloadMultipleTabs) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 428 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 429 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 430 | browsers_[0], embedded_test_server()->GetURL("/beforeunload_hang.html"))); |
| 431 | AddBlankTabAndShow(browsers_[0]); |
| 432 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 433 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 434 | AddBlankTabAndShow(browsers_[0]); |
| 435 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 436 | browsers_[0], embedded_test_server()->GetURL("/beforeunload_hang.html"))); |
| 437 | |
| 438 | RepeatedNotificationObserver cancel_observer( |
| 439 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 440 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 441 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 442 | cancel_observer.Wait(); |
| 443 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 444 | // All tabs should still be open. |
| 445 | EXPECT_EQ(3, browsers_[0]->tab_strip_model()->count()); |
| 446 | |
| 447 | RepeatedNotificationObserver close_observer( |
| 448 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 449 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 450 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 451 | close_observer.Wait(); |
| 452 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 453 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 454 | } |
| 455 | |
| 456 | // Test that tabs in different windows with a beforeunload event that hangs are |
| 457 | // treated the same as the user accepting the close, but do not close the tab |
| 458 | // early. |
| 459 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
| 460 | TestHangInBeforeUnloadMultipleWindows) { |
| 461 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 462 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 463 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 464 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 465 | browsers_[0], embedded_test_server()->GetURL("/beforeunload_hang.html"))); |
| 466 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 467 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 468 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 469 | browsers_[2], embedded_test_server()->GetURL("/beforeunload_hang.html"))); |
| 470 | |
| 471 | RepeatedNotificationObserver cancel_observer( |
| 472 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 473 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 474 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 475 | cancel_observer.Wait(); |
| 476 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 477 | // All windows should still be open. |
| 478 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 479 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 480 | EXPECT_EQ(1, browsers_[2]->tab_strip_model()->count()); |
| 481 | |
| 482 | RepeatedNotificationObserver close_observer( |
| 483 | chrome::NOTIFICATION_BROWSER_CLOSED, 3); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 484 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 485 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 486 | close_observer.Wait(); |
| 487 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 488 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 489 | } |
| 490 | |
| 491 | // Test that a window created during shutdown is closed. |
| 492 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
| 493 | TestAddWindowDuringShutdown) { |
| 494 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 495 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 496 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 497 | |
| 498 | RepeatedNotificationObserver close_observer( |
| 499 | chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 500 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 501 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 502 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 503 | close_observer.Wait(); |
| 504 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 505 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 506 | } |
| 507 | |
| 508 | // Test that a window created during shutdown with a beforeunload handler can |
| 509 | // cancel the shutdown. |
| 510 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
[email protected] | 40cd13a | 2013-10-24 13:42:01 | [diff] [blame] | 511 | TestAddWindowWithBeforeUnloadDuringShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 512 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 513 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 514 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 515 | |
| 516 | RepeatedNotificationObserver cancel_observer( |
| 517 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 518 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 519 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 520 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 521 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 522 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 523 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 524 | cancel_observer.Wait(); |
| 525 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 526 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 527 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 528 | |
| 529 | // Allow shutdown for both beforeunload dialogs. |
| 530 | RepeatedNotificationObserver close_observer( |
| 531 | chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 532 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 533 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
[email protected] | 40cd13a | 2013-10-24 13:42:01 | [diff] [blame] | 534 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 535 | close_observer.Wait(); |
| 536 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 537 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 538 | } |
| 539 | |
| 540 | // Test that tabs added during shutdown are closed. |
| 541 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
| 542 | TestAddTabDuringShutdown) { |
| 543 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 544 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 545 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 546 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 547 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 548 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 549 | |
| 550 | RepeatedNotificationObserver close_observer( |
| 551 | chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 552 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 553 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 554 | AddBlankTabAndShow(browsers_[0]); |
| 555 | AddBlankTabAndShow(browsers_[1]); |
| 556 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 557 | close_observer.Wait(); |
| 558 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 559 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 560 | } |
| 561 | |
| 562 | // Test that tabs created during shutdown with beforeunload handlers can cancel |
| 563 | // the shutdown. |
| 564 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
[email protected] | 40cd13a | 2013-10-24 13:42:01 | [diff] [blame] | 565 | TestAddTabWithBeforeUnloadDuringShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 566 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 567 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 568 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 569 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 570 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 571 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 572 | RepeatedNotificationObserver cancel_observer( |
| 573 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 574 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 575 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 576 | AddBlankTabAndShow(browsers_[0]); |
| 577 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 578 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 579 | AddBlankTabAndShow(browsers_[1]); |
| 580 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 581 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 582 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 583 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 584 | cancel_observer.Wait(); |
| 585 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 586 | EXPECT_EQ(2, browsers_[0]->tab_strip_model()->count()); |
| 587 | EXPECT_EQ(2, browsers_[1]->tab_strip_model()->count()); |
| 588 | |
| 589 | RepeatedNotificationObserver close_observer( |
| 590 | chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 591 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 592 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 593 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
[email protected] | 40cd13a | 2013-10-24 13:42:01 | [diff] [blame] | 594 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 595 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 596 | |
| 597 | close_observer.Wait(); |
| 598 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 599 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 600 | } |
| 601 | |
| 602 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
| 603 | TestCloseTabDuringShutdown) { |
| 604 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 605 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 606 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 607 | RepeatedNotificationObserver cancel_observer( |
| 608 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 609 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 610 | |
| 611 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 612 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 613 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 614 | browsers_[1]->tab_strip_model()->CloseAllTabs(); |
| 615 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 616 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 617 | cancel_observer.Wait(); |
| 618 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 619 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 620 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 621 | |
| 622 | RepeatedNotificationObserver close_observer( |
| 623 | chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 624 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 625 | browsers_[1]->tab_strip_model()->CloseAllTabs(); |
| 626 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 627 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 628 | |
| 629 | close_observer.Wait(); |
| 630 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 631 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 632 | } |
| 633 | |
[email protected] | 8376e17 | 2013-10-03 08:42:49 | [diff] [blame] | 634 | // Test is flaky on windows, disabled. See http://crbug.com/276366 |
| 635 | #if defined(OS_WIN) |
| 636 | #define MAYBE_TestOpenAndCloseWindowDuringShutdown \ |
| 637 | DISABLED_TestOpenAndCloseWindowDuringShutdown |
| 638 | #else |
| 639 | #define MAYBE_TestOpenAndCloseWindowDuringShutdown \ |
| 640 | TestOpenAndCloseWindowDuringShutdown |
| 641 | #endif |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 642 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
[email protected] | 8376e17 | 2013-10-03 08:42:49 | [diff] [blame] | 643 | MAYBE_TestOpenAndCloseWindowDuringShutdown) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 644 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 645 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 646 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 647 | RepeatedNotificationObserver cancel_observer( |
| 648 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 649 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 650 | |
| 651 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 652 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 653 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 654 | ASSERT_FALSE(browsers_[1]->ShouldCloseWindow()); |
| 655 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 656 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 657 | cancel_observer.Wait(); |
| 658 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 659 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 660 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 661 | |
| 662 | RepeatedNotificationObserver close_observer( |
| 663 | chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 664 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 665 | ASSERT_FALSE(browsers_[1]->ShouldCloseWindow()); |
| 666 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 667 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 668 | |
| 669 | close_observer.Wait(); |
| 670 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 671 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 672 | } |
| 673 | |
| 674 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
| 675 | TestCloseWindowDuringShutdown) { |
| 676 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 677 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 678 | browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 679 | browsers_.push_back(CreateBrowser(browser()->profile())); |
| 680 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 681 | browsers_[1], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 682 | RepeatedNotificationObserver cancel_observer( |
| 683 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 684 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 685 | |
| 686 | ASSERT_FALSE(browsers_[0]->ShouldCloseWindow()); |
| 687 | ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose()); |
| 688 | cancel_observer.Wait(); |
| 689 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 690 | EXPECT_EQ(1, browsers_[0]->tab_strip_model()->count()); |
| 691 | EXPECT_EQ(1, browsers_[1]->tab_strip_model()->count()); |
| 692 | |
| 693 | RepeatedNotificationObserver close_observer( |
| 694 | chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 695 | chrome::CloseAllBrowsersAndQuit(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 696 | ASSERT_FALSE(browsers_[0]->ShouldCloseWindow()); |
| 697 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 698 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 699 | |
| 700 | close_observer.Wait(); |
| 701 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 702 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 703 | } |
| 704 | |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 705 | INSTANTIATE_TEST_CASE_P(BrowserCloseManagerBrowserTest, |
| 706 | BrowserCloseManagerBrowserTest, |
| 707 | testing::Bool()); |
| 708 | |
| 709 | class BrowserCloseManagerWithDownloadsBrowserTest : |
| 710 | public BrowserCloseManagerBrowserTest { |
| 711 | public: |
| 712 | BrowserCloseManagerWithDownloadsBrowserTest() {} |
| 713 | virtual ~BrowserCloseManagerWithDownloadsBrowserTest() {} |
| 714 | |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame^] | 715 | virtual void SetUpOnMainThread() override { |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 716 | BrowserCloseManagerBrowserTest::SetUpOnMainThread(); |
| 717 | ASSERT_TRUE(scoped_download_directory_.CreateUniqueTempDir()); |
| 718 | } |
| 719 | |
| 720 | void SetDownloadPathForProfile(Profile* profile) { |
| 721 | DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(profile); |
| 722 | download_prefs->SetDownloadPath(download_path()); |
| 723 | } |
| 724 | |
| 725 | const base::FilePath& download_path() const { |
| 726 | return scoped_download_directory_.path(); |
| 727 | } |
| 728 | |
| 729 | private: |
| 730 | base::ScopedTempDir scoped_download_directory_; |
| 731 | }; |
| 732 | |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 733 | // Test shutdown with a DANGEROUS_URL download undecided. |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 734 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 735 | TestWithDangerousUrlDownload) { |
| 736 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 737 | SetDownloadPathForProfile(browser()->profile()); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 738 | |
| 739 | // Set up the fake delegate that forces the download to be malicious. |
[email protected] | 861b4d0a | 2013-12-13 20:10:41 | [diff] [blame] | 740 | scoped_ptr<TestDownloadManagerDelegate> test_delegate( |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 741 | new TestDownloadManagerDelegate(browser()->profile())); |
| 742 | DownloadServiceFactory::GetForBrowserContext(browser()->profile())-> |
[email protected] | 861b4d0a | 2013-12-13 20:10:41 | [diff] [blame] | 743 | SetDownloadManagerDelegateForTesting( |
| 744 | test_delegate.PassAs<ChromeDownloadManagerDelegate>()); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 745 | |
| 746 | // Run a dangerous download, but the user doesn't make a decision. |
| 747 | // This .swf normally would be categorized as DANGEROUS_FILE, but |
| 748 | // TestDownloadManagerDelegate turns it into DANGEROUS_URL. |
| 749 | base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); |
xunjieli | 0332c19 | 2014-09-10 23:23:31 | [diff] [blame] | 750 | GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl(file)); |
[email protected] | 422a7d1 | 2013-10-21 12:10:42 | [diff] [blame] | 751 | content::DownloadTestObserverInterrupted observer( |
| 752 | content::BrowserContext::GetDownloadManager(browser()->profile()), |
| 753 | 1, |
| 754 | content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT); |
| 755 | ui_test_utils::NavigateToURLWithDisposition( |
| 756 | browser(), |
| 757 | GURL(download_url), |
| 758 | NEW_BACKGROUND_TAB, |
| 759 | ui_test_utils::BROWSER_TEST_NONE); |
| 760 | observer.WaitForFinished(); |
| 761 | |
| 762 | // Check that the download manager has the expected state. |
| 763 | EXPECT_EQ(1, content::BrowserContext::GetDownloadManager( |
| 764 | browser()->profile())->InProgressCount()); |
| 765 | EXPECT_EQ(0, content::BrowserContext::GetDownloadManager( |
| 766 | browser()->profile())->NonMaliciousInProgressCount()); |
| 767 | |
| 768 | // Close the browser with no user action. |
| 769 | RepeatedNotificationObserver close_observer( |
| 770 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
| 771 | TestBrowserCloseManager::AttemptClose( |
| 772 | TestBrowserCloseManager::NO_USER_CHOICE); |
| 773 | close_observer.Wait(); |
| 774 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 775 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 776 | } |
| 777 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 778 | // Test shutdown with a download in progress. |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 779 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, |
| 780 | TestWithDownloads) { |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 781 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 782 | SetDownloadPathForProfile(browser()->profile()); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 783 | ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
| 784 | content::TestNavigationObserver navigation_observer( |
| 785 | browser()->tab_strip_model()->GetActiveWebContents(), 1); |
| 786 | TestBrowserCloseManager::AttemptClose( |
| 787 | TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); |
| 788 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 789 | navigation_observer.Wait(); |
| 790 | EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL), |
| 791 | browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 792 | |
| 793 | RepeatedNotificationObserver close_observer( |
| 794 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
| 795 | |
| 796 | TestBrowserCloseManager::AttemptClose( |
| 797 | TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
| 798 | close_observer.Wait(); |
| 799 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 800 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
[email protected] | 5fec470 | 2013-11-20 04:37:38 | [diff] [blame] | 801 | if (browser_defaults::kBrowserAliveWithNoWindows) |
| 802 | EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); |
| 803 | else |
| 804 | EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | // Test shutdown with a download in progress from one profile, where the only |
| 808 | // open windows are for another profile. |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 809 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 810 | TestWithDownloadsFromDifferentProfiles) { |
| 811 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 812 | base::FilePath path = |
| 813 | profile_manager->user_data_dir().AppendASCII("test_profile"); |
| 814 | if (!base::PathExists(path)) |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 815 | ASSERT_TRUE(base::CreateDirectory(path)); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 816 | Profile* other_profile = |
| 817 | Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); |
| 818 | profile_manager->RegisterTestingProfile(other_profile, true, false); |
| 819 | Browser* other_profile_browser = CreateBrowser(other_profile); |
| 820 | |
| 821 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 822 | SetDownloadPathForProfile(browser()->profile()); |
| 823 | SetDownloadPathForProfile(other_profile); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 824 | ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
| 825 | { |
| 826 | RepeatedNotificationObserver close_observer( |
| 827 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
| 828 | browser()->window()->Close(); |
| 829 | close_observer.Wait(); |
| 830 | } |
| 831 | |
| 832 | // When the shutdown is cancelled, the downloads page should be opened in a |
| 833 | // browser for that profile. Because there are no browsers for that profile, a |
| 834 | // new browser should be opened. |
| 835 | ui_test_utils::BrowserAddedObserver new_browser_observer; |
| 836 | TestBrowserCloseManager::AttemptClose( |
| 837 | TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); |
| 838 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 839 | Browser* opened_browser = new_browser_observer.WaitForSingleNewBrowser(); |
| 840 | EXPECT_EQ( |
| 841 | GURL(chrome::kChromeUIDownloadsURL), |
| 842 | opened_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 843 | EXPECT_EQ(GURL("about:blank"), |
| 844 | other_profile_browser->tab_strip_model()->GetActiveWebContents() |
| 845 | ->GetURL()); |
| 846 | |
| 847 | RepeatedNotificationObserver close_observer( |
| 848 | chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
| 849 | TestBrowserCloseManager::AttemptClose( |
| 850 | TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
| 851 | close_observer.Wait(); |
| 852 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 853 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
[email protected] | 5fec470 | 2013-11-20 04:37:38 | [diff] [blame] | 854 | if (browser_defaults::kBrowserAliveWithNoWindows) |
| 855 | EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles()); |
| 856 | else |
| 857 | EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles()); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | // Test shutdown with downloads in progress and beforeunload handlers. |
[email protected] | 4c23057a | 2013-11-06 18:29:52 | [diff] [blame] | 861 | // Disabled, see http://crbug.com/315754. |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 862 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest, |
[email protected] | 4c23057a | 2013-11-06 18:29:52 | [diff] [blame] | 863 | DISABLED_TestBeforeUnloadAndDownloads) { |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 864 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 865 | SetDownloadPathForProfile(browser()->profile()); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 866 | ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser())); |
| 867 | ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 868 | browser(), embedded_test_server()->GetURL("/beforeunload.html"))); |
| 869 | |
| 870 | content::WindowedNotificationObserver cancel_observer( |
| 871 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 872 | content::NotificationService::AllSources()); |
| 873 | TestBrowserCloseManager::AttemptClose( |
| 874 | TestBrowserCloseManager::USER_CHOICE_USER_CANCELS_CLOSE); |
| 875 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
| 876 | cancel_observer.Wait(); |
| 877 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 878 | |
| 879 | RepeatedNotificationObserver close_observer( |
| 880 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
| 881 | TestBrowserCloseManager::AttemptClose( |
| 882 | TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE); |
[email protected] | 40cd13a | 2013-10-24 13:42:01 | [diff] [blame] | 883 | ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose()); |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 884 | close_observer.Wait(); |
| 885 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 886 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 887 | } |
| 888 | |
[email protected] | 0ed5387 | 2014-05-10 05:51:05 | [diff] [blame] | 889 | INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithDownloadsBrowserTest, |
| 890 | BrowserCloseManagerWithDownloadsBrowserTest, |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 891 | testing::Bool()); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 892 | |
| 893 | class BrowserCloseManagerWithBackgroundModeBrowserTest |
| 894 | : public BrowserCloseManagerBrowserTest { |
| 895 | public: |
| 896 | BrowserCloseManagerWithBackgroundModeBrowserTest() {} |
| 897 | |
mostynb | 2b52d1db | 2014-10-07 02:47:17 | [diff] [blame^] | 898 | virtual void SetUpOnMainThread() override { |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 899 | BrowserCloseManagerBrowserTest::SetUpOnMainThread(); |
| 900 | g_browser_process->set_background_mode_manager_for_test( |
| 901 | scoped_ptr<BackgroundModeManager>(new FakeBackgroundModeManager)); |
| 902 | } |
| 903 | |
| 904 | bool IsBackgroundModeSuspended() { |
| 905 | return static_cast<FakeBackgroundModeManager*>( |
| 906 | g_browser_process->background_mode_manager()) |
| 907 | ->IsBackgroundModeSuspended(); |
| 908 | } |
| 909 | |
| 910 | private: |
| 911 | DISALLOW_COPY_AND_ASSIGN(BrowserCloseManagerWithBackgroundModeBrowserTest); |
| 912 | }; |
| 913 | |
| 914 | // Check that background mode is suspended when closing all browsers unless we |
| 915 | // are quitting and that background mode is resumed when a new browser window is |
| 916 | // opened. |
| 917 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
| 918 | CloseAllBrowsersWithBackgroundMode) { |
| 919 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
| 920 | Profile* profile = browser()->profile(); |
| 921 | { |
| 922 | RepeatedNotificationObserver close_observer( |
| 923 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
[email protected] | 9a718b2 | 2014-02-25 15:17:27 | [diff] [blame] | 924 | chrome::IncrementKeepAliveCount(); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 925 | chrome::CloseAllBrowsers(); |
| 926 | close_observer.Wait(); |
| 927 | } |
| 928 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 929 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 930 | EXPECT_TRUE(IsBackgroundModeSuspended()); |
| 931 | |
| 932 | // Background mode should be resumed when a new browser window is opened. |
| 933 | ui_test_utils::BrowserAddedObserver new_browser_observer; |
| 934 | chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 935 | new_browser_observer.WaitForSingleNewBrowser(); |
[email protected] | 9a718b2 | 2014-02-25 15:17:27 | [diff] [blame] | 936 | chrome::DecrementKeepAliveCount(); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 937 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
| 938 | RepeatedNotificationObserver close_observer( |
| 939 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
| 940 | |
| 941 | // Background mode should not be suspended when quitting. |
| 942 | chrome::CloseAllBrowsersAndQuit(); |
| 943 | close_observer.Wait(); |
| 944 | EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 945 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 946 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
| 947 | |
| 948 | } |
| 949 | |
| 950 | // Check that closing the last browser window individually does not affect |
| 951 | // background mode. |
| 952 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
| 953 | CloseSingleBrowserWithBackgroundMode) { |
| 954 | RepeatedNotificationObserver close_observer( |
| 955 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
| 956 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
| 957 | browser()->window()->Close(); |
| 958 | close_observer.Wait(); |
| 959 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 960 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 961 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
| 962 | } |
| 963 | |
| 964 | // Check that closing all browsers with no browser windows open suspends |
| 965 | // background mode but does not cause Chrome to quit. |
| 966 | IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
| 967 | CloseAllBrowsersWithNoOpenBrowsersWithBackgroundMode) { |
| 968 | RepeatedNotificationObserver close_observer( |
| 969 | chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
| 970 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
[email protected] | 9a718b2 | 2014-02-25 15:17:27 | [diff] [blame] | 971 | chrome::IncrementKeepAliveCount(); |
[email protected] | 0c95faf4 | 2013-10-28 06:27:20 | [diff] [blame] | 972 | browser()->window()->Close(); |
| 973 | close_observer.Wait(); |
| 974 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 975 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 976 | EXPECT_FALSE(IsBackgroundModeSuspended()); |
| 977 | |
| 978 | chrome::CloseAllBrowsers(); |
| 979 | EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 980 | EXPECT_TRUE(chrome::BrowserIterator().done()); |
| 981 | EXPECT_TRUE(IsBackgroundModeSuspended()); |
| 982 | } |
| 983 | |
| 984 | INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
| 985 | BrowserCloseManagerWithBackgroundModeBrowserTest, |
| 986 | testing::Bool()); |