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 <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 6394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6405 EXPECT_EQ("hello world", response_data); | 6405 EXPECT_EQ("hello world", response_data); |
| 6406 | 6406 |
| 6407 // Empty the current queue. This is necessary because idle sockets are | 6407 // Empty the current queue. This is necessary because idle sockets are |
| 6408 // added to the connection pool asynchronously with a PostTask. | 6408 // added to the connection pool asynchronously with a PostTask. |
| 6409 base::RunLoop().RunUntilIdle(); | 6409 base::RunLoop().RunUntilIdle(); |
| 6410 | 6410 |
| 6411 // We now check to make sure the socket was added back to the pool. | 6411 // We now check to make sure the socket was added back to the pool. |
| 6412 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); | 6412 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6413 } | 6413 } |
| 6414 | 6414 |
| 6415 // Grab an SSL socket, use it, and put it back into the pool. Then, make | |
| 6416 // low memory notification and ensure the socket pool is flushed. | |
| 6417 TEST_P(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { | |
| 6418 HttpRequestInfo request; | |
| 6419 request.method = "GET"; | |
| 6420 request.url = GURL("https://www.example.org/"); | |
| 6421 request.load_flags = 0; | |
| 6422 | |
| 6423 MockWrite data_writes[] = { | |
| 6424 MockWrite("GET / HTTP/1.1\r\n" | |
| 6425 "Host: www.example.org\r\n" | |
| 6426 "Connection: keep-alive\r\n\r\n"), | |
| 6427 }; | |
| 6428 | |
| 6429 MockRead data_reads[] = { | |
| 6430 MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), | |
| 6431 MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; | |
| 6432 | |
| 6433 SSLSocketDataProvider ssl(ASYNC, OK); | |
| 6434 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
| 6435 | |
| 6436 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, | |
| 6437 arraysize(data_writes)); | |
| 6438 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 6439 | |
| 6440 TestCompletionCallback callback; | |
| 6441 | |
| 6442 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
| 6443 std::unique_ptr<HttpTransaction> trans( | |
| 6444 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
| 6445 | |
| 6446 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
|
mmenke
2016/07/12 18:03:17
Should be checking the SSL socket pool, not the tr
maksims (do not use this acc)
2016/07/13 07:45:53
Done.
| |
| 6447 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
| 6448 | |
| 6449 // Make memory critical notification and ensure the transaction still has been | |
| 6450 // operating right. | |
| 6451 base::MemoryPressureListener::NotifyMemoryPressure( | |
| 6452 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | |
| 6453 base::RunLoop().RunUntilIdle(); | |
| 6454 | |
| 6455 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | |
| 6456 EXPECT_THAT(callback.WaitForResult(), IsOk()); | |
|
mmenke
2016/07/12 18:03:17
It seems weird to have these lines below the memor
maksims (do not use this acc)
2016/07/13 07:45:53
Done.
| |
| 6457 | |
| 6458 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
| 6459 ASSERT_TRUE(response); | |
| 6460 ASSERT_TRUE(response->headers); | |
| 6461 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
| 6462 | |
| 6463 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
|
mmenke
2016/07/12 18:03:17
GetIdleSocketCountInSSLSocketPool
maksims (do not use this acc)
2016/07/13 07:45:53
Done.
| |
| 6464 | |
| 6465 std::string response_data; | |
| 6466 rv = ReadTransaction(trans.get(), &response_data); | |
| 6467 EXPECT_THAT(rv, IsOk()); | |
| 6468 EXPECT_EQ("hello world", response_data); | |
| 6469 | |
| 6470 // Empty the current queue. This is necessary because idle sockets are | |
| 6471 // added to the connection pool asynchronously with a PostTask. | |
| 6472 base::RunLoop().RunUntilIdle(); | |
| 6473 | |
| 6474 // We now check to make sure the socket was added back to the pool. | |
| 6475 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); | |
| 6476 | |
| 6477 // Make memory notification once again and ensure idle socket is closed. | |
| 6478 base::MemoryPressureListener::NotifyMemoryPressure( | |
| 6479 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | |
| 6480 base::RunLoop().RunUntilIdle(); | |
| 6481 | |
| 6482 EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); | |
| 6483 } | |
| 6484 | |
| 6485 // Grab a socket, use it, and put it back into the pool. Then, make | |
| 6486 // low memory notification and ensure the socket pool is flushed. | |
| 6487 TEST_P(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { | |
|
mmenke
2016/07/12 18:03:17
This is the more basic test, so should be before t
maksims (do not use this acc)
2016/07/13 07:45:53
Done.
| |
| 6488 HttpRequestInfo request; | |
| 6489 request.method = "GET"; | |
| 6490 request.url = GURL("http://www.example.org/"); | |
| 6491 request.load_flags = 0; | |
| 6492 | |
| 6493 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | |
| 6494 | |
| 6495 std::unique_ptr<HttpTransaction> trans( | |
| 6496 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
| 6497 | |
| 6498 MockRead data_reads[] = { | |
| 6499 // A part of the response body is received with the response headers. | |
| 6500 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), | |
| 6501 // The rest of the response body is received in two parts. | |
| 6502 MockRead("lo"), MockRead(" world"), | |
| 6503 MockRead("junk"), // Should not be read!! | |
| 6504 MockRead(SYNCHRONOUS, OK), | |
| 6505 }; | |
| 6506 | |
| 6507 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | |
| 6508 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 6509 | |
| 6510 TestCompletionCallback callback; | |
| 6511 | |
| 6512 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
| 6513 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | |
| 6514 | |
| 6515 // Make memory critical notification and ensure the transaction still has been | |
| 6516 // operating right. | |
| 6517 base::MemoryPressureListener::NotifyMemoryPressure( | |
| 6518 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | |
| 6519 base::RunLoop().RunUntilIdle(); | |
| 6520 | |
| 6521 rv = callback.WaitForResult(); | |
| 6522 EXPECT_THAT(rv, IsOk()); | |
| 6523 | |
| 6524 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
| 6525 ASSERT_TRUE(response); | |
| 6526 | |
| 6527 EXPECT_TRUE(response->headers); | |
| 6528 std::string status_line = response->headers->GetStatusLine(); | |
| 6529 EXPECT_EQ("HTTP/1.1 200 OK", status_line); | |
| 6530 | |
| 6531 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
| 6532 | |
| 6533 // Make memory critical notification and ensure the transaction still has been | |
| 6534 // operating right. | |
| 6535 base::MemoryPressureListener::NotifyMemoryPressure( | |
| 6536 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | |
| 6537 base::RunLoop().RunUntilIdle(); | |
| 6538 | |
| 6539 std::string response_data; | |
| 6540 rv = ReadTransaction(trans.get(), &response_data); | |
| 6541 EXPECT_THAT(rv, IsOk()); | |
| 6542 EXPECT_EQ("hello world", response_data); | |
| 6543 | |
| 6544 // Empty the current queue. This is necessary because idle sockets are | |
| 6545 // added to the connection pool asynchronously with a PostTask. | |
| 6546 base::RunLoop().RunUntilIdle(); | |
| 6547 | |
| 6548 // We now check to make sure the socket was added back to the pool. | |
| 6549 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); | |
| 6550 | |
| 6551 // Idle sockets should be flushed now. | |
| 6552 base::MemoryPressureListener::NotifyMemoryPressure( | |
| 6553 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | |
| 6554 base::RunLoop().RunUntilIdle(); | |
| 6555 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); | |
| 6556 } | |
| 6557 | |
| 6415 // Make sure that we recycle a socket after a zero-length response. | 6558 // Make sure that we recycle a socket after a zero-length response. |
| 6416 // http://crbug.com/9880 | 6559 // http://crbug.com/9880 |
| 6417 TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { | 6560 TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
| 6418 HttpRequestInfo request; | 6561 HttpRequestInfo request; |
| 6419 request.method = "GET"; | 6562 request.method = "GET"; |
| 6420 request.url = GURL( | 6563 request.url = GURL( |
| 6421 "http://www.example.org/csi?v=3&s=web&action=&" | 6564 "http://www.example.org/csi?v=3&s=web&action=&" |
| 6422 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" | 6565 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6423 "e=17259,18167,19592,19773,19981,20133,20173,20233&" | 6566 "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6424 "rt=prt.2642,ol.2649,xjs.2951"); | 6567 "rt=prt.2642,ol.2649,xjs.2951"); |
| (...skipping 9458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15883 base::RunLoop().RunUntilIdle(); | 16026 base::RunLoop().RunUntilIdle(); |
| 15884 | 16027 |
| 15885 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16028 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 15886 HttpRequestHeaders headers; | 16029 HttpRequestHeaders headers; |
| 15887 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16030 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 15888 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16031 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 15889 } | 16032 } |
| 15890 #endif // !defined(OS_IOS) | 16033 #endif // !defined(OS_IOS) |
| 15891 | 16034 |
| 15892 } // namespace net | 16035 } // namespace net |
| OLD | NEW |