| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/test/test_render_frame_host.h" | 5 #include "content/test/test_render_frame_host.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/browser/frame_host/frame_tree.h" | 8 #include "content/browser/frame_host/frame_tree.h" |
| 9 #include "content/browser/frame_host/navigation_request.h" | 9 #include "content/browser/frame_host/navigation_request.h" |
| 10 #include "content/browser/frame_host/navigator.h" | 10 #include "content/browser/frame_host/navigator.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 params.page_state = PageState::CreateForTesting( | 193 params.page_state = PageState::CreateForTesting( |
| 194 url, | 194 url, |
| 195 false, | 195 false, |
| 196 file_path_for_history_item ? "data" : NULL, | 196 file_path_for_history_item ? "data" : NULL, |
| 197 file_path_for_history_item); | 197 file_path_for_history_item); |
| 198 | 198 |
| 199 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), params); | 199 FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), params); |
| 200 OnDidCommitProvisionalLoad(msg); | 200 OnDidCommitProvisionalLoad(msg); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void TestRenderFrameHost::SendBeginNavigationWithURL(const GURL& url, | 203 void TestRenderFrameHost::SendRendererInitiatedNavigationRequest( |
| 204 bool has_user_gesture) { | 204 const GURL& url, |
| 205 BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL, | 205 bool has_user_gesture) { |
| 206 has_user_gesture); | 206 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 207 CommonNavigationParams common_params; | 207 switches::kEnableBrowserSideNavigation)) { |
| 208 common_params.url = url; | 208 BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL, |
| 209 common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); | 209 has_user_gesture); |
| 210 common_params.transition = ui::PAGE_TRANSITION_LINK; | 210 CommonNavigationParams common_params; |
| 211 OnBeginNavigation(common_params, begin_params, | 211 common_params.url = url; |
| 212 scoped_refptr<ResourceRequestBody>()); | 212 common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); |
| 213 common_params.transition = ui::PAGE_TRANSITION_LINK; |
| 214 OnBeginNavigation(common_params, begin_params, |
| 215 scoped_refptr<ResourceRequestBody>()); |
| 216 } |
| 213 } | 217 } |
| 214 | 218 |
| 215 void TestRenderFrameHost::DidDisownOpener() { | 219 void TestRenderFrameHost::DidDisownOpener() { |
| 216 OnDidDisownOpener(); | 220 OnDidDisownOpener(); |
| 217 } | 221 } |
| 218 | 222 |
| 219 void TestRenderFrameHost::PrepareForCommit(const GURL& url) { | 223 void TestRenderFrameHost::PrepareForCommit() { |
| 224 PrepareForCommitWithServerRedirect(GURL()); |
| 225 } |
| 226 |
| 227 void TestRenderFrameHost::PrepareForCommitWithServerRedirect( |
| 228 const GURL& redirect_url) { |
| 220 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 229 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 221 switches::kEnableBrowserSideNavigation)) { | 230 switches::kEnableBrowserSideNavigation)) { |
| 231 // Non PlzNavigate |
| 222 SendBeforeUnloadACK(true); | 232 SendBeforeUnloadACK(true); |
| 223 return; | 233 return; |
| 224 } | 234 } |
| 225 | 235 |
| 226 // PlzNavigate | 236 // PlzNavigate |
| 227 // Simulate the network stack commit without any redirects. | |
| 228 NavigationRequest* request = | 237 NavigationRequest* request = |
| 229 static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) | 238 static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) |
| 230 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); | 239 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); |
| 240 CHECK(request); |
| 231 | 241 |
| 232 // We are simulating a renderer-initiated user-initiated navigation. | 242 // Simulate a beforeUnload ACK from the renderer if the browser is waiting for |
| 233 if (!request) { | 243 // it. If it runs it will update the request state. |
| 234 SendBeginNavigationWithURL(url, true); | |
| 235 request = static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) | |
| 236 ->GetNavigationRequestForNodeForTesting(frame_tree_node_); | |
| 237 } | |
| 238 ASSERT_TRUE(request); | |
| 239 | |
| 240 // We may not have simulated the renderer response to the navigation request. | |
| 241 // Do that now. | |
| 242 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) | 244 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) |
| 243 SendBeforeUnloadACK(true); | 245 SendBeforeUnloadACK(true); |
| 244 | 246 |
| 245 // We have already simulated the IO thread commit. Only the | 247 // If a network request is not needed for this URL, just check the request is |
| 246 // DidCommitProvisionalLoad from the renderer is missing. | 248 // in the correct state and return. |
| 247 if (request->state() == NavigationRequest::RESPONSE_STARTED) | 249 if (!request->ShouldMakeNetworkRequest(request->common_params().url)) { |
| 250 CHECK(request->state() == NavigationRequest::RESPONSE_STARTED); |
| 248 return; | 251 return; |
| 252 } |
| 249 | 253 |
| 250 ASSERT_TRUE(request->state() == NavigationRequest::STARTED); | 254 CHECK(request->state() == NavigationRequest::STARTED); |
| 255 |
| 251 TestNavigationURLLoader* url_loader = | 256 TestNavigationURLLoader* url_loader = |
| 252 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | 257 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); |
| 253 ASSERT_TRUE(url_loader); | 258 CHECK(url_loader); |
| 259 |
| 260 // If a non-empty |redirect_url| was provided, simulate a server redirect |
| 261 if (!redirect_url.is_empty()) |
| 262 url_loader->SimulateServerRedirect(redirect_url); |
| 263 |
| 264 // Simulate the network stack commit |
| 254 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 265 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| 266 // TODO(carlosk): ideally with PlzNavigate it should be possible someday to |
| 267 // fully commit the navigation at this call to CallOnResponseStarted. |
| 255 url_loader->CallOnResponseStarted(response, MakeEmptyStream()); | 268 url_loader->CallOnResponseStarted(response, MakeEmptyStream()); |
| 256 } | 269 } |
| 257 | 270 |
| 258 void TestRenderFrameHost::SendBeforeUnloadHandlersPresent(bool present) { | 271 void TestRenderFrameHost::SendBeforeUnloadHandlersPresent(bool present) { |
| 259 OnBeforeUnloadHandlersPresent(present); | 272 OnBeforeUnloadHandlersPresent(present); |
| 260 } | 273 } |
| 261 | 274 |
| 262 void TestRenderFrameHost::SendUnloadHandlersPresent(bool present) { | 275 void TestRenderFrameHost::SendUnloadHandlersPresent(bool present) { |
| 263 OnUnloadHandlersPresent(present); | 276 OnUnloadHandlersPresent(present); |
| 264 } | 277 } |
| 265 | 278 |
| 266 } // namespace content | 279 } // namespace content |
| OLD | NEW |