Index: net/url_request/url_request_unittest.cc |
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc |
index 4f223e5c8333c3471de00b90643961173537cf1f..aae8f313e1fe3ac12219e8df077cca1b3e447b2a 100644 |
--- a/net/url_request/url_request_unittest.cc |
+++ b/net/url_request/url_request_unittest.cc |
@@ -58,6 +58,8 @@ |
#include "net/proxy/proxy_service.h" |
#include "net/socket/ssl_client_socket.h" |
#include "net/test/test_server.h" |
+#include "net/url_request/data_protocol_handler.h" |
+#include "net/url_request/file_protocol_handler.h" |
#include "net/url_request/ftp_protocol_handler.h" |
#include "net/url_request/static_http_user_agent_settings.h" |
#include "net/url_request/url_request.h" |
@@ -514,6 +516,9 @@ class URLRequestTest : public PlatformTest { |
URLRequestTest() : default_context_(true) { |
default_context_.set_network_delegate(&default_network_delegate_); |
default_context_.set_net_log(&net_log_); |
+ job_factory_.SetProtocolHandler("data", new DataProtocolHandler); |
+ job_factory_.SetProtocolHandler("file", new FileProtocolHandler); |
+ default_context_.set_job_factory(&job_factory_); |
default_context_.Init(); |
} |
virtual ~URLRequestTest() {} |
@@ -521,16 +526,14 @@ class URLRequestTest : public PlatformTest { |
// Adds the TestJobInterceptor to the default context. |
TestJobInterceptor* AddTestInterceptor() { |
TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); |
- job_factory_.reset(new URLRequestJobFactoryImpl); |
- job_factory_->SetProtocolHandler("http", protocol_handler_); |
- default_context_.set_job_factory(job_factory_.get()); |
+ job_factory_.SetProtocolHandler("http", protocol_handler_); |
return protocol_handler_; |
} |
protected: |
CapturingNetLog net_log_; |
TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
- scoped_ptr<URLRequestJobFactoryImpl> job_factory_; |
+ URLRequestJobFactoryImpl job_factory_; |
TestURLRequestContext default_context_; |
}; |
@@ -3462,6 +3465,20 @@ TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { |
req.Cancel(); |
} |
+TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictRedirects) { |
+ // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). |
+ GURL file_url("file:///foo.txt"); |
+ GURL data_url("data:,foo"); |
+ FileProtocolHandler file_protocol_handler; |
+ EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); |
+ DataProtocolHandler data_protocol_handler; |
+ EXPECT_TRUE(data_protocol_handler.IsSafeRedirectTarget(data_url)); |
+ |
+ // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
+ EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); |
+ EXPECT_TRUE(job_factory_.IsSafeRedirectTarget(data_url)); |
+} |
+ |
TEST_F(URLRequestTestHTTP, RestrictRedirects) { |
ASSERT_TRUE(test_server_.Start()); |
@@ -5028,15 +5045,12 @@ TEST_F(URLRequestTestFTP, UnsafePort) { |
ASSERT_TRUE(test_server_.Start()); |
URLRequestJobFactoryImpl job_factory; |
+ FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); |
GURL url("ftp://127.0.0.1:7"); |
- FtpProtocolHandler ftp_protocol_handler( |
- default_context_.ftp_transaction_factory(), |
- default_context_.ftp_auth_cache()); |
job_factory.SetProtocolHandler( |
"ftp", |
- new FtpProtocolHandler(default_context_.ftp_transaction_factory(), |
- default_context_.ftp_auth_cache())); |
+ new FtpProtocolHandler(&ftp_transaction_factory)); |
default_context_.set_job_factory(&job_factory); |
TestDelegate d; |