| 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/ftp/ftp_network_layer.h" | 51 #include "net/ftp/ftp_network_layer.h" |
| 52 #include "net/http/http_cache.h" | 52 #include "net/http/http_cache.h" |
| 53 #include "net/http/http_network_layer.h" | 53 #include "net/http/http_network_layer.h" |
| 54 #include "net/http/http_network_session.h" | 54 #include "net/http/http_network_session.h" |
| 55 #include "net/http/http_request_headers.h" | 55 #include "net/http/http_request_headers.h" |
| 56 #include "net/http/http_response_headers.h" | 56 #include "net/http/http_response_headers.h" |
| 57 #include "net/ocsp/nss_ocsp.h" | 57 #include "net/ocsp/nss_ocsp.h" |
| 58 #include "net/proxy/proxy_service.h" | 58 #include "net/proxy/proxy_service.h" |
| 59 #include "net/socket/ssl_client_socket.h" | 59 #include "net/socket/ssl_client_socket.h" |
| 60 #include "net/test/test_server.h" | 60 #include "net/test/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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 }; | 509 }; |
| 508 | 510 |
| 509 } // namespace | 511 } // namespace |
| 510 | 512 |
| 511 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. | 513 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
| 512 class URLRequestTest : public PlatformTest { | 514 class URLRequestTest : public PlatformTest { |
| 513 public: | 515 public: |
| 514 URLRequestTest() : default_context_(true) { | 516 URLRequestTest() : default_context_(true) { |
| 515 default_context_.set_network_delegate(&default_network_delegate_); | 517 default_context_.set_network_delegate(&default_network_delegate_); |
| 516 default_context_.set_net_log(&net_log_); | 518 default_context_.set_net_log(&net_log_); |
| 519 job_factory_.SetProtocolHandler("data", new DataProtocolHandler); |
| 520 job_factory_.SetProtocolHandler("file", new FileProtocolHandler); |
| 521 default_context_.set_job_factory(&job_factory_); |
| 517 default_context_.Init(); | 522 default_context_.Init(); |
| 518 } | 523 } |
| 519 virtual ~URLRequestTest() {} | 524 virtual ~URLRequestTest() {} |
| 520 | 525 |
| 521 // Adds the TestJobInterceptor to the default context. | 526 // Adds the TestJobInterceptor to the default context. |
| 522 TestJobInterceptor* AddTestInterceptor() { | 527 TestJobInterceptor* AddTestInterceptor() { |
| 523 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); | 528 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); |
| 524 job_factory_.reset(new URLRequestJobFactoryImpl); | 529 job_factory_.SetProtocolHandler("http", protocol_handler_); |
| 525 job_factory_->SetProtocolHandler("http", protocol_handler_); | |
| 526 default_context_.set_job_factory(job_factory_.get()); | |
| 527 return protocol_handler_; | 530 return protocol_handler_; |
| 528 } | 531 } |
| 529 | 532 |
| 530 protected: | 533 protected: |
| 531 CapturingNetLog net_log_; | 534 CapturingNetLog net_log_; |
| 532 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 535 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 533 scoped_ptr<URLRequestJobFactoryImpl> job_factory_; | 536 URLRequestJobFactoryImpl job_factory_; |
| 534 TestURLRequestContext default_context_; | 537 TestURLRequestContext default_context_; |
| 535 }; | 538 }; |
| 536 | 539 |
| 537 TEST_F(URLRequestTest, AboutBlankTest) { | 540 TEST_F(URLRequestTest, AboutBlankTest) { |
| 538 TestDelegate d; | 541 TestDelegate d; |
| 539 { | 542 { |
| 540 URLRequest r(GURL("about:blank"), &d, &default_context_); | 543 URLRequest r(GURL("about:blank"), &d, &default_context_); |
| 541 | 544 |
| 542 r.Start(); | 545 r.Start(); |
| 543 EXPECT_TRUE(r.is_pending()); | 546 EXPECT_TRUE(r.is_pending()); |
| (...skipping 2911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3455 std::string mime_type; | 3458 std::string mime_type; |
| 3456 req.GetMimeType(&mime_type); | 3459 req.GetMimeType(&mime_type); |
| 3457 EXPECT_EQ("text/html", mime_type); | 3460 EXPECT_EQ("text/html", mime_type); |
| 3458 | 3461 |
| 3459 std::string charset; | 3462 std::string charset; |
| 3460 req.GetCharset(&charset); | 3463 req.GetCharset(&charset); |
| 3461 EXPECT_EQ("utf-8", charset); | 3464 EXPECT_EQ("utf-8", charset); |
| 3462 req.Cancel(); | 3465 req.Cancel(); |
| 3463 } | 3466 } |
| 3464 | 3467 |
| 3468 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictRedirects) { |
| 3469 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). |
| 3470 GURL file_url("file:///foo.txt"); |
| 3471 GURL data_url("data:,foo"); |
| 3472 FileProtocolHandler file_protocol_handler; |
| 3473 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); |
| 3474 DataProtocolHandler data_protocol_handler; |
| 3475 EXPECT_TRUE(data_protocol_handler.IsSafeRedirectTarget(data_url)); |
| 3476 |
| 3477 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
| 3478 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); |
| 3479 EXPECT_TRUE(job_factory_.IsSafeRedirectTarget(data_url)); |
| 3480 } |
| 3481 |
| 3465 TEST_F(URLRequestTestHTTP, RestrictRedirects) { | 3482 TEST_F(URLRequestTestHTTP, RestrictRedirects) { |
| 3466 ASSERT_TRUE(test_server_.Start()); | 3483 ASSERT_TRUE(test_server_.Start()); |
| 3467 | 3484 |
| 3468 TestDelegate d; | 3485 TestDelegate d; |
| 3469 URLRequest req(test_server_.GetURL( | 3486 URLRequest req(test_server_.GetURL( |
| 3470 "files/redirect-to-file.html"), &d, &default_context_); | 3487 "files/redirect-to-file.html"), &d, &default_context_); |
| 3471 req.Start(); | 3488 req.Start(); |
| 3472 MessageLoop::current()->Run(); | 3489 MessageLoop::current()->Run(); |
| 3473 | 3490 |
| 3474 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 3491 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| (...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5021 | 5038 |
| 5022 protected: | 5039 protected: |
| 5023 TestServer test_server_; | 5040 TestServer test_server_; |
| 5024 }; | 5041 }; |
| 5025 | 5042 |
| 5026 // Make sure an FTP request using an unsafe ports fails. | 5043 // Make sure an FTP request using an unsafe ports fails. |
| 5027 TEST_F(URLRequestTestFTP, UnsafePort) { | 5044 TEST_F(URLRequestTestFTP, UnsafePort) { |
| 5028 ASSERT_TRUE(test_server_.Start()); | 5045 ASSERT_TRUE(test_server_.Start()); |
| 5029 | 5046 |
| 5030 URLRequestJobFactoryImpl job_factory; | 5047 URLRequestJobFactoryImpl job_factory; |
| 5048 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); |
| 5031 | 5049 |
| 5032 GURL url("ftp://127.0.0.1:7"); | 5050 GURL url("ftp://127.0.0.1:7"); |
| 5033 FtpProtocolHandler ftp_protocol_handler( | |
| 5034 default_context_.ftp_transaction_factory(), | |
| 5035 default_context_.ftp_auth_cache()); | |
| 5036 job_factory.SetProtocolHandler( | 5051 job_factory.SetProtocolHandler( |
| 5037 "ftp", | 5052 "ftp", |
| 5038 new FtpProtocolHandler(default_context_.ftp_transaction_factory(), | 5053 new FtpProtocolHandler(&ftp_transaction_factory)); |
| 5039 default_context_.ftp_auth_cache())); | |
| 5040 default_context_.set_job_factory(&job_factory); | 5054 default_context_.set_job_factory(&job_factory); |
| 5041 | 5055 |
| 5042 TestDelegate d; | 5056 TestDelegate d; |
| 5043 { | 5057 { |
| 5044 URLRequest r(url, &d, &default_context_); | 5058 URLRequest r(url, &d, &default_context_); |
| 5045 r.Start(); | 5059 r.Start(); |
| 5046 EXPECT_TRUE(r.is_pending()); | 5060 EXPECT_TRUE(r.is_pending()); |
| 5047 | 5061 |
| 5048 MessageLoop::current()->Run(); | 5062 MessageLoop::current()->Run(); |
| 5049 | 5063 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5367 | 5381 |
| 5368 EXPECT_FALSE(r.is_pending()); | 5382 EXPECT_FALSE(r.is_pending()); |
| 5369 EXPECT_EQ(1, d->response_started_count()); | 5383 EXPECT_EQ(1, d->response_started_count()); |
| 5370 EXPECT_FALSE(d->received_data_before_response()); | 5384 EXPECT_FALSE(d->received_data_before_response()); |
| 5371 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 5385 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 5372 } | 5386 } |
| 5373 } | 5387 } |
| 5374 #endif // !defined(DISABLE_FTP_SUPPORT) | 5388 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 5375 | 5389 |
| 5376 } // namespace net | 5390 } // namespace net |
| OLD | NEW |