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

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

Issue 2943693002: Fix TryToCloseBrowserList not checking for null callbacks (Closed)
Patch Set: Incorporate treib@'s comment change into the CL. Created 3 years, 6 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/browser_list.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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 // The test harness cannot close the window automatically, because it requires 456 // The test harness cannot close the window automatically, because it requires
457 // confirmation. We close the window manually instead. 457 // confirmation. We close the window manually instead.
458 content::WindowedNotificationObserver window_observer( 458 content::WindowedNotificationObserver window_observer(
459 chrome::NOTIFICATION_BROWSER_CLOSED, 459 chrome::NOTIFICATION_BROWSER_CLOSED,
460 content::NotificationService::AllSources()); 460 content::NotificationService::AllSources());
461 chrome::CloseWindow(browser()); 461 chrome::CloseWindow(browser());
462 ClickModalDialogButton(true); 462 ClickModalDialogButton(true);
463 window_observer.Wait(); 463 window_observer.Wait();
464 } 464 }
465 465
466 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with
467 // a null success callback, a beforeunload handler and clicking Leave in the
468 // beforeunload confirm dialog. The test succeed if no crash happens.
469 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadNullCallbackOk) {
470 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
471 PrepareForDialog(browser());
472
473 content::WindowedNotificationObserver window_observer(
474 chrome::NOTIFICATION_BROWSER_CLOSED,
475 content::NotificationService::AllSources());
476 UnloadResults unload_results;
477 BrowserList::CloseAllBrowsersWithProfile(browser()->profile(),
478 BrowserList::CloseCallback(),
479 BrowserList::CloseCallback(), false);
480 ClickModalDialogButton(true);
481 window_observer.Wait();
482 }
483
484 // Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with
485 // a null failure callback, a beforeunload handler and clicking Stay in the
486 // beforeunload confirm dialog. The test succeed if no crash happens.
487 IN_PROC_BROWSER_TEST_F(UnloadTest,
488 BrowserListCloseBeforeUnloadNullCallbackCancel) {
489 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
490 PrepareForDialog(browser());
491
492 UnloadResults unload_results;
493 BrowserList::CloseAllBrowsersWithProfile(browser()->profile(),
494 BrowserList::CloseCallback(),
495 BrowserList::CloseCallback(), false);
496
497 // We wait for the title to change after cancelling the closure of browser
498 // window, to ensure that in-flight IPCs from the renderer reach the browser.
499 // Otherwise the browser won't put up the beforeunload dialog because it's
500 // waiting for an ack from the renderer.
501 base::string16 expected_title = base::ASCIIToUTF16("cancelled");
502 content::TitleWatcher title_watcher(
503 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
504 ClickModalDialogButton(false);
505 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
506
507 // The test harness cannot close the window automatically, because it requires
508 // confirmation. We close the window manually instead.
509 content::WindowedNotificationObserver window_observer(
510 chrome::NOTIFICATION_BROWSER_CLOSED,
511 content::NotificationService::AllSources());
512 chrome::CloseWindow(browser());
513 ClickModalDialogButton(true);
514 window_observer.Wait();
515 }
516
466 // Tests terminating the browser with a beforeunload handler. 517 // Tests terminating the browser with a beforeunload handler.
467 // Currently only ChromeOS shuts down gracefully. 518 // Currently only ChromeOS shuts down gracefully.
468 #if defined(OS_CHROMEOS) 519 #if defined(OS_CHROMEOS)
469 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserTerminateBeforeUnload) { 520 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserTerminateBeforeUnload) {
470 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); 521 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
471 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM), 0); 522 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM), 0);
472 } 523 }
473 #endif 524 #endif
474 525
475 // Tests closing the browser and clicking OK in the beforeunload confirm dialog 526 // Tests closing the browser and clicking OK in the beforeunload confirm dialog
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)), 967 base::Bind(&UnloadResults::AddSuccess, base::Unretained(&unload_results)),
917 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)), 968 base::Bind(&UnloadResults::AddAbort, base::Unretained(&unload_results)),
918 true); 969 true);
919 window_observer.Wait(); 970 window_observer.Wait();
920 EXPECT_EQ(1, unload_results.get_successes()); 971 EXPECT_EQ(1, unload_results.get_successes());
921 EXPECT_EQ(0, unload_results.get_aborts()); 972 EXPECT_EQ(0, unload_results.get_aborts());
922 } 973 }
923 974
924 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 975 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
925 // and multiple windows. 976 // and multiple windows.
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698