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

Side by Side Diff: chrome/browser/unload_browsertest.cc

Issue 2681203002: Add Browser::SkipCallBeforeUnload so that the browser windows can be closed regardless of beforeunl… (Closed)
Patch Set: cr - remove delegate in UnloadController Created 3 years, 9 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
« no previous file with comments | « chrome/browser/ui/unload_controller_web_contents_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #if defined(OS_POSIX) 5 #if defined(OS_POSIX)
6 #include <signal.h> 6 #include <signal.h>
7 #endif 7 #endif
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseNoUnloadListeners) { 319 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseNoUnloadListeners) {
320 NavigateToDataURL(NOLISTENERS_HTML, "nolisteners"); 320 NavigateToDataURL(NOLISTENERS_HTML, "nolisteners");
321 321
322 content::WindowedNotificationObserver window_observer( 322 content::WindowedNotificationObserver window_observer(
323 chrome::NOTIFICATION_BROWSER_CLOSED, 323 chrome::NOTIFICATION_BROWSER_CLOSED,
324 content::NotificationService::AllSources()); 324 content::NotificationService::AllSources());
325 UnloadResults unload_results; 325 UnloadResults unload_results;
326 BrowserList::CloseAllBrowsersWithProfile( 326 BrowserList::CloseAllBrowsersWithProfile(
327 browser()->profile(), 327 browser()->profile(),
328 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 328 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
329 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results))); 329 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
330 false);
330 window_observer.Wait(); 331 window_observer.Wait();
331 EXPECT_EQ(1, unload_results.get_successes()); 332 EXPECT_EQ(1, unload_results.get_successes());
332 EXPECT_EQ(0, unload_results.get_aborts()); 333 EXPECT_EQ(0, unload_results.get_aborts());
333 } 334 }
334 335
335 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a 336 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a
336 // beforeunload handler and clicking Leave in the beforeunload confirm dialog. 337 // beforeunload handler and clicking Leave in the beforeunload confirm dialog.
337 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadOK) { 338 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadOK) {
338 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 339 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
339 340
340 content::WindowedNotificationObserver window_observer( 341 content::WindowedNotificationObserver window_observer(
341 chrome::NOTIFICATION_BROWSER_CLOSED, 342 chrome::NOTIFICATION_BROWSER_CLOSED,
342 content::NotificationService::AllSources()); 343 content::NotificationService::AllSources());
343 UnloadResults unload_results; 344 UnloadResults unload_results;
344 BrowserList::CloseAllBrowsersWithProfile( 345 BrowserList::CloseAllBrowsersWithProfile(
345 browser()->profile(), 346 browser()->profile(),
346 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 347 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
347 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results))); 348 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
349 false);
348 ClickModalDialogButton(true); 350 ClickModalDialogButton(true);
349 window_observer.Wait(); 351 window_observer.Wait();
350 EXPECT_EQ(1, unload_results.get_successes()); 352 EXPECT_EQ(1, unload_results.get_successes());
351 EXPECT_EQ(0, unload_results.get_aborts()); 353 EXPECT_EQ(0, unload_results.get_aborts());
352 } 354 }
353 355
354 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a 356 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with a
355 // beforeunload handler and clicking Stay in the beforeunload confirm dialog. 357 // beforeunload handler and clicking Stay in the beforeunload confirm dialog.
356 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadCancel) { 358 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadCancel) {
357 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 359 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
358 360
359 UnloadResults unload_results; 361 UnloadResults unload_results;
360 BrowserList::CloseAllBrowsersWithProfile( 362 BrowserList::CloseAllBrowsersWithProfile(
361 browser()->profile(), 363 browser()->profile(),
362 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 364 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
363 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results))); 365 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
366 false);
364 367
365 // We wait for the title to change after cancelling the closure of browser 368 // We wait for the title to change after cancelling the closure of browser
366 // window, to ensure that in-flight IPCs from the renderer reach the browser. 369 // window, to ensure that in-flight IPCs from the renderer reach the browser.
367 // Otherwise the browser won't put up the beforeunload dialog because it's 370 // Otherwise the browser won't put up the beforeunload dialog because it's
368 // waiting for an ack from the renderer. 371 // waiting for an ack from the renderer.
369 base::string16 expected_title = base::ASCIIToUTF16("cancelled"); 372 base::string16 expected_title = base::ASCIIToUTF16("cancelled");
370 content::TitleWatcher title_watcher( 373 content::TitleWatcher title_watcher(
371 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); 374 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
372 ClickModalDialogButton(false); 375 ClickModalDialogButton(false);
373 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 376 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
(...skipping 16 matching lines...) Expand all
390 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadOK) { 393 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadOK) {
391 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 394 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
392 395
393 content::WindowedNotificationObserver window_observer( 396 content::WindowedNotificationObserver window_observer(
394 chrome::NOTIFICATION_BROWSER_CLOSED, 397 chrome::NOTIFICATION_BROWSER_CLOSED,
395 content::NotificationService::AllSources()); 398 content::NotificationService::AllSources());
396 UnloadResults unload_results; 399 UnloadResults unload_results;
397 BrowserList::CloseAllBrowsersWithProfile( 400 BrowserList::CloseAllBrowsersWithProfile(
398 browser()->profile(), 401 browser()->profile(),
399 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 402 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
400 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results))); 403 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
404 false);
401 BrowserList::CloseAllBrowsersWithProfile( 405 BrowserList::CloseAllBrowsersWithProfile(
402 browser()->profile(), 406 browser()->profile(),
403 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 407 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
404 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results))); 408 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
409 false);
405 ClickModalDialogButton(true); 410 ClickModalDialogButton(true);
406 window_observer.Wait(); 411 window_observer.Wait();
407 EXPECT_EQ(1, unload_results.get_successes()); 412 EXPECT_EQ(1, unload_results.get_successes());
408 EXPECT_EQ(0, unload_results.get_aborts()); 413 EXPECT_EQ(0, unload_results.get_aborts());
409 } 414 }
410 415
411 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a 416 // Tests double calls to BrowserList::CloseAllBrowsersWithProfile, with a
412 // beforeunload handler and clicking Stay in the beforeunload confirm dialog. 417 // beforeunload handler and clicking Stay in the beforeunload confirm dialog.
413 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadCancel) { 418 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadCancel) {
414 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 419 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
415 420
416 UnloadResults unload_results; 421 UnloadResults unload_results;
417 BrowserList::CloseAllBrowsersWithProfile( 422 BrowserList::CloseAllBrowsersWithProfile(
418 browser()->profile(), 423 browser()->profile(),
419 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 424 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
420 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results))); 425 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
426 false);
421 BrowserList::CloseAllBrowsersWithProfile( 427 BrowserList::CloseAllBrowsersWithProfile(
422 browser()->profile(), 428 browser()->profile(),
423 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 429 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
424 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results))); 430 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
431 false);
425 432
426 // We wait for the title to change after cancelling the closure of browser 433 // We wait for the title to change after cancelling the closure of browser
427 // window, to ensure that in-flight IPCs from the renderer reach the browser. 434 // window, to ensure that in-flight IPCs from the renderer reach the browser.
428 // Otherwise the browser won't put up the beforeunload dialog because it's 435 // Otherwise the browser won't put up the beforeunload dialog because it's
429 // waiting for an ack from the renderer. 436 // waiting for an ack from the renderer.
430 base::string16 expected_title = base::ASCIIToUTF16("cancelled"); 437 base::string16 expected_title = base::ASCIIToUTF16("cancelled");
431 content::TitleWatcher title_watcher( 438 content::TitleWatcher title_watcher(
432 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); 439 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
433 ClickModalDialogButton(false); 440 ClickModalDialogButton(false);
434 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 441 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 CheckTitle("popup"); 569 CheckTitle("popup");
563 570
564 content::WebContentsDestroyedWatcher destroyed_watcher( 571 content::WebContentsDestroyedWatcher destroyed_watcher(
565 browser()->tab_strip_model()->GetActiveWebContents()); 572 browser()->tab_strip_model()->GetActiveWebContents());
566 chrome::CloseTab(browser()); 573 chrome::CloseTab(browser());
567 destroyed_watcher.Wait(); 574 destroyed_watcher.Wait();
568 575
569 CheckTitle("only_one_unload"); 576 CheckTitle("only_one_unload");
570 } 577 }
571 578
579 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListForceCloseNoUnloadListeners) {
580 NavigateToDataURL(NOLISTENERS_HTML, "nolisteners");
581
582 content::WindowedNotificationObserver window_observer(
583 chrome::NOTIFICATION_BROWSER_CLOSED,
584 content::NotificationService::AllSources());
585 UnloadResults unload_results;
586 BrowserList::CloseAllBrowsersWithProfile(
587 browser()->profile(),
588 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
589 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
590 true);
591 window_observer.Wait();
592 EXPECT_EQ(1, unload_results.get_successes());
593 EXPECT_EQ(0, unload_results.get_aborts());
594 }
595
596 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListForceCloseWithBeforeUnload) {
597 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
598
599 content::WindowedNotificationObserver window_observer(
600 chrome::NOTIFICATION_BROWSER_CLOSED,
601 content::NotificationService::AllSources());
602 UnloadResults unload_results;
603 BrowserList::CloseAllBrowsersWithProfile(
604 browser()->profile(),
605 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
606 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
607 true);
608 window_observer.Wait();
609 EXPECT_EQ(1, unload_results.get_successes());
610 EXPECT_EQ(0, unload_results.get_aborts());
611 }
612
613 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListForceCloseAfterNormalClose) {
614 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
615
616 content::WindowedNotificationObserver window_observer(
617 chrome::NOTIFICATION_BROWSER_CLOSED,
618 content::NotificationService::AllSources());
619 UnloadResults unload_results;
620 BrowserList::CloseAllBrowsersWithProfile(
621 browser()->profile(),
622 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
623 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
624 false);
625 BrowserList::CloseAllBrowsersWithProfile(
626 browser()->profile(),
627 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
628 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
629 true);
630 window_observer.Wait();
631 EXPECT_EQ(1, unload_results.get_successes());
632 EXPECT_EQ(0, unload_results.get_aborts());
633 }
634
572 class FastUnloadTest : public UnloadTest { 635 class FastUnloadTest : public UnloadTest {
573 public: 636 public:
574 void SetUpCommandLine(base::CommandLine* command_line) override { 637 void SetUpCommandLine(base::CommandLine* command_line) override {
575 UnloadTest::SetUpCommandLine(command_line); 638 UnloadTest::SetUpCommandLine(command_line);
576 command_line->AppendSwitch(switches::kEnableFastUnload); 639 command_line->AppendSwitch(switches::kEnableFastUnload);
577 } 640 }
578 641
579 void SetUpInProcessBrowserTestFixture() override { 642 void SetUpInProcessBrowserTestFixture() override {
580 ASSERT_TRUE(embedded_test_server()->Start()); 643 ASSERT_TRUE(embedded_test_server()->Start());
581 } 644 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 browser()->tab_strip_model()->GetActiveWebContents(); 845 browser()->tab_strip_model()->GetActiveWebContents();
783 846
784 content::WindowedNotificationObserver window_observer( 847 content::WindowedNotificationObserver window_observer(
785 chrome::NOTIFICATION_BROWSER_CLOSED, 848 chrome::NOTIFICATION_BROWSER_CLOSED,
786 content::NotificationService::AllSources()); 849 content::NotificationService::AllSources());
787 chrome::CloseWindow(browser()); 850 chrome::CloseWindow(browser());
788 CrashTab(beforeunload_contents); 851 CrashTab(beforeunload_contents);
789 window_observer.Wait(); 852 window_observer.Wait();
790 } 853 }
791 854
855 IN_PROC_BROWSER_TEST_F(FastUnloadTest,
856 BrowserListForceCloseNoUnloadListenersWithFastUnload) {
857 NavigateToDataURL(NOLISTENERS_HTML, "nolisteners");
858
859 content::WindowedNotificationObserver window_observer(
860 chrome::NOTIFICATION_BROWSER_CLOSED,
861 content::NotificationService::AllSources());
862 UnloadResults unload_results;
863 BrowserList::CloseAllBrowsersWithProfile(
864 browser()->profile(),
865 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
866 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
867 true);
868 window_observer.Wait();
869 EXPECT_EQ(1, unload_results.get_successes());
870 EXPECT_EQ(0, unload_results.get_aborts());
871 }
872
873 IN_PROC_BROWSER_TEST_F(FastUnloadTest,
874 BrowserListForceCloseWithBeforeUnloadWithFastUnload) {
875 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
876
877 content::WindowedNotificationObserver window_observer(
878 chrome::NOTIFICATION_BROWSER_CLOSED,
879 content::NotificationService::AllSources());
880 UnloadResults unload_results;
881 BrowserList::CloseAllBrowsersWithProfile(
882 browser()->profile(),
883 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
884 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
885 true);
886 window_observer.Wait();
887 EXPECT_EQ(1, unload_results.get_successes());
888 EXPECT_EQ(0, unload_results.get_aborts());
889 }
890
891 IN_PROC_BROWSER_TEST_F(FastUnloadTest,
892 BrowserListForceCloseAfterNormalCloseWithFastUnload) {
893 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
894
895 content::WindowedNotificationObserver window_observer(
896 chrome::NOTIFICATION_BROWSER_CLOSED,
897 content::NotificationService::AllSources());
898 UnloadResults unload_results;
899 BrowserList::CloseAllBrowsersWithProfile(
900 browser()->profile(),
901 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
902 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
903 false);
904 BrowserList::CloseAllBrowsersWithProfile(
905 browser()->profile(),
906 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
907 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
908 true);
909 window_observer.Wait();
910 EXPECT_EQ(1, unload_results.get_successes());
911 EXPECT_EQ(0, unload_results.get_aborts());
912 }
913
792 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 914 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
793 // and multiple windows. 915 // and multiple windows.
OLDNEW
« no previous file with comments | « chrome/browser/ui/unload_controller_web_contents_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698