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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include "net/log/net_log.h" | 53 #include "net/log/net_log.h" |
54 #include "net/log/net_log_unittest.h" | 54 #include "net/log/net_log_unittest.h" |
55 #include "net/log/test_net_log.h" | 55 #include "net/log/test_net_log.h" |
56 #include "net/proxy/mock_proxy_resolver.h" | 56 #include "net/proxy/mock_proxy_resolver.h" |
57 #include "net/proxy/proxy_config_service_fixed.h" | 57 #include "net/proxy/proxy_config_service_fixed.h" |
58 #include "net/proxy/proxy_info.h" | 58 #include "net/proxy/proxy_info.h" |
59 #include "net/proxy/proxy_resolver.h" | 59 #include "net/proxy/proxy_resolver.h" |
60 #include "net/proxy/proxy_service.h" | 60 #include "net/proxy/proxy_service.h" |
61 #include "net/socket/client_socket_factory.h" | 61 #include "net/socket/client_socket_factory.h" |
62 #include "net/socket/client_socket_pool_manager.h" | 62 #include "net/socket/client_socket_pool_manager.h" |
| 63 #include "net/socket/connection_attempts.h" |
63 #include "net/socket/mock_client_socket_pool_manager.h" | 64 #include "net/socket/mock_client_socket_pool_manager.h" |
64 #include "net/socket/next_proto.h" | 65 #include "net/socket/next_proto.h" |
65 #include "net/socket/socket_test_util.h" | 66 #include "net/socket/socket_test_util.h" |
66 #include "net/socket/ssl_client_socket.h" | 67 #include "net/socket/ssl_client_socket.h" |
67 #include "net/spdy/spdy_framer.h" | 68 #include "net/spdy/spdy_framer.h" |
68 #include "net/spdy/spdy_session.h" | 69 #include "net/spdy/spdy_session.h" |
69 #include "net/spdy/spdy_session_pool.h" | 70 #include "net/spdy/spdy_session_pool.h" |
70 #include "net/spdy/spdy_test_util_common.h" | 71 #include "net/spdy/spdy_test_util_common.h" |
71 #include "net/ssl/ssl_cert_request_info.h" | 72 #include "net/ssl/ssl_cert_request_info.h" |
72 #include "net/ssl/ssl_config_service.h" | 73 #include "net/ssl/ssl_config_service.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( | 255 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
255 HttpNetworkSession::NORMAL_SOCKET_POOL)) { | 256 HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
256 } | 257 } |
257 | 258 |
258 struct SimpleGetHelperResult { | 259 struct SimpleGetHelperResult { |
259 int rv; | 260 int rv; |
260 std::string status_line; | 261 std::string status_line; |
261 std::string response_data; | 262 std::string response_data; |
262 int64 totalReceivedBytes; | 263 int64 totalReceivedBytes; |
263 LoadTimingInfo load_timing_info; | 264 LoadTimingInfo load_timing_info; |
| 265 ConnectionAttempts connection_attempts; |
264 }; | 266 }; |
265 | 267 |
266 void SetUp() override { | 268 void SetUp() override { |
267 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 269 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
268 base::MessageLoop::current()->RunUntilIdle(); | 270 base::MessageLoop::current()->RunUntilIdle(); |
269 } | 271 } |
270 | 272 |
271 void TearDown() override { | 273 void TearDown() override { |
272 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 274 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
273 base::MessageLoop::current()->RunUntilIdle(); | 275 base::MessageLoop::current()->RunUntilIdle(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 EXPECT_EQ("www.example.org", value); | 377 EXPECT_EQ("www.example.org", value); |
376 EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); | 378 EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
377 EXPECT_EQ("keep-alive", value); | 379 EXPECT_EQ("keep-alive", value); |
378 | 380 |
379 std::string response_headers; | 381 std::string response_headers; |
380 EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); | 382 EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
381 EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", | 383 EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
382 response_headers); | 384 response_headers); |
383 | 385 |
384 out.totalReceivedBytes = trans->GetTotalReceivedBytes(); | 386 out.totalReceivedBytes = trans->GetTotalReceivedBytes(); |
| 387 trans->GetConnectionAttempts(&out.connection_attempts); |
385 return out; | 388 return out; |
386 } | 389 } |
387 | 390 |
388 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], | 391 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
389 size_t reads_count) { | 392 size_t reads_count) { |
390 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); | 393 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
391 StaticSocketDataProvider* data[] = { &reads }; | 394 StaticSocketDataProvider* data[] = { &reads }; |
392 return SimpleGetHelperForData(data, 1); | 395 return SimpleGetHelperForData(data, 1); |
393 } | 396 } |
394 | 397 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 MockRead("hello world"), | 662 MockRead("hello world"), |
660 MockRead(SYNCHRONOUS, OK), | 663 MockRead(SYNCHRONOUS, OK), |
661 }; | 664 }; |
662 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 665 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
663 arraysize(data_reads)); | 666 arraysize(data_reads)); |
664 EXPECT_EQ(OK, out.rv); | 667 EXPECT_EQ(OK, out.rv); |
665 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | 668 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
666 EXPECT_EQ("hello world", out.response_data); | 669 EXPECT_EQ("hello world", out.response_data); |
667 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 670 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
668 EXPECT_EQ(reads_size, out.totalReceivedBytes); | 671 EXPECT_EQ(reads_size, out.totalReceivedBytes); |
| 672 EXPECT_EQ(0u, out.connection_attempts.size()); |
669 } | 673 } |
670 | 674 |
671 // Response with no status line. | 675 // Response with no status line. |
672 TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { | 676 TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
673 MockRead data_reads[] = { | 677 MockRead data_reads[] = { |
674 MockRead("hello world"), | 678 MockRead("hello world"), |
675 MockRead(SYNCHRONOUS, OK), | 679 MockRead(SYNCHRONOUS, OK), |
676 }; | 680 }; |
677 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 681 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
678 arraysize(data_reads)); | 682 arraysize(data_reads)); |
(...skipping 11677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12356 EXPECT_EQ(ERR_IO_PENDING, rv); | 12360 EXPECT_EQ(ERR_IO_PENDING, rv); |
12357 | 12361 |
12358 rv = callback.WaitForResult(); | 12362 rv = callback.WaitForResult(); |
12359 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); | 12363 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
12360 | 12364 |
12361 EXPECT_EQ(NULL, trans->GetResponseInfo()); | 12365 EXPECT_EQ(NULL, trans->GetResponseInfo()); |
12362 | 12366 |
12363 // We don't care whether this succeeds or fails, but it shouldn't crash. | 12367 // We don't care whether this succeeds or fails, but it shouldn't crash. |
12364 HttpRequestHeaders request_headers; | 12368 HttpRequestHeaders request_headers; |
12365 trans->GetFullRequestHeaders(&request_headers); | 12369 trans->GetFullRequestHeaders(&request_headers); |
| 12370 |
| 12371 ConnectionAttempts attempts; |
| 12372 trans->GetConnectionAttempts(&attempts); |
| 12373 ASSERT_EQ(1u, attempts.size()); |
| 12374 EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
12366 } | 12375 } |
12367 | 12376 |
12368 TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { | 12377 TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
12369 HttpRequestInfo request; | 12378 HttpRequestInfo request; |
12370 request.method = "GET"; | 12379 request.method = "GET"; |
12371 request.url = GURL("http://www.example.org/"); | 12380 request.url = GURL("http://www.example.org/"); |
12372 request.load_flags = 0; | 12381 request.load_flags = 0; |
12373 | 12382 |
12374 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 12383 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
12375 scoped_ptr<HttpTransaction> trans( | 12384 scoped_ptr<HttpTransaction> trans( |
(...skipping 10 matching lines...) Expand all Loading... |
12386 EXPECT_EQ(ERR_IO_PENDING, rv); | 12395 EXPECT_EQ(ERR_IO_PENDING, rv); |
12387 | 12396 |
12388 rv = callback.WaitForResult(); | 12397 rv = callback.WaitForResult(); |
12389 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); | 12398 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
12390 | 12399 |
12391 EXPECT_EQ(NULL, trans->GetResponseInfo()); | 12400 EXPECT_EQ(NULL, trans->GetResponseInfo()); |
12392 | 12401 |
12393 // We don't care whether this succeeds or fails, but it shouldn't crash. | 12402 // We don't care whether this succeeds or fails, but it shouldn't crash. |
12394 HttpRequestHeaders request_headers; | 12403 HttpRequestHeaders request_headers; |
12395 trans->GetFullRequestHeaders(&request_headers); | 12404 trans->GetFullRequestHeaders(&request_headers); |
| 12405 |
| 12406 ConnectionAttempts attempts; |
| 12407 trans->GetConnectionAttempts(&attempts); |
| 12408 ASSERT_EQ(1u, attempts.size()); |
| 12409 EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
12396 } | 12410 } |
12397 | 12411 |
12398 TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { | 12412 TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
12399 HttpRequestInfo request; | 12413 HttpRequestInfo request; |
12400 request.method = "GET"; | 12414 request.method = "GET"; |
12401 request.url = GURL("http://www.example.org/"); | 12415 request.url = GURL("http://www.example.org/"); |
12402 request.load_flags = 0; | 12416 request.load_flags = 0; |
12403 | 12417 |
12404 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 12418 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
12405 scoped_ptr<HttpTransaction> trans( | 12419 scoped_ptr<HttpTransaction> trans( |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12731 } | 12745 } |
12732 | 12746 |
12733 void SetPriority(RequestPriority priority) override { priority_ = priority; } | 12747 void SetPriority(RequestPriority priority) override { priority_ = priority; } |
12734 | 12748 |
12735 bool was_npn_negotiated() const override { return false; } | 12749 bool was_npn_negotiated() const override { return false; } |
12736 | 12750 |
12737 NextProto protocol_negotiated() const override { return kProtoUnknown; } | 12751 NextProto protocol_negotiated() const override { return kProtoUnknown; } |
12738 | 12752 |
12739 bool using_spdy() const override { return false; } | 12753 bool using_spdy() const override { return false; } |
12740 | 12754 |
| 12755 const ConnectionAttempts& connection_attempts() const override { |
| 12756 static ConnectionAttempts no_attempts; |
| 12757 return no_attempts; |
| 12758 } |
| 12759 |
12741 private: | 12760 private: |
12742 RequestPriority priority_; | 12761 RequestPriority priority_; |
12743 HttpStreamRequest::Delegate* const delegate_; | 12762 HttpStreamRequest::Delegate* const delegate_; |
12744 WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; | 12763 WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
12745 | 12764 |
12746 DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); | 12765 DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
12747 }; | 12766 }; |
12748 | 12767 |
12749 // Fake HttpStreamFactory that vends FakeStreamRequests. | 12768 // Fake HttpStreamFactory that vends FakeStreamRequests. |
12750 class FakeStreamFactory : public HttpStreamFactory { | 12769 class FakeStreamFactory : public HttpStreamFactory { |
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13879 ASSERT_TRUE(response); | 13898 ASSERT_TRUE(response); |
13880 ASSERT_TRUE(response->headers.get()); | 13899 ASSERT_TRUE(response->headers.get()); |
13881 | 13900 |
13882 EXPECT_EQ(101, response->headers->response_code()); | 13901 EXPECT_EQ(101, response->headers->response_code()); |
13883 | 13902 |
13884 trans.reset(); | 13903 trans.reset(); |
13885 session->CloseAllConnections(); | 13904 session->CloseAllConnections(); |
13886 } | 13905 } |
13887 | 13906 |
13888 } // namespace net | 13907 } // namespace net |
OLD | NEW |