Index: net/http/http_network_transaction_unittest.cc |
=================================================================== |
--- net/http/http_network_transaction_unittest.cc (revision 19002) |
+++ net/http/http_network_transaction_unittest.cc (working copy) |
@@ -3006,6 +3006,115 @@ |
EXPECT_EQ(OK, rv); |
} |
+TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
+ SessionDependencies session_deps; |
+ session_deps.proxy_service.reset(CreateFixedProxyService( |
+ "socks4://myproxy:1080")); |
+ |
+ scoped_ptr<HttpTransaction> trans( |
+ new HttpNetworkTransaction( |
+ CreateSession(&session_deps), |
+ &session_deps.socket_factory)); |
+ |
+ HttpRequestInfo request; |
+ request.method = "GET"; |
+ request.url = GURL("http://www.google.com/"); |
+ request.load_flags = 0; |
+ |
+ char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
+ char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
+ |
+ MockWrite data_writes[] = { |
+ MockWrite(true, write_buffer, 9), |
+ MockWrite("GET / HTTP/1.1\r\n" |
+ "Host: www.google.com\r\n" |
+ "Connection: keep-alive\r\n\r\n") |
+ }; |
+ |
+ MockRead data_reads[] = { |
+ MockWrite(true, read_buffer, 8), |
+ MockRead("HTTP/1.0 200 OK\r\n"), |
+ MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
+ MockRead("Payload"), |
+ MockRead(false, OK) |
+ }; |
+ |
+ StaticMockSocket data(data_reads, data_writes); |
+ session_deps.socket_factory.AddMockSocket(&data); |
+ |
+ TestCompletionCallback callback; |
+ |
+ int rv = trans->Start(&request, &callback); |
+ EXPECT_EQ(ERR_IO_PENDING, rv); |
+ |
+ rv = callback.WaitForResult(); |
+ EXPECT_EQ(OK, rv); |
+ |
+ const HttpResponseInfo* response = trans->GetResponseInfo(); |
+ EXPECT_FALSE(response == NULL); |
+ |
+ std::string response_text; |
+ rv = ReadTransaction(trans.get(), &response_text); |
+ EXPECT_EQ(OK, rv); |
+ EXPECT_EQ("Payload", response_text); |
+} |
+ |
+TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
+ SessionDependencies session_deps; |
+ session_deps.proxy_service.reset(CreateFixedProxyService( |
+ "socks4://myproxy:1080")); |
+ |
+ scoped_ptr<HttpTransaction> trans( |
+ new HttpNetworkTransaction( |
+ CreateSession(&session_deps), |
+ &session_deps.socket_factory)); |
+ |
+ HttpRequestInfo request; |
+ request.method = "GET"; |
+ request.url = GURL("https://www.google.com/"); |
+ request.load_flags = 0; |
+ |
+ unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
+ unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
+ |
+ MockWrite data_writes[] = { |
+ MockWrite(true, reinterpret_cast<char*>(write_buffer), 9), |
+ MockWrite("GET / HTTP/1.1\r\n" |
+ "Host: www.google.com\r\n" |
+ "Connection: keep-alive\r\n\r\n") |
+ }; |
+ |
+ MockRead data_reads[] = { |
+ MockWrite(true, reinterpret_cast<char*>(read_buffer), 8), |
+ MockRead("HTTP/1.0 200 OK\r\n"), |
+ MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
+ MockRead("Payload"), |
+ MockRead(false, OK) |
+ }; |
+ |
+ StaticMockSocket data(data_reads, data_writes); |
+ session_deps.socket_factory.AddMockSocket(&data); |
+ |
+ MockSSLSocket ssl(true, OK); |
+ session_deps.socket_factory.AddMockSSLSocket(&ssl); |
+ |
+ TestCompletionCallback callback; |
+ |
+ int rv = trans->Start(&request, &callback); |
+ EXPECT_EQ(ERR_IO_PENDING, rv); |
+ |
+ rv = callback.WaitForResult(); |
+ EXPECT_EQ(OK, rv); |
+ |
+ const HttpResponseInfo* response = trans->GetResponseInfo(); |
+ EXPECT_FALSE(response == NULL); |
+ |
+ std::string response_text; |
+ rv = ReadTransaction(trans.get(), &response_text); |
+ EXPECT_EQ(OK, rv); |
+ EXPECT_EQ("Payload", response_text); |
+} |
+ |
TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
scoped_refptr<RuleBasedHostMapper> host_mapper(new RuleBasedHostMapper()); |
ScopedHostMapper scoped_host_mapper(host_mapper.get()); |