OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/public/test/navigation_simulator.h" | 5 #include "content/public/test/navigation_simulator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/browser/frame_host/navigation_handle_impl.h" | 10 #include "content/browser/frame_host/navigation_handle_impl.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 true /* user_gesture */, transition_, false /* is_external_protocol */, | 149 true /* user_gesture */, transition_, false /* is_external_protocol */, |
150 REQUEST_CONTEXT_TYPE_LOCATION, | 150 REQUEST_CONTEXT_TYPE_LOCATION, |
151 blink::WebMixedContentContextType::kNotMixedContent, | 151 blink::WebMixedContentContextType::kNotMixedContent, |
152 base::Callback<void(NavigationThrottle::ThrottleCheckResult)>()); | 152 base::Callback<void(NavigationThrottle::ThrottleCheckResult)>()); |
153 } | 153 } |
154 | 154 |
155 CHECK(handle_); | 155 CHECK(handle_); |
156 WaitForThrottleChecksComplete(); | 156 WaitForThrottleChecksComplete(); |
157 | 157 |
158 CHECK_EQ(1, num_did_start_navigation_called_); | 158 CHECK_EQ(1, num_did_start_navigation_called_); |
159 if (GetLastThrottleCheckResult() == NavigationThrottle::PROCEED) { | 159 NavigationThrottle::ThrottleCheckResult result = GetLastThrottleCheckResult(); |
| 160 if (result.action() == NavigationThrottle::PROCEED) { |
160 CHECK_EQ(1, num_will_start_request_called_); | 161 CHECK_EQ(1, num_will_start_request_called_); |
161 } else { | 162 } else { |
162 FailFromThrottleCheck(GetLastThrottleCheckResult()); | 163 FailFromThrottleCheck(result); |
163 } | 164 } |
164 } | 165 } |
165 | 166 |
166 void NavigationSimulator::Redirect(const GURL& new_url) { | 167 void NavigationSimulator::Redirect(const GURL& new_url) { |
167 CHECK(state_ <= STARTED) << "NavigationSimulator::Redirect should be " | 168 CHECK(state_ <= STARTED) << "NavigationSimulator::Redirect should be " |
168 "called before Fail or Commit"; | 169 "called before Fail or Commit"; |
169 CHECK_EQ(0, num_did_finish_navigation_called_) | 170 CHECK_EQ(0, num_did_finish_navigation_called_) |
170 << "NavigationSimulator::Redirect cannot be called after the " | 171 << "NavigationSimulator::Redirect cannot be called after the " |
171 "navigation has finished"; | 172 "navigation has finished"; |
172 | 173 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 redirect_info, scoped_refptr<ResourceResponse>(new ResourceResponse)); | 205 redirect_info, scoped_refptr<ResourceResponse>(new ResourceResponse)); |
205 } else { | 206 } else { |
206 handle_->WillRedirectRequest( | 207 handle_->WillRedirectRequest( |
207 new_url, "GET", referrer_.url, false /* is_external_protocol */, | 208 new_url, "GET", referrer_.url, false /* is_external_protocol */, |
208 scoped_refptr<net::HttpResponseHeaders>(), | 209 scoped_refptr<net::HttpResponseHeaders>(), |
209 net::HttpResponseInfo::ConnectionInfo(), | 210 net::HttpResponseInfo::ConnectionInfo(), |
210 base::Callback<void(NavigationThrottle::ThrottleCheckResult)>()); | 211 base::Callback<void(NavigationThrottle::ThrottleCheckResult)>()); |
211 } | 212 } |
212 | 213 |
213 WaitForThrottleChecksComplete(); | 214 WaitForThrottleChecksComplete(); |
214 | 215 NavigationThrottle::ThrottleCheckResult result = GetLastThrottleCheckResult(); |
215 if (GetLastThrottleCheckResult() == NavigationThrottle::PROCEED) { | 216 if (result.action() == NavigationThrottle::PROCEED) { |
216 CHECK_EQ(previous_num_will_redirect_request_called + 1, | 217 CHECK_EQ(previous_num_will_redirect_request_called + 1, |
217 num_will_redirect_request_called_); | 218 num_will_redirect_request_called_); |
218 CHECK_EQ(previous_did_redirect_navigation_called + 1, | 219 CHECK_EQ(previous_did_redirect_navigation_called + 1, |
219 num_did_redirect_navigation_called_); | 220 num_did_redirect_navigation_called_); |
220 } else { | 221 } else { |
221 FailFromThrottleCheck(GetLastThrottleCheckResult()); | 222 FailFromThrottleCheck(result); |
222 } | 223 } |
223 } | 224 } |
224 | 225 |
225 void NavigationSimulator::Commit() { | 226 void NavigationSimulator::Commit() { |
226 CHECK_LE(state_, STARTED) << "NavigationSimulator::Commit can only be " | 227 CHECK_LE(state_, STARTED) << "NavigationSimulator::Commit can only be " |
227 "called once, and cannot be called after " | 228 "called once, and cannot be called after " |
228 "NavigationSimulator::Fail"; | 229 "NavigationSimulator::Fail"; |
229 CHECK_EQ(0, num_did_finish_navigation_called_) | 230 CHECK_EQ(0, num_did_finish_navigation_called_) |
230 << "NavigationSimulator::Commit cannot be called after the " | 231 << "NavigationSimulator::Commit cannot be called after the " |
231 "navigation has finished"; | 232 "navigation has finished"; |
(...skipping 22 matching lines...) Expand all Loading... |
254 handle_->WillProcessResponse( | 255 handle_->WillProcessResponse( |
255 render_frame_host_, scoped_refptr<net::HttpResponseHeaders>(), | 256 render_frame_host_, scoped_refptr<net::HttpResponseHeaders>(), |
256 net::HttpResponseInfo::ConnectionInfo(), SSLStatus(), GlobalRequestID(), | 257 net::HttpResponseInfo::ConnectionInfo(), SSLStatus(), GlobalRequestID(), |
257 false /* should_replace_current_entry */, false /* is_download */, | 258 false /* should_replace_current_entry */, false /* is_download */, |
258 false /* is_stream */, base::Closure(), | 259 false /* is_stream */, base::Closure(), |
259 base::Callback<void(NavigationThrottle::ThrottleCheckResult)>()); | 260 base::Callback<void(NavigationThrottle::ThrottleCheckResult)>()); |
260 } | 261 } |
261 | 262 |
262 WaitForThrottleChecksComplete(); | 263 WaitForThrottleChecksComplete(); |
263 | 264 |
264 if (GetLastThrottleCheckResult() != NavigationThrottle::PROCEED) { | 265 NavigationThrottle::ThrottleCheckResult result = GetLastThrottleCheckResult(); |
265 FailFromThrottleCheck(GetLastThrottleCheckResult()); | 266 if (result.action() != NavigationThrottle::PROCEED) { |
| 267 FailFromThrottleCheck(result); |
266 return; | 268 return; |
267 } | 269 } |
268 | 270 |
269 CHECK_EQ(1, num_will_process_response_called_); | 271 CHECK_EQ(1, num_will_process_response_called_); |
270 CHECK_EQ(1, num_ready_to_commit_called_); | 272 CHECK_EQ(1, num_ready_to_commit_called_); |
271 | 273 |
272 // Update the RenderFrameHost now that we know which RenderFrameHost will | 274 // Update the RenderFrameHost now that we know which RenderFrameHost will |
273 // commit the navigation. | 275 // commit the navigation. |
274 TestRenderFrameHost* new_render_frame_host = | 276 TestRenderFrameHost* new_render_frame_host = |
275 static_cast<TestRenderFrameHost*>(handle_->GetRenderFrameHost()); | 277 static_cast<TestRenderFrameHost*>(handle_->GetRenderFrameHost()); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 weak_factory_.GetWeakPtr())); | 570 weak_factory_.GetWeakPtr())); |
569 } | 571 } |
570 | 572 |
571 RenderFrameHost* NavigationSimulator::GetFinalRenderFrameHost() { | 573 RenderFrameHost* NavigationSimulator::GetFinalRenderFrameHost() { |
572 CHECK_EQ(state_, FINISHED); | 574 CHECK_EQ(state_, FINISHED); |
573 return render_frame_host_; | 575 return render_frame_host_; |
574 } | 576 } |
575 | 577 |
576 void NavigationSimulator::FailFromThrottleCheck( | 578 void NavigationSimulator::FailFromThrottleCheck( |
577 NavigationThrottle::ThrottleCheckResult result) { | 579 NavigationThrottle::ThrottleCheckResult result) { |
578 DCHECK_NE(result, NavigationThrottle::PROCEED); | 580 DCHECK_NE(result.action(), NavigationThrottle::PROCEED); |
579 state_ = FAILED; | 581 state_ = FAILED; |
580 | 582 |
581 // Special failure logic only needed for non-PlzNavigate case. | 583 // Special failure logic only needed for non-PlzNavigate case. |
582 if (IsBrowserSideNavigationEnabled()) | 584 if (IsBrowserSideNavigationEnabled()) |
583 return; | 585 return; |
584 int error_code = net::OK; | 586 DCHECK_NE(result.action(), NavigationThrottle::DEFER); |
585 switch (result) { | 587 DCHECK_NE(result.net_error_code(), net::OK); |
586 case NavigationThrottle::PROCEED: | |
587 case NavigationThrottle::DEFER: | |
588 NOTREACHED(); | |
589 break; | |
590 case NavigationThrottle::CANCEL: | |
591 case NavigationThrottle::CANCEL_AND_IGNORE: | |
592 error_code = net::ERR_ABORTED; | |
593 break; | |
594 case NavigationThrottle::BLOCK_REQUEST: | |
595 error_code = net::ERR_BLOCKED_BY_CLIENT; | |
596 break; | |
597 case NavigationThrottle::BLOCK_RESPONSE: | |
598 error_code = net::ERR_BLOCKED_BY_RESPONSE; | |
599 break; | |
600 }; | |
601 | 588 |
602 FrameHostMsg_DidFailProvisionalLoadWithError_Params error_params; | 589 FrameHostMsg_DidFailProvisionalLoadWithError_Params error_params; |
603 error_params.error_code = error_code; | 590 error_params.error_code = result.net_error_code(); |
604 error_params.url = navigation_url_; | 591 error_params.url = navigation_url_; |
605 render_frame_host_->OnMessageReceived( | 592 render_frame_host_->OnMessageReceived( |
606 FrameHostMsg_DidFailProvisionalLoadWithError( | 593 FrameHostMsg_DidFailProvisionalLoadWithError( |
607 render_frame_host_->GetRoutingID(), error_params)); | 594 render_frame_host_->GetRoutingID(), error_params)); |
608 bool should_result_in_error_page = error_code != net::ERR_ABORTED; | 595 bool should_result_in_error_page = |
| 596 result.net_error_code() != net::ERR_ABORTED; |
609 if (!should_result_in_error_page) { | 597 if (!should_result_in_error_page) { |
610 render_frame_host_->OnMessageReceived( | 598 render_frame_host_->OnMessageReceived( |
611 FrameHostMsg_DidStopLoading(render_frame_host_->GetRoutingID())); | 599 FrameHostMsg_DidStopLoading(render_frame_host_->GetRoutingID())); |
612 CHECK_EQ(1, num_did_finish_navigation_called_); | 600 CHECK_EQ(1, num_did_finish_navigation_called_); |
613 } else { | 601 } else { |
614 CHECK_EQ(0, num_did_finish_navigation_called_); | 602 CHECK_EQ(0, num_did_finish_navigation_called_); |
615 } | 603 } |
616 } | 604 } |
617 | 605 |
618 } // namespace content | 606 } // namespace content |
OLD | NEW |