Chromium Code Reviews| 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 slow to respond are not closed prematurely. | |
| 483 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, | |
| 484 TestUnloadMultipleSlowTabs) { | |
| 485 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 486 for (int i = 0; i < 7; i++) { | |
|
Charlie Reis
2016/05/13 22:24:01
Can you add a comment to this block saying why you
Mikhail Goncharov
2016/05/16 06:10:30
I have added comment and uploaded next patchset.
| |
| 487 if (i) | |
| 488 AddBlankTabAndShow(browsers_[0]); | |
| 489 if (i == 3) { | |
| 490 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( | |
| 491 browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); | |
| 492 } else { | |
| 493 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( | |
| 494 browsers_[0], | |
| 495 embedded_test_server()->GetURL("/beforeunload_slow.html"))); | |
| 496 } | |
| 497 } | |
| 498 RepeatedNotificationObserver cancel_observer( | |
| 499 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1); | |
| 500 chrome::CloseAllBrowsersAndQuit(); | |
| 501 ASSERT_NO_FATAL_FAILURE(CancelClose()); | |
| 502 cancel_observer.Wait(); | |
| 503 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | |
| 504 // All tabs should still be open. | |
| 505 EXPECT_EQ(7, browsers_[0]->tab_strip_model()->count()); | |
| 506 | |
| 507 RepeatedNotificationObserver close_observer( | |
| 508 chrome::NOTIFICATION_BROWSER_CLOSED, 1); | |
| 509 chrome::CloseAllBrowsersAndQuit(); | |
| 510 ASSERT_NO_FATAL_FAILURE(AcceptClose()); | |
| 511 close_observer.Wait(); | |
| 512 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | |
| 513 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | |
| 514 } | |
| 515 | |
| 516 // Test that tabs in different windows with a slow beforeunload event response | |
| 517 // are treated the same as the user accepting the close, but do not close the | |
| 518 // tab early. | |
| 519 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, | |
| 520 TestBeforeUnloadMultipleSlowWindows) { | |
|
Charlie Reis
2016/05/13 22:24:01
Is there a meaningful difference between slow wind
Mikhail Goncharov
2016/05/16 04:50:40
There is a subtle difference on how unload control
| |
| 521 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 522 for (int i = 0; i < 5; i++) { | |
| 523 if (i) | |
| 524 browsers_.push_back(CreateBrowser(browser()->profile())); | |
| 525 if (i == 2) { | |
| 526 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( | |
| 527 browsers_[i], embedded_test_server()->GetURL("/beforeunload.html"))); | |
| 528 } else { | |
| 529 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( | |
| 530 browsers_[i], | |
| 531 embedded_test_server()->GetURL("/beforeunload_slow.html"))); | |
| 532 } | |
| 533 } | |
| 534 | |
| 535 RepeatedNotificationObserver cancel_observer( | |
| 536 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 3); | |
| 537 chrome::CloseAllBrowsersAndQuit(); | |
| 538 ASSERT_NO_FATAL_FAILURE(CancelClose()); | |
| 539 cancel_observer.Wait(); | |
| 540 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | |
| 541 // All windows should still be open. | |
| 542 for (int i = 0; i < 5; i++) | |
| 543 EXPECT_EQ(1, browsers_[i]->tab_strip_model()->count()); | |
| 544 | |
| 545 RepeatedNotificationObserver close_observer( | |
| 546 chrome::NOTIFICATION_BROWSER_CLOSED, 5); | |
| 547 chrome::CloseAllBrowsersAndQuit(); | |
| 548 ASSERT_NO_FATAL_FAILURE(AcceptClose()); | |
| 549 close_observer.Wait(); | |
| 550 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | |
| 551 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | |
| 552 } | |
| 553 | |
| 482 // Test that a window created during shutdown is closed. | 554 // Test that a window created during shutdown is closed. |
| 483 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, | 555 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, |
| 484 TestAddWindowDuringShutdown) { | 556 TestAddWindowDuringShutdown) { |
| 485 ASSERT_TRUE(embedded_test_server()->Start()); | 557 ASSERT_TRUE(embedded_test_server()->Start()); |
| 486 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( | 558 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
| 487 browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); | 559 browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); |
| 488 | 560 |
| 489 RepeatedNotificationObserver close_observer( | 561 RepeatedNotificationObserver close_observer( |
| 490 chrome::NOTIFICATION_BROWSER_CLOSED, 2); | 562 chrome::NOTIFICATION_BROWSER_CLOSED, 2); |
| 491 chrome::CloseAllBrowsersAndQuit(); | 563 chrome::CloseAllBrowsersAndQuit(); |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1033 | 1105 |
| 1034 chrome::CloseAllBrowsers(); | 1106 chrome::CloseAllBrowsers(); |
| 1035 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 1107 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
| 1036 EXPECT_TRUE(BrowserList::GetInstance()->empty()); | 1108 EXPECT_TRUE(BrowserList::GetInstance()->empty()); |
| 1037 EXPECT_TRUE(IsBackgroundModeSuspended()); | 1109 EXPECT_TRUE(IsBackgroundModeSuspended()); |
| 1038 } | 1110 } |
| 1039 | 1111 |
| 1040 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, | 1112 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
| 1041 BrowserCloseManagerWithBackgroundModeBrowserTest, | 1113 BrowserCloseManagerWithBackgroundModeBrowserTest, |
| 1042 testing::Bool()); | 1114 testing::Bool()); |
| OLD | NEW |