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

Unified Diff: chrome/browser/unload_browsertest.cc

Issue 2787393003: Fix races in tests waiting for beforeunload dialogs. (Closed)
Patch Set: rev Created 3 years, 8 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 2af1a45082547fa5dad650df28f6867d2e6445cd..d1658351bd69b3bf6dcded60f037a3c97380c932 100644
--- a/chrome/browser/unload_browsertest.cc
+++ b/chrome/browser/unload_browsertest.cc
@@ -24,6 +24,7 @@
#include "components/app_modal/native_app_modal_dialog.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
@@ -278,6 +279,13 @@ 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();
content::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
@@ -292,6 +300,14 @@ 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();
+
chrome::CloseWindow(browser());
// We wait for the title to change after cancelling the closure of browser
@@ -337,6 +353,13 @@ 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();
content::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
@@ -357,6 +380,13 @@ 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();
UnloadResults unload_results;
BrowserList::CloseAllBrowsersWithProfile(
@@ -392,6 +422,13 @@ 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();
content::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
@@ -417,6 +454,13 @@ 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();
UnloadResults unload_results;
BrowserList::CloseAllBrowsersWithProfile(
@@ -467,6 +511,13 @@ 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();
content::WindowedNotificationObserver window_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,

Powered by Google App Engine
This is Rietveld 408576698