Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: content/public/test/navigation_simulator.cc

Issue 2744593004: Fix use-after-free in NavigationSimulator test util (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 << "NavigationSimulator::Commit cannot be called after the " 223 << "NavigationSimulator::Commit cannot be called after the "
224 "navigation has finished"; 224 "navigation has finished";
225 225
226 if (state_ == INITIALIZATION) 226 if (state_ == INITIALIZATION)
227 Start(); 227 Start();
228 228
229 PrepareCompleteCallbackOnHandle(); 229 PrepareCompleteCallbackOnHandle();
230 if (IsBrowserSideNavigationEnabled() && 230 if (IsBrowserSideNavigationEnabled() &&
231 render_frame_host_->frame_tree_node()->navigation_request()) { 231 render_frame_host_->frame_tree_node()->navigation_request()) {
232 render_frame_host_->PrepareForCommit(); 232 render_frame_host_->PrepareForCommit();
233 // Synchronous failure can cause the navigation to finish here.
234 if (!handle_) {
235 state_ = FAILED;
236 return;
237 }
233 } 238 }
234 239
235 // Call NavigationHandle::WillProcessResponse if needed. 240 // Call NavigationHandle::WillProcessResponse if needed.
236 // Note that the handle's state can be CANCELING if a throttle cancelled it 241 // Note that the handle's state can be CANCELING if a throttle cancelled it
237 // synchronously in PrepareForCommit. 242 // synchronously in PrepareForCommit.
238 if (handle_->state_for_testing() < NavigationHandleImpl::CANCELING) { 243 if (handle_->state_for_testing() < NavigationHandleImpl::CANCELING) {
239 handle_->WillProcessResponse( 244 handle_->WillProcessResponse(
240 render_frame_host_, scoped_refptr<net::HttpResponseHeaders>(), 245 render_frame_host_, scoped_refptr<net::HttpResponseHeaders>(),
241 net::HttpResponseInfo::ConnectionInfo(), SSLStatus(), GlobalRequestID(), 246 net::HttpResponseInfo::ConnectionInfo(), SSLStatus(), GlobalRequestID(),
242 false /* should_replace_current_entry */, false /* is_download */, 247 false /* should_replace_current_entry */, false /* is_download */,
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 } 506 }
502 507
503 void NavigationSimulator::ReadyToCommitNavigation( 508 void NavigationSimulator::ReadyToCommitNavigation(
504 NavigationHandle* navigation_handle) { 509 NavigationHandle* navigation_handle) {
505 if (navigation_handle == handle_) 510 if (navigation_handle == handle_)
506 num_ready_to_commit_called_++; 511 num_ready_to_commit_called_++;
507 } 512 }
508 513
509 void NavigationSimulator::DidFinishNavigation( 514 void NavigationSimulator::DidFinishNavigation(
510 NavigationHandle* navigation_handle) { 515 NavigationHandle* navigation_handle) {
511 if (navigation_handle == handle_) 516 if (navigation_handle == handle_) {
512 num_did_finish_navigation_called_++; 517 num_did_finish_navigation_called_++;
518 handle_ = nullptr;
519 }
513 } 520 }
514 521
515 void NavigationSimulator::OnWillStartRequest() { 522 void NavigationSimulator::OnWillStartRequest() {
516 num_will_start_request_called_++; 523 num_will_start_request_called_++;
517 } 524 }
518 525
519 void NavigationSimulator::OnWillRedirectRequest() { 526 void NavigationSimulator::OnWillRedirectRequest() {
520 num_will_redirect_request_called_++; 527 num_will_redirect_request_called_++;
521 } 528 }
522 529
(...skipping 22 matching lines...) Expand all
545 } 552 }
546 553
547 void NavigationSimulator::PrepareCompleteCallbackOnHandle() { 554 void NavigationSimulator::PrepareCompleteCallbackOnHandle() {
548 last_throttle_check_result_.reset(); 555 last_throttle_check_result_.reset();
549 handle_->set_complete_callback_for_testing( 556 handle_->set_complete_callback_for_testing(
550 base::Bind(&NavigationSimulator::OnThrottleChecksComplete, 557 base::Bind(&NavigationSimulator::OnThrottleChecksComplete,
551 weak_factory_.GetWeakPtr())); 558 weak_factory_.GetWeakPtr()));
552 } 559 }
553 560
554 } // namespace content 561 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698