diff options
Diffstat (limited to 'net/http/http_network_transaction_unittest.cc')
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index d5f0228..c362e04 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -856,3 +856,72 @@ TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { const net::HttpResponseInfo* response = trans->GetResponseInfo(); EXPECT_TRUE(response == NULL); } + +// Make sure that we don't try to reuse a TCPClientSocket when failing to +// establish tunnel. +// http://code.google.com/p/chromium/issues/detail?id=3772 +TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { + // Configure against proxy server "myproxy:70". + net::ProxyInfo proxy_info; + proxy_info.UseNamedProxy("myproxy:70"); + + scoped_refptr<net::HttpNetworkSession> session( + CreateSession(new net::ProxyResolverFixed(proxy_info))); + + scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( + session.get(), &mock_socket_factory)); + + net::HttpRequestInfo request; + request.method = "GET"; + request.url = GURL("https://www.google.com/"); + request.load_flags = 0; + + // Since we have proxy, should try to establish tunnel. + MockWrite data_writes1[] = { + MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" + "Host: www.google.com\r\n\r\n"), + }; + + // The proxy responds to the connect with a 404, using a persistent + // connection. Usually a proxy would return 501 (not implemented), + // or 200 (tunnel established). + MockRead data_reads1[] = { + MockRead("HTTP/1.1 404 Not Found\r\n"), + MockRead("Content-Length: 10\r\n\r\n"), + MockRead("0123456789"), + MockRead(false, net::ERR_UNEXPECTED), // Should not be reached. + }; + + MockSocket data1; + data1.writes = data_writes1; + data1.reads = data_reads1; + mock_sockets[0] = &data1; + mock_sockets[1] = NULL; + + TestCompletionCallback callback1; + + int rv = trans->Start(&request, &callback1); + EXPECT_EQ(net::ERR_IO_PENDING, rv); + + rv = callback1.WaitForResult(); + EXPECT_EQ(net::OK, rv); + + const net::HttpResponseInfo* response = trans->GetResponseInfo(); + EXPECT_FALSE(response == NULL); + + EXPECT_TRUE(response->headers->IsKeepAlive()); + EXPECT_EQ(404, response->headers->response_code()); + EXPECT_EQ(10, response->headers->GetContentLength()); + EXPECT_TRUE(net::HttpVersion(1, 1) == response->headers->GetHttpVersion()); + + std::string response_data; + rv = ReadTransaction(trans.get(), &response_data); + EXPECT_STREQ("0123456789", response_data.c_str()); + + // We now check to make sure the TCPClientSocket was not added back to + // the pool. + EXPECT_EQ(0, session->connection_pool()->idle_socket_count()); + trans.reset(); + // Make sure that the socket didn't get recycled after calling the destructor. + EXPECT_EQ(0, session->connection_pool()->idle_socket_count()); +} |