Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 1006643002: Plumb connection attempts from (non-proxy) ConnectJobs to HttpNetworkTransaction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, resolve conflict Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/http_stream_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "net/log/net_log.h" 54 #include "net/log/net_log.h"
55 #include "net/log/net_log_unittest.h" 55 #include "net/log/net_log_unittest.h"
56 #include "net/log/test_net_log.h" 56 #include "net/log/test_net_log.h"
57 #include "net/proxy/mock_proxy_resolver.h" 57 #include "net/proxy/mock_proxy_resolver.h"
58 #include "net/proxy/proxy_config_service_fixed.h" 58 #include "net/proxy/proxy_config_service_fixed.h"
59 #include "net/proxy/proxy_info.h" 59 #include "net/proxy/proxy_info.h"
60 #include "net/proxy/proxy_resolver.h" 60 #include "net/proxy/proxy_resolver.h"
61 #include "net/proxy/proxy_service.h" 61 #include "net/proxy/proxy_service.h"
62 #include "net/socket/client_socket_factory.h" 62 #include "net/socket/client_socket_factory.h"
63 #include "net/socket/client_socket_pool_manager.h" 63 #include "net/socket/client_socket_pool_manager.h"
64 #include "net/socket/connection_attempts.h"
64 #include "net/socket/mock_client_socket_pool_manager.h" 65 #include "net/socket/mock_client_socket_pool_manager.h"
65 #include "net/socket/next_proto.h" 66 #include "net/socket/next_proto.h"
66 #include "net/socket/socket_test_util.h" 67 #include "net/socket/socket_test_util.h"
67 #include "net/socket/ssl_client_socket.h" 68 #include "net/socket/ssl_client_socket.h"
68 #include "net/spdy/spdy_framer.h" 69 #include "net/spdy/spdy_framer.h"
69 #include "net/spdy/spdy_session.h" 70 #include "net/spdy/spdy_session.h"
70 #include "net/spdy/spdy_session_pool.h" 71 #include "net/spdy/spdy_session_pool.h"
71 #include "net/spdy/spdy_test_util_common.h" 72 #include "net/spdy/spdy_test_util_common.h"
72 #include "net/ssl/ssl_cert_request_info.h" 73 #include "net/ssl/ssl_cert_request_info.h"
73 #include "net/ssl/ssl_config_service.h" 74 #include "net/ssl/ssl_config_service.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( 256 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool(
256 HttpNetworkSession::NORMAL_SOCKET_POOL)) { 257 HttpNetworkSession::NORMAL_SOCKET_POOL)) {
257 } 258 }
258 259
259 struct SimpleGetHelperResult { 260 struct SimpleGetHelperResult {
260 int rv; 261 int rv;
261 std::string status_line; 262 std::string status_line;
262 std::string response_data; 263 std::string response_data;
263 int64 totalReceivedBytes; 264 int64 totalReceivedBytes;
264 LoadTimingInfo load_timing_info; 265 LoadTimingInfo load_timing_info;
266 ConnectionAttempts connection_attempts;
265 }; 267 };
266 268
267 void SetUp() override { 269 void SetUp() override {
268 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 270 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
269 base::MessageLoop::current()->RunUntilIdle(); 271 base::MessageLoop::current()->RunUntilIdle();
270 } 272 }
271 273
272 void TearDown() override { 274 void TearDown() override {
273 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 275 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
274 base::MessageLoop::current()->RunUntilIdle(); 276 base::MessageLoop::current()->RunUntilIdle();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 EXPECT_EQ("www.example.org", value); 378 EXPECT_EQ("www.example.org", value);
377 EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); 379 EXPECT_TRUE(request_headers.GetHeader("Connection", &value));
378 EXPECT_EQ("keep-alive", value); 380 EXPECT_EQ("keep-alive", value);
379 381
380 std::string response_headers; 382 std::string response_headers;
381 EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); 383 EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers));
382 EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", 384 EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']",
383 response_headers); 385 response_headers);
384 386
385 out.totalReceivedBytes = trans->GetTotalReceivedBytes(); 387 out.totalReceivedBytes = trans->GetTotalReceivedBytes();
388 trans->GetConnectionAttempts(&out.connection_attempts);
386 return out; 389 return out;
387 } 390 }
388 391
389 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], 392 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[],
390 size_t reads_count) { 393 size_t reads_count) {
391 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); 394 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0);
392 StaticSocketDataProvider* data[] = { &reads }; 395 StaticSocketDataProvider* data[] = { &reads };
393 return SimpleGetHelperForData(data, 1); 396 return SimpleGetHelperForData(data, 1);
394 } 397 }
395 398
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 MockRead("hello world"), 663 MockRead("hello world"),
661 MockRead(SYNCHRONOUS, OK), 664 MockRead(SYNCHRONOUS, OK),
662 }; 665 };
663 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 666 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
664 arraysize(data_reads)); 667 arraysize(data_reads));
665 EXPECT_EQ(OK, out.rv); 668 EXPECT_EQ(OK, out.rv);
666 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); 669 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
667 EXPECT_EQ("hello world", out.response_data); 670 EXPECT_EQ("hello world", out.response_data);
668 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); 671 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
669 EXPECT_EQ(reads_size, out.totalReceivedBytes); 672 EXPECT_EQ(reads_size, out.totalReceivedBytes);
673 EXPECT_EQ(0u, out.connection_attempts.size());
670 } 674 }
671 675
672 // Response with no status line. 676 // Response with no status line.
673 TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { 677 TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) {
674 MockRead data_reads[] = { 678 MockRead data_reads[] = {
675 MockRead("hello world"), 679 MockRead("hello world"),
676 MockRead(SYNCHRONOUS, OK), 680 MockRead(SYNCHRONOUS, OK),
677 }; 681 };
678 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 682 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
679 arraysize(data_reads)); 683 arraysize(data_reads));
(...skipping 11666 matching lines...) Expand 10 before | Expand all | Expand 10 after
12346 EXPECT_EQ(ERR_IO_PENDING, rv); 12350 EXPECT_EQ(ERR_IO_PENDING, rv);
12347 12351
12348 rv = callback.WaitForResult(); 12352 rv = callback.WaitForResult();
12349 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); 12353 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv);
12350 12354
12351 EXPECT_EQ(NULL, trans->GetResponseInfo()); 12355 EXPECT_EQ(NULL, trans->GetResponseInfo());
12352 12356
12353 // We don't care whether this succeeds or fails, but it shouldn't crash. 12357 // We don't care whether this succeeds or fails, but it shouldn't crash.
12354 HttpRequestHeaders request_headers; 12358 HttpRequestHeaders request_headers;
12355 trans->GetFullRequestHeaders(&request_headers); 12359 trans->GetFullRequestHeaders(&request_headers);
12360
12361 ConnectionAttempts attempts;
12362 trans->GetConnectionAttempts(&attempts);
12363 ASSERT_EQ(1u, attempts.size());
12364 EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result);
12356 } 12365 }
12357 12366
12358 TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { 12367 TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) {
12359 HttpRequestInfo request; 12368 HttpRequestInfo request;
12360 request.method = "GET"; 12369 request.method = "GET";
12361 request.url = GURL("http://www.example.org/"); 12370 request.url = GURL("http://www.example.org/");
12362 request.load_flags = 0; 12371 request.load_flags = 0;
12363 12372
12364 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 12373 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12365 scoped_ptr<HttpTransaction> trans( 12374 scoped_ptr<HttpTransaction> trans(
(...skipping 10 matching lines...) Expand all
12376 EXPECT_EQ(ERR_IO_PENDING, rv); 12385 EXPECT_EQ(ERR_IO_PENDING, rv);
12377 12386
12378 rv = callback.WaitForResult(); 12387 rv = callback.WaitForResult();
12379 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); 12388 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv);
12380 12389
12381 EXPECT_EQ(NULL, trans->GetResponseInfo()); 12390 EXPECT_EQ(NULL, trans->GetResponseInfo());
12382 12391
12383 // We don't care whether this succeeds or fails, but it shouldn't crash. 12392 // We don't care whether this succeeds or fails, but it shouldn't crash.
12384 HttpRequestHeaders request_headers; 12393 HttpRequestHeaders request_headers;
12385 trans->GetFullRequestHeaders(&request_headers); 12394 trans->GetFullRequestHeaders(&request_headers);
12395
12396 ConnectionAttempts attempts;
12397 trans->GetConnectionAttempts(&attempts);
12398 ASSERT_EQ(1u, attempts.size());
12399 EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result);
12386 } 12400 }
12387 12401
12388 TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { 12402 TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) {
12389 HttpRequestInfo request; 12403 HttpRequestInfo request;
12390 request.method = "GET"; 12404 request.method = "GET";
12391 request.url = GURL("http://www.example.org/"); 12405 request.url = GURL("http://www.example.org/");
12392 request.load_flags = 0; 12406 request.load_flags = 0;
12393 12407
12394 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 12408 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12395 scoped_ptr<HttpTransaction> trans( 12409 scoped_ptr<HttpTransaction> trans(
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
12721 } 12735 }
12722 12736
12723 void SetPriority(RequestPriority priority) override { priority_ = priority; } 12737 void SetPriority(RequestPriority priority) override { priority_ = priority; }
12724 12738
12725 bool was_npn_negotiated() const override { return false; } 12739 bool was_npn_negotiated() const override { return false; }
12726 12740
12727 NextProto protocol_negotiated() const override { return kProtoUnknown; } 12741 NextProto protocol_negotiated() const override { return kProtoUnknown; }
12728 12742
12729 bool using_spdy() const override { return false; } 12743 bool using_spdy() const override { return false; }
12730 12744
12745 const ConnectionAttempts& connection_attempts() const override {
12746 static ConnectionAttempts no_attempts;
12747 return no_attempts;
12748 }
12749
12731 private: 12750 private:
12732 RequestPriority priority_; 12751 RequestPriority priority_;
12733 HttpStreamRequest::Delegate* const delegate_; 12752 HttpStreamRequest::Delegate* const delegate_;
12734 WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; 12753 WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_;
12735 12754
12736 DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); 12755 DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest);
12737 }; 12756 };
12738 12757
12739 // Fake HttpStreamFactory that vends FakeStreamRequests. 12758 // Fake HttpStreamFactory that vends FakeStreamRequests.
12740 class FakeStreamFactory : public HttpStreamFactory { 12759 class FakeStreamFactory : public HttpStreamFactory {
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
13869 ASSERT_TRUE(response); 13888 ASSERT_TRUE(response);
13870 ASSERT_TRUE(response->headers.get()); 13889 ASSERT_TRUE(response->headers.get());
13871 13890
13872 EXPECT_EQ(101, response->headers->response_code()); 13891 EXPECT_EQ(101, response->headers->response_code());
13873 13892
13874 trans.reset(); 13893 trans.reset();
13875 session->CloseAllConnections(); 13894 session->CloseAllConnections();
13876 } 13895 }
13877 13896
13878 } // namespace net 13897 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/http_stream_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698