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