Chromium Code Reviews| 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 2de47f8cf685e8a83c1c3ff3d447f77c4152883c..142d6d756c487a06bc0d734b1b555111cb6aa223 100644 |
| --- a/content/browser/frame_host/navigator_impl_unittest.cc |
| +++ b/content/browser/frame_host/navigator_impl_unittest.cc |
| @@ -100,30 +100,120 @@ class NavigatorTestWithBrowserSideNavigation |
| } |
| }; |
| -// PlzNavigate: Test final state after a complete navigation (to avoid repeating |
| -// these checks in other tests). |
| -TEST_F(NavigatorTestWithBrowserSideNavigation, NavigationFinishedState) { |
| +// PlzNavigate: Test a complete browser-initiated navigation starting with a |
| +// non-live renderer. |
|
nasko
2015/02/11 19:22:22
Do we have a test for the same, but starting with
carlosk
2015/02/11 19:54:29
Yes, there's others below starting from a live one
|
| +TEST_F(NavigatorTestWithBrowserSideNavigation, |
| + SimpleBrowserInitiatedNavigationFromNonLiveRenderer) { |
| const GURL kUrl("http://chromium.org/"); |
| - contents()->NavigateAndCommit(kUrl); |
| - ASSERT_TRUE(main_test_rfh()); |
| + |
| + EXPECT_FALSE(main_test_rfh()->IsRenderFrameLive()); |
|
nasko
2015/02/11 19:22:22
Note: I wonder if this will conflict in functional
carlosk
2015/02/11 19:54:29
Acknowledged.
|
| + |
| + // Start a browser-initiated navigation. |
| + int32 site_instance_id = main_test_rfh()->GetSiteInstance()->GetId(); |
| + FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| + SendRequestNavigation(node, kUrl); |
|
nasko
2015/02/11 19:22:22
Shouldn't this method name change? We no longer se
carlosk
2015/02/11 19:54:29
Indeed Send* seemed to imply an IPC that doesn't e
|
| + NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node); |
| + ASSERT_TRUE(request); |
| + EXPECT_EQ(kUrl, request->common_params().url); |
| + EXPECT_TRUE(request->browser_initiated()); |
| + |
| + // As there's no live renderer the navigation should not wait for a |
| + // beforeUnload ACK from the renderer and start right away. |
| + EXPECT_EQ(NavigationRequest::STARTED, request->state()); |
| + ASSERT_TRUE(GetLoaderForNavigationRequest(request)); |
| + EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| + EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
| + |
| + // Have the current RenderFrameHost commit the navigation. |
| + scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| + GetLoaderForNavigationRequest(request) |
| + ->CallOnResponseStarted(response, MakeEmptyStream()); |
| + EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); |
| + EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state()); |
| + |
| + // The navigation commits. |
| + main_test_rfh()->SendNavigate(0, kUrl); |
| EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); |
| EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl), |
| main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
| EXPECT_EQ(kUrl, contents()->GetLastCommittedURL()); |
| + EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); |
| + EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
| + |
| + // The main RFH should not have been changed, and the renderer should have |
| + // been initialized. |
| + EXPECT_EQ(site_instance_id, main_test_rfh()->GetSiteInstance()->GetId()); |
| + EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); |
| // After a navigation is finished no speculative RenderFrameHost should |
| // exist. |
| - FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| // With PlzNavigate enabled a pending RenderFrameHost should never exist. |
| EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
| } |
| +// PlzNavigate: Test a complete renderer-initiated navigation starting with a |
| +// non-live renderer. |
|
nasko
2015/02/11 19:22:22
I'll echo clamy@'s comment here. How do we start a
carlosk
2015/02/11 19:54:29
Done.
|
| +TEST_F(NavigatorTestWithBrowserSideNavigation, |
| + SimpleRendererInitiatedNavigation) { |
| + const GURL kUrl("http://chromium.org/"); |
| + |
| + EXPECT_FALSE(main_test_rfh()->IsRenderFrameLive()); |
| + |
| + // Start a renderer-initiated navigation. |
| + main_test_rfh()->SendBeginNavigationWithURL(kUrl); |
| + FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| + NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node); |
| + ASSERT_TRUE(request); |
| + EXPECT_EQ(kUrl, request->common_params().url); |
| + EXPECT_FALSE(request->browser_initiated()); |
| + EXPECT_EQ(NavigationRequest::STARTED, request->state()); |
| + EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| + |
| + // Have the current RenderFrameHost commit the navigation. |
| + scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| + GetLoaderForNavigationRequest(request) |
| + ->CallOnResponseStarted(response, MakeEmptyStream()); |
| + EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); |
| + EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state()); |
| + |
| + // The navigation commits. |
| + main_test_rfh()->SendNavigate(0, kUrl); |
| + EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); |
| + EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl), |
| + main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
| + EXPECT_EQ(kUrl, contents()->GetLastCommittedURL()); |
| + EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); |
| + EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| + EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
| +} |
| + |
| +// PlzNavigate: Test that a beforeUnload denial cancels the navigation. |
| +TEST_F(NavigatorTestWithBrowserSideNavigation, |
| + BeforeUnloadDenialCancelNavigation) { |
| + const GURL kUrl1("http://www.google.com/"); |
| + const GURL kUrl2("http://www.chromium.org/"); |
| + |
| + contents()->NavigateAndCommit(kUrl1); |
| + |
| + // Start a new navigation. |
| + FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| + SendRequestNavigation(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)); |
| + |
| + // Simulate a beforeUnload denial. |
| + main_test_rfh()->SendBeforeUnloadACK(false); |
| + EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); |
| + EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| +} |
| + |
| // PlzNavigate: Test that a proper NavigationRequest is created by |
| -// BeginNavigation. |
| -// Note that all PlzNavigate methods on the browser side require the use of the |
| -// flag kEnableBrowserSideNavigation. |
| +// RequestNavigation. |
| TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { |
| const GURL kUrl1("http://www.google.com/"); |
| const GURL kUrl2("http://www.chromium.org/"); |
| @@ -136,21 +226,26 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { |
| TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child"); |
| ASSERT_TRUE(subframe_rfh); |
| + // Start a navigation at the subframe. |
| FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); |
| SendRequestNavigation(subframe_node, kUrl2); |
| - // There is no previous renderer in the subframe, so BeginNavigation is |
| - // handled already. |
| NavigationRequest* subframe_request = |
| GetNavigationRequestForFrameTreeNode(subframe_node); |
| TestNavigationURLLoader* subframe_loader = |
| GetLoaderForNavigationRequest(subframe_request); |
| + |
| + // Subframe navigations should start right away as they don't have to request |
| + // beforeUnload to run at the renderer. |
|
nasko
2015/02/11 19:22:22
FYI, this might change in the future.
carlosk
2015/02/11 19:54:29
Yes, I am aware. :)
See my last comment reply in
|
| ASSERT_TRUE(subframe_request); |
| + ASSERT_TRUE(subframe_loader); |
| + EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state()); |
| EXPECT_EQ(kUrl2, subframe_request->common_params().url); |
| EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url); |
| // First party for cookies url should be that of the main frame. |
| EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies); |
| EXPECT_FALSE(subframe_loader->request_info()->is_main_frame); |
| EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame); |
| + EXPECT_TRUE(subframe_request->browser_initiated()); |
| EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node)); |
| // Subframe navigations should never create a speculative RenderFrameHost, |
| @@ -163,19 +258,28 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { |
| EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); |
| } |
| + // Now start a navigation at the root node. |
| SendRequestNavigation(root_node, kUrl3); |
| - // Simulate a BeginNavigation IPC on the main frame. |
| - main_test_rfh()->SendBeginNavigationWithURL(kUrl3); |
| 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); |
| TestNavigationURLLoader* main_loader = |
| GetLoaderForNavigationRequest(main_request); |
| - ASSERT_TRUE(main_request); |
| EXPECT_EQ(kUrl3, main_request->common_params().url); |
| EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url); |
| EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); |
| 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. |
| @@ -191,38 +295,6 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { |
| } |
| } |
| -// PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that |
| -// RenderFrameHost is not modified when the navigation commits. |
| -TEST_F(NavigatorTestWithBrowserSideNavigation, NoLiveRenderer) { |
| - const GURL kUrl("http://www.google.com/"); |
| - |
| - EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
| - RenderFrameHostImpl* rfh = main_test_rfh(); |
| - FrameTreeNode* node = rfh->frame_tree_node(); |
| - SendRequestNavigation(node, kUrl); |
| - |
| - // A NavigationRequest should have been generated. |
| - NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
| - EXPECT_TRUE(main_request != NULL); |
| - |
| - // Since we're re-using the current RenderFrameHost, no speculative one should |
| - // be created. |
| - EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| - |
| - // Now return the response without any redirects. This will cause the |
| - // navigation to commit at the same URL. |
| - scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| - GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
| - response, MakeEmptyStream()); |
| - main_request = GetNavigationRequestForFrameTreeNode(node); |
| - |
| - // The main RFH should not have been changed, and the renderer should have |
| - // been initialized. |
| - EXPECT_EQ(rfh, main_test_rfh()); |
| - EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); |
| - EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
| -} |
| - |
| // PlzNavigate: Test that committing an HTTP 204 or HTTP 205 response cancels |
| // the navigation. |
| TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) { |
| @@ -236,7 +308,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) { |
| // Navigate to a different site. |
| process()->sink().ClearMessages(); |
| SendRequestNavigation(node, kUrl2); |
| - main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
| + main_test_rfh()->SendBeforeUnloadACK(true); |
| NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
| ASSERT_TRUE(main_request); |
| @@ -264,7 +336,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) { |
| // Navigate to a different site again. |
| process()->sink().ClearMessages(); |
| SendRequestNavigation(node, kUrl2); |
| - main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
| + main_test_rfh()->SendBeforeUnloadACK(true); |
| main_request = GetNavigationRequestForFrameTreeNode(node); |
| ASSERT_TRUE(main_request); |
| @@ -299,7 +371,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, CrossSiteNavigation) { |
| // Navigate to a different site. |
| process()->sink().ClearMessages(); |
| SendRequestNavigation(node, kUrl2); |
| - main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
| + main_test_rfh()->SendBeforeUnloadACK(true); |
| NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
| ASSERT_TRUE(main_request); |
| EXPECT_TRUE(GetSpeculativeRenderFrameHost(node)); |
| @@ -335,7 +407,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) { |
| // Navigate to a URL on the same site. |
| process()->sink().ClearMessages(); |
| SendRequestNavigation(node, kUrl1); |
| - main_test_rfh()->SendBeginNavigationWithURL(kUrl1); |
| + main_test_rfh()->SendBeforeUnloadACK(true); |
| NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
| ASSERT_TRUE(main_request); |
| EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| @@ -363,7 +435,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) { |
| EXPECT_TRUE(final_speculative_rfh); |
| EXPECT_TRUE(DidRenderFrameHostRequestCommit(final_speculative_rfh)); |
| - // And commit provisional load. |
| + // The navigation commits. |
| final_speculative_rfh->SendNavigate(0, kUrl2); |
| RenderFrameHostImpl* final_rfh = main_test_rfh(); |
| ASSERT_TRUE(final_rfh); |
| @@ -374,10 +446,11 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) { |
| EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| } |
| -// PlzNavigate: Test that a navigation is canceled if another request has been |
| -// issued in the meantime. Also confirms that the speculative RenderFrameHost is |
| -// correctly updated in the process. |
| -TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) { |
| +// PlzNavigate: Test that a navigation is canceled if another browser-initiated |
| +// request has been issued in the meantime. Also confirms that the speculative |
| +// RenderFrameHost is correctly updated in the process. |
| +TEST_F(NavigatorTestWithBrowserSideNavigation, |
| + BrowserInitiatedNavigationCancel) { |
| const GURL kUrl0("http://www.wikipedia.org/"); |
| const GURL kUrl1("http://www.chromium.org/"); |
| const GURL kUrl1_site = SiteInstance::GetSiteForURL(browser_context(), kUrl1); |
| @@ -391,10 +464,11 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) { |
| // Request navigation to the 1st URL. |
| process()->sink().ClearMessages(); |
| SendRequestNavigation(node, kUrl1); |
| - main_test_rfh()->SendBeginNavigationWithURL(kUrl1); |
| + main_test_rfh()->SendBeforeUnloadACK(true); |
| NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node); |
| ASSERT_TRUE(request1); |
| EXPECT_EQ(kUrl1, request1->common_params().url); |
| + EXPECT_TRUE(request1->browser_initiated()); |
| base::WeakPtr<TestNavigationURLLoader> loader1 = |
| GetLoaderForNavigationRequest(request1)->AsWeakPtr(); |
| @@ -407,10 +481,11 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) { |
| // Request navigation to the 2nd URL; the NavigationRequest must have been |
| // replaced by a new one with a different URL. |
| SendRequestNavigation(node, kUrl2); |
| - main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
| + main_test_rfh()->SendBeforeUnloadACK(true); |
| NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); |
| ASSERT_TRUE(request2); |
| EXPECT_EQ(kUrl2, request2->common_params().url); |
| + EXPECT_TRUE(request2->browser_initiated()); |
| // Confirm that the first loader got destroyed. |
| EXPECT_FALSE(loader1); |
| @@ -428,7 +503,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) { |
| EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh)); |
| EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh())); |
| - // And commit provisional load. |
| + // The navigation commits. |
|
nasko
2015/02/11 19:22:22
nit: Let's match the style of the rest of the comm
carlosk
2015/02/11 19:54:28
Done here and in a few other tests.
|
| speculative_rfh->SendNavigate(0, kUrl2); |
| // Confirm that the commit corresponds to the new request. |
| @@ -489,7 +564,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, |
| const GURL kUrl("http://google.com/"); |
| process()->sink().ClearMessages(); |
| SendRequestNavigation(node, kUrl); |
| - main_test_rfh()->SendBeginNavigationWithURL(kUrl); |
| + main_test_rfh()->SendBeforeUnloadACK(true); |
| TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node); |
| ASSERT_TRUE(speculative_rfh); |
| EXPECT_NE(speculative_rfh, main_test_rfh()); |
| @@ -530,7 +605,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, |
| const GURL kUrl("http://google.com/"); |
| process()->sink().ClearMessages(); |
| SendRequestNavigation(node, kUrl); |
| - main_test_rfh()->SendBeginNavigationWithURL(kUrl); |
| + main_test_rfh()->SendBeforeUnloadACK(true); |
| TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node); |
| int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId(); |
| EXPECT_NE(init_site_instance_id, site_instance_id); |
| @@ -620,7 +695,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, |
| ->sink() |
| .ClearMessages(); |
| SendRequestNavigation(node, kUrl1); |
| - main_test_rfh()->SendBeginNavigationWithURL(kUrl1); |
| + main_test_rfh()->SendBeforeUnloadACK(true); |
| EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node)); |
| EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, |
| GetSpeculativeRenderFrameHost(node)->rfh_state()); |