OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "net/base/address_list.h" | 11 #include "net/base/address_list.h" |
12 #include "net/base/host_cache.h" | 12 #include "net/base/host_cache.h" |
13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
14 #include "net/base/mock_host_resolver.h" | 14 #include "net/base/mock_host_resolver.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
17 #include "net/base/request_priority.h" | 17 #include "net/base/request_priority.h" |
18 #include "net/base/ssl_config_service_defaults.h" | 18 #include "net/base/ssl_config_service_defaults.h" |
19 #include "net/http/http_auth_handler_mock.h" | 19 #include "net/http/http_auth_handler_mock.h" |
20 #include "net/http/http_network_session.h" | 20 #include "net/http/http_network_session.h" |
21 #include "net/http/http_network_transaction.h" | 21 #include "net/http/http_network_transaction.h" |
22 #include "net/http/http_request_info.h" | 22 #include "net/http/http_request_info.h" |
23 #include "net/http/http_server_properties_impl.h" | 23 #include "net/http/http_server_properties_impl.h" |
24 #include "net/proxy/proxy_config_service.h" | 24 #include "net/proxy/proxy_config_service.h" |
25 #include "net/proxy/proxy_service.h" | 25 #include "net/proxy/proxy_service.h" |
26 #include "net/socket/client_socket_handle.h" | 26 #include "net/socket/client_socket_handle.h" |
27 #include "net/socket/client_socket_pool_histograms.h" | 27 #include "net/socket/client_socket_pool_histograms.h" |
| 28 #include "net/socket/client_socket_pool_manager.h" |
28 #include "net/socket/socket_test_util.h" | 29 #include "net/socket/socket_test_util.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 | 32 |
32 using testing::StrEq; | 33 using testing::StrEq; |
33 | 34 |
34 namespace net { | 35 namespace net { |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), | 273 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"), |
273 MockRead(SYNCHRONOUS, 6, "Content-Length: 8\r\n\r\n"), | 274 MockRead(SYNCHRONOUS, 6, "Content-Length: 8\r\n\r\n"), |
274 MockRead(SYNCHRONOUS, 7, "two.html"), | 275 MockRead(SYNCHRONOUS, 7, "two.html"), |
275 }; | 276 }; |
276 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); | 277 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
277 | 278 |
278 CompleteTwoRequests(0, 5); | 279 CompleteTwoRequests(0, 5); |
279 } | 280 } |
280 | 281 |
281 TEST_F(HttpPipelinedNetworkTransactionTest, ReusesOnSpaceAvailable) { | 282 TEST_F(HttpPipelinedNetworkTransactionTest, ReusesOnSpaceAvailable) { |
282 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group(); | 283 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group( |
283 ClientSocketPoolManager::set_max_sockets_per_group(1); | 284 HttpNetworkSession::NORMAL_SOCKET_POOL); |
| 285 ClientSocketPoolManager::set_max_sockets_per_group( |
| 286 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
284 Initialize(false); | 287 Initialize(false); |
285 | 288 |
286 MockWrite writes[] = { | 289 MockWrite writes[] = { |
287 MockWrite(SYNCHRONOUS, 0, "GET /one.html HTTP/1.1\r\n" | 290 MockWrite(SYNCHRONOUS, 0, "GET /one.html HTTP/1.1\r\n" |
288 "Host: localhost\r\n" | 291 "Host: localhost\r\n" |
289 "Connection: keep-alive\r\n\r\n"), | 292 "Connection: keep-alive\r\n\r\n"), |
290 MockWrite(SYNCHRONOUS, 4, "GET /two.html HTTP/1.1\r\n" | 293 MockWrite(SYNCHRONOUS, 4, "GET /two.html HTTP/1.1\r\n" |
291 "Host: localhost\r\n" | 294 "Host: localhost\r\n" |
292 "Connection: keep-alive\r\n\r\n"), | 295 "Connection: keep-alive\r\n\r\n"), |
293 MockWrite(SYNCHRONOUS, 7, "GET /three.html HTTP/1.1\r\n" | 296 MockWrite(SYNCHRONOUS, 7, "GET /three.html HTTP/1.1\r\n" |
(...skipping 14 matching lines...) Expand all Loading... |
308 MockRead(SYNCHRONOUS, 10, "Content-Length: 10\r\n\r\n"), | 311 MockRead(SYNCHRONOUS, 10, "Content-Length: 10\r\n\r\n"), |
309 MockRead(SYNCHRONOUS, 11, "three.html"), | 312 MockRead(SYNCHRONOUS, 11, "three.html"), |
310 MockRead(SYNCHRONOUS, 13, "HTTP/1.1 200 OK\r\n"), | 313 MockRead(SYNCHRONOUS, 13, "HTTP/1.1 200 OK\r\n"), |
311 MockRead(SYNCHRONOUS, 14, "Content-Length: 9\r\n\r\n"), | 314 MockRead(SYNCHRONOUS, 14, "Content-Length: 9\r\n\r\n"), |
312 MockRead(SYNCHRONOUS, 15, "four.html"), | 315 MockRead(SYNCHRONOUS, 15, "four.html"), |
313 }; | 316 }; |
314 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); | 317 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
315 | 318 |
316 CompleteFourRequests(); | 319 CompleteFourRequests(); |
317 | 320 |
318 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets); | 321 ClientSocketPoolManager::set_max_sockets_per_group( |
| 322 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_sockets); |
319 } | 323 } |
320 | 324 |
321 TEST_F(HttpPipelinedNetworkTransactionTest, UnknownSizeEvictsToNewPipeline) { | 325 TEST_F(HttpPipelinedNetworkTransactionTest, UnknownSizeEvictsToNewPipeline) { |
322 Initialize(false); | 326 Initialize(false); |
323 | 327 |
324 MockWrite writes[] = { | 328 MockWrite writes[] = { |
325 MockWrite(SYNCHRONOUS, 0, "GET /one.html HTTP/1.1\r\n" | 329 MockWrite(SYNCHRONOUS, 0, "GET /one.html HTTP/1.1\r\n" |
326 "Host: localhost\r\n" | 330 "Host: localhost\r\n" |
327 "Connection: keep-alive\r\n\r\n"), | 331 "Connection: keep-alive\r\n\r\n"), |
328 }; | 332 }; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 ExpectResponse("pipelined.html", one_transaction, SYNCHRONOUS); | 614 ExpectResponse("pipelined.html", one_transaction, SYNCHRONOUS); |
611 | 615 |
612 CompleteTwoRequests(1, 4); | 616 CompleteTwoRequests(1, 4); |
613 } | 617 } |
614 | 618 |
615 TEST_F(HttpPipelinedNetworkTransactionTest, PipelinesImmediatelyIfKnownGood) { | 619 TEST_F(HttpPipelinedNetworkTransactionTest, PipelinesImmediatelyIfKnownGood) { |
616 // The first request gets us an HTTP/1.1. The next 3 test pipelining. When the | 620 // The first request gets us an HTTP/1.1. The next 3 test pipelining. When the |
617 // 3rd request completes, we know pipelining is safe. After the first 4 | 621 // 3rd request completes, we know pipelining is safe. After the first 4 |
618 // complete, the 5th and 6th should then be immediately sent pipelined on a | 622 // complete, the 5th and 6th should then be immediately sent pipelined on a |
619 // new HttpPipelinedConnection. | 623 // new HttpPipelinedConnection. |
620 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group(); | 624 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group( |
621 ClientSocketPoolManager::set_max_sockets_per_group(1); | 625 HttpNetworkSession::NORMAL_SOCKET_POOL); |
| 626 ClientSocketPoolManager::set_max_sockets_per_group( |
| 627 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
622 Initialize(false); | 628 Initialize(false); |
623 | 629 |
624 MockWrite writes[] = { | 630 MockWrite writes[] = { |
625 MockWrite(SYNCHRONOUS, 0, "GET /one.html HTTP/1.1\r\n" | 631 MockWrite(SYNCHRONOUS, 0, "GET /one.html HTTP/1.1\r\n" |
626 "Host: localhost\r\n" | 632 "Host: localhost\r\n" |
627 "Connection: keep-alive\r\n\r\n"), | 633 "Connection: keep-alive\r\n\r\n"), |
628 MockWrite(SYNCHRONOUS, 4, "GET /two.html HTTP/1.1\r\n" | 634 MockWrite(SYNCHRONOUS, 4, "GET /two.html HTTP/1.1\r\n" |
629 "Host: localhost\r\n" | 635 "Host: localhost\r\n" |
630 "Connection: keep-alive\r\n\r\n"), | 636 "Connection: keep-alive\r\n\r\n"), |
631 MockWrite(SYNCHRONOUS, 7, "GET /three.html HTTP/1.1\r\n" | 637 MockWrite(SYNCHRONOUS, 7, "GET /three.html HTTP/1.1\r\n" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 | 688 |
683 data_vector_[0]->RunFor(3); | 689 data_vector_[0]->RunFor(3); |
684 EXPECT_EQ(OK, second_one_callback.WaitForResult()); | 690 EXPECT_EQ(OK, second_one_callback.WaitForResult()); |
685 data_vector_[0]->StopAfter(100); | 691 data_vector_[0]->StopAfter(100); |
686 ExpectResponse("second-pipeline-one.html", second_one_transaction, | 692 ExpectResponse("second-pipeline-one.html", second_one_transaction, |
687 SYNCHRONOUS); | 693 SYNCHRONOUS); |
688 EXPECT_EQ(OK, second_two_callback.WaitForResult()); | 694 EXPECT_EQ(OK, second_two_callback.WaitForResult()); |
689 ExpectResponse("second-pipeline-two.html", second_two_transaction, | 695 ExpectResponse("second-pipeline-two.html", second_two_transaction, |
690 SYNCHRONOUS); | 696 SYNCHRONOUS); |
691 | 697 |
692 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets); | 698 ClientSocketPoolManager::set_max_sockets_per_group( |
| 699 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_sockets); |
693 } | 700 } |
694 | 701 |
695 class DataRunnerObserver : public MessageLoop::TaskObserver { | 702 class DataRunnerObserver : public MessageLoop::TaskObserver { |
696 public: | 703 public: |
697 DataRunnerObserver(DeterministicSocketData* data, int run_before_task) | 704 DataRunnerObserver(DeterministicSocketData* data, int run_before_task) |
698 : data_(data), | 705 : data_(data), |
699 run_before_task_(run_before_task), | 706 run_before_task_(run_before_task), |
700 current_task_(0) { } | 707 current_task_(0) { } |
701 | 708 |
702 virtual void WillProcessTask(base::TimeTicks) OVERRIDE { | 709 virtual void WillProcessTask(base::TimeTicks) OVERRIDE { |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 EXPECT_EQ(ERR_PIPELINE_EVICTION, two_callback.WaitForResult()); | 982 EXPECT_EQ(ERR_PIPELINE_EVICTION, two_callback.WaitForResult()); |
976 two_transaction.reset(); | 983 two_transaction.reset(); |
977 EXPECT_EQ(ERR_PIPELINE_EVICTION, three_callback.WaitForResult()); | 984 EXPECT_EQ(ERR_PIPELINE_EVICTION, three_callback.WaitForResult()); |
978 three_transaction.reset(); | 985 three_transaction.reset(); |
979 EXPECT_EQ(ERR_PIPELINE_EVICTION, four_callback.WaitForResult()); | 986 EXPECT_EQ(ERR_PIPELINE_EVICTION, four_callback.WaitForResult()); |
980 } | 987 } |
981 | 988 |
982 } // anonymous namespace | 989 } // anonymous namespace |
983 | 990 |
984 } // namespace net | 991 } // namespace net |
OLD | NEW |