| 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/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/run_loop.h" |
| 8 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
| 9 #include "content/browser/frame_host/navigation_handle_impl.h" | 10 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 10 #include "content/browser/frame_host/navigation_request.h" | 11 #include "content/browser/frame_host/navigation_request.h" |
| 11 #include "content/browser/frame_host/navigator.h" | 12 #include "content/browser/frame_host/navigator.h" |
| 12 #include "content/browser/frame_host/navigator_impl.h" | 13 #include "content/browser/frame_host/navigator_impl.h" |
| 13 #include "content/browser/frame_host/render_frame_host_delegate.h" | 14 #include "content/browser/frame_host/render_frame_host_delegate.h" |
| 14 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
| 15 #include "content/common/frame_messages.h" | 16 #include "content/common/frame_messages.h" |
| 16 #include "content/common/frame_owner_properties.h" | 17 #include "content/common/frame_owner_properties.h" |
| 17 #include "content/public/browser/navigation_throttle.h" | 18 #include "content/public/browser/navigation_throttle.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 111 } |
| 111 | 112 |
| 112 OnDidStartLoading(true); | 113 OnDidStartLoading(true); |
| 113 OnDidStartProvisionalLoad(url, base::TimeTicks::Now()); | 114 OnDidStartProvisionalLoad(url, base::TimeTicks::Now()); |
| 114 SimulateWillStartRequest(ui::PAGE_TRANSITION_LINK); | 115 SimulateWillStartRequest(ui::PAGE_TRANSITION_LINK); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void TestRenderFrameHost::SimulateRedirect(const GURL& new_url) { | 118 void TestRenderFrameHost::SimulateRedirect(const GURL& new_url) { |
| 118 if (IsBrowserSideNavigationEnabled()) { | 119 if (IsBrowserSideNavigationEnabled()) { |
| 119 NavigationRequest* request = frame_tree_node_->navigation_request(); | 120 NavigationRequest* request = frame_tree_node_->navigation_request(); |
| 121 if (!request->loader_for_testing()) { |
| 122 base::RunLoop loop; |
| 123 request->set_on_start_checks_complete_closure_for_testing( |
| 124 loop.QuitClosure()); |
| 125 loop.Run(); |
| 126 } |
| 120 TestNavigationURLLoader* url_loader = | 127 TestNavigationURLLoader* url_loader = |
| 121 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | 128 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); |
| 122 CHECK(url_loader); | 129 CHECK(url_loader); |
| 123 url_loader->SimulateServerRedirect(new_url); | 130 url_loader->SimulateServerRedirect(new_url); |
| 124 return; | 131 return; |
| 125 } | 132 } |
| 126 | 133 |
| 127 navigation_handle()->CallWillRedirectRequestForTesting(new_url, false, GURL(), | 134 navigation_handle()->CallWillRedirectRequestForTesting(new_url, false, GURL(), |
| 128 false); | 135 false); |
| 129 } | 136 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 int error_code) { | 183 int error_code) { |
| 177 if (IsBrowserSideNavigationEnabled()) { | 184 if (IsBrowserSideNavigationEnabled()) { |
| 178 NavigationRequest* request = frame_tree_node_->navigation_request(); | 185 NavigationRequest* request = frame_tree_node_->navigation_request(); |
| 179 CHECK(request); | 186 CHECK(request); |
| 180 // Simulate a beforeUnload ACK from the renderer if the browser is waiting | 187 // Simulate a beforeUnload ACK from the renderer if the browser is waiting |
| 181 // for it. If it runs it will update the request state. | 188 // for it. If it runs it will update the request state. |
| 182 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) { | 189 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) { |
| 183 static_cast<TestRenderFrameHost*>(frame_tree_node()->current_frame_host()) | 190 static_cast<TestRenderFrameHost*>(frame_tree_node()->current_frame_host()) |
| 184 ->SendBeforeUnloadACK(true); | 191 ->SendBeforeUnloadACK(true); |
| 185 } | 192 } |
| 193 if (!request->loader_for_testing()) { |
| 194 base::RunLoop loop; |
| 195 request->set_on_start_checks_complete_closure_for_testing( |
| 196 loop.QuitClosure()); |
| 197 loop.Run(); |
| 198 } |
| 186 TestNavigationURLLoader* url_loader = | 199 TestNavigationURLLoader* url_loader = |
| 187 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | 200 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); |
| 188 CHECK(url_loader); | 201 CHECK(url_loader); |
| 189 url_loader->SimulateError(error_code); | 202 url_loader->SimulateError(error_code); |
| 190 return; | 203 return; |
| 191 } | 204 } |
| 192 | 205 |
| 193 FrameHostMsg_DidFailProvisionalLoadWithError_Params error_params; | 206 FrameHostMsg_DidFailProvisionalLoadWithError_Params error_params; |
| 194 error_params.error_code = error_code; | 207 error_params.error_code = error_code; |
| 195 error_params.url = url; | 208 error_params.url = url; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) { | 453 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) { |
| 441 static_cast<TestRenderFrameHost*>(frame_tree_node()->current_frame_host()) | 454 static_cast<TestRenderFrameHost*>(frame_tree_node()->current_frame_host()) |
| 442 ->SendBeforeUnloadACK(true); | 455 ->SendBeforeUnloadACK(true); |
| 443 } | 456 } |
| 444 | 457 |
| 445 if (!have_to_make_network_request) | 458 if (!have_to_make_network_request) |
| 446 return; // |request| is destructed by now. | 459 return; // |request| is destructed by now. |
| 447 | 460 |
| 448 CHECK(request->state() == NavigationRequest::STARTED); | 461 CHECK(request->state() == NavigationRequest::STARTED); |
| 449 | 462 |
| 463 if (!request->loader_for_testing()) { |
| 464 base::RunLoop loop; |
| 465 request->set_on_start_checks_complete_closure_for_testing( |
| 466 loop.QuitClosure()); |
| 467 loop.Run(); |
| 468 } |
| 469 |
| 450 TestNavigationURLLoader* url_loader = | 470 TestNavigationURLLoader* url_loader = |
| 451 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | 471 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); |
| 452 CHECK(url_loader); | 472 CHECK(url_loader); |
| 453 | 473 |
| 454 // If a non-empty |redirect_url| was provided, simulate a server redirect. | 474 // If a non-empty |redirect_url| was provided, simulate a server redirect. |
| 455 if (!redirect_url.is_empty()) | 475 if (!redirect_url.is_empty()) |
| 456 url_loader->SimulateServerRedirect(redirect_url); | 476 url_loader->SimulateServerRedirect(redirect_url); |
| 457 | 477 |
| 458 // Simulate the network stack commit. | 478 // Simulate the network stack commit. |
| 459 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 479 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 482 // PlzNavigate: NavigationHandle::WillStartRequest has already been called at | 502 // PlzNavigate: NavigationHandle::WillStartRequest has already been called at |
| 483 // this point. | 503 // this point. |
| 484 if (!navigation_handle() || IsBrowserSideNavigationEnabled()) | 504 if (!navigation_handle() || IsBrowserSideNavigationEnabled()) |
| 485 return; | 505 return; |
| 486 navigation_handle()->CallWillStartRequestForTesting( | 506 navigation_handle()->CallWillStartRequestForTesting( |
| 487 false /* is_post */, Referrer(GURL(), blink::WebReferrerPolicyDefault), | 507 false /* is_post */, Referrer(GURL(), blink::WebReferrerPolicyDefault), |
| 488 true /* user_gesture */, transition, false /* is_external_protocol */); | 508 true /* user_gesture */, transition, false /* is_external_protocol */); |
| 489 } | 509 } |
| 490 | 510 |
| 491 } // namespace content | 511 } // namespace content |
| OLD | NEW |