summaryrefslogtreecommitdiffstats
path: root/net/http/http_network_transaction_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/http/http_network_transaction_unittest.cc')
-rw-r--r--net/http/http_network_transaction_unittest.cc122
1 files changed, 93 insertions, 29 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 7dda13e..ca06785 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -289,7 +289,8 @@ class HttpNetworkTransactionTest
// failure should cause the network transaction to resend the request, and the
// other argument should be NULL.
void PreconnectErrorResendRequestTest(const MockWrite* write_failure,
- const MockRead* read_failure);
+ const MockRead* read_failure,
+ bool use_spdy);
SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[],
size_t data_count) {
@@ -1308,46 +1309,81 @@ void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest(
void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest(
const MockWrite* write_failure,
- const MockRead* read_failure) {
+ const MockRead* read_failure,
+ bool use_spdy) {
HttpRequestInfo request;
request.method = "GET";
- request.url = GURL("http://www.foo.com/");
+ request.url = GURL("https://www.foo.com/");
request.load_flags = 0;
CapturingNetLog net_log;
session_deps_.net_log = &net_log;
scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
- // Written data for successfully sending a request.
- MockWrite data1_writes[] = {
- MockWrite("GET / HTTP/1.1\r\n"
- "Host: www.foo.com\r\n"
- "Connection: keep-alive\r\n\r\n"),
- };
+ SSLSocketDataProvider ssl1(ASYNC, OK);
+ SSLSocketDataProvider ssl2(ASYNC, OK);
+ if (use_spdy) {
+ ssl1.SetNextProto(GetParam());
+ ssl2.SetNextProto(GetParam());
+ }
+ session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1);
+ session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
- // Read results for the first request.
- MockRead data1_reads[] = {
- MockRead(ASYNC, OK),
- };
+ // SPDY versions of the request and response.
+ scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet(
+ request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY));
+ scoped_ptr<SpdyFrame> spdy_response(
+ spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
+ scoped_ptr<SpdyFrame> spdy_data(
+ spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true));
+ // HTTP/1.1 versions of the request and response.
+ const char kHttpRequest[] = "GET / HTTP/1.1\r\n"
+ "Host: www.foo.com\r\n"
+ "Connection: keep-alive\r\n\r\n";
+ const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n";
+ const char kHttpData[] = "hello";
+
+ std::vector<MockRead> data1_reads;
+ std::vector<MockWrite> data1_writes;
if (write_failure) {
ASSERT_FALSE(read_failure);
- data1_writes[0] = *write_failure;
+ data1_writes.push_back(*write_failure);
+ data1_reads.push_back(MockRead(ASYNC, OK));
} else {
ASSERT_TRUE(read_failure);
- data1_reads[0] = *read_failure;
+ if (use_spdy) {
+ data1_writes.push_back(CreateMockWrite(*spdy_request));
+ } else {
+ data1_writes.push_back(MockWrite(kHttpRequest));
+ }
+ data1_reads.push_back(*read_failure);
}
- StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads),
- data1_writes, arraysize(data1_writes));
+ StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(),
+ &data1_writes[0], data1_writes.size());
session_deps_.socket_factory->AddSocketDataProvider(&data1);
- MockRead data2_reads[] = {
- MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
- MockRead("hello"),
- MockRead(ASYNC, OK),
- };
- StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0);
+ std::vector<MockRead> data2_reads;
+ std::vector<MockWrite> data2_writes;
+
+ if (use_spdy) {
+ data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC));
+
+ data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC));
+ data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC));
+ data2_reads.push_back(MockRead(ASYNC, OK, 3));
+ } else {
+ data2_writes.push_back(
+ MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0));
+
+ data2_reads.push_back(
+ MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1));
+ data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2));
+ data2_reads.push_back(MockRead(ASYNC, OK, 3));
+ }
+ OrderedSocketData data2(&data2_reads[0], data2_reads.size(),
+ &data2_writes[0], data2_writes.size());
session_deps_.socket_factory->AddSocketDataProvider(&data2);
// Preconnect a socket.
@@ -1360,7 +1396,7 @@ void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest(
// Wait for the preconnect to complete.
// TODO(davidben): Some way to wait for an idle socket count might be handy.
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
+ EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get()));
// Make the request.
TestCompletionCallback callback;
@@ -1376,7 +1412,9 @@ void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest(
LoadTimingInfo load_timing_info;
EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
- TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
+ TestLoadTimingNotReused(
+ load_timing_info,
+ CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES);
const HttpResponseInfo* response = trans->GetResponseInfo();
ASSERT_TRUE(response != NULL);
@@ -1387,7 +1425,7 @@ void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest(
std::string response_data;
rv = ReadTransaction(trans.get(), &response_data);
EXPECT_EQ(OK, rv);
- EXPECT_EQ("hello", response_data);
+ EXPECT_EQ(kHttpData, response_data);
}
TEST_P(HttpNetworkTransactionTest,
@@ -1409,17 +1447,43 @@ TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) {
TEST_P(HttpNetworkTransactionTest,
PreconnectErrorNotConnectedOnWrite) {
MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED);
- PreconnectErrorResendRequestTest(&write_failure, NULL);
+ PreconnectErrorResendRequestTest(&write_failure, NULL, false);
}
TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) {
MockRead read_failure(ASYNC, ERR_CONNECTION_RESET);
- PreconnectErrorResendRequestTest(NULL, &read_failure);
+ PreconnectErrorResendRequestTest(NULL, &read_failure, false);
}
TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) {
MockRead read_failure(SYNCHRONOUS, OK); // EOF
- PreconnectErrorResendRequestTest(NULL, &read_failure);
+ PreconnectErrorResendRequestTest(NULL, &read_failure, false);
+}
+
+TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) {
+ MockRead read_failure(ASYNC, OK); // EOF
+ PreconnectErrorResendRequestTest(NULL, &read_failure, false);
+}
+
+TEST_P(HttpNetworkTransactionTest,
+ SpdyPreconnectErrorNotConnectedOnWrite) {
+ MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED);
+ PreconnectErrorResendRequestTest(&write_failure, NULL, true);
+}
+
+TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) {
+ MockRead read_failure(ASYNC, ERR_CONNECTION_RESET);
+ PreconnectErrorResendRequestTest(NULL, &read_failure, true);
+}
+
+TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) {
+ MockRead read_failure(SYNCHRONOUS, OK); // EOF
+ PreconnectErrorResendRequestTest(NULL, &read_failure, true);
+}
+
+TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) {
+ MockRead read_failure(ASYNC, OK); // EOF
+ PreconnectErrorResendRequestTest(NULL, &read_failure, true);
}
TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {