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

Unified Diff: content/browser/frame_host/navigator_impl_unittest.cc

Issue 903043002: Skip BeforeUnload on cross-site navigations when there are no handlers Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 10 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 | « no previous file | content/browser/frame_host/render_frame_host_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/frame_host/navigator_impl_unittest.cc
diff --git a/content/browser/frame_host/navigator_impl_unittest.cc b/content/browser/frame_host/navigator_impl_unittest.cc
index e31ce22eb170c76e91378ca9d111bec52f4da125..0f73230a5bf58373f4e87a3b8c66ad4e7038f214 100644
--- a/content/browser/frame_host/navigator_impl_unittest.cc
+++ b/content/browser/frame_host/navigator_impl_unittest.cc
@@ -193,6 +193,33 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
EXPECT_FALSE(node->render_manager()->pending_frame_host());
}
+// PlzNavigate: Test that the navigator waits for a beforeUnload ack before
+// starting the navigation when beforeUnload handlers are present in the frame.
+TEST_F(NavigatorTestWithBrowserSideNavigation, BeforeUnloadACK) {
+ const GURL kUrl1("http://www.google.com/");
+ const GURL kUrl2("http://www.chromium.org/");
+
+ contents()->NavigateAndCommit(kUrl1);
+ main_test_rfh()->SendBeforeUnloadHandlersPresent(true);
+
+ // Start a new navigation.
+ FrameTreeNode* node = main_test_rfh()->frame_tree_node();
+ RequestNavigation(node, kUrl2);
+ NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node);
+ ASSERT_TRUE(request);
+ EXPECT_TRUE(request->browser_initiated());
+ EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, request->state());
+ EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
+ EXPECT_FALSE(request->loader_for_testing());
+
+ // Simulate a beforeUnload ACK.
+ main_test_rfh()->SendBeforeUnloadACK(true);
+ EXPECT_TRUE(GetNavigationRequestForFrameTreeNode(node));
+ EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
+ EXPECT_EQ(NavigationRequest::STARTED, request->state());
+ EXPECT_TRUE(request->loader_for_testing());
+}
+
// PlzNavigate: Test that a beforeUnload denial cancels the navigation.
TEST_F(NavigatorTestWithBrowserSideNavigation,
BeforeUnloadDenialCancelNavigation) {
@@ -200,6 +227,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
const GURL kUrl2("http://www.chromium.org/");
contents()->NavigateAndCommit(kUrl1);
+ main_test_rfh()->SendBeforeUnloadHandlersPresent(true);
// Start a new navigation.
FrameTreeNode* node = main_test_rfh()->frame_tree_node();
@@ -267,12 +295,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
NavigationRequest* main_request =
GetNavigationRequestForFrameTreeNode(root_node);
ASSERT_TRUE(main_request);
- EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE,
- main_request->state());
- EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node));
-
- // Simulate a BeforeUnloadACK IPC on the main frame.
- main_test_rfh()->SendBeforeUnloadACK(true);
+ EXPECT_EQ(NavigationRequest::STARTED, main_request->state());
TestNavigationURLLoader* main_loader =
GetLoaderForNavigationRequest(main_request);
EXPECT_EQ(kUrl3, main_request->common_params().url);
@@ -281,9 +304,6 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
EXPECT_TRUE(main_loader->request_info()->is_main_frame);
EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame);
EXPECT_TRUE(main_request->browser_initiated());
- // BeforeUnloadACK was received from the renderer so the navigation should
- // have started.
- EXPECT_EQ(NavigationRequest::STARTED, main_request->state());
// Main frame navigation to a different site should use a speculative
// RenderFrameHost.
@@ -698,7 +718,6 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
->sink()
.ClearMessages();
RequestNavigation(node, kUrl1);
- main_test_rfh()->SendBeforeUnloadACK(true);
EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT,
GetSpeculativeRenderFrameHost(node)->rfh_state());
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698