| 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 658dc7d69ab38736232b242408daa663d62b5009..54a768c14583c66d459c64f87db92c5f29bcbdf6 100644
|
| --- a/net/http/http_network_transaction_unittest.cc
|
| +++ b/net/http/http_network_transaction_unittest.cc
|
| @@ -6296,6 +6296,142 @@ TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) {
|
| EXPECT_EQ(1, 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) {
|
| + 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));
|
| +
|
| + EXPECT_THAT(callback.GetResult(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);
|
| +
|
| + // 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();
|
| +
|
| + // Socket should not be flushed as long as it is not idle.
|
| + EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
|
| +
|
| + 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()));
|
| +}
|
| +
|
| +// 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, GetIdleSocketCountInSSLSocketPool(session.get()));
|
| + int rv = trans->Start(&request, callback.callback(), BoundNetLog());
|
| +
|
| + EXPECT_THAT(callback.GetResult(rv), IsOk());
|
| +
|
| + const HttpResponseInfo* response = trans->GetResponseInfo();
|
| + ASSERT_TRUE(response);
|
| + ASSERT_TRUE(response->headers);
|
| + EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
|
| +
|
| + // 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_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get()));
|
| +
|
| + 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()));
|
| +}
|
| +
|
| // Make sure that we recycle a socket after a zero-length response.
|
| // http://crbug.com/9880
|
| TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) {
|
|
|