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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <math.h> // ceil 5 #include <math.h> // ceil
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "net/base/client_socket_factory.h" 8 #include "net/base/client_socket_factory.h"
9 #include "net/base/completion_callback.h" 9 #include "net/base/completion_callback.h"
10 #include "net/base/ssl_client_socket.h" 10 #include "net/base/ssl_client_socket.h"
(...skipping 2170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2181 2181
2182 int rv = trans->Start(&request, &callback1); 2182 int rv = trans->Start(&request, &callback1);
2183 EXPECT_EQ(net::ERR_IO_PENDING, rv); 2183 EXPECT_EQ(net::ERR_IO_PENDING, rv);
2184 2184
2185 rv = callback1.WaitForResult(); 2185 rv = callback1.WaitForResult();
2186 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, rv); 2186 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, rv);
2187 2187
2188 const net::HttpResponseInfo* response = trans->GetResponseInfo(); 2188 const net::HttpResponseInfo* response = trans->GetResponseInfo();
2189 EXPECT_TRUE(response == NULL); 2189 EXPECT_TRUE(response == NULL);
2190 2190
2191 // Empty the current queue. This is necessary because idle sockets are
2192 // added to the connection pool asynchronously with a PostTask.
2193 MessageLoop::current()->RunAllPending();
2194
2191 // We now check to make sure the TCPClientSocket was not added back to 2195 // We now check to make sure the TCPClientSocket was not added back to
2192 // the pool. 2196 // the pool.
2193 EXPECT_EQ(0, session->connection_pool()->idle_socket_count()); 2197 EXPECT_EQ(0, session->connection_pool()->idle_socket_count());
2194 trans.reset(); 2198 trans.reset();
2199 MessageLoop::current()->RunAllPending();
2195 // Make sure that the socket didn't get recycled after calling the destructor. 2200 // Make sure that the socket didn't get recycled after calling the destructor.
2196 EXPECT_EQ(0, session->connection_pool()->idle_socket_count()); 2201 EXPECT_EQ(0, session->connection_pool()->idle_socket_count());
2197 } 2202 }
2198 2203
2204 // Make sure that we recycle a socket after a zero-length response.
2205 // http://crbug.com/9880
2206 TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) {
2207 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
2208 scoped_refptr<net::HttpNetworkSession> session(
2209 CreateSession(proxy_service.get()));
2210
2211 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
2212 session.get(), &mock_socket_factory));
2213
2214 net::HttpRequestInfo request;
2215 request.method = "GET";
2216 request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&"
2217 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&"
2218 "e=17259,18167,19592,19773,19981,20133,20173,20233&"
2219 "rt=prt.2642,ol.2649,xjs.2951");
2220 request.load_flags = 0;
2221
2222 MockRead data_reads[] = {
2223 MockRead("HTTP/1.1 204 No Content\r\n"
2224 "Content-Length: 0\r\n"
2225 "Content-Type: text/html\r\n\r\n"),
2226 MockRead("junk"), // Should not be read!!
2227 MockRead(false, net::OK),
2228 };
2229
2230 MockSocket data;
2231 data.reads = data_reads;
2232 mock_sockets[0] = &data;
2233 mock_sockets[1] = NULL;
2234
2235 TestCompletionCallback callback;
2236
2237 int rv = trans->Start(&request, &callback);
2238 EXPECT_EQ(net::ERR_IO_PENDING, rv);
2239
2240 rv = callback.WaitForResult();
2241 EXPECT_EQ(net::OK, rv);
2242
2243 const net::HttpResponseInfo* response = trans->GetResponseInfo();
2244 EXPECT_TRUE(response != NULL);
2245
2246 EXPECT_TRUE(response->headers != NULL);
2247 std::string status_line = response->headers->GetStatusLine();
2248 EXPECT_EQ("HTTP/1.1 204 No Content", status_line);
2249
2250 EXPECT_EQ(0, session->connection_pool()->idle_socket_count());
2251
2252 std::string response_data;
2253 rv = ReadTransaction(trans.get(), &response_data);
2254 EXPECT_EQ(net::OK, rv);
2255 EXPECT_EQ("", response_data);
2256
2257 // Empty the current queue. This is necessary because idle sockets are
2258 // added to the connection pool asynchronously with a PostTask.
2259 MessageLoop::current()->RunAllPending();
2260
2261 // We now check to make sure the socket was added back to the pool.
2262 EXPECT_EQ(1, session->connection_pool()->idle_socket_count());
2263 }
2264
2199 TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { 2265 TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) {
2200 net::HttpRequestInfo request[2]; 2266 net::HttpRequestInfo request[2];
2201 // Transaction 1: a GET request that succeeds. The socket is recycled 2267 // Transaction 1: a GET request that succeeds. The socket is recycled
2202 // after use. 2268 // after use.
2203 request[0].method = "GET"; 2269 request[0].method = "GET";
2204 request[0].url = GURL("http://www.google.com/"); 2270 request[0].url = GURL("http://www.google.com/");
2205 request[0].load_flags = 0; 2271 request[0].load_flags = 0;
2206 // Transaction 2: a POST request. Reuses the socket kept alive from 2272 // Transaction 2: a POST request. Reuses the socket kept alive from
2207 // transaction 1. The first attempts fails when writing the POST data. 2273 // transaction 1. The first attempts fails when writing the POST data.
2208 // This causes the transaction to retry with a new socket. The second 2274 // This causes the transaction to retry with a new socket. The second
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
2805 trans->response_body_read_ = 1; 2871 trans->response_body_read_ = 1;
2806 trans->read_buf_ = new IOBuffer(15); 2872 trans->read_buf_ = new IOBuffer(15);
2807 trans->read_buf_len_ = 15; 2873 trans->read_buf_len_ = 15;
2808 trans->request_headers_ = "Authorization: NTLM"; 2874 trans->request_headers_ = "Authorization: NTLM";
2809 trans->request_headers_bytes_sent_ = 3; 2875 trans->request_headers_bytes_sent_ = 3;
2810 2876
2811 // Setup state in response_ 2877 // Setup state in response_
2812 trans->response_.auth_challenge = new AuthChallengeInfo(); 2878 trans->response_.auth_challenge = new AuthChallengeInfo();
2813 trans->response_.ssl_info.cert_status = -15; 2879 trans->response_.ssl_info.cert_status = -15;
2814 trans->response_.response_time = base::Time::Now(); 2880 trans->response_.response_time = base::Time::Now();
2815 trans->response_.was_cached = true; // (Wouldn't ever actually be true...) 2881 trans->response_.was_cached = true; // (Wouldn't ever actually be true...)
2816 2882
2817 { // Setup state for response_.vary_data 2883 { // Setup state for response_.vary_data
2818 HttpRequestInfo request; 2884 HttpRequestInfo request;
2819 std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); 2885 std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n");
2820 std::replace(temp.begin(), temp.end(), '\n', '\0'); 2886 std::replace(temp.begin(), temp.end(), '\n', '\0');
2821 scoped_refptr<HttpResponseHeaders> response = new HttpResponseHeaders(temp); 2887 scoped_refptr<HttpResponseHeaders> response = new HttpResponseHeaders(temp);
2822 request.extra_headers = "Foo: 1\nbar: 23"; 2888 request.extra_headers = "Foo: 1\nbar: 23";
2823 EXPECT_TRUE(trans->response_.vary_data.Init(request, *response)); 2889 EXPECT_TRUE(trans->response_.vary_data.Init(request, *response));
2824 } 2890 }
2825 2891
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2976 EXPECT_EQ(OK, rv); 3042 EXPECT_EQ(OK, rv);
2977 3043
2978 const HttpResponseInfo* response = trans->GetResponseInfo(); 3044 const HttpResponseInfo* response = trans->GetResponseInfo();
2979 3045
2980 EXPECT_FALSE(response == NULL); 3046 EXPECT_FALSE(response == NULL);
2981 EXPECT_EQ(100, response->headers->GetContentLength()); 3047 EXPECT_EQ(100, response->headers->GetContentLength());
2982 } 3048 }
2983 } 3049 }
2984 3050
2985 } // namespace net 3051 } // namespace net
OLDNEW
« 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