OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_stream_factory_impl_job_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <string> |
| 8 #include <utility> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
12 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
13 #include "base/test/scoped_feature_list.h" | 14 #include "base/test/scoped_feature_list.h" |
14 #include "base/test/scoped_mock_time_message_loop_task_runner.h" | 15 #include "base/test/scoped_mock_time_message_loop_task_runner.h" |
15 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
16 #include "net/base/test_proxy_delegate.h" | 17 #include "net/base/test_proxy_delegate.h" |
17 #include "net/dns/mock_host_resolver.h" | 18 #include "net/dns/mock_host_resolver.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 enable_ip_based_pooling_ = false; | 151 enable_ip_based_pooling_ = false; |
151 } | 152 } |
152 | 153 |
153 void DisableAlternativeServices() { | 154 void DisableAlternativeServices() { |
154 ASSERT_FALSE(test_proxy_delegate_); | 155 ASSERT_FALSE(test_proxy_delegate_); |
155 enable_alternative_services_ = false; | 156 enable_alternative_services_ = false; |
156 } | 157 } |
157 | 158 |
158 void Initialize(const HttpRequestInfo& request_info) { | 159 void Initialize(const HttpRequestInfo& request_info) { |
159 ASSERT_FALSE(test_proxy_delegate_); | 160 ASSERT_FALSE(test_proxy_delegate_); |
160 std::unique_ptr<TestProxyDelegate> test_proxy_delegate( | 161 auto test_proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
161 new TestProxyDelegate()); | |
162 test_proxy_delegate_ = test_proxy_delegate.get(); | 162 test_proxy_delegate_ = test_proxy_delegate.get(); |
163 | 163 |
164 test_proxy_delegate->set_alternative_proxy_server( | 164 test_proxy_delegate->set_alternative_proxy_server( |
165 ProxyServer::FromPacString("QUIC myproxy.org:443")); | 165 ProxyServer::FromPacString("QUIC myproxy.org:443")); |
166 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); | 166 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); |
167 session_deps_.proxy_delegate = std::move(test_proxy_delegate); | 167 session_deps_.proxy_delegate = std::move(test_proxy_delegate); |
168 | 168 |
169 if (use_alternative_proxy_) { | 169 if (use_alternative_proxy_) { |
170 std::unique_ptr<ProxyService> proxy_service = | 170 std::unique_ptr<ProxyService> proxy_service = |
171 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); | 171 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 1097 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
1098 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); | 1098 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); |
1099 EXPECT_FALSE(test_task_runner->HasPendingTask()); | 1099 EXPECT_FALSE(test_task_runner->HasPendingTask()); |
1100 EXPECT_FALSE(job_controller_->alternative_job()); | 1100 EXPECT_FALSE(job_controller_->alternative_job()); |
1101 } | 1101 } |
1102 | 1102 |
1103 // Verifies that the alternative proxy server job is not created if the URL | 1103 // Verifies that the alternative proxy server job is not created if the URL |
1104 // scheme is HTTPS. | 1104 // scheme is HTTPS. |
1105 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) { | 1105 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) { |
1106 // Using hanging resolver will cause the alternative job to hang indefinitely. | 1106 // Using hanging resolver will cause the alternative job to hang indefinitely. |
1107 HangingResolver* resolver = new HangingResolver(); | 1107 session_deps_.host_resolver = base::MakeUnique<HangingResolver>(); |
1108 session_deps_.host_resolver.reset(resolver); | |
1109 | 1108 |
1110 HttpRequestInfo request_info; | 1109 HttpRequestInfo request_info; |
1111 request_info.method = "GET"; | 1110 request_info.method = "GET"; |
1112 request_info.url = GURL("https://mail.example.org/"); | 1111 request_info.url = GURL("https://mail.example.org/"); |
1113 Initialize(request_info); | 1112 Initialize(request_info); |
1114 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 1113 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
1115 | 1114 |
1116 request_.reset( | 1115 request_.reset( |
1117 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1116 job_controller_->Start(request_info, &request_delegate_, nullptr, |
1118 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1117 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
1119 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 1118 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
1120 EXPECT_TRUE(job_controller_->main_job()); | 1119 EXPECT_TRUE(job_controller_->main_job()); |
1121 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | 1120 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
1122 EXPECT_FALSE(job_controller_->alternative_job()); | 1121 EXPECT_FALSE(job_controller_->alternative_job()); |
1123 | 1122 |
1124 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 1123 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
1125 base::RunLoop().RunUntilIdle(); | 1124 base::RunLoop().RunUntilIdle(); |
1126 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); | 1125 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
1127 } | 1126 } |
1128 | 1127 |
1129 // Verifies that the alternative proxy server job is not created if the main job | 1128 // Verifies that the alternative proxy server job is not created if the main job |
1130 // does not fetch the resource through a proxy. | 1129 // does not fetch the resource through a proxy. |
1131 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { | 1130 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { |
1132 // Using hanging resolver will cause the alternative job to hang indefinitely. | 1131 // Using hanging resolver will cause the alternative job to hang indefinitely. |
1133 HangingResolver* resolver = new HangingResolver(); | 1132 session_deps_.host_resolver = base::MakeUnique<HangingResolver>(); |
1134 session_deps_.host_resolver.reset(resolver); | |
1135 | 1133 |
1136 HttpRequestInfo request_info; | 1134 HttpRequestInfo request_info; |
1137 request_info.method = "GET"; | 1135 request_info.method = "GET"; |
1138 request_info.url = GURL("http://mail.example.org/"); | 1136 request_info.url = GURL("http://mail.example.org/"); |
1139 | 1137 |
1140 Initialize(request_info); | 1138 Initialize(request_info); |
1141 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 1139 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
1142 | 1140 |
1143 request_.reset( | 1141 request_.reset( |
1144 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1142 job_controller_->Start(request_info, &request_delegate_, nullptr, |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 Preconnect(kNumPreconects); | 1474 Preconnect(kNumPreconects); |
1477 // If experiment is enabled, only 1 stream is requested. | 1475 // If experiment is enabled, only 1 stream is requested. |
1478 EXPECT_EQ( | 1476 EXPECT_EQ( |
1479 (int)actual_num_connects, | 1477 (int)actual_num_connects, |
1480 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); | 1478 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); |
1481 base::RunLoop().RunUntilIdle(); | 1479 base::RunLoop().RunUntilIdle(); |
1482 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1480 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
1483 } | 1481 } |
1484 | 1482 |
1485 } // namespace net | 1483 } // namespace net |
OLD | NEW |