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 |