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

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

Issue 10855209: Refactoring: ProtocolHandler::MaybeCreateJob takes NetworkDelegate as argument (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #endif 10 #endif
(...skipping 3620 matching lines...) Expand 10 before | Expand all | Expand 10 after
3631 simulate_main_network_error_ = false; 3631 simulate_main_network_error_ = false;
3632 did_simulate_error_main_ = true; 3632 did_simulate_error_main_ = true;
3633 // will error since the requeted url is not one of its canned urls 3633 // will error since the requeted url is not one of its canned urls
3634 return new URLRequestTestJob(request, true); 3634 return new URLRequestTestJob(request, true);
3635 } 3635 }
3636 if (!intercept_main_request_) 3636 if (!intercept_main_request_)
3637 return NULL; 3637 return NULL;
3638 intercept_main_request_ = false; 3638 intercept_main_request_ = false;
3639 did_intercept_main_ = true; 3639 did_intercept_main_ = true;
3640 return new URLRequestTestJob(request, 3640 return new URLRequestTestJob(request,
3641 main_headers_, 3641 request->context()->network_delegate(),
3642 main_data_, 3642 main_headers_,
3643 true); 3643 main_data_,
3644 true);
3644 } 3645 }
3645 3646
3646 virtual URLRequestJob* MaybeInterceptRedirect(URLRequest* request, 3647 virtual URLRequestJob* MaybeInterceptRedirect(URLRequest* request,
3647 const GURL& location) { 3648 const GURL& location) {
3648 if (cancel_redirect_request_) { 3649 if (cancel_redirect_request_) {
3649 cancel_redirect_request_ = false; 3650 cancel_redirect_request_ = false;
3650 did_cancel_redirect_ = true; 3651 did_cancel_redirect_ = true;
3651 return new CancelTestJob(request); 3652 return new CancelTestJob(request);
3652 } 3653 }
3653 if (!intercept_redirect_) 3654 if (!intercept_redirect_)
3654 return NULL; 3655 return NULL;
3655 intercept_redirect_ = false; 3656 intercept_redirect_ = false;
3656 did_intercept_redirect_ = true; 3657 did_intercept_redirect_ = true;
3657 return new URLRequestTestJob(request, 3658 return new URLRequestTestJob(request,
3658 redirect_headers_, 3659 request->context()->network_delegate(),
3659 redirect_data_, 3660 redirect_headers_,
3660 true); 3661 redirect_data_,
3662 true);
3661 } 3663 }
3662 3664
3663 virtual URLRequestJob* MaybeInterceptResponse(URLRequest* request) { 3665 virtual URLRequestJob* MaybeInterceptResponse(URLRequest* request) {
3664 if (cancel_final_request_) { 3666 if (cancel_final_request_) {
3665 cancel_final_request_ = false; 3667 cancel_final_request_ = false;
3666 did_cancel_final_ = true; 3668 did_cancel_final_ = true;
3667 return new CancelTestJob(request); 3669 return new CancelTestJob(request);
3668 } 3670 }
3669 if (!intercept_final_response_) 3671 if (!intercept_final_response_)
3670 return NULL; 3672 return NULL;
3671 intercept_final_response_ = false; 3673 intercept_final_response_ = false;
3672 did_intercept_final_ = true; 3674 did_intercept_final_ = true;
3673 return new URLRequestTestJob(request, 3675 return new URLRequestTestJob(request,
3674 final_headers_, 3676 request->context()->network_delegate(),
3675 final_data_, 3677 final_headers_,
3676 true); 3678 final_data_,
3679 true);
3677 } 3680 }
3678 3681
3679 // Whether to intercept the main request, and if so the response to return. 3682 // Whether to intercept the main request, and if so the response to return.
3680 bool intercept_main_request_; 3683 bool intercept_main_request_;
3681 std::string main_headers_; 3684 std::string main_headers_;
3682 std::string main_data_; 3685 std::string main_data_;
3683 3686
3684 // Other actions we take at MaybeIntercept time 3687 // Other actions we take at MaybeIntercept time
3685 bool restart_main_request_; 3688 bool restart_main_request_;
3686 bool cancel_main_request_; 3689 bool cancel_main_request_;
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
4110 }; 4113 };
4111 4114
4112 // Make sure an FTP request using an unsafe ports fails. 4115 // Make sure an FTP request using an unsafe ports fails.
4113 TEST_F(URLRequestTestFTP, UnsafePort) { 4116 TEST_F(URLRequestTestFTP, UnsafePort) {
4114 ASSERT_TRUE(test_server_.Start()); 4117 ASSERT_TRUE(test_server_.Start());
4115 4118
4116 URLRequestJobFactory job_factory; 4119 URLRequestJobFactory job_factory;
4117 4120
4118 GURL url("ftp://127.0.0.1:7"); 4121 GURL url("ftp://127.0.0.1:7");
4119 FtpProtocolHandler ftp_protocol_handler( 4122 FtpProtocolHandler ftp_protocol_handler(
4120 default_context_.network_delegate(),
4121 default_context_.ftp_transaction_factory(), 4123 default_context_.ftp_transaction_factory(),
4122 default_context_.ftp_auth_cache()); 4124 default_context_.ftp_auth_cache());
4123 job_factory.SetProtocolHandler( 4125 job_factory.SetProtocolHandler(
4124 "ftp", 4126 "ftp",
4125 new FtpProtocolHandler(default_context_.network_delegate(), 4127 new FtpProtocolHandler(default_context_.ftp_transaction_factory(),
4126 default_context_.ftp_transaction_factory(),
4127 default_context_.ftp_auth_cache())); 4128 default_context_.ftp_auth_cache()));
4128 default_context_.set_job_factory(&job_factory); 4129 default_context_.set_job_factory(&job_factory);
4129 4130
4130 TestDelegate d; 4131 TestDelegate d;
4131 { 4132 {
4132 URLRequest r(url, &d, &default_context_); 4133 URLRequest r(url, &d, &default_context_);
4133 r.Start(); 4134 r.Start();
4134 EXPECT_TRUE(r.is_pending()); 4135 EXPECT_TRUE(r.is_pending());
4135 4136
4136 MessageLoop::current()->Run(); 4137 MessageLoop::current()->Run();
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
4628 req.SetExtraRequestHeaders(headers); 4629 req.SetExtraRequestHeaders(headers);
4629 req.Start(); 4630 req.Start();
4630 MessageLoop::current()->Run(); 4631 MessageLoop::current()->Run();
4631 // If the net tests are being run with ChromeFrame then we need to allow for 4632 // If the net tests are being run with ChromeFrame then we need to allow for
4632 // the 'chromeframe' suffix which is added to the user agent before the 4633 // the 'chromeframe' suffix which is added to the user agent before the
4633 // closing parentheses. 4634 // closing parentheses.
4634 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 4635 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
4635 } 4636 }
4636 4637
4637 } // namespace net 4638 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698