| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 262 } |
| 263 virtual base::TimeDelta ConnectionTimeout() const { | 263 virtual base::TimeDelta ConnectionTimeout() const { |
| 264 return base::TimeDelta(); | 264 return base::TimeDelta(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 private: | 267 private: |
| 268 std::string last_group_name_; | 268 std::string last_group_name_; |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 typedef CaptureGroupNameSocketPool<TCPClientSocketPool> | 271 typedef CaptureGroupNameSocketPool<TCPClientSocketPool> |
| 272 CaptureGroupNameTCPSocketPool; | 272 CaptureGroupNameTCPSocketPool; |
| 273 typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> | 273 typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
| 274 CaptureGroupNameSOCKSSocketPool; | 274 CaptureGroupNameSOCKSSocketPool; |
| 275 |
| 275 //----------------------------------------------------------------------------- | 276 //----------------------------------------------------------------------------- |
| 276 | 277 |
| 277 TEST_F(HttpNetworkTransactionTest, Basic) { | 278 TEST_F(HttpNetworkTransactionTest, Basic) { |
| 278 SessionDependencies session_deps; | 279 SessionDependencies session_deps; |
| 279 scoped_ptr<HttpTransaction> trans( | 280 scoped_ptr<HttpTransaction> trans( |
| 280 new HttpNetworkTransaction(CreateSession(&session_deps))); | 281 new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 281 } | 282 } |
| 282 | 283 |
| 283 TEST_F(HttpNetworkTransactionTest, SimpleGET) { | 284 TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
| 284 MockRead data_reads[] = { | 285 MockRead data_reads[] = { |
| (...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 // can't hook into its internals to cause it to generate predictable NTLM | 1724 // can't hook into its internals to cause it to generate predictable NTLM |
| 1724 // authorization headers. | 1725 // authorization headers. |
| 1725 #if defined(NTLM_PORTABLE) | 1726 #if defined(NTLM_PORTABLE) |
| 1726 // The NTLM authentication unit tests were generated by capturing the HTTP | 1727 // The NTLM authentication unit tests were generated by capturing the HTTP |
| 1727 // requests and responses using Fiddler 2 and inspecting the generated random | 1728 // requests and responses using Fiddler 2 and inspecting the generated random |
| 1728 // bytes in the debugger. | 1729 // bytes in the debugger. |
| 1729 | 1730 |
| 1730 // Enter the correct password and authenticate successfully. | 1731 // Enter the correct password and authenticate successfully. |
| 1731 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { | 1732 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
| 1732 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, | 1733 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 1733 MockGetHostName); | 1734 MockGetHostName); |
| 1734 SessionDependencies session_deps; | 1735 SessionDependencies session_deps; |
| 1735 scoped_ptr<HttpTransaction> trans( | 1736 scoped_ptr<HttpTransaction> trans( |
| 1736 new HttpNetworkTransaction(CreateSession(&session_deps))); | 1737 new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 1737 | 1738 |
| 1738 HttpRequestInfo request; | 1739 HttpRequestInfo request; |
| 1739 request.method = "GET"; | 1740 request.method = "GET"; |
| 1740 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | 1741 request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 1741 request.load_flags = 0; | 1742 request.load_flags = 0; |
| 1742 | 1743 |
| 1743 MockWrite data_writes1[] = { | 1744 MockWrite data_writes1[] = { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 EXPECT_EQ(OK, rv); | 1847 EXPECT_EQ(OK, rv); |
| 1847 | 1848 |
| 1848 response = trans->GetResponseInfo(); | 1849 response = trans->GetResponseInfo(); |
| 1849 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1850 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1850 EXPECT_EQ(13, response->headers->GetContentLength()); | 1851 EXPECT_EQ(13, response->headers->GetContentLength()); |
| 1851 } | 1852 } |
| 1852 | 1853 |
| 1853 // Enter a wrong password, and then the correct one. | 1854 // Enter a wrong password, and then the correct one. |
| 1854 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { | 1855 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
| 1855 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, | 1856 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 1856 MockGetHostName); | 1857 MockGetHostName); |
| 1857 SessionDependencies session_deps; | 1858 SessionDependencies session_deps; |
| 1858 scoped_ptr<HttpTransaction> trans( | 1859 scoped_ptr<HttpTransaction> trans( |
| 1859 new HttpNetworkTransaction(CreateSession(&session_deps))); | 1860 new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 1860 | 1861 |
| 1861 HttpRequestInfo request; | 1862 HttpRequestInfo request; |
| 1862 request.method = "GET"; | 1863 request.method = "GET"; |
| 1863 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | 1864 request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 1864 request.load_flags = 0; | 1865 request.load_flags = 0; |
| 1865 | 1866 |
| 1866 MockWrite data_writes1[] = { | 1867 MockWrite data_writes1[] = { |
| (...skipping 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4789 // EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 4790 // EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4790 // | 4791 // |
| 4791 // std::string response_data; | 4792 // std::string response_data; |
| 4792 // ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 4793 // ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4793 // EXPECT_EQ("hello world", response_data); | 4794 // EXPECT_EQ("hello world", response_data); |
| 4794 // } | 4795 // } |
| 4795 | 4796 |
| 4796 TEST_F(HttpNetworkTransactionTest, FailNpnSpdyAndFallback) { | 4797 TEST_F(HttpNetworkTransactionTest, FailNpnSpdyAndFallback) { |
| 4797 HttpNetworkTransaction::SetUseAlternateProtocols(true); | 4798 HttpNetworkTransaction::SetUseAlternateProtocols(true); |
| 4798 HttpNetworkTransaction::SetNextProtos( | 4799 HttpNetworkTransaction::SetNextProtos( |
| 4799 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); | 4800 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); |
| 4800 SessionDependencies session_deps; | 4801 SessionDependencies session_deps; |
| 4801 | 4802 |
| 4802 HttpRequestInfo request; | 4803 HttpRequestInfo request; |
| 4803 request.method = "GET"; | 4804 request.method = "GET"; |
| 4804 request.url = GURL("http://www.google.com/"); | 4805 request.url = GURL("http://www.google.com/"); |
| 4805 request.load_flags = 0; | 4806 request.load_flags = 0; |
| 4806 | 4807 |
| 4807 StaticSocketDataProvider first_tcp_connect; | 4808 StaticSocketDataProvider first_tcp_connect; |
| 4808 session_deps.socket_factory.AddSocketDataProvider(&first_tcp_connect); | 4809 session_deps.socket_factory.AddSocketDataProvider(&first_tcp_connect); |
| 4809 | 4810 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4846 std::string response_data; | 4847 std::string response_data; |
| 4847 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 4848 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4848 EXPECT_EQ("hello world", response_data); | 4849 EXPECT_EQ("hello world", response_data); |
| 4849 HttpNetworkTransaction::SetNextProtos(""); | 4850 HttpNetworkTransaction::SetNextProtos(""); |
| 4850 HttpNetworkTransaction::SetUseAlternateProtocols(false); | 4851 HttpNetworkTransaction::SetUseAlternateProtocols(false); |
| 4851 } | 4852 } |
| 4852 | 4853 |
| 4853 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { | 4854 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
| 4854 HttpNetworkTransaction::SetUseAlternateProtocols(true); | 4855 HttpNetworkTransaction::SetUseAlternateProtocols(true); |
| 4855 HttpNetworkTransaction::SetNextProtos( | 4856 HttpNetworkTransaction::SetNextProtos( |
| 4856 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); | 4857 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); |
| 4857 SessionDependencies session_deps; | 4858 SessionDependencies session_deps; |
| 4858 | 4859 |
| 4859 HttpRequestInfo request; | 4860 HttpRequestInfo request; |
| 4860 request.method = "GET"; | 4861 request.method = "GET"; |
| 4861 request.url = GURL("http://www.google.com/"); | 4862 request.url = GURL("http://www.google.com/"); |
| 4862 request.load_flags = 0; | 4863 request.load_flags = 0; |
| 4863 | 4864 |
| 4864 MockRead data_reads[] = { | 4865 MockRead data_reads[] = { |
| 4865 MockRead("HTTP/1.1 200 OK\r\n"), | 4866 MockRead("HTTP/1.1 200 OK\r\n"), |
| 4866 MockRead("Alternate-Protocol: 443:npn-spdy/1\r\n\r\n"), | 4867 MockRead("Alternate-Protocol: 443:npn-spdy/1\r\n\r\n"), |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4970 // response, and then send the request, and then read the response. | 4971 // response, and then send the request, and then read the response. |
| 4971 // DelayedSocketDataProvider doesn't permit this yet. | 4972 // DelayedSocketDataProvider doesn't permit this yet. |
| 4972 #if 0 | 4973 #if 0 |
| 4973 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) { | 4974 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) { |
| 4974 HttpNetworkTransaction::SetUseAlternateProtocols(true); | 4975 HttpNetworkTransaction::SetUseAlternateProtocols(true); |
| 4975 HttpNetworkTransaction::SetNextProtos( | 4976 HttpNetworkTransaction::SetNextProtos( |
| 4976 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); | 4977 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); |
| 4977 | 4978 |
| 4978 ProxyConfig proxy_config; | 4979 ProxyConfig proxy_config; |
| 4979 proxy_config.proxy_rules().ParseFromString("myproxy:80"); | 4980 proxy_config.proxy_rules().ParseFromString("myproxy:80"); |
| 4980 | 4981 |
| 4981 CapturingProxyResolver* capturing_proxy_resolver = | 4982 CapturingProxyResolver* capturing_proxy_resolver = |
| 4982 new CapturingProxyResolver(); | 4983 new CapturingProxyResolver(); |
| 4983 SessionDependencies session_deps( | 4984 SessionDependencies session_deps( |
| 4984 new ProxyService(new ProxyConfigServiceFixed(proxy_config), | 4985 new ProxyService(new ProxyConfigServiceFixed(proxy_config), |
| 4985 capturing_proxy_resolver, | 4986 capturing_proxy_resolver, |
| 4986 NULL, | 4987 NULL, |
| 4987 NULL)); | 4988 NULL)); |
| 4988 | 4989 |
| 4989 HttpRequestInfo request; | 4990 HttpRequestInfo request; |
| 4990 request.method = "GET"; | 4991 request.method = "GET"; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5068 | 5069 |
| 5069 HttpNetworkTransaction::SetNextProtos(""); | 5070 HttpNetworkTransaction::SetNextProtos(""); |
| 5070 HttpNetworkTransaction::SetUseAlternateProtocols(false); | 5071 HttpNetworkTransaction::SetUseAlternateProtocols(false); |
| 5071 } | 5072 } |
| 5072 #endif | 5073 #endif |
| 5073 | 5074 |
| 5074 TEST_F(HttpNetworkTransactionTest, | 5075 TEST_F(HttpNetworkTransactionTest, |
| 5075 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { | 5076 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
| 5076 HttpNetworkTransaction::SetUseAlternateProtocols(true); | 5077 HttpNetworkTransaction::SetUseAlternateProtocols(true); |
| 5077 HttpNetworkTransaction::SetNextProtos( | 5078 HttpNetworkTransaction::SetNextProtos( |
| 5078 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); | 5079 "\x08http/1.1\x07http1.1\x06spdy/1\x04spdy"); |
| 5079 SessionDependencies session_deps; | 5080 SessionDependencies session_deps; |
| 5080 | 5081 |
| 5081 HttpRequestInfo request; | 5082 HttpRequestInfo request; |
| 5082 request.method = "GET"; | 5083 request.method = "GET"; |
| 5083 request.url = GURL("http://www.google.com/"); | 5084 request.url = GURL("http://www.google.com/"); |
| 5084 request.load_flags = 0; | 5085 request.load_flags = 0; |
| 5085 | 5086 |
| 5086 MockRead data_reads[] = { | 5087 MockRead data_reads[] = { |
| 5087 MockRead("HTTP/1.1 200 OK\r\n"), | 5088 MockRead("HTTP/1.1 200 OK\r\n"), |
| 5088 MockRead("Alternate-Protocol: 443:npn-spdy/1\r\n\r\n"), | 5089 MockRead("Alternate-Protocol: 443:npn-spdy/1\r\n\r\n"), |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5304 auth_factory->set_mock_handler(auth_handler); | 5305 auth_factory->set_mock_handler(auth_handler); |
| 5305 session_deps.http_auth_handler_factory.reset(auth_factory); | 5306 session_deps.http_auth_handler_factory.reset(auth_factory); |
| 5306 | 5307 |
| 5307 for (int i = 0; i < 2; ++i) { | 5308 for (int i = 0; i < 2; ++i) { |
| 5308 scoped_ptr<HttpTransaction> trans( | 5309 scoped_ptr<HttpTransaction> trans( |
| 5309 new HttpNetworkTransaction(CreateSession(&session_deps))); | 5310 new HttpNetworkTransaction(CreateSession(&session_deps))); |
| 5310 | 5311 |
| 5311 // Set up expectations for this pass of the test. Many of the EXPECT calls | 5312 // Set up expectations for this pass of the test. Many of the EXPECT calls |
| 5312 // are contained inside the MockAuthHandlerCanonical codebase in response to | 5313 // are contained inside the MockAuthHandlerCanonical codebase in response to |
| 5313 // the expectations. | 5314 // the expectations. |
| 5314 MockAuthHandlerCanonical::Resolve resolve = (i == 0) ? | 5315 MockAuthHandlerCanonical::Resolve resolve = |
| 5316 (i == 0) ? |
| 5315 MockAuthHandlerCanonical::RESOLVE_SYNC : | 5317 MockAuthHandlerCanonical::RESOLVE_SYNC : |
| 5316 MockAuthHandlerCanonical::RESOLVE_ASYNC; | 5318 MockAuthHandlerCanonical::RESOLVE_ASYNC; |
| 5317 auth_handler->SetResolveExpectation(resolve); | 5319 auth_handler->SetResolveExpectation(resolve); |
| 5318 HttpRequestInfo request; | 5320 HttpRequestInfo request; |
| 5319 request.method = "GET"; | 5321 request.method = "GET"; |
| 5320 request.url = GURL("http://myserver/"); | 5322 request.url = GURL("http://myserver/"); |
| 5321 request.load_flags = 0; | 5323 request.load_flags = 0; |
| 5322 | 5324 |
| 5323 MockWrite data_writes1[] = { | 5325 MockWrite data_writes1[] = { |
| 5324 MockWrite("GET / HTTP/1.1\r\n" | 5326 MockWrite("GET / HTTP/1.1\r\n" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5393 HttpRequestInfo request; | 5395 HttpRequestInfo request; |
| 5394 request.method = "GET"; | 5396 request.method = "GET"; |
| 5395 request.url = GURL("https://tlsdecompressionfailure.example.com/"); | 5397 request.url = GURL("https://tlsdecompressionfailure.example.com/"); |
| 5396 request.load_flags = 0; | 5398 request.load_flags = 0; |
| 5397 | 5399 |
| 5398 SessionDependencies session_deps; | 5400 SessionDependencies session_deps; |
| 5399 TLSDecompressionFailureSocketDataProvider socket_data_provider1( | 5401 TLSDecompressionFailureSocketDataProvider socket_data_provider1( |
| 5400 false /* fail all reads */); | 5402 false /* fail all reads */); |
| 5401 TLSDecompressionFailureSocketDataProvider socket_data_provider2(false); | 5403 TLSDecompressionFailureSocketDataProvider socket_data_provider2(false); |
| 5402 SSLSocketDataProvider ssl_socket_data_provider1( | 5404 SSLSocketDataProvider ssl_socket_data_provider1( |
| 5403 false, ERR_SSL_DECOMPRESSION_FAILURE_ALERT); | 5405 false, ERR_SSL_DECOMPRESSION_FAILURE_ALERT); |
| 5404 SSLSocketDataProvider ssl_socket_data_provider2(false, OK); | 5406 SSLSocketDataProvider ssl_socket_data_provider2(false, OK); |
| 5405 session_deps.socket_factory.AddSocketDataProvider(&socket_data_provider1); | 5407 session_deps.socket_factory.AddSocketDataProvider(&socket_data_provider1); |
| 5406 session_deps.socket_factory.AddSocketDataProvider(&socket_data_provider2); | 5408 session_deps.socket_factory.AddSocketDataProvider(&socket_data_provider2); |
| 5407 session_deps.socket_factory.AddSSLSocketDataProvider( | 5409 session_deps.socket_factory.AddSSLSocketDataProvider( |
| 5408 &ssl_socket_data_provider1); | 5410 &ssl_socket_data_provider1); |
| 5409 session_deps.socket_factory.AddSSLSocketDataProvider( | 5411 session_deps.socket_factory.AddSSLSocketDataProvider( |
| 5410 &ssl_socket_data_provider2); | 5412 &ssl_socket_data_provider2); |
| 5411 | 5413 |
| 5412 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 5414 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 5413 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); | 5415 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5463 ASSERT_TRUE(response != NULL); | 5465 ASSERT_TRUE(response != NULL); |
| 5464 ASSERT_TRUE(response->headers != NULL); | 5466 ASSERT_TRUE(response->headers != NULL); |
| 5465 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 5467 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5466 | 5468 |
| 5467 std::string response_data; | 5469 std::string response_data; |
| 5468 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 5470 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 5469 EXPECT_EQ("ok.", response_data); | 5471 EXPECT_EQ("ok.", response_data); |
| 5470 } | 5472 } |
| 5471 | 5473 |
| 5472 } // namespace net | 5474 } // namespace net |
| OLD | NEW |