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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "net/http/http_network_layer.h" | 51 #include "net/http/http_network_layer.h" |
52 #include "net/http/http_network_session.h" | 52 #include "net/http/http_network_session.h" |
53 #include "net/http/http_request_headers.h" | 53 #include "net/http/http_request_headers.h" |
54 #include "net/http/http_response_headers.h" | 54 #include "net/http/http_response_headers.h" |
55 #include "net/ocsp/nss_ocsp.h" | 55 #include "net/ocsp/nss_ocsp.h" |
56 #include "net/proxy/proxy_service.h" | 56 #include "net/proxy/proxy_service.h" |
57 #include "net/socket/ssl_client_socket.h" | 57 #include "net/socket/ssl_client_socket.h" |
58 #include "net/ssl/ssl_connection_status_flags.h" | 58 #include "net/ssl/ssl_connection_status_flags.h" |
59 #include "net/test/cert_test_util.h" | 59 #include "net/test/cert_test_util.h" |
60 #include "net/test/spawned_test_server/spawned_test_server.h" | 60 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 61 #include "net/url_request/data_protocol_handler.h" |
| 62 #include "net/url_request/file_protocol_handler.h" |
61 #include "net/url_request/ftp_protocol_handler.h" | 63 #include "net/url_request/ftp_protocol_handler.h" |
62 #include "net/url_request/static_http_user_agent_settings.h" | 64 #include "net/url_request/static_http_user_agent_settings.h" |
63 #include "net/url_request/url_request.h" | 65 #include "net/url_request/url_request.h" |
64 #include "net/url_request/url_request_file_dir_job.h" | 66 #include "net/url_request/url_request_file_dir_job.h" |
65 #include "net/url_request/url_request_http_job.h" | 67 #include "net/url_request/url_request_http_job.h" |
66 #include "net/url_request/url_request_job_factory_impl.h" | 68 #include "net/url_request/url_request_job_factory_impl.h" |
67 #include "net/url_request/url_request_redirect_job.h" | 69 #include "net/url_request/url_request_redirect_job.h" |
68 #include "net/url_request/url_request_test_job.h" | 70 #include "net/url_request/url_request_test_job.h" |
69 #include "net/url_request/url_request_test_util.h" | 71 #include "net/url_request/url_request_test_util.h" |
70 #include "testing/gtest/include/gtest/gtest.h" | 72 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 }; | 553 }; |
552 | 554 |
553 } // namespace | 555 } // namespace |
554 | 556 |
555 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. | 557 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
556 class URLRequestTest : public PlatformTest { | 558 class URLRequestTest : public PlatformTest { |
557 public: | 559 public: |
558 URLRequestTest() : default_context_(true) { | 560 URLRequestTest() : default_context_(true) { |
559 default_context_.set_network_delegate(&default_network_delegate_); | 561 default_context_.set_network_delegate(&default_network_delegate_); |
560 default_context_.set_net_log(&net_log_); | 562 default_context_.set_net_log(&net_log_); |
| 563 job_factory_.SetProtocolHandler("data", new DataProtocolHandler); |
| 564 job_factory_.SetProtocolHandler("file", new FileProtocolHandler); |
| 565 default_context_.set_job_factory(&job_factory_); |
561 default_context_.Init(); | 566 default_context_.Init(); |
562 } | 567 } |
563 virtual ~URLRequestTest() {} | 568 virtual ~URLRequestTest() {} |
564 | 569 |
565 // Adds the TestJobInterceptor to the default context. | 570 // Adds the TestJobInterceptor to the default context. |
566 TestJobInterceptor* AddTestInterceptor() { | 571 TestJobInterceptor* AddTestInterceptor() { |
567 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); | 572 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); |
568 job_factory_.reset(new URLRequestJobFactoryImpl); | 573 job_factory_.SetProtocolHandler("http", NULL); |
569 job_factory_->SetProtocolHandler("http", protocol_handler_); | 574 job_factory_.SetProtocolHandler("http", protocol_handler_); |
570 default_context_.set_job_factory(job_factory_.get()); | |
571 return protocol_handler_; | 575 return protocol_handler_; |
572 } | 576 } |
573 | 577 |
574 protected: | 578 protected: |
575 CapturingNetLog net_log_; | 579 CapturingNetLog net_log_; |
576 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 580 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
577 scoped_ptr<URLRequestJobFactoryImpl> job_factory_; | 581 URLRequestJobFactoryImpl job_factory_; |
578 TestURLRequestContext default_context_; | 582 TestURLRequestContext default_context_; |
579 }; | 583 }; |
580 | 584 |
581 TEST_F(URLRequestTest, AboutBlankTest) { | 585 TEST_F(URLRequestTest, AboutBlankTest) { |
582 TestDelegate d; | 586 TestDelegate d; |
583 { | 587 { |
584 URLRequest r(GURL("about:blank"), &d, &default_context_); | 588 URLRequest r(GURL("about:blank"), &d, &default_context_); |
585 | 589 |
586 r.Start(); | 590 r.Start(); |
587 EXPECT_TRUE(r.is_pending()); | 591 EXPECT_TRUE(r.is_pending()); |
(...skipping 3267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3855 std::string mime_type; | 3859 std::string mime_type; |
3856 req.GetMimeType(&mime_type); | 3860 req.GetMimeType(&mime_type); |
3857 EXPECT_EQ("text/html", mime_type); | 3861 EXPECT_EQ("text/html", mime_type); |
3858 | 3862 |
3859 std::string charset; | 3863 std::string charset; |
3860 req.GetCharset(&charset); | 3864 req.GetCharset(&charset); |
3861 EXPECT_EQ("utf-8", charset); | 3865 EXPECT_EQ("utf-8", charset); |
3862 req.Cancel(); | 3866 req.Cancel(); |
3863 } | 3867 } |
3864 | 3868 |
| 3869 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictRedirects) { |
| 3870 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). |
| 3871 GURL file_url("file:///foo.txt"); |
| 3872 GURL data_url("data:,foo"); |
| 3873 FileProtocolHandler file_protocol_handler; |
| 3874 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); |
| 3875 DataProtocolHandler data_protocol_handler; |
| 3876 EXPECT_TRUE(data_protocol_handler.IsSafeRedirectTarget(data_url)); |
| 3877 |
| 3878 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
| 3879 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); |
| 3880 EXPECT_TRUE(job_factory_.IsSafeRedirectTarget(data_url)); |
| 3881 } |
| 3882 |
3865 TEST_F(URLRequestTestHTTP, RestrictRedirects) { | 3883 TEST_F(URLRequestTestHTTP, RestrictRedirects) { |
3866 ASSERT_TRUE(test_server_.Start()); | 3884 ASSERT_TRUE(test_server_.Start()); |
3867 | 3885 |
3868 TestDelegate d; | 3886 TestDelegate d; |
3869 URLRequest req(test_server_.GetURL( | 3887 URLRequest req(test_server_.GetURL( |
3870 "files/redirect-to-file.html"), &d, &default_context_); | 3888 "files/redirect-to-file.html"), &d, &default_context_); |
3871 req.Start(); | 3889 req.Start(); |
3872 MessageLoop::current()->Run(); | 3890 MessageLoop::current()->Run(); |
3873 | 3891 |
3874 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 3892 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5445 | 5463 |
5446 protected: | 5464 protected: |
5447 SpawnedTestServer test_server_; | 5465 SpawnedTestServer test_server_; |
5448 }; | 5466 }; |
5449 | 5467 |
5450 // Make sure an FTP request using an unsafe ports fails. | 5468 // Make sure an FTP request using an unsafe ports fails. |
5451 TEST_F(URLRequestTestFTP, UnsafePort) { | 5469 TEST_F(URLRequestTestFTP, UnsafePort) { |
5452 ASSERT_TRUE(test_server_.Start()); | 5470 ASSERT_TRUE(test_server_.Start()); |
5453 | 5471 |
5454 URLRequestJobFactoryImpl job_factory; | 5472 URLRequestJobFactoryImpl job_factory; |
| 5473 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); |
5455 | 5474 |
5456 GURL url("ftp://127.0.0.1:7"); | 5475 GURL url("ftp://127.0.0.1:7"); |
5457 FtpProtocolHandler ftp_protocol_handler( | |
5458 default_context_.ftp_transaction_factory(), | |
5459 default_context_.ftp_auth_cache()); | |
5460 job_factory.SetProtocolHandler( | 5476 job_factory.SetProtocolHandler( |
5461 "ftp", | 5477 "ftp", |
5462 new FtpProtocolHandler(default_context_.ftp_transaction_factory(), | 5478 new FtpProtocolHandler(&ftp_transaction_factory)); |
5463 default_context_.ftp_auth_cache())); | |
5464 default_context_.set_job_factory(&job_factory); | 5479 default_context_.set_job_factory(&job_factory); |
5465 | 5480 |
5466 TestDelegate d; | 5481 TestDelegate d; |
5467 { | 5482 { |
5468 URLRequest r(url, &d, &default_context_); | 5483 URLRequest r(url, &d, &default_context_); |
5469 r.Start(); | 5484 r.Start(); |
5470 EXPECT_TRUE(r.is_pending()); | 5485 EXPECT_TRUE(r.is_pending()); |
5471 | 5486 |
5472 MessageLoop::current()->Run(); | 5487 MessageLoop::current()->Run(); |
5473 | 5488 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5791 | 5806 |
5792 EXPECT_FALSE(r.is_pending()); | 5807 EXPECT_FALSE(r.is_pending()); |
5793 EXPECT_EQ(1, d->response_started_count()); | 5808 EXPECT_EQ(1, d->response_started_count()); |
5794 EXPECT_FALSE(d->received_data_before_response()); | 5809 EXPECT_FALSE(d->received_data_before_response()); |
5795 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 5810 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
5796 } | 5811 } |
5797 } | 5812 } |
5798 #endif // !defined(DISABLE_FTP_SUPPORT) | 5813 #endif // !defined(DISABLE_FTP_SUPPORT) |
5799 | 5814 |
5800 } // namespace net | 5815 } // namespace net |
OLD | NEW |