Chromium Code Reviews| Index: net/http/http_network_transaction_unittest.cc |
| diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc |
| index 1ec6f3f5d434b0516b1c48fe3586ad9c1d03403d..2ba0a363e02a2ebd0c74ca6887d91fc5a91b9da3 100644 |
| --- a/net/http/http_network_transaction_unittest.cc |
| +++ b/net/http/http_network_transaction_unittest.cc |
| @@ -6412,6 +6412,149 @@ TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
| EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| } |
| +// Grab an SSL socket, use it, and put it back into the pool. Then, make |
| +// low memory notification and ensure the socket pool is flushed. |
| +TEST_P(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
| + HttpRequestInfo request; |
| + request.method = "GET"; |
| + request.url = GURL("https://www.example.org/"); |
| + request.load_flags = 0; |
| + |
| + MockWrite data_writes[] = { |
| + MockWrite("GET / HTTP/1.1\r\n" |
| + "Host: www.example.org\r\n" |
| + "Connection: keep-alive\r\n\r\n"), |
| + }; |
| + |
| + MockRead data_reads[] = { |
| + MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| + MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| + |
| + SSLSocketDataProvider ssl(ASYNC, OK); |
| + session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| + |
| + StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| + arraysize(data_writes)); |
| + session_deps_.socket_factory->AddSocketDataProvider(&data); |
| + |
| + TestCompletionCallback callback; |
| + |
| + std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| + std::unique_ptr<HttpTransaction> trans( |
| + new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| + |
| + 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.
|
| + int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| + |
| + // Make memory critical notification and ensure the transaction still has been |
| + // operating right. |
| + base::MemoryPressureListener::NotifyMemoryPressure( |
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| + 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.
|
| + |
| + const HttpResponseInfo* response = trans->GetResponseInfo(); |
| + ASSERT_TRUE(response); |
| + ASSERT_TRUE(response->headers); |
| + EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| + |
| + 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.
|
| + |
| + std::string response_data; |
| + rv = ReadTransaction(trans.get(), &response_data); |
| + EXPECT_THAT(rv, IsOk()); |
| + EXPECT_EQ("hello world", response_data); |
| + |
| + // Empty the current queue. This is necessary because idle sockets are |
| + // added to the connection pool asynchronously with a PostTask. |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // We now check to make sure the socket was added back to the pool. |
| + EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| + |
| + // Make memory notification once again and ensure idle socket is closed. |
| + base::MemoryPressureListener::NotifyMemoryPressure( |
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| +} |
| + |
| +// Grab a socket, use it, and put it back into the pool. Then, make |
| +// low memory notification and ensure the socket pool is flushed. |
| +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.
|
| + HttpRequestInfo request; |
| + request.method = "GET"; |
| + request.url = GURL("http://www.example.org/"); |
| + request.load_flags = 0; |
| + |
| + std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| + |
| + std::unique_ptr<HttpTransaction> trans( |
| + new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| + |
| + MockRead data_reads[] = { |
| + // A part of the response body is received with the response headers. |
| + MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| + // The rest of the response body is received in two parts. |
| + MockRead("lo"), MockRead(" world"), |
| + MockRead("junk"), // Should not be read!! |
| + MockRead(SYNCHRONOUS, OK), |
| + }; |
| + |
| + StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| + session_deps_.socket_factory->AddSocketDataProvider(&data); |
| + |
| + TestCompletionCallback callback; |
| + |
| + int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| + EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| + |
| + // Make memory critical notification and ensure the transaction still has been |
| + // operating right. |
| + base::MemoryPressureListener::NotifyMemoryPressure( |
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + rv = callback.WaitForResult(); |
| + EXPECT_THAT(rv, IsOk()); |
| + |
| + const HttpResponseInfo* response = trans->GetResponseInfo(); |
| + ASSERT_TRUE(response); |
| + |
| + EXPECT_TRUE(response->headers); |
| + std::string status_line = response->headers->GetStatusLine(); |
| + EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| + |
| + EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| + |
| + // Make memory critical notification and ensure the transaction still has been |
| + // operating right. |
| + base::MemoryPressureListener::NotifyMemoryPressure( |
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + std::string response_data; |
| + rv = ReadTransaction(trans.get(), &response_data); |
| + EXPECT_THAT(rv, IsOk()); |
| + EXPECT_EQ("hello world", response_data); |
| + |
| + // Empty the current queue. This is necessary because idle sockets are |
| + // added to the connection pool asynchronously with a PostTask. |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // We now check to make sure the socket was added back to the pool. |
| + EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| + |
| + // Idle sockets should be flushed now. |
| + base::MemoryPressureListener::NotifyMemoryPressure( |
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| + base::RunLoop().RunUntilIdle(); |
| + EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| +} |
| + |
| // Make sure that we recycle a socket after a zero-length response. |
| // http://crbug.com/9880 |
| TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |