OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/proxy/mojo_proxy_resolver_impl.h" | 5 #include "net/proxy/mojo_proxy_resolver_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 MockProxyResolverV8Tracing* mock_proxy_resolver_; | 185 MockProxyResolverV8Tracing* mock_proxy_resolver_; |
186 | 186 |
187 std::unique_ptr<MojoProxyResolverImpl> resolver_impl_; | 187 std::unique_ptr<MojoProxyResolverImpl> resolver_impl_; |
188 interfaces::ProxyResolver* resolver_; | 188 interfaces::ProxyResolver* resolver_; |
189 }; | 189 }; |
190 | 190 |
191 TEST_F(MojoProxyResolverImplTest, GetProxyForUrl) { | 191 TEST_F(MojoProxyResolverImplTest, GetProxyForUrl) { |
192 interfaces::ProxyResolverRequestClientPtr client_ptr; | 192 interfaces::ProxyResolverRequestClientPtr client_ptr; |
193 TestRequestClient client(mojo::GetProxy(&client_ptr)); | 193 TestRequestClient client(mojo::GetProxy(&client_ptr)); |
194 | 194 |
195 resolver_->GetProxyForUrl("http://example.com", std::move(client_ptr)); | 195 resolver_->GetProxyForUrl(GURL("http://example.com"), std::move(client_ptr)); |
196 ASSERT_EQ(1u, mock_proxy_resolver_->pending_requests().size()); | 196 ASSERT_EQ(1u, mock_proxy_resolver_->pending_requests().size()); |
197 const MockProxyResolverV8Tracing::Request& request = | 197 const MockProxyResolverV8Tracing::Request& request = |
198 mock_proxy_resolver_->pending_requests()[0]; | 198 mock_proxy_resolver_->pending_requests()[0]; |
199 EXPECT_EQ(GURL("http://example.com"), request.url); | 199 EXPECT_EQ(GURL("http://example.com"), request.url); |
200 | 200 |
201 request.results->UsePacString( | 201 request.results->UsePacString( |
202 "PROXY proxy.example.com:1; " | 202 "PROXY proxy.example.com:1; " |
203 "SOCKS4 socks4.example.com:2; " | 203 "SOCKS4 socks4.example.com:2; " |
204 "SOCKS5 socks5.example.com:3; " | 204 "SOCKS5 socks5.example.com:3; " |
205 "HTTPS https.example.com:4; " | 205 "HTTPS https.example.com:4; " |
(...skipping 26 matching lines...) Expand all Loading... |
232 EXPECT_EQ("quic.example.com", servers[4].host_port_pair().host()); | 232 EXPECT_EQ("quic.example.com", servers[4].host_port_pair().host()); |
233 EXPECT_EQ(65000, servers[4].host_port_pair().port()); | 233 EXPECT_EQ(65000, servers[4].host_port_pair().port()); |
234 | 234 |
235 EXPECT_EQ(ProxyServer::SCHEME_DIRECT, servers[5].scheme()); | 235 EXPECT_EQ(ProxyServer::SCHEME_DIRECT, servers[5].scheme()); |
236 } | 236 } |
237 | 237 |
238 TEST_F(MojoProxyResolverImplTest, GetProxyForUrlFailure) { | 238 TEST_F(MojoProxyResolverImplTest, GetProxyForUrlFailure) { |
239 interfaces::ProxyResolverRequestClientPtr client_ptr; | 239 interfaces::ProxyResolverRequestClientPtr client_ptr; |
240 TestRequestClient client(mojo::GetProxy(&client_ptr)); | 240 TestRequestClient client(mojo::GetProxy(&client_ptr)); |
241 | 241 |
242 resolver_->GetProxyForUrl("http://example.com", std::move(client_ptr)); | 242 resolver_->GetProxyForUrl(GURL("http://example.com"), std::move(client_ptr)); |
243 ASSERT_EQ(1u, mock_proxy_resolver_->pending_requests().size()); | 243 ASSERT_EQ(1u, mock_proxy_resolver_->pending_requests().size()); |
244 const MockProxyResolverV8Tracing::Request& request = | 244 const MockProxyResolverV8Tracing::Request& request = |
245 mock_proxy_resolver_->pending_requests()[0]; | 245 mock_proxy_resolver_->pending_requests()[0]; |
246 EXPECT_EQ(GURL("http://example.com"), request.url); | 246 EXPECT_EQ(GURL("http://example.com"), request.url); |
247 request.callback.Run(ERR_FAILED); | 247 request.callback.Run(ERR_FAILED); |
248 client.WaitForResult(); | 248 client.WaitForResult(); |
249 | 249 |
250 EXPECT_EQ(ERR_FAILED, client.error()); | 250 EXPECT_EQ(ERR_FAILED, client.error()); |
251 std::vector<ProxyServer> proxy_servers = | 251 std::vector<ProxyServer> proxy_servers = |
252 client.results().To<std::vector<ProxyServer>>(); | 252 client.results().To<std::vector<ProxyServer>>(); |
253 EXPECT_TRUE(proxy_servers.empty()); | 253 EXPECT_TRUE(proxy_servers.empty()); |
254 } | 254 } |
255 | 255 |
256 TEST_F(MojoProxyResolverImplTest, GetProxyForUrlMultiple) { | 256 TEST_F(MojoProxyResolverImplTest, GetProxyForUrlMultiple) { |
257 interfaces::ProxyResolverRequestClientPtr client_ptr1; | 257 interfaces::ProxyResolverRequestClientPtr client_ptr1; |
258 TestRequestClient client1(mojo::GetProxy(&client_ptr1)); | 258 TestRequestClient client1(mojo::GetProxy(&client_ptr1)); |
259 interfaces::ProxyResolverRequestClientPtr client_ptr2; | 259 interfaces::ProxyResolverRequestClientPtr client_ptr2; |
260 TestRequestClient client2(mojo::GetProxy(&client_ptr2)); | 260 TestRequestClient client2(mojo::GetProxy(&client_ptr2)); |
261 | 261 |
262 resolver_->GetProxyForUrl("http://example.com", std::move(client_ptr1)); | 262 resolver_->GetProxyForUrl(GURL("http://example.com"), std::move(client_ptr1)); |
263 resolver_->GetProxyForUrl("https://example.com", std::move(client_ptr2)); | 263 resolver_->GetProxyForUrl(GURL("https://example.com"), |
| 264 std::move(client_ptr2)); |
264 ASSERT_EQ(2u, mock_proxy_resolver_->pending_requests().size()); | 265 ASSERT_EQ(2u, mock_proxy_resolver_->pending_requests().size()); |
265 const MockProxyResolverV8Tracing::Request& request1 = | 266 const MockProxyResolverV8Tracing::Request& request1 = |
266 mock_proxy_resolver_->pending_requests()[0]; | 267 mock_proxy_resolver_->pending_requests()[0]; |
267 EXPECT_EQ(GURL("http://example.com"), request1.url); | 268 EXPECT_EQ(GURL("http://example.com"), request1.url); |
268 const MockProxyResolverV8Tracing::Request& request2 = | 269 const MockProxyResolverV8Tracing::Request& request2 = |
269 mock_proxy_resolver_->pending_requests()[1]; | 270 mock_proxy_resolver_->pending_requests()[1]; |
270 EXPECT_EQ(GURL("https://example.com"), request2.url); | 271 EXPECT_EQ(GURL("https://example.com"), request2.url); |
271 request1.results->UsePacString("HTTPS proxy.example.com:12345"); | 272 request1.results->UsePacString("HTTPS proxy.example.com:12345"); |
272 request1.callback.Run(OK); | 273 request1.callback.Run(OK); |
273 request2.results->UsePacString("SOCKS5 another-proxy.example.com:6789"); | 274 request2.results->UsePacString("SOCKS5 another-proxy.example.com:6789"); |
(...skipping 18 matching lines...) Expand all Loading... |
292 EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, server2.scheme()); | 293 EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, server2.scheme()); |
293 EXPECT_EQ("another-proxy.example.com", server2.host_port_pair().host()); | 294 EXPECT_EQ("another-proxy.example.com", server2.host_port_pair().host()); |
294 EXPECT_EQ(6789, server2.host_port_pair().port()); | 295 EXPECT_EQ(6789, server2.host_port_pair().port()); |
295 } | 296 } |
296 | 297 |
297 TEST_F(MojoProxyResolverImplTest, DestroyClient) { | 298 TEST_F(MojoProxyResolverImplTest, DestroyClient) { |
298 interfaces::ProxyResolverRequestClientPtr client_ptr; | 299 interfaces::ProxyResolverRequestClientPtr client_ptr; |
299 std::unique_ptr<TestRequestClient> client( | 300 std::unique_ptr<TestRequestClient> client( |
300 new TestRequestClient(mojo::GetProxy(&client_ptr))); | 301 new TestRequestClient(mojo::GetProxy(&client_ptr))); |
301 | 302 |
302 resolver_->GetProxyForUrl("http://example.com", std::move(client_ptr)); | 303 resolver_->GetProxyForUrl(GURL("http://example.com"), std::move(client_ptr)); |
303 ASSERT_EQ(1u, mock_proxy_resolver_->pending_requests().size()); | 304 ASSERT_EQ(1u, mock_proxy_resolver_->pending_requests().size()); |
304 const MockProxyResolverV8Tracing::Request& request = | 305 const MockProxyResolverV8Tracing::Request& request = |
305 mock_proxy_resolver_->pending_requests()[0]; | 306 mock_proxy_resolver_->pending_requests()[0]; |
306 EXPECT_EQ(GURL("http://example.com"), request.url); | 307 EXPECT_EQ(GURL("http://example.com"), request.url); |
307 request.results->UsePacString("PROXY proxy.example.com:8080"); | 308 request.results->UsePacString("PROXY proxy.example.com:8080"); |
308 client.reset(); | 309 client.reset(); |
309 mock_proxy_resolver_->WaitForCancel(); | 310 mock_proxy_resolver_->WaitForCancel(); |
310 } | 311 } |
311 | 312 |
312 TEST_F(MojoProxyResolverImplTest, DestroyService) { | 313 TEST_F(MojoProxyResolverImplTest, DestroyService) { |
313 interfaces::ProxyResolverRequestClientPtr client_ptr; | 314 interfaces::ProxyResolverRequestClientPtr client_ptr; |
314 TestRequestClient client(mojo::GetProxy(&client_ptr)); | 315 TestRequestClient client(mojo::GetProxy(&client_ptr)); |
315 | 316 |
316 resolver_->GetProxyForUrl("http://example.com", std::move(client_ptr)); | 317 resolver_->GetProxyForUrl(GURL("http://example.com"), std::move(client_ptr)); |
317 ASSERT_EQ(1u, mock_proxy_resolver_->pending_requests().size()); | 318 ASSERT_EQ(1u, mock_proxy_resolver_->pending_requests().size()); |
318 resolver_impl_.reset(); | 319 resolver_impl_.reset(); |
319 client.event_waiter().WaitForEvent(TestRequestClient::CONNECTION_ERROR); | 320 client.event_waiter().WaitForEvent(TestRequestClient::CONNECTION_ERROR); |
320 } | 321 } |
321 | 322 |
322 } // namespace net | 323 } // namespace net |
OLD | NEW |