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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/browser_list.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/unload_browsertest.cc
diff --git a/chrome/browser/unload_browsertest.cc b/chrome/browser/unload_browsertest.cc
index 92a2c1b618e0a861bfdbf4fcea7cc6afb1a72a00..4b5ac4d99723fb93bb2cd232f87d8f2c8afec85d 100644
--- a/chrome/browser/unload_browsertest.cc
+++ b/chrome/browser/unload_browsertest.cc
@@ -463,6 +463,57 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadCancel) {
window_observer.Wait();
}
+// Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with
+// a null success callback, a beforeunload handler and clicking Leave in the
+// beforeunload confirm dialog. The test succeed if no crash happens.
+IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadNullCallbackOk) {
+ NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
+ PrepareForDialog(browser());
+
+ content::WindowedNotificationObserver window_observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::NotificationService::AllSources());
+ UnloadResults unload_results;
+ BrowserList::CloseAllBrowsersWithProfile(browser()->profile(),
+ BrowserList::CloseCallback(),
+ BrowserList::CloseCallback(), false);
+ ClickModalDialogButton(true);
+ window_observer.Wait();
+}
+
+// Tests closing the browser by BrowserList::CloseAllBrowsersWithProfile, with
+// a null failure callback, a beforeunload handler and clicking Stay in the
+// beforeunload confirm dialog. The test succeed if no crash happens.
+IN_PROC_BROWSER_TEST_F(UnloadTest,
+ BrowserListCloseBeforeUnloadNullCallbackCancel) {
+ NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
+ PrepareForDialog(browser());
+
+ UnloadResults unload_results;
+ BrowserList::CloseAllBrowsersWithProfile(browser()->profile(),
+ BrowserList::CloseCallback(),
+ BrowserList::CloseCallback(), false);
+
+ // We wait for the title to change after cancelling the closure of browser
+ // window, to ensure that in-flight IPCs from the renderer reach the browser.
+ // Otherwise the browser won't put up the beforeunload dialog because it's
+ // waiting for an ack from the renderer.
+ base::string16 expected_title = base::ASCIIToUTF16("cancelled");
+ content::TitleWatcher title_watcher(
+ browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
+ ClickModalDialogButton(false);
+ ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
+
+ // The test harness cannot close the window automatically, because it requires
+ // confirmation. We close the window manually instead.
+ content::WindowedNotificationObserver window_observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::NotificationService::AllSources());
+ chrome::CloseWindow(browser());
+ ClickModalDialogButton(true);
+ window_observer.Wait();
+}
+
// Tests terminating the browser with a beforeunload handler.
// Currently only ChromeOS shuts down gracefully.
#if defined(OS_CHROMEOS)
« 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