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

Side by Side Diff: net/url_request/url_request_test_util.cc

Issue 2542843006: ResourceLoader: Fix a bunch of double-cancellation/double-error notification cases. (Closed)
Patch Set: Inline ReadMore Created 4 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/url_request/url_request_test_util.h" 5 #include "net/url_request/url_request_test_util.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 DCHECK_NE(bytes_read, ERR_IO_PENDING); 283 DCHECK_NE(bytes_read, ERR_IO_PENDING);
284 284
285 // If the request was cancelled in a redirect, it should not signal 285 // If the request was cancelled in a redirect, it should not signal
286 // OnReadCompleted. Note that |cancel_in_rs_| may be true due to 286 // OnReadCompleted. Note that |cancel_in_rs_| may be true due to
287 // https://crbug.com/564848. 287 // https://crbug.com/564848.
288 EXPECT_FALSE(cancel_in_rr_); 288 EXPECT_FALSE(cancel_in_rr_);
289 289
290 if (response_started_count_ == 0) 290 if (response_started_count_ == 0)
291 received_data_before_response_ = true; 291 received_data_before_response_ = true;
292 292
293 if (cancel_in_rd_)
294 request_status_ = request->Cancel();
295
296 if (bytes_read >= 0) { 293 if (bytes_read >= 0) {
297 // There is data to read. 294 // There is data to read.
298 received_bytes_count_ += bytes_read; 295 received_bytes_count_ += bytes_read;
299 296
300 // consume the data 297 // Consume the data.
301 data_received_.append(buf_->data(), bytes_read); 298 data_received_.append(buf_->data(), bytes_read);
299
300 if (cancel_in_rd_) {
301 request_status_ = request->Cancel();
302 // If bytes_read is 0, won't get a notification on cancelation.
303 if (bytes_read == 0 && quit_on_complete_) {
304 base::ThreadTaskRunnerHandle::Get()->PostTask(
305 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
306 }
307 return;
308 }
302 } 309 }
303 310
304 // If it was not end of stream, request to read more. 311 // If it was not end of stream, request to read more.
305 while (bytes_read > 0) { 312 while (bytes_read > 0) {
306 bytes_read = request->Read(buf_.get(), kBufferSize); 313 bytes_read = request->Read(buf_.get(), kBufferSize);
307 if (bytes_read > 0) { 314 if (bytes_read > 0) {
308 data_received_.append(buf_->data(), bytes_read); 315 data_received_.append(buf_->data(), bytes_read);
309 received_bytes_count_ += bytes_read; 316 received_bytes_count_ += bytes_read;
310 } 317 }
311 } 318 }
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 NetworkDelegate* network_delegate) const { 679 NetworkDelegate* network_delegate) const {
673 return main_intercept_job_.release(); 680 return main_intercept_job_.release();
674 } 681 }
675 682
676 void TestJobInterceptor::set_main_intercept_job( 683 void TestJobInterceptor::set_main_intercept_job(
677 std::unique_ptr<URLRequestJob> job) { 684 std::unique_ptr<URLRequestJob> job) {
678 main_intercept_job_ = std::move(job); 685 main_intercept_job_ = std::move(job);
679 } 686 }
680 687
681 } // namespace net 688 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698