EME test page application.
[chromium-blink-merge.git] / chrome / browser / lifetime / browser_close_manager_browsertest.cc
blobef424b8f40e235d547d981df6c0e0ea62d9a1ca4
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/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"
27 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_iterator.h"
29 #include "chrome/browser/ui/browser_window.h"
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"
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 "content/test/net/url_request_mock_http_job.h"
43 #include "content/test/net/url_request_slow_download_job.h"
44 #include "net/test/embedded_test_server/embedded_test_server.h"
46 #if defined(OS_CHROMEOS)
47 #include "chromeos/chromeos_switches.h"
48 #endif
50 namespace {
52 class AppModalDialogObserver {
53 public:
54 AppModalDialogObserver() {}
56 void Start() {
57 observer_.reset(new content::WindowedNotificationObserver(
58 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN,
59 content::NotificationService::AllSources()));
62 void AcceptClose() {
63 NativeAppModalDialog* dialog = GetNextDialog();
64 ASSERT_TRUE(dialog);
65 dialog->AcceptAppModalDialog();
68 void CancelClose() {
69 NativeAppModalDialog* dialog = GetNextDialog();
70 ASSERT_TRUE(dialog);
71 dialog->CancelAppModalDialog();
74 private:
75 NativeAppModalDialog* GetNextDialog() {
76 DCHECK(observer_);
77 observer_->Wait();
78 if (observer_->source() == content::NotificationService::AllSources())
79 return NULL;
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();
92 scoped_ptr<content::WindowedNotificationObserver> observer_;
94 DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver);
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());
104 virtual void Observe(int type,
105 const content::NotificationSource& source,
106 const content::NotificationDetails& details) OVERRIDE {
107 ASSERT_GT(num_outstanding_, 0);
108 if (!--num_outstanding_ && running_) {
109 content::BrowserThread::PostTask(
110 content::BrowserThread::UI, FROM_HERE, run_loop_.QuitClosure());
114 void Wait() {
115 if (num_outstanding_ <= 0)
116 return;
118 running_ = true;
119 run_loop_.Run();
120 running_ = false;
123 private:
124 int num_outstanding_;
125 content::NotificationRegistrar registrar_;
126 bool running_;
127 base::RunLoop run_loop_;
129 DISALLOW_COPY_AND_ASSIGN(RepeatedNotificationObserver);
132 class TestBrowserCloseManager : public BrowserCloseManager {
133 public:
134 enum UserChoice {
135 USER_CHOICE_USER_CANCELS_CLOSE,
136 USER_CHOICE_USER_ALLOWS_CLOSE,
137 NO_USER_CHOICE
140 static void AttemptClose(UserChoice user_choice) {
141 scoped_refptr<BrowserCloseManager> browser_close_manager =
142 new TestBrowserCloseManager(user_choice);
143 browser_shutdown::SetTryingToQuit(true);
144 browser_close_manager->StartClosingBrowsers();
147 protected:
148 virtual ~TestBrowserCloseManager() {}
150 virtual void ConfirmCloseWithPendingDownloads(
151 int download_count,
152 const base::Callback<void(bool)>& callback) OVERRIDE {
153 EXPECT_NE(NO_USER_CHOICE, user_choice_);
154 switch (user_choice_) {
155 case NO_USER_CHOICE:
156 case USER_CHOICE_USER_CANCELS_CLOSE: {
157 callback.Run(false);
158 break;
160 case USER_CHOICE_USER_ALLOWS_CLOSE: {
161 callback.Run(true);
162 break;
167 private:
168 explicit TestBrowserCloseManager(UserChoice user_choice)
169 : user_choice_(user_choice) {}
171 UserChoice user_choice_;
173 DISALLOW_COPY_AND_ASSIGN(TestBrowserCloseManager);
176 class TestDownloadManagerDelegate : public ChromeDownloadManagerDelegate {
177 public:
178 explicit TestDownloadManagerDelegate(Profile* profile)
179 : ChromeDownloadManagerDelegate(profile) {
180 GetDownloadIdReceiverCallback().Run(content::DownloadItem::kInvalidId + 1);
182 virtual ~TestDownloadManagerDelegate() {}
184 virtual bool DetermineDownloadTarget(
185 content::DownloadItem* item,
186 const content::DownloadTargetCallback& callback) OVERRIDE {
187 content::DownloadTargetCallback dangerous_callback =
188 base::Bind(&TestDownloadManagerDelegate::SetDangerous, callback);
189 return ChromeDownloadManagerDelegate::DetermineDownloadTarget(
190 item, dangerous_callback);
193 static void SetDangerous(
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);
206 class FakeBackgroundModeManager : public BackgroundModeManager {
207 public:
208 FakeBackgroundModeManager()
209 : BackgroundModeManager(
210 CommandLine::ForCurrentProcess(),
211 &g_browser_process->profile_manager()->GetProfileInfoCache()),
212 suspended_(false) {}
214 virtual void SuspendBackgroundMode() OVERRIDE {
215 BackgroundModeManager::SuspendBackgroundMode();
216 suspended_ = true;
219 virtual void ResumeBackgroundMode() OVERRIDE {
220 BackgroundModeManager::ResumeBackgroundMode();
221 suspended_ = false;
224 bool IsBackgroundModeSuspended() {
225 return suspended_;
228 private:
229 bool suspended_;
231 DISALLOW_COPY_AND_ASSIGN(FakeBackgroundModeManager);
234 } // namespace
236 class BrowserCloseManagerBrowserTest
237 : public InProcessBrowserTest,
238 public testing::WithParamInterface<bool> {
239 protected:
240 virtual void SetUpOnMainThread() OVERRIDE {
241 InProcessBrowserTest::SetUpOnMainThread();
242 SessionStartupPref::SetStartupPref(
243 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST));
244 browsers_.push_back(browser());
245 dialogs_.Start();
246 content::BrowserThread::PostTask(
247 content::BrowserThread::IO,
248 FROM_HERE,
249 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
252 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
253 if (GetParam())
254 command_line->AppendSwitch(switches::kEnableFastUnload);
255 #if defined(OS_CHROMEOS)
256 command_line->AppendSwitch(
257 chromeos::switches::kIgnoreUserProfileMappingForTests);
258 #endif
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));
275 std::vector<Browser*> browsers_;
276 AppModalDialogObserver dialogs_;
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);
285 chrome::CloseAllBrowsersAndQuit();
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());
291 RepeatedNotificationObserver close_observer(
292 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
293 chrome::CloseAllBrowsersAndQuit();
294 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
295 close_observer.Wait();
296 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
297 EXPECT_TRUE(chrome::BrowserIterator().done());
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);
307 chrome::CloseAllBrowsersAndQuit();
308 chrome::CloseAllBrowsersAndQuit();
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());
314 RepeatedNotificationObserver close_observer(
315 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
316 chrome::CloseAllBrowsersAndQuit();
317 chrome::CloseAllBrowsersAndQuit();
318 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
319 close_observer.Wait();
320 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
321 EXPECT_TRUE(chrome::BrowserIterator().done());
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);
333 chrome::CloseAllBrowsersAndQuit();
334 ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose());
335 cancel_observer.Wait();
336 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
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();
350 RepeatedNotificationObserver close_observer(
351 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
352 chrome::CloseAllBrowsersAndQuit();
353 close_observer.Wait();
354 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
355 EXPECT_TRUE(chrome::BrowserIterator().done());
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());
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.
371 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, TestMultipleWindows) {
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")));
379 // Cancel shutdown on the first beforeunload event.
381 RepeatedNotificationObserver cancel_observer(
382 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1);
383 chrome::CloseAllBrowsersAndQuit();
384 ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose());
385 cancel_observer.Wait();
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());
391 // Cancel shutdown on the second beforeunload event.
393 RepeatedNotificationObserver cancel_observer(
394 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2);
395 chrome::CloseAllBrowsersAndQuit();
396 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
397 ASSERT_NO_FATAL_FAILURE(dialogs_.CancelClose());
398 cancel_observer.Wait();
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());
404 // Allow shutdown for both beforeunload events.
405 RepeatedNotificationObserver close_observer(
406 chrome::NOTIFICATION_BROWSER_CLOSED, 2);
407 chrome::CloseAllBrowsersAndQuit();
408 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
409 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
410 close_observer.Wait();
411 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
412 EXPECT_TRUE(chrome::BrowserIterator().done());
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.
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
426 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest,
427 MAYBE_TestHangInBeforeUnloadMultipleTabs) {
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")));
438 RepeatedNotificationObserver cancel_observer(
439 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1);
440 chrome::CloseAllBrowsersAndQuit();
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());
447 RepeatedNotificationObserver close_observer(
448 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
449 chrome::CloseAllBrowsersAndQuit();
450 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
451 close_observer.Wait();
452 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
453 EXPECT_TRUE(chrome::BrowserIterator().done());
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")));
471 RepeatedNotificationObserver cancel_observer(
472 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2);
473 chrome::CloseAllBrowsersAndQuit();
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());
482 RepeatedNotificationObserver close_observer(
483 chrome::NOTIFICATION_BROWSER_CLOSED, 3);
484 chrome::CloseAllBrowsersAndQuit();
485 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
486 close_observer.Wait();
487 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
488 EXPECT_TRUE(chrome::BrowserIterator().done());
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")));
498 RepeatedNotificationObserver close_observer(
499 chrome::NOTIFICATION_BROWSER_CLOSED, 2);
500 chrome::CloseAllBrowsersAndQuit();
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());
508 // Test that a window created during shutdown with a beforeunload handler can
509 // cancel the shutdown.
510 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest,
511 TestAddWindowWithBeforeUnloadDuringShutdown) {
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")));
516 RepeatedNotificationObserver cancel_observer(
517 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 2);
518 chrome::CloseAllBrowsersAndQuit();
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());
529 // Allow shutdown for both beforeunload dialogs.
530 RepeatedNotificationObserver close_observer(
531 chrome::NOTIFICATION_BROWSER_CLOSED, 2);
532 chrome::CloseAllBrowsersAndQuit();
533 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
534 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
535 close_observer.Wait();
536 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
537 EXPECT_TRUE(chrome::BrowserIterator().done());
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")));
550 RepeatedNotificationObserver close_observer(
551 chrome::NOTIFICATION_BROWSER_CLOSED, 2);
552 chrome::CloseAllBrowsersAndQuit();
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());
562 // Test that tabs created during shutdown with beforeunload handlers can cancel
563 // the shutdown.
564 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest,
565 TestAddTabWithBeforeUnloadDuringShutdown) {
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);
574 chrome::CloseAllBrowsersAndQuit();
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());
589 RepeatedNotificationObserver close_observer(
590 chrome::NOTIFICATION_BROWSER_CLOSED, 2);
591 chrome::CloseAllBrowsersAndQuit();
592 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
593 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
594 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
595 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
597 close_observer.Wait();
598 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
599 EXPECT_TRUE(chrome::BrowserIterator().done());
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);
609 chrome::CloseAllBrowsersAndQuit();
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());
622 RepeatedNotificationObserver close_observer(
623 chrome::NOTIFICATION_BROWSER_CLOSED, 2);
624 chrome::CloseAllBrowsersAndQuit();
625 browsers_[1]->tab_strip_model()->CloseAllTabs();
626 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
627 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
629 close_observer.Wait();
630 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
631 EXPECT_TRUE(chrome::BrowserIterator().done());
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
642 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest,
643 MAYBE_TestOpenAndCloseWindowDuringShutdown) {
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);
649 chrome::CloseAllBrowsersAndQuit();
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());
662 RepeatedNotificationObserver close_observer(
663 chrome::NOTIFICATION_BROWSER_CLOSED, 2);
664 chrome::CloseAllBrowsersAndQuit();
665 ASSERT_FALSE(browsers_[1]->ShouldCloseWindow());
666 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
667 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
669 close_observer.Wait();
670 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
671 EXPECT_TRUE(chrome::BrowserIterator().done());
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);
684 chrome::CloseAllBrowsersAndQuit();
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());
693 RepeatedNotificationObserver close_observer(
694 chrome::NOTIFICATION_BROWSER_CLOSED, 2);
695 chrome::CloseAllBrowsersAndQuit();
696 ASSERT_FALSE(browsers_[0]->ShouldCloseWindow());
697 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
698 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
700 close_observer.Wait();
701 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
702 EXPECT_TRUE(chrome::BrowserIterator().done());
705 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerBrowserTest,
706 BrowserCloseManagerBrowserTest,
707 testing::Bool());
709 class BrowserCloseManagerWithDownloadsBrowserTest :
710 public BrowserCloseManagerBrowserTest {
711 public:
712 BrowserCloseManagerWithDownloadsBrowserTest() {}
713 virtual ~BrowserCloseManagerWithDownloadsBrowserTest() {}
715 virtual void SetUpOnMainThread() OVERRIDE {
716 BrowserCloseManagerBrowserTest::SetUpOnMainThread();
717 ASSERT_TRUE(scoped_download_directory_.CreateUniqueTempDir());
720 void SetDownloadPathForProfile(Profile* profile) {
721 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(profile);
722 download_prefs->SetDownloadPath(download_path());
725 const base::FilePath& download_path() const {
726 return scoped_download_directory_.path();
729 private:
730 base::ScopedTempDir scoped_download_directory_;
733 // Test shutdown with a DANGEROUS_URL download undecided.
734 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest,
735 TestWithDangerousUrlDownload) {
736 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
737 SetDownloadPathForProfile(browser()->profile());
739 // Set up the fake delegate that forces the download to be malicious.
740 scoped_ptr<TestDownloadManagerDelegate> test_delegate(
741 new TestDownloadManagerDelegate(browser()->profile()));
742 DownloadServiceFactory::GetForBrowserContext(browser()->profile())->
743 SetDownloadManagerDelegateForTesting(
744 test_delegate.PassAs<ChromeDownloadManagerDelegate>());
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"));
750 GURL download_url(content::URLRequestMockHTTPJob::GetMockUrl(file));
751 content::DownloadTestObserverInterrupted observer(
752 content::BrowserContext::GetDownloadManager(browser()->profile()),
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();
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());
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());
778 // Test shutdown with a download in progress.
779 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest,
780 TestWithDownloads) {
781 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
782 SetDownloadPathForProfile(browser()->profile());
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());
793 RepeatedNotificationObserver close_observer(
794 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
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());
801 if (browser_defaults::kBrowserAliveWithNoWindows)
802 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles());
803 else
804 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles());
807 // Test shutdown with a download in progress from one profile, where the only
808 // open windows are for another profile.
809 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest,
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))
815 ASSERT_TRUE(base::CreateDirectory(path));
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);
821 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
822 SetDownloadPathForProfile(browser()->profile());
823 SetDownloadPathForProfile(other_profile);
824 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser()));
826 RepeatedNotificationObserver close_observer(
827 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
828 browser()->window()->Close();
829 close_observer.Wait();
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());
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());
854 if (browser_defaults::kBrowserAliveWithNoWindows)
855 EXPECT_EQ(1, DownloadService::NonMaliciousDownloadCountAllProfiles());
856 else
857 EXPECT_EQ(0, DownloadService::NonMaliciousDownloadCountAllProfiles());
860 // Test shutdown with downloads in progress and beforeunload handlers.
861 // Disabled, see http://crbug.com/315754.
862 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerWithDownloadsBrowserTest,
863 DISABLED_TestBeforeUnloadAndDownloads) {
864 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
865 SetDownloadPathForProfile(browser()->profile());
866 ASSERT_NO_FATAL_FAILURE(CreateStalledDownload(browser()));
867 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
868 browser(), embedded_test_server()->GetURL("/beforeunload.html")));
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());
879 RepeatedNotificationObserver close_observer(
880 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
881 TestBrowserCloseManager::AttemptClose(
882 TestBrowserCloseManager::USER_CHOICE_USER_ALLOWS_CLOSE);
883 ASSERT_NO_FATAL_FAILURE(dialogs_.AcceptClose());
884 close_observer.Wait();
885 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
886 EXPECT_TRUE(chrome::BrowserIterator().done());
889 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithDownloadsBrowserTest,
890 BrowserCloseManagerWithDownloadsBrowserTest,
891 testing::Bool());
893 class BrowserCloseManagerWithBackgroundModeBrowserTest
894 : public BrowserCloseManagerBrowserTest {
895 public:
896 BrowserCloseManagerWithBackgroundModeBrowserTest() {}
898 virtual void SetUpOnMainThread() OVERRIDE {
899 BrowserCloseManagerBrowserTest::SetUpOnMainThread();
900 g_browser_process->set_background_mode_manager_for_test(
901 scoped_ptr<BackgroundModeManager>(new FakeBackgroundModeManager));
904 bool IsBackgroundModeSuspended() {
905 return static_cast<FakeBackgroundModeManager*>(
906 g_browser_process->background_mode_manager())
907 ->IsBackgroundModeSuspended();
910 private:
911 DISALLOW_COPY_AND_ASSIGN(BrowserCloseManagerWithBackgroundModeBrowserTest);
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();
922 RepeatedNotificationObserver close_observer(
923 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
924 chrome::IncrementKeepAliveCount();
925 chrome::CloseAllBrowsers();
926 close_observer.Wait();
928 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
929 EXPECT_TRUE(chrome::BrowserIterator().done());
930 EXPECT_TRUE(IsBackgroundModeSuspended());
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();
936 chrome::DecrementKeepAliveCount();
937 EXPECT_FALSE(IsBackgroundModeSuspended());
938 RepeatedNotificationObserver close_observer(
939 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
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());
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());
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());
971 chrome::IncrementKeepAliveCount();
972 browser()->window()->Close();
973 close_observer.Wait();
974 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
975 EXPECT_TRUE(chrome::BrowserIterator().done());
976 EXPECT_FALSE(IsBackgroundModeSuspended());
978 chrome::CloseAllBrowsers();
979 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
980 EXPECT_TRUE(chrome::BrowserIterator().done());
981 EXPECT_TRUE(IsBackgroundModeSuspended());
984 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest,
985 BrowserCloseManagerWithBackgroundModeBrowserTest,
986 testing::Bool());