OLD | NEW |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "net/ftp/ftp_network_layer.h" | 48 #include "net/ftp/ftp_network_layer.h" |
49 #include "net/http/http_cache.h" | 49 #include "net/http/http_cache.h" |
50 #include "net/http/http_network_layer.h" | 50 #include "net/http/http_network_layer.h" |
51 #include "net/http/http_network_session.h" | 51 #include "net/http/http_network_session.h" |
52 #include "net/http/http_request_headers.h" | 52 #include "net/http/http_request_headers.h" |
53 #include "net/http/http_response_headers.h" | 53 #include "net/http/http_response_headers.h" |
54 #include "net/ocsp/nss_ocsp.h" | 54 #include "net/ocsp/nss_ocsp.h" |
55 #include "net/proxy/proxy_service.h" | 55 #include "net/proxy/proxy_service.h" |
56 #include "net/socket/ssl_client_socket.h" | 56 #include "net/socket/ssl_client_socket.h" |
57 #include "net/test/test_server.h" | 57 #include "net/test/test_server.h" |
| 58 #include "net/url_request/data_protocol_handler.h" |
| 59 #include "net/url_request/file_protocol_handler.h" |
58 #include "net/url_request/ftp_protocol_handler.h" | 60 #include "net/url_request/ftp_protocol_handler.h" |
59 #include "net/url_request/static_http_user_agent_settings.h" | 61 #include "net/url_request/static_http_user_agent_settings.h" |
60 #include "net/url_request/url_request.h" | 62 #include "net/url_request/url_request.h" |
61 #include "net/url_request/url_request_file_dir_job.h" | 63 #include "net/url_request/url_request_file_dir_job.h" |
62 #include "net/url_request/url_request_http_job.h" | 64 #include "net/url_request/url_request_http_job.h" |
63 #include "net/url_request/url_request_job_factory_impl.h" | 65 #include "net/url_request/url_request_job_factory_impl.h" |
64 #include "net/url_request/url_request_redirect_job.h" | 66 #include "net/url_request/url_request_redirect_job.h" |
65 #include "net/url_request/url_request_test_job.h" | 67 #include "net/url_request/url_request_test_job.h" |
66 #include "net/url_request/url_request_test_util.h" | 68 #include "net/url_request/url_request_test_util.h" |
67 #include "testing/gtest/include/gtest/gtest.h" | 69 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 virtual ~TestURLRequestContextWithProxy() {} | 459 virtual ~TestURLRequestContextWithProxy() {} |
458 }; | 460 }; |
459 | 461 |
460 } // namespace | 462 } // namespace |
461 | 463 |
462 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. | 464 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
463 class URLRequestTest : public PlatformTest { | 465 class URLRequestTest : public PlatformTest { |
464 public: | 466 public: |
465 URLRequestTest() : default_context_(true) { | 467 URLRequestTest() : default_context_(true) { |
466 default_context_.set_network_delegate(&default_network_delegate_); | 468 default_context_.set_network_delegate(&default_network_delegate_); |
| 469 job_factory_.SetProtocolHandler("data", new DataProtocolHandler); |
| 470 job_factory_.SetProtocolHandler("file", new FileProtocolHandler); |
| 471 default_context_.set_job_factory(&job_factory_); |
467 default_context_.Init(); | 472 default_context_.Init(); |
468 } | 473 } |
469 virtual ~URLRequestTest() {} | 474 virtual ~URLRequestTest() {} |
470 | 475 |
471 // Adds the TestJobInterceptor to the default context. | 476 // Adds the TestJobInterceptor to the default context. |
472 TestJobInterceptor* AddTestInterceptor() { | 477 TestJobInterceptor* AddTestInterceptor() { |
473 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); | 478 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); |
474 job_factory_.reset(new URLRequestJobFactoryImpl); | 479 job_factory_.SetProtocolHandler("http", protocol_handler_); |
475 job_factory_->SetProtocolHandler("http", protocol_handler_); | |
476 default_context_.set_job_factory(job_factory_.get()); | |
477 return protocol_handler_; | 480 return protocol_handler_; |
478 } | 481 } |
479 | 482 |
480 protected: | 483 protected: |
481 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 484 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
482 scoped_ptr<URLRequestJobFactoryImpl> job_factory_; | 485 URLRequestJobFactoryImpl job_factory_; |
483 TestURLRequestContext default_context_; | 486 TestURLRequestContext default_context_; |
484 }; | 487 }; |
485 | 488 |
486 TEST_F(URLRequestTest, AboutBlankTest) { | 489 TEST_F(URLRequestTest, AboutBlankTest) { |
487 TestDelegate d; | 490 TestDelegate d; |
488 { | 491 { |
489 URLRequest r(GURL("about:blank"), &d, &default_context_); | 492 URLRequest r(GURL("about:blank"), &d, &default_context_); |
490 | 493 |
491 r.Start(); | 494 r.Start(); |
492 EXPECT_TRUE(r.is_pending()); | 495 EXPECT_TRUE(r.is_pending()); |
(...skipping 4353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4846 | 4849 |
4847 protected: | 4850 protected: |
4848 TestServer test_server_; | 4851 TestServer test_server_; |
4849 }; | 4852 }; |
4850 | 4853 |
4851 // Make sure an FTP request using an unsafe ports fails. | 4854 // Make sure an FTP request using an unsafe ports fails. |
4852 TEST_F(URLRequestTestFTP, UnsafePort) { | 4855 TEST_F(URLRequestTestFTP, UnsafePort) { |
4853 ASSERT_TRUE(test_server_.Start()); | 4856 ASSERT_TRUE(test_server_.Start()); |
4854 | 4857 |
4855 URLRequestJobFactoryImpl job_factory; | 4858 URLRequestJobFactoryImpl job_factory; |
| 4859 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); |
4856 | 4860 |
4857 GURL url("ftp://127.0.0.1:7"); | 4861 GURL url("ftp://127.0.0.1:7"); |
4858 FtpProtocolHandler ftp_protocol_handler( | |
4859 default_context_.ftp_transaction_factory(), | |
4860 default_context_.ftp_auth_cache()); | |
4861 job_factory.SetProtocolHandler( | 4862 job_factory.SetProtocolHandler( |
4862 "ftp", | 4863 "ftp", |
4863 new FtpProtocolHandler(default_context_.ftp_transaction_factory(), | 4864 new FtpProtocolHandler(&ftp_transaction_factory)); |
4864 default_context_.ftp_auth_cache())); | |
4865 default_context_.set_job_factory(&job_factory); | 4865 default_context_.set_job_factory(&job_factory); |
4866 | 4866 |
4867 TestDelegate d; | 4867 TestDelegate d; |
4868 { | 4868 { |
4869 URLRequest r(url, &d, &default_context_); | 4869 URLRequest r(url, &d, &default_context_); |
4870 r.Start(); | 4870 r.Start(); |
4871 EXPECT_TRUE(r.is_pending()); | 4871 EXPECT_TRUE(r.is_pending()); |
4872 | 4872 |
4873 MessageLoop::current()->Run(); | 4873 MessageLoop::current()->Run(); |
4874 | 4874 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5188 | 5188 |
5189 EXPECT_FALSE(r.is_pending()); | 5189 EXPECT_FALSE(r.is_pending()); |
5190 EXPECT_EQ(1, d->response_started_count()); | 5190 EXPECT_EQ(1, d->response_started_count()); |
5191 EXPECT_FALSE(d->received_data_before_response()); | 5191 EXPECT_FALSE(d->received_data_before_response()); |
5192 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 5192 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
5193 } | 5193 } |
5194 } | 5194 } |
5195 #endif // !defined(DISABLE_FTP_SUPPORT) | 5195 #endif // !defined(DISABLE_FTP_SUPPORT) |
5196 | 5196 |
5197 } // namespace net | 5197 } // namespace net |
OLD | NEW |