| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/lifetime/browser_close_manager.h" | 5 #include "chrome/browser/lifetime/browser_close_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 472 |
| 473 RepeatedNotificationObserver close_observer( | 473 RepeatedNotificationObserver close_observer( |
| 474 chrome::NOTIFICATION_BROWSER_CLOSED, 3); | 474 chrome::NOTIFICATION_BROWSER_CLOSED, 3); |
| 475 chrome::CloseAllBrowsersAndQuit(); | 475 chrome::CloseAllBrowsersAndQuit(); |
| 476 ASSERT_NO_FATAL_FAILURE(AcceptClose()); | 476 ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 477 close_observer.Wait(); | 477 close_observer.Wait(); |
| 478 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 478 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 479 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 479 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
| 480 } | 480 } |
| 481 | 481 |
| 482 // Test that tabs that are slow to respond are not closed prematurely. |
| 483 // Regression for crbug.com/365052 caused some of tabs to be closed even if |
| 484 // user chose to cancel browser close. |
| 485 // |
| 486 // Test is disabled as it likely to flack for the same reason as |
| 487 // TestHangInBeforeUnloadMultipleTabs: there is a chance (especially under |
| 488 // load) that normal tab will not answer within |
| 489 // RenderViewHostImpl::kUnloadTimeoutMS thus |AcceptClose| or |CancelClose| |
| 490 // will not find a dialog and fail. |
| 491 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
| 492 DISABLED_TestUnloadMultipleSlowTabs) { |
| 493 ASSERT_TRUE(embedded_test_server()->Start()); |
| 494 const int kTabCount = 5; |
| 495 const int kResposiveTabIndex = 2; |
| 496 // Create tab strip with all tabs except one responding after |
| 497 // RenderViewHostImpl::kUnloadTimeoutMS. |
| 498 // Minimum configuration is two slow tabs and then responsive tab. |
| 499 // But we also want to check how slow tabs behave in tail. |
| 500 for (int i = 0; i < kTabCount; i++) { |
| 501 if (i) |
| 502 AddBlankTabAndShow(browsers_[0]); |
| 503 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 504 browsers_[0], |
| 505 embedded_test_server()->GetURL((i == kResposiveTabIndex) |
| 506 ? "/beforeunload.html" |
| 507 : "/beforeunload_slow.html"))); |
| 508 } |
| 509 RepeatedNotificationObserver cancel_observer( |
| 510 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); |
| 511 chrome::CloseAllBrowsersAndQuit(); |
| 512 ASSERT_NO_FATAL_FAILURE(CancelClose()); |
| 513 cancel_observer.Wait(); |
| 514 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 515 |
| 516 // All tabs should still be open. |
| 517 EXPECT_EQ(kTabCount, browsers_[0]->tab_strip_model()->count()); |
| 518 RepeatedNotificationObserver close_observer( |
| 519 chrome::NOTIFICATION_BROWSER_CLOSED, 1); |
| 520 |
| 521 // Quit, this time accepting close confirmation dialog. |
| 522 chrome::CloseAllBrowsersAndQuit(); |
| 523 ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 524 close_observer.Wait(); |
| 525 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 526 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
| 527 } |
| 528 |
| 529 // Test that tabs in different windows with a slow beforeunload event response |
| 530 // are treated the same as the user accepting the close, but do not close the |
| 531 // tab early. |
| 532 // Regression for crbug.com/365052 caused CHECK in tabstrip. |
| 533 // |
| 534 // Test is disabled as it likely to flack for the same reason as |
| 535 // TestHangInBeforeUnloadMultipleTabs: there is a chance (especially under |
| 536 // load) that normal tab will not answer within |
| 537 // RenderViewHostImpl::kUnloadTimeoutMS thus |AcceptClose| or |CancelClose| |
| 538 // will not find a dialog and fail. |
| 539 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
| 540 DISABLED_TestBeforeUnloadMultipleSlowWindows) { |
| 541 ASSERT_TRUE(embedded_test_server()->Start()); |
| 542 const int kBrowserCount = 5; |
| 543 const int kResposiveBrowserIndex = 2; |
| 544 // Create multiple browsers with all tabs except one responding after |
| 545 // RenderViewHostImpl::kUnloadTimeoutMS . |
| 546 // Minimum configuration is just one browser with slow tab and then |
| 547 // browser with responsive tab. |
| 548 // But we also want to check how slow tabs behave in tail and make test |
| 549 // more robust. |
| 550 for (int i = 0; i < kBrowserCount; i++) { |
| 551 if (i) |
| 552 browsers_.push_back(CreateBrowser(browser()->profile())); |
| 553 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 554 browsers_[i], |
| 555 embedded_test_server()->GetURL((i == kResposiveBrowserIndex) |
| 556 ? "/beforeunload.html" |
| 557 : "/beforeunload_slow.html"))); |
| 558 } |
| 559 |
| 560 RepeatedNotificationObserver cancel_observer( |
| 561 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, kResposiveBrowserIndex + 1); |
| 562 chrome::CloseAllBrowsersAndQuit(); |
| 563 ASSERT_NO_FATAL_FAILURE(CancelClose()); |
| 564 cancel_observer.Wait(); |
| 565 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 566 |
| 567 // All windows should still be open. |
| 568 for (int i = 0; i < kBrowserCount; i++) |
| 569 EXPECT_EQ(1, browsers_[i]->tab_strip_model()->count()); |
| 570 |
| 571 // Quit, this time accepting close confirmation dialog. |
| 572 RepeatedNotificationObserver close_observer( |
| 573 chrome::NOTIFICATION_BROWSER_CLOSED, kBrowserCount); |
| 574 chrome::CloseAllBrowsersAndQuit(); |
| 575 ASSERT_NO_FATAL_FAILURE(AcceptClose()); |
| 576 close_observer.Wait(); |
| 577 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 578 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
| 579 } |
| 580 |
| 482 // Test that a window created during shutdown is closed. | 581 // Test that a window created during shutdown is closed. |
| 483 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, | 582 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
| 484 TestAddWindowDuringShutdown) { | 583 TestAddWindowDuringShutdown) { |
| 485 ASSERT_TRUE(embedded_test_server()->Start()); | 584 ASSERT_TRUE(embedded_test_server()->Start()); |
| 486 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( | 585 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 487 browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); | 586 browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 488 | 587 |
| 489 RepeatedNotificationObserver close_observer( | 588 RepeatedNotificationObserver close_observer( |
| 490 chrome::NOTIFICATION_BROWSER_CLOSED, 2); | 589 chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
| 491 chrome::CloseAllBrowsersAndQuit(); | 590 chrome::CloseAllBrowsersAndQuit(); |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 | 1132 |
| 1034 chrome::CloseAllBrowsers(); | 1133 chrome::CloseAllBrowsers(); |
| 1035 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 1134 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 1036 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 1135 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
| 1037 EXPECT_TRUE(IsBackgroundModeSuspended()); | 1136 EXPECT_TRUE(IsBackgroundModeSuspended()); |
| 1038 } | 1137 } |
| 1039 | 1138 |
| 1040 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, | 1139 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
| 1041 BrowserCloseManagerWithBackgroundModeBrowserTest, | 1140 BrowserCloseManagerWithBackgroundModeBrowserTest, |
| 1042 testing::Bool()); | 1141 testing::Bool()); |
| OLD | NEW |