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

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

Issue 2262653003: Make URLRequest::Read to return net errors or bytes read instead of a bool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 3 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
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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
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 "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 4988 matching lines...) Expand 10 before | Expand all | Expand 10 after
4999 AsyncDelegateLogger::Run( 4999 AsyncDelegateLogger::Run(
5000 request, 5000 request,
5001 LOAD_STATE_WAITING_FOR_DELEGATE, 5001 LOAD_STATE_WAITING_FOR_DELEGATE,
5002 LOAD_STATE_WAITING_FOR_DELEGATE, 5002 LOAD_STATE_WAITING_FOR_DELEGATE,
5003 LOAD_STATE_WAITING_FOR_DELEGATE, 5003 LOAD_STATE_WAITING_FOR_DELEGATE,
5004 base::Bind( 5004 base::Bind(
5005 &AsyncLoggingUrlRequestDelegate::OnReceivedRedirectLoggingComplete, 5005 &AsyncLoggingUrlRequestDelegate::OnReceivedRedirectLoggingComplete,
5006 base::Unretained(this), request, redirect_info)); 5006 base::Unretained(this), request, redirect_info));
5007 } 5007 }
5008 5008
5009 void OnResponseStarted(URLRequest* request) override { 5009 void OnResponseStarted(URLRequest* request, int net_error) override {
5010 AsyncDelegateLogger::Run( 5010 AsyncDelegateLogger::Run(
5011 request, 5011 request, LOAD_STATE_WAITING_FOR_DELEGATE,
5012 LOAD_STATE_WAITING_FOR_DELEGATE, 5012 LOAD_STATE_WAITING_FOR_DELEGATE, LOAD_STATE_WAITING_FOR_DELEGATE,
5013 LOAD_STATE_WAITING_FOR_DELEGATE, 5013 base::Bind(
5014 LOAD_STATE_WAITING_FOR_DELEGATE, 5014 &AsyncLoggingUrlRequestDelegate::OnResponseStartedLoggingComplete,
5015 base::Bind( 5015 base::Unretained(this), request, net_error));
5016 &AsyncLoggingUrlRequestDelegate::OnResponseStartedLoggingComplete,
5017 base::Unretained(this), request));
5018 } 5016 }
5019 5017
5020 void OnReadCompleted(URLRequest* request, int bytes_read) override { 5018 void OnReadCompleted(URLRequest* request, int bytes_read) override {
5021 AsyncDelegateLogger::Run( 5019 AsyncDelegateLogger::Run(
5022 request, 5020 request,
5023 LOAD_STATE_IDLE, 5021 LOAD_STATE_IDLE,
5024 LOAD_STATE_IDLE, 5022 LOAD_STATE_IDLE,
5025 LOAD_STATE_IDLE, 5023 LOAD_STATE_IDLE,
5026 base::Bind( 5024 base::Bind(
5027 &AsyncLoggingUrlRequestDelegate::AfterReadCompletedLoggingComplete, 5025 &AsyncLoggingUrlRequestDelegate::AfterReadCompletedLoggingComplete,
5028 base::Unretained(this), request, bytes_read)); 5026 base::Unretained(this), request, bytes_read));
5029 } 5027 }
5030 5028
5031 private: 5029 private:
5032 void OnReceivedRedirectLoggingComplete(URLRequest* request, 5030 void OnReceivedRedirectLoggingComplete(URLRequest* request,
5033 const RedirectInfo& redirect_info) { 5031 const RedirectInfo& redirect_info) {
5034 bool defer_redirect = false; 5032 bool defer_redirect = false;
5035 TestDelegate::OnReceivedRedirect(request, redirect_info, &defer_redirect); 5033 TestDelegate::OnReceivedRedirect(request, redirect_info, &defer_redirect);
5036 // FollowDeferredRedirect should not be called after cancellation. 5034 // FollowDeferredRedirect should not be called after cancellation.
5037 if (cancel_stage_ == CANCEL_ON_RECEIVED_REDIRECT) 5035 if (cancel_stage_ == CANCEL_ON_RECEIVED_REDIRECT)
5038 return; 5036 return;
5039 if (!defer_redirect) 5037 if (!defer_redirect)
5040 request->FollowDeferredRedirect(); 5038 request->FollowDeferredRedirect();
5041 } 5039 }
5042 5040
5043 void OnResponseStartedLoggingComplete(URLRequest* request) { 5041 void OnResponseStartedLoggingComplete(URLRequest* request, int net_error) {
5044 // The parent class continues the request. 5042 // The parent class continues the request.
5045 TestDelegate::OnResponseStarted(request); 5043 TestDelegate::OnResponseStarted(request, net_error);
5046 } 5044 }
5047 5045
5048 void AfterReadCompletedLoggingComplete(URLRequest* request, int bytes_read) { 5046 void AfterReadCompletedLoggingComplete(URLRequest* request, int bytes_read) {
5049 // The parent class continues the request. 5047 // The parent class continues the request.
5050 TestDelegate::OnReadCompleted(request, bytes_read); 5048 TestDelegate::OnReadCompleted(request, bytes_read);
5051 } 5049 }
5052 5050
5053 const CancelStage cancel_stage_; 5051 const CancelStage cancel_stage_;
5054 5052
5055 DISALLOW_COPY_AND_ASSIGN(AsyncLoggingUrlRequestDelegate); 5053 DISALLOW_COPY_AND_ASSIGN(AsyncLoggingUrlRequestDelegate);
(...skipping 5198 matching lines...) Expand 10 before | Expand all | Expand 10 after
10254 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10252 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10255 10253
10256 req->Start(); 10254 req->Start();
10257 req->Cancel(); 10255 req->Cancel();
10258 base::RunLoop().RunUntilIdle(); 10256 base::RunLoop().RunUntilIdle();
10259 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 10257 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
10260 EXPECT_EQ(0, d.received_redirect_count()); 10258 EXPECT_EQ(0, d.received_redirect_count());
10261 } 10259 }
10262 10260
10263 } // namespace net 10261 } // namespace net
OLDNEW
« net/base/layered_network_delegate.h ('K') | « net/url_request/url_request_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698