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

Unified Diff: chrome/browser/unload_browsertest.cc

Issue 2801813005: Only show a beforeunload dialog if a frame has had a user gesture since its load. (Closed)
Patch Set: one last bit Created 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/unload_browsertest.cc
diff --git a/chrome/browser/unload_browsertest.cc b/chrome/browser/unload_browsertest.cc
index ae66d8c3002daa0b7a8d0c0df32da291f1b1a834..10517248137e4395c5b68bf1eacefab446260d39 100644
--- a/chrome/browser/unload_browsertest.cc
+++ b/chrome/browser/unload_browsertest.cc
@@ -204,6 +204,13 @@ class UnloadTest : public InProcessBrowserTest {
else
js_dialog->native_dialog()->CancelAppModalDialog();
}
+
+ void PrepareForDialog(Browser* browser) {
+ for (int i = 0; i < browser->tab_strip_model()->count(); i++) {
+ content::PrepContentsForBeforeUnloadTest(
+ browser->tab_strip_model()->GetWebContentsAt(i));
+ }
+ }
};
// Navigate to a page with an infinite unload handler.
@@ -282,13 +289,7 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, DISABLED_BrowserCloseUnload) {
// OK in the beforeunload confirm dialog.
IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) {
NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
- // Disable the hang monitor, otherwise there will be a race between the
- // beforeunload dialog and the beforeunload hang timer.
- browser()
- ->tab_strip_model()
- ->GetActiveWebContents()
- ->GetMainFrame()
- ->DisableBeforeUnloadHangMonitorForTesting();
+ PrepareForDialog(browser());
content::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
@@ -303,14 +304,7 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) {
// If this test flakes, reopen http://crbug.com/123110
IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
- // Disable the hang monitor, otherwise there will be a race between the
- // beforeunload dialog and the beforeunload hang timer.
- browser()
- ->tab_strip_model()
- ->GetActiveWebContents()
- ->GetMainFrame()
- ->DisableBeforeUnloadHangMonitorForTesting();
-
+ PrepareForDialog(browser());
chrome::CloseWindow(browser());
// We wait for the title to change after cancelling the closure of browser
@@ -356,13 +350,7 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseNoUnloadListeners) {
// beforeunload handler and clicking Leave in the beforeunload confirm dialog.
IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadOK) {
NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
- // Disable the hang monitor, otherwise there will be a race between the
- // beforeunload dialog and the beforeunload hang timer.
- browser()
- ->tab_strip_model()
- ->GetActiveWebContents()
- ->GetMainFrame()
- ->DisableBeforeUnloadHangMonitorForTesting();
+ PrepareForDialog(browser());
content::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
@@ -383,13 +371,7 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadOK) {
// beforeunload handler and clicking Stay in the beforeunload confirm dialog.
IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadCancel) {
NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
- // Disable the hang monitor, otherwise there will be a race between the
- // beforeunload dialog and the beforeunload hang timer.
- browser()
- ->tab_strip_model()
- ->GetActiveWebContents()
- ->GetMainFrame()
- ->DisableBeforeUnloadHangMonitorForTesting();
+ PrepareForDialog(browser());
UnloadResults unload_results;
BrowserList::CloseAllBrowsersWithProfile(
@@ -425,13 +407,7 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListCloseBeforeUnloadCancel) {
// beforeunload handler and clicking Leave in the beforeunload confirm dialog.
IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadOK) {
NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
- // Disable the hang monitor, otherwise there will be a race between the
- // beforeunload dialog and the beforeunload hang timer.
- browser()
- ->tab_strip_model()
- ->GetActiveWebContents()
- ->GetMainFrame()
- ->DisableBeforeUnloadHangMonitorForTesting();
+ PrepareForDialog(browser());
content::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
@@ -457,13 +433,7 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadOK) {
// beforeunload handler and clicking Stay in the beforeunload confirm dialog.
IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserListDoubleCloseBeforeUnloadCancel) {
NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
- // Disable the hang monitor, otherwise there will be a race between the
- // beforeunload dialog and the beforeunload hang timer.
- browser()
- ->tab_strip_model()
- ->GetActiveWebContents()
- ->GetMainFrame()
- ->DisableBeforeUnloadHangMonitorForTesting();
+ PrepareForDialog(browser());
UnloadResults unload_results;
BrowserList::CloseAllBrowsersWithProfile(
@@ -514,13 +484,7 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserTerminateBeforeUnload) {
// If this flakes, use http://crbug.com/32615 and http://crbug.com/45675
IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseWithInnerFocusedFrame) {
NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus");
- // Disable the hang monitor, otherwise there will be a race between the
- // beforeunload dialog and the beforeunload hang timer.
- browser()
- ->tab_strip_model()
- ->GetActiveWebContents()
- ->GetMainFrame()
- ->DisableBeforeUnloadHangMonitorForTesting();
+ PrepareForDialog(browser());
content::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
@@ -895,6 +859,7 @@ IN_PROC_BROWSER_TEST_F(FastUnloadTest,
return;
NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
+ PrepareForDialog(browser());
content::WebContents* beforeunload_contents =
browser()->tab_strip_model()->GetActiveWebContents();
@@ -927,6 +892,7 @@ IN_PROC_BROWSER_TEST_F(FastUnloadTest,
IN_PROC_BROWSER_TEST_F(FastUnloadTest,
BrowserListForceCloseWithBeforeUnloadWithFastUnload) {
NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
+ PrepareForDialog(browser());
content::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
@@ -945,6 +911,7 @@ IN_PROC_BROWSER_TEST_F(FastUnloadTest,
IN_PROC_BROWSER_TEST_F(FastUnloadTest,
BrowserListForceCloseAfterNormalCloseWithFastUnload) {
NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload");
+ PrepareForDialog(browser());
content::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
« no previous file with comments | « chrome/browser/ui/browser_browsertest.cc ('k') | content/browser/frame_host/render_frame_host_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698