Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdarg.h> | 8 #include <stdarg.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 #include "net/http/http_auth_challenge_tokenizer.h" | 38 #include "net/http/http_auth_challenge_tokenizer.h" |
| 39 #include "net/http/http_auth_handler_digest.h" | 39 #include "net/http/http_auth_handler_digest.h" |
| 40 #include "net/http/http_auth_handler_mock.h" | 40 #include "net/http/http_auth_handler_mock.h" |
| 41 #include "net/http/http_auth_handler_ntlm.h" | 41 #include "net/http/http_auth_handler_ntlm.h" |
| 42 #include "net/http/http_basic_stream.h" | 42 #include "net/http/http_basic_stream.h" |
| 43 #include "net/http/http_network_session.h" | 43 #include "net/http/http_network_session.h" |
| 44 #include "net/http/http_network_session_peer.h" | 44 #include "net/http/http_network_session_peer.h" |
| 45 #include "net/http/http_server_properties_impl.h" | 45 #include "net/http/http_server_properties_impl.h" |
| 46 #include "net/http/http_stream.h" | 46 #include "net/http/http_stream.h" |
| 47 #include "net/http/http_stream_factory.h" | 47 #include "net/http/http_stream_factory.h" |
| 48 #include "net/http/http_stream_factory_test_util.h" | |
| 48 #include "net/http/http_transaction_unittest.h" | 49 #include "net/http/http_transaction_unittest.h" |
| 49 #include "net/proxy/proxy_config_service_fixed.h" | 50 #include "net/proxy/proxy_config_service_fixed.h" |
| 50 #include "net/proxy/proxy_info.h" | 51 #include "net/proxy/proxy_info.h" |
| 51 #include "net/proxy/proxy_resolver.h" | 52 #include "net/proxy/proxy_resolver.h" |
| 52 #include "net/proxy/proxy_service.h" | 53 #include "net/proxy/proxy_service.h" |
| 53 #include "net/socket/client_socket_factory.h" | 54 #include "net/socket/client_socket_factory.h" |
| 54 #include "net/socket/client_socket_pool_manager.h" | 55 #include "net/socket/client_socket_pool_manager.h" |
| 55 #include "net/socket/mock_client_socket_pool_manager.h" | 56 #include "net/socket/mock_client_socket_pool_manager.h" |
| 56 #include "net/socket/next_proto.h" | 57 #include "net/socket/next_proto.h" |
| 57 #include "net/socket/socket_test_util.h" | 58 #include "net/socket/socket_test_util.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 "\r\n\r\n"; | 277 "\r\n\r\n"; |
| 277 } | 278 } |
| 278 | 279 |
| 279 // Either |write_failure| specifies a write failure or |read_failure| | 280 // Either |write_failure| specifies a write failure or |read_failure| |
| 280 // specifies a read failure when using a reused socket. In either case, the | 281 // specifies a read failure when using a reused socket. In either case, the |
| 281 // failure should cause the network transaction to resend the request, and the | 282 // failure should cause the network transaction to resend the request, and the |
| 282 // other argument should be NULL. | 283 // other argument should be NULL. |
| 283 void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, | 284 void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 284 const MockRead* read_failure); | 285 const MockRead* read_failure); |
| 285 | 286 |
| 287 // Either |write_failure| specifies a write failure or |read_failure| | |
| 288 // specifies a read failure when using a reused socket. In either case, the | |
| 289 // failure should cause the network transaction to resend the request, and the | |
| 290 // other argument should be NULL. | |
| 291 void PreconnectMissResendRequestTest(const MockWrite* write_failure, | |
| 292 const MockRead* read_failure); | |
| 293 | |
| 286 SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], | 294 SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 287 size_t data_count) { | 295 size_t data_count) { |
| 288 SimpleGetHelperResult out; | 296 SimpleGetHelperResult out; |
| 289 | 297 |
| 290 HttpRequestInfo request; | 298 HttpRequestInfo request; |
| 291 request.method = "GET"; | 299 request.method = "GET"; |
| 292 request.url = GURL("http://www.google.com/"); | 300 request.url = GURL("http://www.google.com/"); |
| 293 request.load_flags = 0; | 301 request.load_flags = 0; |
| 294 | 302 |
| 295 CapturingBoundNetLog log; | 303 CapturingBoundNetLog log; |
| (...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1291 EXPECT_TRUE(response->headers.get() != NULL); | 1299 EXPECT_TRUE(response->headers.get() != NULL); |
| 1292 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 1300 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1293 | 1301 |
| 1294 std::string response_data; | 1302 std::string response_data; |
| 1295 rv = ReadTransaction(trans.get(), &response_data); | 1303 rv = ReadTransaction(trans.get(), &response_data); |
| 1296 EXPECT_EQ(OK, rv); | 1304 EXPECT_EQ(OK, rv); |
| 1297 EXPECT_EQ(kExpectedResponseData[i], response_data); | 1305 EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 1298 } | 1306 } |
| 1299 } | 1307 } |
| 1300 | 1308 |
| 1309 void HttpNetworkTransactionTest::PreconnectMissResendRequestTest( | |
|
mmenke
2014/03/14 16:38:06
Not sure if "PreconnectMiss" is quite the right na
davidben
2014/03/14 18:35:03
Done.
| |
| 1310 const MockWrite* write_failure, | |
| 1311 const MockRead* read_failure) { | |
| 1312 HttpRequestInfo request; | |
| 1313 request.method = "GET"; | |
| 1314 request.url = GURL("http://www.foo.com/"); | |
| 1315 request.load_flags = 0; | |
| 1316 | |
| 1317 CapturingNetLog net_log; | |
| 1318 session_deps_.net_log = &net_log; | |
| 1319 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
| 1320 | |
| 1321 // Swap out the HttpStreamFactory. | |
| 1322 HttpNetworkSessionPeer peer(session.get()); | |
| 1323 MockHttpStreamFactoryImplForPreconnect* mock_factory = | |
| 1324 new MockHttpStreamFactoryImplForPreconnect(session.get(), false); | |
| 1325 peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(mock_factory)); | |
| 1326 | |
| 1327 // Written data for successfully sending a request. | |
| 1328 MockWrite data1_writes[] = { | |
| 1329 MockWrite("GET / HTTP/1.1\r\n" | |
| 1330 "Host: www.foo.com\r\n" | |
| 1331 "Connection: keep-alive\r\n\r\n"), | |
| 1332 }; | |
| 1333 | |
| 1334 // Read results for the first request. | |
| 1335 MockRead data1_reads[] = { | |
| 1336 MockRead(ASYNC, OK), | |
| 1337 }; | |
| 1338 | |
| 1339 if (write_failure) { | |
| 1340 ASSERT_TRUE(!read_failure); | |
|
mmenke
2014/03/14 16:38:06
Hrm...ASSERT_FALSE? Guess this was just copied fr
davidben
2014/03/14 18:35:03
Eh. Flipped both of them.
| |
| 1341 data1_writes[0] = *write_failure; | |
| 1342 } else { | |
| 1343 ASSERT_TRUE(read_failure); | |
| 1344 data1_reads[0] = *read_failure; | |
| 1345 } | |
| 1346 | |
| 1347 StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), | |
| 1348 data1_writes, arraysize(data1_writes)); | |
| 1349 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
| 1350 | |
| 1351 MockRead data2_reads[] = { | |
| 1352 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | |
| 1353 MockRead("hello"), | |
| 1354 MockRead(ASYNC, OK), | |
| 1355 }; | |
| 1356 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); | |
| 1357 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
| 1358 | |
| 1359 // Preconnect a socket. | |
| 1360 net::SSLConfig ssl_config; | |
| 1361 session->ssl_config_service()->GetSSLConfig(&ssl_config); | |
| 1362 if (session->http_stream_factory()->has_next_protos()) | |
| 1363 ssl_config.next_protos = session->http_stream_factory()->next_protos(); | |
| 1364 session->http_stream_factory()->PreconnectStreams( | |
| 1365 1, request, DEFAULT_PRIORITY, ssl_config, ssl_config); | |
| 1366 mock_factory->WaitForPreconnects(); | |
| 1367 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); | |
| 1368 | |
| 1369 // Make the request. | |
| 1370 TestCompletionCallback callback; | |
| 1371 | |
| 1372 scoped_ptr<HttpTransaction> trans( | |
| 1373 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
| 1374 | |
| 1375 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
| 1376 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 1377 | |
| 1378 rv = callback.WaitForResult(); | |
| 1379 EXPECT_EQ(OK, rv); | |
| 1380 | |
| 1381 LoadTimingInfo load_timing_info; | |
| 1382 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | |
| 1383 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | |
| 1384 | |
| 1385 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
| 1386 ASSERT_TRUE(response != NULL); | |
| 1387 | |
| 1388 EXPECT_TRUE(response->headers.get() != NULL); | |
| 1389 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
| 1390 | |
| 1391 std::string response_data; | |
| 1392 rv = ReadTransaction(trans.get(), &response_data); | |
| 1393 EXPECT_EQ(OK, rv); | |
| 1394 EXPECT_EQ("hello", response_data); | |
| 1395 } | |
| 1396 | |
| 1301 TEST_P(HttpNetworkTransactionTest, | 1397 TEST_P(HttpNetworkTransactionTest, |
| 1302 KeepAliveConnectionNotConnectedOnWrite) { | 1398 KeepAliveConnectionNotConnectedOnWrite) { |
| 1303 MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); | 1399 MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1304 KeepAliveConnectionResendRequestTest(&write_failure, NULL); | 1400 KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1305 } | 1401 } |
| 1306 | 1402 |
| 1307 TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { | 1403 TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
| 1308 MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); | 1404 MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1309 KeepAliveConnectionResendRequestTest(NULL, &read_failure); | 1405 KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1310 } | 1406 } |
| 1311 | 1407 |
| 1312 TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { | 1408 TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
| 1313 MockRead read_failure(SYNCHRONOUS, OK); // EOF | 1409 MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1314 KeepAliveConnectionResendRequestTest(NULL, &read_failure); | 1410 KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1315 } | 1411 } |
| 1316 | 1412 |
| 1413 TEST_P(HttpNetworkTransactionTest, | |
| 1414 PreconnectMissNotConnectedOnWrite) { | |
| 1415 MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); | |
| 1416 PreconnectMissResendRequestTest(&write_failure, NULL); | |
| 1417 } | |
| 1418 | |
| 1419 TEST_P(HttpNetworkTransactionTest, PreconnectMissReset) { | |
| 1420 MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); | |
| 1421 PreconnectMissResendRequestTest(NULL, &read_failure); | |
| 1422 } | |
| 1423 | |
| 1424 TEST_P(HttpNetworkTransactionTest, PreconnectMissEOF) { | |
| 1425 MockRead read_failure(SYNCHRONOUS, OK); // EOF | |
| 1426 PreconnectMissResendRequestTest(NULL, &read_failure); | |
| 1427 } | |
| 1428 | |
| 1317 TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { | 1429 TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
| 1318 HttpRequestInfo request; | 1430 HttpRequestInfo request; |
| 1319 request.method = "GET"; | 1431 request.method = "GET"; |
| 1320 request.url = GURL("http://www.google.com/"); | 1432 request.url = GURL("http://www.google.com/"); |
| 1321 request.load_flags = 0; | 1433 request.load_flags = 0; |
| 1322 | 1434 |
| 1323 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 1435 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1324 scoped_ptr<HttpTransaction> trans( | 1436 scoped_ptr<HttpTransaction> trans( |
| 1325 new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); | 1437 new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
| 1326 | 1438 |
| (...skipping 11108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12435 // established, to let the HTTP request start. | 12547 // established, to let the HTTP request start. |
| 12436 ASSERT_EQ(OK, http_callback.WaitForResult()); | 12548 ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 12437 std::string response_data; | 12549 std::string response_data; |
| 12438 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); | 12550 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 12439 EXPECT_EQ("falafel", response_data); | 12551 EXPECT_EQ("falafel", response_data); |
| 12440 | 12552 |
| 12441 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); | 12553 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); |
| 12442 } | 12554 } |
| 12443 | 12555 |
| 12444 } // namespace net | 12556 } // namespace net |
| OLD | NEW |