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..0d9f9a2e5903a37e63fc8fcc12127c3c9323887d 100644 |
| --- a/content/browser/frame_host/navigator_impl_unittest.cc |
| +++ b/content/browser/frame_host/navigator_impl_unittest.cc |
| @@ -100,30 +100,95 @@ class NavigatorTestWithBrowserSideNavigation |
| } |
| }; |
| -// PlzNavigate: Test final state after a complete navigation (to avoid repeating |
| -// these checks in other tests). |
| -TEST_F(NavigatorTestWithBrowserSideNavigation, NavigationFinishedState) { |
| +// PlzNavigate: Test final state after a complete browser-initiated navigation |
| +// (to avoid repeating these checks in other tests). |
| +TEST_F(NavigatorTestWithBrowserSideNavigation, |
| + BrowserInitiatedNavigateAndCommit) { |
| const GURL kUrl("http://chromium.org/"); |
| + |
| + EXPECT_FALSE(main_test_rfh()->IsRenderFrameLive()); |
| + |
| contents()->NavigateAndCommit(kUrl); |
| + FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
| ASSERT_TRUE(main_test_rfh()); |
| 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)); |
| // After a navigation is finished no speculative RenderFrameHost should |
| // exist. |
| + EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| + // With PlzNavigate enabled a pending RenderFrameHost should never exist. |
| + EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
| +} |
| + |
| +// PlzNavigate: Test a simple renderer initiated navigation starting with a |
|
clamy
2015/02/10 15:41:22
nit: renderer-initiated.
carlosk
2015/02/10 18:27:09
Done.
|
| +// non-live renderer. |
| +TEST_F(NavigatorTestWithBrowserSideNavigation, |
| + SimpleRendererInitiatedNavigation) { |
|
clamy
2015/02/10 15:41:22
nit: I would rename the test RendererInitiatedNavi
carlosk
2015/02/10 18:27:09
Done. As discussed offline I'm expanding the previ
|
| + const GURL kUrl("http://chromium.org/"); |
| + |
| + EXPECT_FALSE(main_test_rfh()->IsRenderFrameLive()); |
| + |
| + main_test_rfh()->SendBeginNavigationWithURL(kUrl); |
|
clamy
2015/02/10 15:41:22
nit: Maybe a "// Start a renderer-initiated naviga
carlosk
2015/02/10 18:27:09
Done.
|
| 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)); |
|
clamy
2015/02/10 15:41:22
nit: do not remove the empty line here.
carlosk
2015/02/10 18:27:09
Done.
|
| + // Request the RenderFrameHost to commit. |
|
clamy
2015/02/10 15:41:22
I would rephrase that as: Have the current RenderF
carlosk
2015/02/10 18:27:09
Done.
|
| + scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| + GetLoaderForNavigationRequest(request) |
| + ->CallOnResponseStarted(response, MakeEmptyStream()); |
| + EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh())); |
| + EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state()); |
| + |
| + // And commit provisional load. |
|
clamy
2015/02/10 15:41:22
nit: maybe rephrase as The navigation commits. ?
carlosk
2015/02/10 18:27:09
Done.
|
| + 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)); |
| + |
| + // After a navigation is finished no speculative RenderFrameHost should |
| + // exist. |
| + EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); |
| // With PlzNavigate enabled a pending RenderFrameHost should never exist. |
|
clamy
2015/02/10 15:41:22
nit: add an empty line above the comment.
carlosk
2015/02/10 18:27:09
Done. In fact moved the comments to the previous t
|
| EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
| } |
| +// PlzNavigate: Test that the renderer can cancel a navigation with a proper |
| +// BeforeUnloadACK. |
|
clamy
2015/02/10 15:41:22
I would rephrase as: Test that a beforeUnload deni
carlosk
2015/02/10 18:27:09
Done.
|
| +TEST_F(NavigatorTestWithBrowserSideNavigation, |
| + BeforeUnloadCancelledNavigation) { |
|
clamy
2015/02/10 15:41:22
nit: maybe rename the test to BeforeUnloadDenialCa
carlosk
2015/02/10 18:27:09
Done.
|
| + const GURL kUrl1("http://www.google.com/"); |
| + const GURL kUrl2("http://www.chromium.org/"); |
| + |
| + contents()->NavigateAndCommit(kUrl1); |
| + |
| + // Start a new navigation |
|
clamy
2015/02/10 15:41:22
nit: add a . at the end of the comment.
carlosk
2015/02/10 18:27:09
Done.
|
| + 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 BeforeUnloadACK IPC with a signal to NOT proceed. |
|
clamy
2015/02/10 15:41:22
nit: Simulate a beforeUnload denial.
carlosk
2015/02/10 18:27:09
Done.
|
| + 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,10 +201,9 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { |
| TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child"); |
| ASSERT_TRUE(subframe_rfh); |
| + // Start a navigation at the subframe |
|
clamy
2015/02/10 15:41:22
nit: add . at the end of the comment.
carlosk
2015/02/10 18:27:09
Done.
|
| 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 = |
| @@ -151,6 +215,10 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { |
| 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()); |
| + // Subframe navigations should start right away as they don't have to request |
| + // beforeUnload to run at the renderer. |
|
clamy
2015/02/10 15:41:22
Please move this comment to where the previous rem
carlosk
2015/02/10 18:27:09
Done. But I moved a bit more things around so that
|
| + EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state()); |
|
clamy
2015/02/10 15:41:22
Please move this expect below the call creating th
carlosk
2015/02/10 18:27:09
Yes, precisely. :)
|
| EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node)); |
| // Subframe navigations should never create a speculative RenderFrameHost, |
| @@ -163,11 +231,16 @@ 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); |
| + 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); |
| @@ -176,6 +249,10 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { |
| 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 form the renderer so the navigation should |
|
clamy
2015/02/10 15:41:22
nit: s/form/from
carlosk
2015/02/10 18:27:09
Done.
|
| + // have started. |
| + EXPECT_EQ(NavigationRequest::STARTED, main_request->state()); |
| // Main frame navigation to a different site should use a speculative |
| // RenderFrameHost. |
| @@ -204,6 +281,9 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, NoLiveRenderer) { |
| // A NavigationRequest should have been generated. |
| NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
| EXPECT_TRUE(main_request != NULL); |
| + // As there's not live renderer the navigation should not wait for a response |
|
clamy
2015/02/10 15:41:22
nit: s/not/no
nit: s/response/beforeUnload ACK
carlosk
2015/02/10 18:27:09
Done but mind that this whole test moved into the
|
| + // from the renderer and start right away. |
| + EXPECT_EQ(NavigationRequest::STARTED, main_request->state()); |
| // Since we're re-using the current RenderFrameHost, no speculative one should |
| // be created. |
| @@ -214,7 +294,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, NoLiveRenderer) { |
| scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
| response, MakeEmptyStream()); |
| - main_request = GetNavigationRequestForFrameTreeNode(node); |
| + EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, main_request->state()); |
| // The main RFH should not have been changed, and the renderer should have |
| // been initialized. |
| @@ -236,7 +316,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 +344,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 +379,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 +415,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)); |
| @@ -374,10 +454,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 +472,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 +489,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); |
| @@ -489,7 +572,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 +613,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 +703,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()); |