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

Unified Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 1825523002: Do not reset navigation state when BeforeUnload is cancelled by a commit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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: content/browser/web_contents/web_contents_impl_browsertest.cc
diff --git a/content/browser/web_contents/web_contents_impl_browsertest.cc b/content/browser/web_contents/web_contents_impl_browsertest.cc
index 61043a399b99f44fa0342c5f1bb3df55eb353612..e2c1ab795a2654865a8b86878bfdcdaa4b3d3ddd 100644
--- a/content/browser/web_contents/web_contents_impl_browsertest.cc
+++ b/content/browser/web_contents/web_contents_impl_browsertest.cc
@@ -815,4 +815,39 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) {
}
}
+// This CL tests that if a BeforeUnload dialog is destroyed due to the commit
+// of a cross-site navigation, it will not reset the loading state.
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
+ NoResetOnBeforeUnloadCanceledOnCommit) {
+ ASSERT_TRUE(embedded_test_server()->Start());
+ const GURL kStartURL(
+ embedded_test_server()->GetURL("/hang_before_unload.html"));
+ const GURL kCrossSiteURL(
+ embedded_test_server()->GetURL("bar.com", "/title1.html"));
+
+ // Navigate to a first web page with a BeforeUnload event listener.
+ EXPECT_TRUE(NavigateToURL(shell(), kStartURL));
+
+ // Start a cross-site navigation that will not commit for the moment.
+ NavigationDelayer cross_site_delayer(shell()->web_contents(), kCrossSiteURL);
+ shell()->LoadURL(kCrossSiteURL);
+ cross_site_delayer.WaitForNavigationPaused();
+
+ // Click on a link in the page. This will show the BeforeUnload dialog. Have
+ // it hang.
+ // Note: the javascript function executed will not do the link click but
+ // schedule it for afterwards. Since the BeforeUnload event is synchronous,
+ // clicking on the link right away would cause the ExecuteScript to never
+ // return.
+ SetProceedByDefaultOnBeforeUnload(shell(), false);
+ EXPECT_TRUE(ExecuteScript(shell()->web_contents(), "clickLinkSoon()"));
+ WaitForAppModalDialog(shell());
+
+ // Have the cross-site navigation commit. The main RenderFrameHost should
+ // still be loading after that.
+ cross_site_delayer.ResumeNavigation();
+ cross_site_delayer.WaitForNavigationFinished();
+ EXPECT_TRUE(shell()->web_contents()->IsLoading());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698