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

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

Issue 12605011: Revert 188912 "Removed static factories for data, ftp, file, and..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 9 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
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "net/http/http_cache.h" 51 #include "net/http/http_cache.h"
52 #include "net/http/http_network_layer.h" 52 #include "net/http/http_network_layer.h"
53 #include "net/http/http_network_session.h" 53 #include "net/http/http_network_session.h"
54 #include "net/http/http_request_headers.h" 54 #include "net/http/http_request_headers.h"
55 #include "net/http/http_response_headers.h" 55 #include "net/http/http_response_headers.h"
56 #include "net/ocsp/nss_ocsp.h" 56 #include "net/ocsp/nss_ocsp.h"
57 #include "net/proxy/proxy_service.h" 57 #include "net/proxy/proxy_service.h"
58 #include "net/socket/ssl_client_socket.h" 58 #include "net/socket/ssl_client_socket.h"
59 #include "net/ssl/ssl_connection_status_flags.h" 59 #include "net/ssl/ssl_connection_status_flags.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"
63 #include "net/url_request/ftp_protocol_handler.h" 61 #include "net/url_request/ftp_protocol_handler.h"
64 #include "net/url_request/static_http_user_agent_settings.h" 62 #include "net/url_request/static_http_user_agent_settings.h"
65 #include "net/url_request/url_request.h" 63 #include "net/url_request/url_request.h"
66 #include "net/url_request/url_request_file_dir_job.h" 64 #include "net/url_request/url_request_file_dir_job.h"
67 #include "net/url_request/url_request_http_job.h" 65 #include "net/url_request/url_request_http_job.h"
68 #include "net/url_request/url_request_job_factory_impl.h" 66 #include "net/url_request/url_request_job_factory_impl.h"
69 #include "net/url_request/url_request_redirect_job.h" 67 #include "net/url_request/url_request_redirect_job.h"
70 #include "net/url_request/url_request_test_job.h" 68 #include "net/url_request/url_request_test_job.h"
71 #include "net/url_request/url_request_test_util.h" 69 #include "net/url_request/url_request_test_util.h"
72 #include "testing/gtest/include/gtest/gtest.h" 70 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 }; 507 };
510 508
511 } // namespace 509 } // namespace
512 510
513 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. 511 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.
514 class URLRequestTest : public PlatformTest { 512 class URLRequestTest : public PlatformTest {
515 public: 513 public:
516 URLRequestTest() : default_context_(true) { 514 URLRequestTest() : default_context_(true) {
517 default_context_.set_network_delegate(&default_network_delegate_); 515 default_context_.set_network_delegate(&default_network_delegate_);
518 default_context_.set_net_log(&net_log_); 516 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_);
522 default_context_.Init(); 517 default_context_.Init();
523 } 518 }
524 virtual ~URLRequestTest() {} 519 virtual ~URLRequestTest() {}
525 520
526 // Adds the TestJobInterceptor to the default context. 521 // Adds the TestJobInterceptor to the default context.
527 TestJobInterceptor* AddTestInterceptor() { 522 TestJobInterceptor* AddTestInterceptor() {
528 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); 523 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor();
529 job_factory_.SetProtocolHandler("http", protocol_handler_); 524 job_factory_.reset(new URLRequestJobFactoryImpl);
525 job_factory_->SetProtocolHandler("http", protocol_handler_);
526 default_context_.set_job_factory(job_factory_.get());
530 return protocol_handler_; 527 return protocol_handler_;
531 } 528 }
532 529
533 protected: 530 protected:
534 CapturingNetLog net_log_; 531 CapturingNetLog net_log_;
535 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 532 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
536 URLRequestJobFactoryImpl job_factory_; 533 scoped_ptr<URLRequestJobFactoryImpl> job_factory_;
537 TestURLRequestContext default_context_; 534 TestURLRequestContext default_context_;
538 }; 535 };
539 536
540 TEST_F(URLRequestTest, AboutBlankTest) { 537 TEST_F(URLRequestTest, AboutBlankTest) {
541 TestDelegate d; 538 TestDelegate d;
542 { 539 {
543 URLRequest r(GURL("about:blank"), &d, &default_context_); 540 URLRequest r(GURL("about:blank"), &d, &default_context_);
544 541
545 r.Start(); 542 r.Start();
546 EXPECT_TRUE(r.is_pending()); 543 EXPECT_TRUE(r.is_pending());
(...skipping 2913 matching lines...) Expand 10 before | Expand all | Expand 10 after
3460 std::string mime_type; 3457 std::string mime_type;
3461 req.GetMimeType(&mime_type); 3458 req.GetMimeType(&mime_type);
3462 EXPECT_EQ("text/html", mime_type); 3459 EXPECT_EQ("text/html", mime_type);
3463 3460
3464 std::string charset; 3461 std::string charset;
3465 req.GetCharset(&charset); 3462 req.GetCharset(&charset);
3466 EXPECT_EQ("utf-8", charset); 3463 EXPECT_EQ("utf-8", charset);
3467 req.Cancel(); 3464 req.Cancel();
3468 } 3465 }
3469 3466
3470 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictRedirects) {
3471 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget().
3472 GURL file_url("file:///foo.txt");
3473 GURL data_url("data:,foo");
3474 FileProtocolHandler file_protocol_handler;
3475 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url));
3476 DataProtocolHandler data_protocol_handler;
3477 EXPECT_TRUE(data_protocol_handler.IsSafeRedirectTarget(data_url));
3478
3479 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget().
3480 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url));
3481 EXPECT_TRUE(job_factory_.IsSafeRedirectTarget(data_url));
3482 }
3483
3484 TEST_F(URLRequestTestHTTP, RestrictRedirects) { 3467 TEST_F(URLRequestTestHTTP, RestrictRedirects) {
3485 ASSERT_TRUE(test_server_.Start()); 3468 ASSERT_TRUE(test_server_.Start());
3486 3469
3487 TestDelegate d; 3470 TestDelegate d;
3488 URLRequest req(test_server_.GetURL( 3471 URLRequest req(test_server_.GetURL(
3489 "files/redirect-to-file.html"), &d, &default_context_); 3472 "files/redirect-to-file.html"), &d, &default_context_);
3490 req.Start(); 3473 req.Start();
3491 MessageLoop::current()->Run(); 3474 MessageLoop::current()->Run();
3492 3475
3493 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 3476 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status());
(...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after
4993 4976
4994 protected: 4977 protected:
4995 TestServer test_server_; 4978 TestServer test_server_;
4996 }; 4979 };
4997 4980
4998 // Make sure an FTP request using an unsafe ports fails. 4981 // Make sure an FTP request using an unsafe ports fails.
4999 TEST_F(URLRequestTestFTP, UnsafePort) { 4982 TEST_F(URLRequestTestFTP, UnsafePort) {
5000 ASSERT_TRUE(test_server_.Start()); 4983 ASSERT_TRUE(test_server_.Start());
5001 4984
5002 URLRequestJobFactoryImpl job_factory; 4985 URLRequestJobFactoryImpl job_factory;
5003 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver());
5004 4986
5005 GURL url("ftp://127.0.0.1:7"); 4987 GURL url("ftp://127.0.0.1:7");
4988 FtpProtocolHandler ftp_protocol_handler(
4989 default_context_.ftp_transaction_factory(),
4990 default_context_.ftp_auth_cache());
5006 job_factory.SetProtocolHandler( 4991 job_factory.SetProtocolHandler(
5007 "ftp", 4992 "ftp",
5008 new FtpProtocolHandler(&ftp_transaction_factory)); 4993 new FtpProtocolHandler(default_context_.ftp_transaction_factory(),
4994 default_context_.ftp_auth_cache()));
5009 default_context_.set_job_factory(&job_factory); 4995 default_context_.set_job_factory(&job_factory);
5010 4996
5011 TestDelegate d; 4997 TestDelegate d;
5012 { 4998 {
5013 URLRequest r(url, &d, &default_context_); 4999 URLRequest r(url, &d, &default_context_);
5014 r.Start(); 5000 r.Start();
5015 EXPECT_TRUE(r.is_pending()); 5001 EXPECT_TRUE(r.is_pending());
5016 5002
5017 MessageLoop::current()->Run(); 5003 MessageLoop::current()->Run();
5018 5004
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
5336 5322
5337 EXPECT_FALSE(r.is_pending()); 5323 EXPECT_FALSE(r.is_pending());
5338 EXPECT_EQ(1, d->response_started_count()); 5324 EXPECT_EQ(1, d->response_started_count());
5339 EXPECT_FALSE(d->received_data_before_response()); 5325 EXPECT_FALSE(d->received_data_before_response());
5340 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 5326 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
5341 } 5327 }
5342 } 5328 }
5343 #endif // !defined(DISABLE_FTP_SUPPORT) 5329 #endif // !defined(DISABLE_FTP_SUPPORT)
5344 5330
5345 } // namespace net 5331 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/url_request/url_request_test_util.cc ('k') | trunk/src/webkit/tools/test_shell/test_shell_request_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698