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

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

Issue 253603004: Make it so net/ can be built without file:// support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Add TODO, minor cleanups Created 6 years, 7 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
« net/BUILD.gn ('K') | « net/url_request/url_request_context_builder.cc ('k') | 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 (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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #include "net/http/http_request_headers.h" 59 #include "net/http/http_request_headers.h"
60 #include "net/http/http_response_headers.h" 60 #include "net/http/http_response_headers.h"
61 #include "net/http/http_util.h" 61 #include "net/http/http_util.h"
62 #include "net/ocsp/nss_ocsp.h" 62 #include "net/ocsp/nss_ocsp.h"
63 #include "net/proxy/proxy_service.h" 63 #include "net/proxy/proxy_service.h"
64 #include "net/socket/ssl_client_socket.h" 64 #include "net/socket/ssl_client_socket.h"
65 #include "net/ssl/ssl_connection_status_flags.h" 65 #include "net/ssl/ssl_connection_status_flags.h"
66 #include "net/test/cert_test_util.h" 66 #include "net/test/cert_test_util.h"
67 #include "net/test/spawned_test_server/spawned_test_server.h" 67 #include "net/test/spawned_test_server/spawned_test_server.h"
68 #include "net/url_request/data_protocol_handler.h" 68 #include "net/url_request/data_protocol_handler.h"
69 #include "net/url_request/file_protocol_handler.h"
70 #include "net/url_request/ftp_protocol_handler.h"
71 #include "net/url_request/static_http_user_agent_settings.h" 69 #include "net/url_request/static_http_user_agent_settings.h"
72 #include "net/url_request/url_request.h" 70 #include "net/url_request/url_request.h"
73 #include "net/url_request/url_request_file_dir_job.h"
74 #include "net/url_request/url_request_http_job.h" 71 #include "net/url_request/url_request_http_job.h"
75 #include "net/url_request/url_request_job_factory_impl.h" 72 #include "net/url_request/url_request_job_factory_impl.h"
76 #include "net/url_request/url_request_redirect_job.h" 73 #include "net/url_request/url_request_redirect_job.h"
77 #include "net/url_request/url_request_test_job.h" 74 #include "net/url_request/url_request_test_job.h"
78 #include "net/url_request/url_request_test_util.h" 75 #include "net/url_request/url_request_test_util.h"
79 #include "testing/gtest/include/gtest/gtest.h" 76 #include "testing/gtest/include/gtest/gtest.h"
80 #include "testing/platform_test.h" 77 #include "testing/platform_test.h"
81 78
79 #if !defined(DISABLE_FILE_SUPPORT)
80 #include "net/url_request/file_protocol_handler.h"
81 #include "net/url_request/url_request_file_dir_job.h"
82 #endif
83
84 #if !defined(DISABLE_FTP_SUPPORT)
85 #include "net/url_request/ftp_protocol_handler.h"
86 #endif
87
82 #if defined(OS_WIN) 88 #if defined(OS_WIN)
83 #include "base/win/scoped_com_initializer.h" 89 #include "base/win/scoped_com_initializer.h"
84 #include "base/win/scoped_comptr.h" 90 #include "base/win/scoped_comptr.h"
85 #include "base/win/windows_version.h" 91 #include "base/win/windows_version.h"
86 #endif 92 #endif
87 93
88 using base::ASCIIToUTF16; 94 using base::ASCIIToUTF16;
89 using base::Time; 95 using base::Time;
90 96
91 namespace net { 97 namespace net {
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 597
592 } // namespace 598 } // namespace
593 599
594 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. 600 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.
595 class URLRequestTest : public PlatformTest { 601 class URLRequestTest : public PlatformTest {
596 public: 602 public:
597 URLRequestTest() : default_context_(true) { 603 URLRequestTest() : default_context_(true) {
598 default_context_.set_network_delegate(&default_network_delegate_); 604 default_context_.set_network_delegate(&default_network_delegate_);
599 default_context_.set_net_log(&net_log_); 605 default_context_.set_net_log(&net_log_);
600 job_factory_.SetProtocolHandler("data", new DataProtocolHandler); 606 job_factory_.SetProtocolHandler("data", new DataProtocolHandler);
607 #if !defined(DISABLE_FILE_SUPPORT)
601 job_factory_.SetProtocolHandler( 608 job_factory_.SetProtocolHandler(
602 "file", new FileProtocolHandler(base::MessageLoopProxy::current())); 609 "file", new FileProtocolHandler(base::MessageLoopProxy::current()));
610 #endif
603 default_context_.set_job_factory(&job_factory_); 611 default_context_.set_job_factory(&job_factory_);
604 default_context_.Init(); 612 default_context_.Init();
605 } 613 }
606 virtual ~URLRequestTest() { 614 virtual ~URLRequestTest() {
607 // URLRequestJobs may post clean-up tasks on destruction. 615 // URLRequestJobs may post clean-up tasks on destruction.
608 base::RunLoop().RunUntilIdle(); 616 base::RunLoop().RunUntilIdle();
609 } 617 }
610 618
611 // Adds the TestJobInterceptor to the default context. 619 // Adds the TestJobInterceptor to the default context.
612 TestJobInterceptor* AddTestInterceptor() { 620 TestJobInterceptor* AddTestInterceptor() {
(...skipping 4530 matching lines...) Expand 10 before | Expand all | Expand 10 after
5143 EXPECT_EQ("text/html", mime_type); 5151 EXPECT_EQ("text/html", mime_type);
5144 5152
5145 std::string charset; 5153 std::string charset;
5146 req.GetCharset(&charset); 5154 req.GetCharset(&charset);
5147 EXPECT_EQ("utf-8", charset); 5155 EXPECT_EQ("utf-8", charset);
5148 req.Cancel(); 5156 req.Cancel();
5149 } 5157 }
5150 5158
5151 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictRedirects) { 5159 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictRedirects) {
5152 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). 5160 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget().
5153 GURL file_url("file:///foo.txt");
5154 GURL data_url("data:,foo"); 5161 GURL data_url("data:,foo");
5155 FileProtocolHandler file_protocol_handler(base::MessageLoopProxy::current());
5156 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url));
5157 DataProtocolHandler data_protocol_handler; 5162 DataProtocolHandler data_protocol_handler;
5158 EXPECT_FALSE(data_protocol_handler.IsSafeRedirectTarget(data_url)); 5163 EXPECT_FALSE(data_protocol_handler.IsSafeRedirectTarget(data_url));
5159 5164
5160 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). 5165 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget().
5166 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url));
5167
5168 #if !defined(DISABLE_FILE_SUPPORT)
mef 2014/05/06 15:21:30 Should this be a separate test?
mmenke 2014/05/06 18:13:06 Good idea, done.
5169 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget().
5170 GURL file_url("file:///foo.txt");
5171 FileProtocolHandler file_protocol_handler(base::MessageLoopProxy::current());
5172 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url));
5173
5174 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget().
5161 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); 5175 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url));
5162 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url)); 5176 #endif // !defined(DISABLE_FILE_SUPPORT)
5163 } 5177 }
5164 5178
5179 #if !defined(DISABLE_FILE_SUPPORT)
5165 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { 5180 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) {
5166 ASSERT_TRUE(test_server_.Start()); 5181 ASSERT_TRUE(test_server_.Start());
5167 5182
5168 TestDelegate d; 5183 TestDelegate d;
5169 URLRequest req(test_server_.GetURL("files/redirect-to-file.html"), 5184 URLRequest req(test_server_.GetURL("files/redirect-to-file.html"),
5170 DEFAULT_PRIORITY, 5185 DEFAULT_PRIORITY,
5171 &d, 5186 &d,
5172 &default_context_); 5187 &default_context_);
5173 req.Start(); 5188 req.Start();
5174 base::RunLoop().Run(); 5189 base::RunLoop().Run();
5175 5190
5176 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 5191 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status());
5177 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); 5192 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error());
5178 } 5193 }
5194 #endif // !defined(DISABLE_FILE_SUPPORT)
5179 5195
5180 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { 5196 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) {
5181 ASSERT_TRUE(test_server_.Start()); 5197 ASSERT_TRUE(test_server_.Start());
5182 5198
5183 TestDelegate d; 5199 TestDelegate d;
5184 URLRequest req(test_server_.GetURL("files/redirect-to-data.html"), 5200 URLRequest req(test_server_.GetURL("files/redirect-to-data.html"),
5185 DEFAULT_PRIORITY, 5201 DEFAULT_PRIORITY,
5186 &d, 5202 &d,
5187 &default_context_); 5203 &default_context_);
5188 req.Start(); 5204 req.Start();
(...skipping 2805 matching lines...) Expand 10 before | Expand all | Expand 10 after
7994 8010
7995 EXPECT_FALSE(r.is_pending()); 8011 EXPECT_FALSE(r.is_pending());
7996 EXPECT_EQ(1, d->response_started_count()); 8012 EXPECT_EQ(1, d->response_started_count());
7997 EXPECT_FALSE(d->received_data_before_response()); 8013 EXPECT_FALSE(d->received_data_before_response());
7998 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 8014 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
7999 } 8015 }
8000 } 8016 }
8001 #endif // !defined(DISABLE_FTP_SUPPORT) 8017 #endif // !defined(DISABLE_FTP_SUPPORT)
8002 8018
8003 } // namespace net 8019 } // namespace net
OLDNEW
« net/BUILD.gn ('K') | « net/url_request/url_request_context_builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698