Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chrome/browser/lifetime/browser_close_manager_browsertest.cc

Issue 1968933002: Fix: tabs slow to response to beforeunload are closed prematurely. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use whole rfhi::BeforeUnloadAck Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 chrbug.com/365052 caused some of tabs to be closed even if
Charlie Reis 2016/05/19 22:11:56 nit: No h in crbug.com.
484 // user chose to cancel browser close.
485 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest,
486 TestUnloadMultipleSlowTabs) {
487 ASSERT_TRUE(embedded_test_server()->Start());
488 const int kTabCount = 5;
489 const int kResposiveTabIndex = 2;
490 // Create tab strip with all tabs except one responding after
491 // RenderViewHostImpl::kUnloadTimeoutMS .
Charlie Reis 2016/05/19 22:11:55 nit: No space before period.
492 // Minimum configuration is two slow tabs and then responsive tab.
493 // But we also want to check how slow tabs behave in tail.
494 for (int i = 0; i < kTabCount; i++) {
495 if (i)
496 AddBlankTabAndShow(browsers_[0]);
497 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
498 browsers_[0],
499 embedded_test_server()->GetURL((i == kResposiveTabIndex)
500 ? "/beforeunload.html"
501 : "/beforeunload_slow.html")));
502 }
503 RepeatedNotificationObserver cancel_observer(
504 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 1);
505 chrome::CloseAllBrowsersAndQuit();
506 ASSERT_NO_FATAL_FAILURE(CancelClose());
Charlie Reis 2016/05/19 22:11:55 Yep, this is where the test will be flaky, as you
Mikhail Goncharov 2016/05/20 04:20:01 That's right. I have experimented with different t
507 cancel_observer.Wait();
508 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
509 // All tabs should still be open.
Charlie Reis 2016/05/19 22:11:56 nit: Add blank line before.
510 EXPECT_EQ(kTabCount, browsers_[0]->tab_strip_model()->count());
511 RepeatedNotificationObserver close_observer(
Charlie Reis 2016/05/19 22:11:56 nit: Add blank line and comment before (e.g., Quit
512 chrome::NOTIFICATION_BROWSER_CLOSED, 1);
513 chrome::CloseAllBrowsersAndQuit();
514 ASSERT_NO_FATAL_FAILURE(AcceptClose());
515 close_observer.Wait();
516 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
517 EXPECT_TRUE(BrowserList::GetInstance()->empty());
518 }
519
520 // Test that tabs in different windows with a slow beforeunload event response
521 // are treated the same as the user accepting the close, but do not close the
522 // tab early.
523 // Regression for chrbug.com/365052 caused CHECK in tabstrip.
Charlie Reis 2016/05/19 22:11:55 nit: No h in crbug.com.
524 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest,
525 TestBeforeUnloadMultipleSlowWindows) {
526 ASSERT_TRUE(embedded_test_server()->Start());
527 const int kBrowserCount = 5;
528 const int kResposiveBrowserIndex = 2;
529 // Create multiple browsers with all tabs except one responding after
530 // RenderViewHostImpl::kUnloadTimeoutMS .
531 // Minimum configuration is just one browser with slow tab and then
532 // browser with responsive tab.
533 // But we also want to check how slow tabs behave in tail and make test
534 // more robust.
535 for (int i = 0; i < kBrowserCount; i++) {
536 if (i)
537 browsers_.push_back(CreateBrowser(browser()->profile()));
538 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
539 browsers_[i],
540 embedded_test_server()->GetURL((i == kResposiveBrowserIndex)
541 ? "/beforeunload.html"
542 : "/beforeunload_slow.html")));
543 }
544
545 RepeatedNotificationObserver cancel_observer(
546 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, kResposiveBrowserIndex + 1);
547 chrome::CloseAllBrowsersAndQuit();
548 ASSERT_NO_FATAL_FAILURE(CancelClose());
549 cancel_observer.Wait();
550 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
551 // All windows should still be open.
Charlie Reis 2016/05/19 22:11:55 nit: Blank line before.
552 for (int i = 0; i < kBrowserCount; i++)
553 EXPECT_EQ(1, browsers_[i]->tab_strip_model()->count());
554
555 RepeatedNotificationObserver close_observer(
Charlie Reis 2016/05/19 22:11:55 nit: Comment before.
556 chrome::NOTIFICATION_BROWSER_CLOSED, kBrowserCount);
557 chrome::CloseAllBrowsersAndQuit();
558 ASSERT_NO_FATAL_FAILURE(AcceptClose());
559 close_observer.Wait();
560 EXPECT_TRUE(browser_shutdown::IsTryingToQuit());
561 EXPECT_TRUE(BrowserList::GetInstance()->empty());
562 }
563
482 // Test that a window created during shutdown is closed. 564 // Test that a window created during shutdown is closed.
483 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, 565 IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest,
484 TestAddWindowDuringShutdown) { 566 TestAddWindowDuringShutdown) {
485 ASSERT_TRUE(embedded_test_server()->Start()); 567 ASSERT_TRUE(embedded_test_server()->Start());
486 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( 568 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
487 browsers_[0], embedded_test_server()->GetURL("/beforeunload.html"))); 569 browsers_[0], embedded_test_server()->GetURL("/beforeunload.html")));
488 570
489 RepeatedNotificationObserver close_observer( 571 RepeatedNotificationObserver close_observer(
490 chrome::NOTIFICATION_BROWSER_CLOSED, 2); 572 chrome::NOTIFICATION_BROWSER_CLOSED, 2);
491 chrome::CloseAllBrowsersAndQuit(); 573 chrome::CloseAllBrowsersAndQuit();
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 1115
1034 chrome::CloseAllBrowsers(); 1116 chrome::CloseAllBrowsers();
1035 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); 1117 EXPECT_FALSE(browser_shutdown::IsTryingToQuit());
1036 EXPECT_TRUE(BrowserList::GetInstance()->empty()); 1118 EXPECT_TRUE(BrowserList::GetInstance()->empty());
1037 EXPECT_TRUE(IsBackgroundModeSuspended()); 1119 EXPECT_TRUE(IsBackgroundModeSuspended());
1038 } 1120 }
1039 1121
1040 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, 1122 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest,
1041 BrowserCloseManagerWithBackgroundModeBrowserTest, 1123 BrowserCloseManagerWithBackgroundModeBrowserTest,
1042 testing::Bool()); 1124 testing::Bool());
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/beforeunload_slow.html » ('j') | chrome/test/data/beforeunload_slow.html » ('J')

Powered by Google App Engine
This is Rietveld 408576698