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

Unified Diff: net/http/http_network_transaction_unittest.cc

Issue 63139: Add a boolean data member called_socket_read_ to help... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_network_transaction_unittest.cc
===================================================================
--- net/http/http_network_transaction_unittest.cc (revision 13379)
+++ net/http/http_network_transaction_unittest.cc (working copy)
@@ -2188,14 +2188,80 @@
const net::HttpResponseInfo* response = trans->GetResponseInfo();
EXPECT_TRUE(response == NULL);
+ // Empty the current queue. This is necessary because idle sockets are
+ // added to the connection pool asynchronously with a PostTask.
+ MessageLoop::current()->RunAllPending();
+
// 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();
+ MessageLoop::current()->RunAllPending();
// Make sure that the socket didn't get recycled after calling the destructor.
EXPECT_EQ(0, session->connection_pool()->idle_socket_count());
}
+// Make sure that we recycle a socket after a zero-length response.
+// http://crbug.com/9880
+TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) {
+ scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
+ scoped_refptr<net::HttpNetworkSession> session(
+ CreateSession(proxy_service.get()));
+
+ scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
+ session.get(), &mock_socket_factory));
+
+ net::HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&"
+ "tran=undefined&ei=mAXcSeegAo-SMurloeUN&"
+ "e=17259,18167,19592,19773,19981,20133,20173,20233&"
+ "rt=prt.2642,ol.2649,xjs.2951");
+ request.load_flags = 0;
+
+ MockRead data_reads[] = {
+ MockRead("HTTP/1.1 204 No Content\r\n"
+ "Content-Length: 0\r\n"
+ "Content-Type: text/html\r\n\r\n"),
+ MockRead("junk"), // Should not be read!!
+ MockRead(false, net::OK),
+ };
+
+ MockSocket data;
+ data.reads = data_reads;
+ mock_sockets[0] = &data;
+ mock_sockets[1] = NULL;
+
+ TestCompletionCallback callback;
+
+ int rv = trans->Start(&request, &callback);
+ EXPECT_EQ(net::ERR_IO_PENDING, rv);
+
+ rv = callback.WaitForResult();
+ EXPECT_EQ(net::OK, rv);
+
+ const net::HttpResponseInfo* response = trans->GetResponseInfo();
+ EXPECT_TRUE(response != NULL);
+
+ EXPECT_TRUE(response->headers != NULL);
+ std::string status_line = response->headers->GetStatusLine();
+ EXPECT_EQ("HTTP/1.1 204 No Content", status_line);
+
+ EXPECT_EQ(0, session->connection_pool()->idle_socket_count());
+
+ std::string response_data;
+ rv = ReadTransaction(trans.get(), &response_data);
+ EXPECT_EQ(net::OK, rv);
+ EXPECT_EQ("", response_data);
+
+ // Empty the current queue. This is necessary because idle sockets are
+ // added to the connection pool asynchronously with a PostTask.
+ MessageLoop::current()->RunAllPending();
+
+ // We now check to make sure the socket was added back to the pool.
+ EXPECT_EQ(1, session->connection_pool()->idle_socket_count());
+}
+
TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) {
net::HttpRequestInfo request[2];
// Transaction 1: a GET request that succeeds. The socket is recycled
@@ -2812,7 +2878,7 @@
trans->response_.auth_challenge = new AuthChallengeInfo();
trans->response_.ssl_info.cert_status = -15;
trans->response_.response_time = base::Time::Now();
- trans->response_.was_cached = true; // (Wouldn't ever actually be true...)
+ trans->response_.was_cached = true; // (Wouldn't ever actually be true...)
{ // Setup state for response_.vary_data
HttpRequestInfo request;
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698