| 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 "base/run_loop.h" |
| 9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
| 10 #include "content/browser/frame_host/navigation_handle_impl.h" | 10 #include "content/browser/frame_host/navigation_handle_impl.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
| 28 #include "third_party/WebKit/public/platform/WebMixedContentContextType.h" | 28 #include "third_party/WebKit/public/platform/WebMixedContentContextType.h" |
| 29 #include "third_party/WebKit/public/platform/WebPageVisibilityState.h" | 29 #include "third_party/WebKit/public/platform/WebPageVisibilityState.h" |
| 30 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
om.h" | 30 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
om.h" |
| 31 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 31 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 32 #include "third_party/WebKit/public/web/WebTreeScopeType.h" | 32 #include "third_party/WebKit/public/web/WebTreeScopeType.h" |
| 33 #include "ui/base/page_transition_types.h" | 33 #include "ui/base/page_transition_types.h" |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 | 36 |
| 37 namespace { |
| 38 |
| 39 void CallbackRunner(const base::Closure& closure, |
| 40 NavigationThrottle::ThrottleCheckResult result) { |
| 41 closure.Run(); |
| 42 } |
| 43 |
| 44 } // namesapce |
| 45 |
| 37 TestRenderFrameHostCreationObserver::TestRenderFrameHostCreationObserver( | 46 TestRenderFrameHostCreationObserver::TestRenderFrameHostCreationObserver( |
| 38 WebContents* web_contents) | 47 WebContents* web_contents) |
| 39 : WebContentsObserver(web_contents), last_created_frame_(NULL) { | 48 : WebContentsObserver(web_contents), last_created_frame_(NULL) { |
| 40 } | 49 } |
| 41 | 50 |
| 42 TestRenderFrameHostCreationObserver::~TestRenderFrameHostCreationObserver() { | 51 TestRenderFrameHostCreationObserver::~TestRenderFrameHostCreationObserver() { |
| 43 } | 52 } |
| 44 | 53 |
| 45 void TestRenderFrameHostCreationObserver::RenderFrameCreated( | 54 void TestRenderFrameHostCreationObserver::RenderFrameCreated( |
| 46 RenderFrameHost* render_frame_host) { | 55 RenderFrameHost* render_frame_host) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 OnDidStartLoading(true); | 124 OnDidStartLoading(true); |
| 116 OnDidStartProvisionalLoad(url, std::vector<GURL>(), base::TimeTicks::Now()); | 125 OnDidStartProvisionalLoad(url, std::vector<GURL>(), base::TimeTicks::Now()); |
| 117 SimulateWillStartRequest(ui::PAGE_TRANSITION_LINK); | 126 SimulateWillStartRequest(ui::PAGE_TRANSITION_LINK); |
| 118 } | 127 } |
| 119 | 128 |
| 120 void TestRenderFrameHost::SimulateRedirect(const GURL& new_url) { | 129 void TestRenderFrameHost::SimulateRedirect(const GURL& new_url) { |
| 121 if (IsBrowserSideNavigationEnabled()) { | 130 if (IsBrowserSideNavigationEnabled()) { |
| 122 NavigationRequest* request = frame_tree_node_->navigation_request(); | 131 NavigationRequest* request = frame_tree_node_->navigation_request(); |
| 123 if (!request->loader_for_testing()) { | 132 if (!request->loader_for_testing()) { |
| 124 base::RunLoop loop; | 133 base::RunLoop loop; |
| 125 request->set_on_start_checks_complete_closure_for_testing( | 134 request->set_on_checks_complete_callback_for_testing( |
| 126 loop.QuitClosure()); | 135 base::Bind(&CallbackRunner, loop.QuitClosure())); |
| 127 loop.Run(); | 136 loop.Run(); |
| 128 } | 137 } |
| 129 TestNavigationURLLoader* url_loader = | 138 TestNavigationURLLoader* url_loader = |
| 130 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | 139 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); |
| 131 CHECK(url_loader); | 140 CHECK(url_loader); |
| 132 url_loader->SimulateServerRedirect(new_url); | 141 url_loader->SimulateServerRedirect(new_url); |
| 133 return; | 142 return; |
| 134 } | 143 } |
| 135 | 144 |
| 136 navigation_handle()->CallWillRedirectRequestForTesting(new_url, false, GURL(), | 145 navigation_handle()->CallWillRedirectRequestForTesting(new_url, false, GURL(), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 NavigationRequest* request = frame_tree_node_->navigation_request(); | 196 NavigationRequest* request = frame_tree_node_->navigation_request(); |
| 188 CHECK(request); | 197 CHECK(request); |
| 189 // Simulate a beforeUnload ACK from the renderer if the browser is waiting | 198 // Simulate a beforeUnload ACK from the renderer if the browser is waiting |
| 190 // for it. If it runs it will update the request state. | 199 // for it. If it runs it will update the request state. |
| 191 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) { | 200 if (request->state() == NavigationRequest::WAITING_FOR_RENDERER_RESPONSE) { |
| 192 static_cast<TestRenderFrameHost*>(frame_tree_node()->current_frame_host()) | 201 static_cast<TestRenderFrameHost*>(frame_tree_node()->current_frame_host()) |
| 193 ->SendBeforeUnloadACK(true); | 202 ->SendBeforeUnloadACK(true); |
| 194 } | 203 } |
| 195 if (!request->loader_for_testing()) { | 204 if (!request->loader_for_testing()) { |
| 196 base::RunLoop loop; | 205 base::RunLoop loop; |
| 197 request->set_on_start_checks_complete_closure_for_testing( | 206 request->set_on_checks_complete_callback_for_testing( |
| 198 loop.QuitClosure()); | 207 base::Bind(&CallbackRunner, loop.QuitClosure())); |
| 199 loop.Run(); | 208 loop.Run(); |
| 200 } | 209 } |
| 201 TestNavigationURLLoader* url_loader = | 210 TestNavigationURLLoader* url_loader = |
| 202 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | 211 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); |
| 203 CHECK(url_loader); | 212 CHECK(url_loader); |
| 204 url_loader->SimulateError(error_code); | 213 url_loader->SimulateError(error_code); |
| 205 return; | 214 return; |
| 206 } | 215 } |
| 207 | 216 |
| 208 FrameHostMsg_DidFailProvisionalLoadWithError_Params error_params; | 217 FrameHostMsg_DidFailProvisionalLoadWithError_Params error_params; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 ->SendBeforeUnloadACK(true); | 480 ->SendBeforeUnloadACK(true); |
| 472 } | 481 } |
| 473 | 482 |
| 474 if (!have_to_make_network_request) | 483 if (!have_to_make_network_request) |
| 475 return; // |request| is destructed by now. | 484 return; // |request| is destructed by now. |
| 476 | 485 |
| 477 CHECK(request->state() == NavigationRequest::STARTED); | 486 CHECK(request->state() == NavigationRequest::STARTED); |
| 478 | 487 |
| 479 if (!request->loader_for_testing()) { | 488 if (!request->loader_for_testing()) { |
| 480 base::RunLoop loop; | 489 base::RunLoop loop; |
| 481 request->set_on_start_checks_complete_closure_for_testing( | 490 request->set_on_checks_complete_callback_for_testing( |
| 482 loop.QuitClosure()); | 491 base::Bind(&CallbackRunner, loop.QuitClosure())); |
| 483 loop.Run(); | 492 loop.Run(); |
| 484 } | 493 } |
| 485 | 494 |
| 486 TestNavigationURLLoader* url_loader = | 495 TestNavigationURLLoader* url_loader = |
| 487 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | 496 static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); |
| 488 CHECK(url_loader); | 497 CHECK(url_loader); |
| 489 | 498 |
| 490 // If a non-empty |redirect_url| was provided, simulate a server redirect. | 499 // If a non-empty |redirect_url| was provided, simulate a server redirect. |
| 491 if (!redirect_url.is_empty()) | 500 if (!redirect_url.is_empty()) |
| 492 url_loader->SimulateServerRedirect(redirect_url); | 501 url_loader->SimulateServerRedirect(redirect_url); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 518 // PlzNavigate: NavigationHandle::WillStartRequest has already been called at | 527 // PlzNavigate: NavigationHandle::WillStartRequest has already been called at |
| 519 // this point. | 528 // this point. |
| 520 if (!navigation_handle() || IsBrowserSideNavigationEnabled()) | 529 if (!navigation_handle() || IsBrowserSideNavigationEnabled()) |
| 521 return; | 530 return; |
| 522 navigation_handle()->CallWillStartRequestForTesting( | 531 navigation_handle()->CallWillStartRequestForTesting( |
| 523 false /* is_post */, Referrer(GURL(), blink::WebReferrerPolicyDefault), | 532 false /* is_post */, Referrer(GURL(), blink::WebReferrerPolicyDefault), |
| 524 true /* user_gesture */, transition, false /* is_external_protocol */); | 533 true /* user_gesture */, transition, false /* is_external_protocol */); |
| 525 } | 534 } |
| 526 | 535 |
| 527 } // namespace content | 536 } // namespace content |
| OLD | NEW |