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

Unified Diff: content/public/test/browser_test_utils.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
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/test/data/render_frame_host/beforeunload.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/test/browser_test_utils.cc
diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc
index 052ffca5772fabc52cc6e6cfd336c9c52f51db39..b9a3011b3e9321b4dd11c57cc67f7c085808a229 100644
--- a/content/public/test/browser_test_utils.cc
+++ b/content/public/test/browser_test_utils.cc
@@ -471,6 +471,18 @@ bool WaitForLoadStop(WebContents* web_contents) {
return IsLastCommittedEntryOfPageType(web_contents, PAGE_TYPE_NORMAL);
}
+void PrepContentsForBeforeUnloadTest(WebContents* web_contents) {
+ for (auto* frame : web_contents->GetAllFrames()) {
+ // JavaScript onbeforeunload dialogs are ignored unless the frame received a
+ // user gesture. Make sure the frames have user gestures.
+ frame->ExecuteJavaScriptWithUserGestureForTests(base::string16());
+
+ // Disable the hang monitor, otherwise there will be a race between the
+ // beforeunload dialog and the beforeunload hang timer.
+ frame->DisableBeforeUnloadHangMonitorForTesting();
+ }
+}
+
bool IsLastCommittedEntryOfPageType(WebContents* web_contents,
content::PageType page_type) {
NavigationEntry* last_entry =
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/test/data/render_frame_host/beforeunload.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698