Commit d6a4ef36 authored by carlosk's avatar carlosk Committed by Commit bot

PlzNavigate: test updates post beforeUnload IPC refactor.

This CL adapts several test classes with changes due now that
the IPCS for beforeUnload ack and renderer navigation requests are not
one and the same anymore.

BUG=440266

Review URL: https://codereview.chromium.org/953503002

Cr-Commit-Position: refs/heads/master@{#319049}
parent 10f7c9d7
...@@ -163,7 +163,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ...@@ -163,7 +163,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
// Start a renderer-initiated non-user-initiated navigation. // Start a renderer-initiated non-user-initiated navigation.
process()->sink().ClearMessages(); process()->sink().ClearMessages();
main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false); main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false);
FrameTreeNode* node = main_test_rfh()->frame_tree_node(); FrameTreeNode* node = main_test_rfh()->frame_tree_node();
NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node); NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(request); ASSERT_TRUE(request);
...@@ -421,21 +421,14 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) { ...@@ -421,21 +421,14 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) {
EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
// It then redirects to another site. // It then redirects to another site.
net::RedirectInfo redirect_info; GetLoaderForNavigationRequest(main_request)->SimulateServerRedirect(kUrl2);
redirect_info.status_code = 302;
redirect_info.new_method = "GET";
redirect_info.new_url = kUrl2;
redirect_info.new_first_party_for_cookies = kUrl2;
scoped_refptr<ResourceResponse> response(new ResourceResponse);
GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected(
redirect_info, response);
// The redirect should have been followed. // The redirect should have been followed.
EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count()); EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count());
EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
// Have the RenderFrameHost commit the navigation. // Have the RenderFrameHost commit the navigation.
response = new ResourceResponse; scoped_refptr<ResourceResponse> response(new ResourceResponse);
GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
response, MakeEmptyStream()); response, MakeEmptyStream());
TestRenderFrameHost* final_speculative_rfh = TestRenderFrameHost* final_speculative_rfh =
...@@ -556,7 +549,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ...@@ -556,7 +549,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
// Now receive a renderer-initiated user-initiated request. It should replace // Now receive a renderer-initiated user-initiated request. It should replace
// the current NavigationRequest. // the current NavigationRequest.
main_test_rfh()->SendBeginNavigationWithURL(kUrl2, true); main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true);
NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(request2); ASSERT_TRUE(request2);
EXPECT_EQ(kUrl2, request2->common_params().url); EXPECT_EQ(kUrl2, request2->common_params().url);
...@@ -605,7 +598,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ...@@ -605,7 +598,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
// Start a renderer-initiated user-initiated navigation to the 1st URL. // Start a renderer-initiated user-initiated navigation to the 1st URL.
process()->sink().ClearMessages(); process()->sink().ClearMessages();
main_test_rfh()->SendBeginNavigationWithURL(kUrl1, true); main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true);
NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node); NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(request1); ASSERT_TRUE(request1);
EXPECT_EQ(kUrl1, request1->common_params().url); EXPECT_EQ(kUrl1, request1->common_params().url);
...@@ -615,7 +608,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ...@@ -615,7 +608,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
// Now receive a renderer-initiated non-user-initiated request. Nothing should // Now receive a renderer-initiated non-user-initiated request. Nothing should
// change. // change.
main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false); main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false);
NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(request2); ASSERT_TRUE(request2);
EXPECT_EQ(request1, request2); EXPECT_EQ(request1, request2);
...@@ -660,7 +653,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ...@@ -660,7 +653,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
// Now receive a renderer-initiated non-user-initiated request. Nothing should // Now receive a renderer-initiated non-user-initiated request. Nothing should
// change. // change.
main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false); main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false);
NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(request2); ASSERT_TRUE(request2);
EXPECT_EQ(request1, request2); EXPECT_EQ(request1, request2);
...@@ -699,7 +692,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ...@@ -699,7 +692,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
// Start a renderer-initiated non-user-initiated navigation to the 1st URL. // Start a renderer-initiated non-user-initiated navigation to the 1st URL.
process()->sink().ClearMessages(); process()->sink().ClearMessages();
main_test_rfh()->SendBeginNavigationWithURL(kUrl1, false); main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, false);
NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node); NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(request1); ASSERT_TRUE(request1);
EXPECT_EQ(kUrl1, request1->common_params().url); EXPECT_EQ(kUrl1, request1->common_params().url);
...@@ -711,7 +704,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ...@@ -711,7 +704,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
EXPECT_TRUE(loader1); EXPECT_TRUE(loader1);
// Now receive a 2nd similar request that should replace the current one. // Now receive a 2nd similar request that should replace the current one.
main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false); main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false);
NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
EXPECT_EQ(kUrl2, request2->common_params().url); EXPECT_EQ(kUrl2, request2->common_params().url);
EXPECT_FALSE(request2->browser_initiated()); EXPECT_FALSE(request2->browser_initiated());
...@@ -750,7 +743,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { ...@@ -750,7 +743,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
ASSERT_TRUE(main_request != NULL); ASSERT_TRUE(main_request != NULL);
EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD, EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD,
main_request->common_params().navigation_type); main_request->common_params().navigation_type);
main_test_rfh()->PrepareForCommit(kUrl); main_test_rfh()->PrepareForCommit();
EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
main_test_rfh()->SendNavigate(0, kUrl); main_test_rfh()->SendNavigate(0, kUrl);
...@@ -765,7 +758,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { ...@@ -765,7 +758,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
ASSERT_TRUE(main_request != NULL); ASSERT_TRUE(main_request != NULL);
EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE,
main_request->common_params().navigation_type); main_request->common_params().navigation_type);
main_test_rfh()->PrepareForCommit(kUrl); main_test_rfh()->PrepareForCommit();
EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
} }
...@@ -843,14 +836,8 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ...@@ -843,14 +836,8 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(main_request); ASSERT_TRUE(main_request);
const GURL kUrlRedirect("https://www.google.com/"); const GURL kUrlRedirect("https://www.google.com/");
net::RedirectInfo redirect_info;
redirect_info.status_code = 302;
redirect_info.new_method = "GET";
redirect_info.new_url = kUrlRedirect;
redirect_info.new_first_party_for_cookies = kUrlRedirect;
scoped_refptr<ResourceResponse> response(new ResourceResponse);
GetLoaderForNavigationRequest(main_request) GetLoaderForNavigationRequest(main_request)
->CallOnRequestRedirected(redirect_info, response); ->SimulateServerRedirect(kUrlRedirect);
EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId()); EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
speculative_rfh = GetSpeculativeRenderFrameHost(node); speculative_rfh = GetSpeculativeRenderFrameHost(node);
ASSERT_TRUE(speculative_rfh); ASSERT_TRUE(speculative_rfh);
...@@ -863,7 +850,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, ...@@ -863,7 +850,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation,
// Commit the navigation with Navigator by simulating the call to // Commit the navigation with Navigator by simulating the call to
// OnResponseStarted. // OnResponseStarted.
response = new ResourceResponse; scoped_refptr<ResourceResponse> response(new ResourceResponse);
GetLoaderForNavigationRequest(main_request) GetLoaderForNavigationRequest(main_request)
->CallOnResponseStarted(response, MakeEmptyStream()); ->CallOnResponseStarted(response, MakeEmptyStream());
speculative_rfh = GetSpeculativeRenderFrameHost(node); speculative_rfh = GetSpeculativeRenderFrameHost(node);
...@@ -975,7 +962,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, DataUrls) { ...@@ -975,7 +962,7 @@ TEST_F(NavigatorTestWithBrowserSideNavigation, DataUrls) {
// Do a renderer-initiated navigation to a data url. The request should not be // Do a renderer-initiated navigation to a data url. The request should not be
// sent to the IO thread, nor committed. // sent to the IO thread, nor committed.
TestRenderFrameHost* main_rfh = main_test_rfh(); TestRenderFrameHost* main_rfh = main_test_rfh();
main_rfh->SendBeginNavigationWithURL(kUrl2, true); main_rfh->SendRendererInitiatedNavigationRequest(kUrl2, true);
navigation_request = GetNavigationRequestForFrameTreeNode(node); navigation_request = GetNavigationRequestForFrameTreeNode(node);
ASSERT_TRUE(navigation_request); ASSERT_TRUE(navigation_request);
EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, EXPECT_EQ(NavigationRequest::RESPONSE_STARTED,
......
...@@ -272,7 +272,7 @@ class RenderFrameHostManagerTest : public RenderViewHostImplTestHarness { ...@@ -272,7 +272,7 @@ class RenderFrameHostManagerTest : public RenderViewHostImplTestHarness {
// is replaced without a pending frame being created, and we don't get the // is replaced without a pending frame being created, and we don't get the
// right values for the RFH to navigate: we try to use the old one that has // right values for the RFH to navigate: we try to use the old one that has
// been deleted in the meantime. // been deleted in the meantime.
contents()->GetMainFrame()->PrepareForCommit(url); contents()->GetMainFrame()->PrepareForCommit();
TestRenderFrameHost* old_rfh = contents()->GetMainFrame(); TestRenderFrameHost* old_rfh = contents()->GetMainFrame();
TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame() TestRenderFrameHost* active_rfh = contents()->GetPendingMainFrame()
...@@ -351,7 +351,7 @@ class RenderFrameHostManagerTest : public RenderViewHostImplTestHarness { ...@@ -351,7 +351,7 @@ class RenderFrameHostManagerTest : public RenderViewHostImplTestHarness {
// Navigate to a cross-site URL. // Navigate to a cross-site URL.
contents()->GetController().LoadURL( contents()->GetController().LoadURL(
kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
contents()->GetMainFrame()->PrepareForCommit(kDestUrl); contents()->GetMainFrame()->PrepareForCommit();
EXPECT_TRUE(contents()->cross_navigation_pending()); EXPECT_TRUE(contents()->cross_navigation_pending());
// Manually increase the number of active frames in the // Manually increase the number of active frames in the
...@@ -430,7 +430,7 @@ TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { ...@@ -430,7 +430,7 @@ TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) {
// we use the committed one. // we use the committed one.
contents2->GetController().LoadURL( contents2->GetController().LoadURL(
kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
contents2->GetMainFrame()->PrepareForCommit(kChromeUrl); contents2->GetMainFrame()->PrepareForCommit();
TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame(); TestRenderFrameHost* ntp_rfh2 = contents2->GetMainFrame();
EXPECT_FALSE(contents2->cross_navigation_pending()); EXPECT_FALSE(contents2->cross_navigation_pending());
ntp_rfh2->SendNavigate(100, kChromeUrl); ntp_rfh2->SendNavigate(100, kChromeUrl);
...@@ -439,7 +439,7 @@ TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { ...@@ -439,7 +439,7 @@ TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) {
// requiring a beforeunload ack. // requiring a beforeunload ack.
contents2->GetController().LoadURL( contents2->GetController().LoadURL(
kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); kDestUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
contents2->GetMainFrame()->PrepareForCommit(kDestUrl); contents2->GetMainFrame()->PrepareForCommit();
EXPECT_TRUE(contents2->cross_navigation_pending()); EXPECT_TRUE(contents2->cross_navigation_pending());
TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame(); TestRenderFrameHost* dest_rfh2 = contents2->GetPendingMainFrame();
ASSERT_TRUE(dest_rfh2); ASSERT_TRUE(dest_rfh2);
...@@ -460,7 +460,7 @@ TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { ...@@ -460,7 +460,7 @@ TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) {
contents2->GetController().LoadURL( contents2->GetController().LoadURL(
kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); kChromeUrl, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
contents2->GetMainFrame()->PrepareForCommit(kChromeUrl); contents2->GetMainFrame()->PrepareForCommit();
contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl); contents2->GetPendingMainFrame()->SendNavigate(102, kChromeUrl);
EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(), EXPECT_NE(contents()->GetMainFrame()->GetSiteInstance(),
...@@ -795,7 +795,7 @@ TEST_F(RenderFrameHostManagerTest, AlwaysSendEnableViewSourceMode) { ...@@ -795,7 +795,7 @@ TEST_F(RenderFrameHostManagerTest, AlwaysSendEnableViewSourceMode) {
controller().LoadURL( controller().LoadURL(
kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
// Simulate response from RenderFrame for DispatchBeforeUnload. // Simulate response from RenderFrame for DispatchBeforeUnload.
contents()->GetMainFrame()->PrepareForCommit(kUrl); contents()->GetMainFrame()->PrepareForCommit();
ASSERT_TRUE(contents()->GetPendingMainFrame()) ASSERT_TRUE(contents()->GetPendingMainFrame())
<< "Expected new pending RenderFrameHost to be created."; << "Expected new pending RenderFrameHost to be created.";
RenderFrameHost* last_rfh = contents()->GetPendingMainFrame(); RenderFrameHost* last_rfh = contents()->GetPendingMainFrame();
...@@ -815,7 +815,7 @@ TEST_F(RenderFrameHostManagerTest, AlwaysSendEnableViewSourceMode) { ...@@ -815,7 +815,7 @@ TEST_F(RenderFrameHostManagerTest, AlwaysSendEnableViewSourceMode) {
// Navigate, again. // Navigate, again.
controller().LoadURL( controller().LoadURL(
kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); kUrl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
contents()->GetMainFrame()->PrepareForCommit(kUrl); contents()->GetMainFrame()->PrepareForCommit();
// The same RenderViewHost should be reused. // The same RenderViewHost should be reused.
EXPECT_FALSE(contents()->GetPendingMainFrame()); EXPECT_FALSE(contents()->GetPendingMainFrame());
EXPECT_TRUE(last_rfh == contents()->GetMainFrame()); EXPECT_TRUE(last_rfh == contents()->GetMainFrame());
...@@ -1075,7 +1075,7 @@ TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) { ...@@ -1075,7 +1075,7 @@ TEST_F(RenderFrameHostManagerTest, PageDoesBackAndReload) {
// Now let's simulate the evil page calling history.back(). // Now let's simulate the evil page calling history.back().
contents()->OnGoToEntryAtOffset(-1); contents()->OnGoToEntryAtOffset(-1);
contents()->GetMainFrame()->PrepareForCommit(kUrl1); contents()->GetMainFrame()->PrepareForCommit();
// We should have a new pending RFH. // We should have a new pending RFH.
// Note that in this case, the navigation has not committed, so evil_rfh will // Note that in this case, the navigation has not committed, so evil_rfh will
// not be deleted yet. // not be deleted yet.
...@@ -1160,7 +1160,7 @@ TEST_F(RenderFrameHostManagerTest, NavigateAfterMissingSwapOutACK) { ...@@ -1160,7 +1160,7 @@ TEST_F(RenderFrameHostManagerTest, NavigateAfterMissingSwapOutACK) {
// (http://crbug.com/93427). // (http://crbug.com/93427).
contents()->GetController().GoBack(); contents()->GetController().GoBack();
EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK()); EXPECT_TRUE(rfh2->IsWaitingForBeforeUnloadACK());
contents()->GetMainFrame()->PrepareForCommit(kUrl1); contents()->GetMainFrame()->PrepareForCommit();
EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK()); EXPECT_FALSE(rfh2->IsWaitingForBeforeUnloadACK());
// The back navigation commits. // The back navigation commits.
...@@ -1171,7 +1171,7 @@ TEST_F(RenderFrameHostManagerTest, NavigateAfterMissingSwapOutACK) { ...@@ -1171,7 +1171,7 @@ TEST_F(RenderFrameHostManagerTest, NavigateAfterMissingSwapOutACK) {
// We should be able to navigate forward. // We should be able to navigate forward.
contents()->GetController().GoForward(); contents()->GetController().GoForward();
contents()->GetMainFrame()->PrepareForCommit(kUrl2); contents()->GetMainFrame()->PrepareForCommit();
const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry();
rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); rfh2->SendNavigate(entry2->GetPageID(), entry2->GetURL());
EXPECT_EQ(rfh2, main_test_rfh()); EXPECT_EQ(rfh2, main_test_rfh());
...@@ -1342,7 +1342,7 @@ TEST_F(RenderFrameHostManagerTest, DisownOpenerDuringNavigation) { ...@@ -1342,7 +1342,7 @@ TEST_F(RenderFrameHostManagerTest, DisownOpenerDuringNavigation) {
// Start a back navigation so that rfh1 becomes the pending RFH. // Start a back navigation so that rfh1 becomes the pending RFH.
contents()->GetController().GoBack(); contents()->GetController().GoBack();
contents()->GetMainFrame()->PrepareForCommit(kUrl1); contents()->GetMainFrame()->PrepareForCommit();
// Disown the opener from rfh2. // Disown the opener from rfh2.
rfh2->DidDisownOpener(); rfh2->DidDisownOpener();
...@@ -1383,7 +1383,7 @@ TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) { ...@@ -1383,7 +1383,7 @@ TEST_F(RenderFrameHostManagerTest, DisownOpenerAfterNavigation) {
// Commit a back navigation before the DidDisownOpener message arrives. // Commit a back navigation before the DidDisownOpener message arrives.
// rfh1 will be kept alive because of the opener tab. // rfh1 will be kept alive because of the opener tab.
contents()->GetController().GoBack(); contents()->GetController().GoBack();
contents()->GetMainFrame()->PrepareForCommit(kUrl1); contents()->GetMainFrame()->PrepareForCommit();
const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry();
rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); rfh1->SendNavigate(entry1->GetPageID(), entry1->GetURL());
...@@ -1449,7 +1449,7 @@ TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) { ...@@ -1449,7 +1449,7 @@ TEST_F(RenderFrameHostManagerTest, CleanUpSwappedOutRVHOnProcessCrash) {
// Reload the initial tab. This should recreate the opener's swapped out RVH // Reload the initial tab. This should recreate the opener's swapped out RVH
// in the original SiteInstance. // in the original SiteInstance.
contents()->GetController().Reload(true); contents()->GetController().Reload(true);
contents()->GetMainFrame()->PrepareForCommit(kUrl1); contents()->GetMainFrame()->PrepareForCommit();
EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost( EXPECT_EQ(opener1_manager->GetSwappedOutRenderViewHost(
rvh1->GetSiteInstance())->GetRoutingID(), rvh1->GetSiteInstance())->GetRoutingID(),
test_rvh()->opener_route_id()); test_rvh()->opener_route_id());
...@@ -1644,7 +1644,7 @@ TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) { ...@@ -1644,7 +1644,7 @@ TEST_F(RenderFrameHostManagerTest, CloseWithPendingWhileUnresponsive) {
kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
if (base::CommandLine::ForCurrentProcess()->HasSwitch( if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableBrowserSideNavigation)) { switches::kEnableBrowserSideNavigation)) {
rfh1->PrepareForCommit(kUrl2); rfh1->PrepareForCommit();
} }
EXPECT_TRUE(contents()->cross_navigation_pending()); EXPECT_TRUE(contents()->cross_navigation_pending());
...@@ -1669,7 +1669,7 @@ TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) { ...@@ -1669,7 +1669,7 @@ TEST_F(RenderFrameHostManagerTest, DeleteFrameAfterSwapOutACK) {
// Navigate to new site, simulating onbeforeunload approval. // Navigate to new site, simulating onbeforeunload approval.
controller().LoadURL( controller().LoadURL(
kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
contents()->GetMainFrame()->PrepareForCommit(kUrl2); contents()->GetMainFrame()->PrepareForCommit();
EXPECT_TRUE(contents()->cross_navigation_pending()); EXPECT_TRUE(contents()->cross_navigation_pending());
EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
...@@ -1717,7 +1717,7 @@ TEST_F(RenderFrameHostManagerTest, SwapOutFrameAfterSwapOutACK) { ...@@ -1717,7 +1717,7 @@ TEST_F(RenderFrameHostManagerTest, SwapOutFrameAfterSwapOutACK) {
// Navigate to new site, simulating onbeforeunload approval. // Navigate to new site, simulating onbeforeunload approval.
controller().LoadURL( controller().LoadURL(
kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
contents()->GetMainFrame()->PrepareForCommit(kUrl2); contents()->GetMainFrame()->PrepareForCommit();
EXPECT_TRUE(contents()->cross_navigation_pending()); EXPECT_TRUE(contents()->cross_navigation_pending());
EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
...@@ -1760,7 +1760,7 @@ TEST_F(RenderFrameHostManagerTest, ...@@ -1760,7 +1760,7 @@ TEST_F(RenderFrameHostManagerTest,
// Navigate to new site, simulating onbeforeunload approval. // Navigate to new site, simulating onbeforeunload approval.
controller().LoadURL( controller().LoadURL(
kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); kUrl2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
rfh1->PrepareForCommit(kUrl2); rfh1->PrepareForCommit();
EXPECT_TRUE(contents()->cross_navigation_pending()); EXPECT_TRUE(contents()->cross_navigation_pending());
TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame(); TestRenderFrameHost* rfh2 = contents()->GetPendingMainFrame();
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "content/browser/loader/navigation_url_loader_delegate.h" #include "content/browser/loader/navigation_url_loader_delegate.h"
#include "content/public/browser/stream_handle.h" #include "content/public/browser/stream_handle.h"
#include "content/public/common/resource_response.h"
#include "net/url_request/redirect_info.h"
namespace content { namespace content {
...@@ -21,6 +23,16 @@ void TestNavigationURLLoader::FollowRedirect() { ...@@ -21,6 +23,16 @@ void TestNavigationURLLoader::FollowRedirect() {
redirect_count_++; redirect_count_++;
} }
void TestNavigationURLLoader::SimulateServerRedirect(const GURL& redirect_url) {
net::RedirectInfo redirect_info;
redirect_info.status_code = 302;
redirect_info.new_method = "GET";
redirect_info.new_url = redirect_url;
redirect_info.new_first_party_for_cookies = redirect_url;
scoped_refptr<ResourceResponse> response(new ResourceResponse);
CallOnRequestRedirected(redirect_info, response);
}
void TestNavigationURLLoader::CallOnRequestRedirected( void TestNavigationURLLoader::CallOnRequestRedirected(
const net::RedirectInfo& redirect_info, const net::RedirectInfo& redirect_info,
const scoped_refptr<ResourceResponse>& response) { const scoped_refptr<ResourceResponse>& response) {
......
...@@ -36,6 +36,8 @@ class TestNavigationURLLoader ...@@ -36,6 +36,8 @@ class TestNavigationURLLoader
NavigationRequestInfo* request_info() const { return request_info_.get(); } NavigationRequestInfo* request_info() const { return request_info_.get(); }
void SimulateServerRedirect(const GURL& redirect_url);
void CallOnRequestRedirected(const net::RedirectInfo& redirect_info, void CallOnRequestRedirected(const net::RedirectInfo& redirect_info,
const scoped_refptr<ResourceResponse>& response); const scoped_refptr<ResourceResponse>& response);
void CallOnResponseStarted(const scoped_refptr<ResourceResponse>& response, void CallOnResponseStarted(const scoped_refptr<ResourceResponse>& response,
......
...@@ -200,58 +200,71 @@ void TestRenderFrameHost::SendNavigateWithParameters( ...@@ -200,58 +200,71 @@ void TestRenderFrameHost::SendNavigateWithParameters(
OnDidCommitProvisionalLoad(msg); OnDidCommitProvisionalLoad(msg);
} }
void TestRenderFrameHost::SendBeginNavigationWithURL(const GURL& url, void TestRenderFrameHost::SendRendererInitiatedNavigationRequest(
bool has_user_gesture) { const GURL& url,
BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL, bool has_user_gesture) {
has_user_gesture); if (base::CommandLine::ForCurrentProcess()->HasSwitch(
CommonNavigationParams common_params; switches::kEnableBrowserSideNavigation)) {
common_params.url = url; BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL,
common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); has_user_gesture);
common_params.transition = ui::PAGE_TRANSITION_LINK; CommonNavigationParams common_params;
OnBeginNavigation(common_params, begin_params, common_params.url = url;
scoped_refptr<ResourceRequestBody>()); common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault);
common_params.transition = ui::PAGE_TRANSITION_LINK;
OnBeginNavigation(common_params, begin_params,
scoped_refptr<ResourceRequestBody>());
}
} }
void TestRenderFrameHost::DidDisownOpener() { void TestRenderFrameHost::DidDisownOpener() {
OnDidDisownOpener(); OnDidDisownOpener();
} }
void TestRenderFrameHost::PrepareForCommit(const GURL& url) { void TestRenderFrameHost::PrepareForCommit() {
PrepareForCommitWithServerRedirect(GURL());
}
void TestRenderFrameHost::PrepareForCommitWithServerRedirect(
const GURL& redirect_url) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch( if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableBrowserSideNavigation)) { switches::kEnableBrowserSideNavigation)) {
// Non PlzNavigate
SendBeforeUnloadACK(true); SendBeforeUnloadACK(true);
return; return;
} }
// PlzNavigate // PlzNavigate
// Simulate the network stack commit without any redirects.
NavigationRequest* request = NavigationRequest* request =
static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
->GetNavigationRequestForNodeForTesting(frame_tree_node_); ->GetNavigationRequestForNodeForTesting(frame_tree_node_);
CHECK(request);
// We are simulating a renderer-initiated user-initiated navigation. // Simulate a beforeUnload ACK from the renderer if the browser is waiting for
if (!request) { // it. If it runs it will update the request state.
SendBeginNavigationWithURL(url, true);
request = static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
->GetNavigationRequestForNodeForTesting(frame_tree_node_);
}
ASSERT_TRUE(request);
// We may not have simulated the renderer response to the navigation request.
// Do that now.
if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE)
SendBeforeUnloadACK(true); SendBeforeUnloadACK(true);
// We have already simulated the IO thread commit. Only the // If a network request is not needed for this URL, just check the request is
// DidCommitProvisionalLoad from the renderer is missing. // in the correct state and return.
if (request->state() == NavigationRequest::RESPONSE_STARTED) if (!request->ShouldMakeNetworkRequest(request->common_params().url)) {
CHECK(request->state() == NavigationRequest::RESPONSE_STARTED);
return; return;
}
CHECK(request->state() == NavigationRequest::STARTED);
ASSERT_TRUE(request->state() == NavigationRequest::STARTED);
TestNavigationURLLoader* url_loader = TestNavigationURLLoader* url_loader =
static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
ASSERT_TRUE(url_loader); CHECK(url_loader);
// If a non-empty |redirect_url| was provided, simulate a server redirect.
if (!redirect_url.is_empty())
url_loader->SimulateServerRedirect(redirect_url);
// Simulate the network stack commit.
scoped_refptr<ResourceResponse> response(new ResourceResponse); scoped_refptr<ResourceResponse> response(new ResourceResponse);
// TODO(carlosk): ideally with PlzNavigate it should be possible someday to
// fully commit the navigation at this call to CallOnResponseStarted.
url_loader->CallOnResponseStarted(response, MakeEmptyStream()); url_loader->CallOnResponseStarted(response, MakeEmptyStream());
} }
......
...@@ -85,7 +85,11 @@ class TestRenderFrameHost : public RenderFrameHostImpl, ...@@ -85,7 +85,11 @@ class TestRenderFrameHost : public RenderFrameHostImpl,
int response_code, int response_code,
const base::FilePath* file_path_for_history_item, const base::FilePath* file_path_for_history_item,
const std::vector<GURL>& redirects); const std::vector<GURL>& redirects);
void SendBeginNavigationWithURL(const GURL& url, bool has_user_gesture);
// With the current navigation logic this method is a no-op.
// PlzNavigate: this method simulates receiving a BeginNavigation IPC.
void SendRendererInitiatedNavigationRequest(const GURL& url,
bool has_user_gesture);
void DidDisownOpener(); void DidDisownOpener();
...@@ -102,7 +106,13 @@ class TestRenderFrameHost : public RenderFrameHostImpl, ...@@ -102,7 +106,13 @@ class TestRenderFrameHost : public RenderFrameHostImpl,
// this simulates a BeforeUnload ACK from the renderer. // this simulates a BeforeUnload ACK from the renderer.
// PlzNavigate: this simulates a BeforeUnload ACK from the renderer, and the // PlzNavigate: this simulates a BeforeUnload ACK from the renderer, and the
// interaction with the IO thread up until the response is ready to commit. // interaction with the IO thread up until the response is ready to commit.
void PrepareForCommit(const GURL& url); void PrepareForCommit();
// This method does the same as PrepareForCommit.
// PlzNavigate: Beyond doing the same as PrepareForCommit, this method will
// also simulate a server redirect to |redirect_url|. If the URL is empty the
// redirect step is ignored.
void PrepareForCommitWithServerRedirect(const GURL& redirect_url);
// Simulate receiving a FrameHostMsg_BeforeUnloadHandlersPresent. // Simulate receiving a FrameHostMsg_BeforeUnloadHandlersPresent.
void SendBeforeUnloadHandlersPresent(bool present); void SendBeforeUnloadHandlersPresent(bool present);
......
...@@ -158,7 +158,7 @@ void TestWebContents::CommitPendingNavigation() { ...@@ -158,7 +158,7 @@ void TestWebContents::CommitPendingNavigation() {
// replaced without a pending frame being created, and we don't get the right // replaced without a pending frame being created, and we don't get the right
// values for the RFH to navigate: we try to use the old one that has been // values for the RFH to navigate: we try to use the old one that has been
// deleted in the meantime. // deleted in the meantime.
GetMainFrame()->PrepareForCommit(entry->GetURL()); GetMainFrame()->PrepareForCommit();
TestRenderFrameHost* old_rfh = GetMainFrame(); TestRenderFrameHost* old_rfh = GetMainFrame();
TestRenderFrameHost* rfh = GetPendingMainFrame(); TestRenderFrameHost* rfh = GetPendingMainFrame();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment