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/proxy_resolver_mojo.h" | 5 #include "net/proxy/proxy_resolver_mojo.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <map> | 8 #include <map> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "mojo/common/common_type_converters.h" | 17 #include "mojo/common/common_type_converters.h" |
| 18 #include "net/base/load_states.h" |
18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
19 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
20 #include "net/log/net_log.h" | 21 #include "net/log/net_log.h" |
21 #include "net/proxy/mojo_proxy_resolver_factory.h" | 22 #include "net/proxy/mojo_proxy_resolver_factory.h" |
22 #include "net/proxy/mojo_proxy_type_converters.h" | 23 #include "net/proxy/mojo_proxy_type_converters.h" |
23 #include "net/proxy/proxy_info.h" | 24 #include "net/proxy/proxy_info.h" |
| 25 #include "net/proxy/proxy_resolver.h" |
| 26 #include "net/proxy/proxy_resolver_error_observer.h" |
24 #include "net/proxy/proxy_resolver_script_data.h" | 27 #include "net/proxy/proxy_resolver_script_data.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 29 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
27 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" | 30 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" |
28 #include "url/gurl.h" | 31 #include "url/gurl.h" |
29 | 32 |
30 namespace net { | 33 namespace net { |
31 | 34 |
32 namespace { | 35 namespace { |
33 | 36 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 void WaitForNextRequest(); | 312 void WaitForNextRequest(); |
310 | 313 |
311 void ClearBlockedClients(); | 314 void ClearBlockedClients(); |
312 | 315 |
313 private: | 316 private: |
314 // Overridden from interfaces::ProxyResolver: | 317 // Overridden from interfaces::ProxyResolver: |
315 void CreateResolver( | 318 void CreateResolver( |
316 const mojo::String& pac_url, | 319 const mojo::String& pac_url, |
317 mojo::InterfaceRequest<interfaces::ProxyResolver> request, | 320 mojo::InterfaceRequest<interfaces::ProxyResolver> request, |
318 interfaces::HostResolverPtr host_resolver, | 321 interfaces::HostResolverPtr host_resolver, |
| 322 interfaces::ProxyResolverErrorObserverPtr error_observer, |
319 interfaces::ProxyResolverFactoryRequestClientPtr client) override; | 323 interfaces::ProxyResolverFactoryRequestClientPtr client) override; |
320 | 324 |
321 void WakeWaiter(); | 325 void WakeWaiter(); |
322 | 326 |
323 MockMojoProxyResolver* resolver_; | 327 MockMojoProxyResolver* resolver_; |
324 std::queue<CreateProxyResolverAction> create_resolver_actions_; | 328 std::queue<CreateProxyResolverAction> create_resolver_actions_; |
325 | 329 |
326 base::Closure quit_closure_; | 330 base::Closure quit_closure_; |
327 | 331 |
328 ScopedVector<interfaces::ProxyResolverFactoryRequestClientPtr> | 332 ScopedVector<interfaces::ProxyResolverFactoryRequestClientPtr> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 } | 365 } |
362 | 366 |
363 void MockMojoProxyResolverFactory::ClearBlockedClients() { | 367 void MockMojoProxyResolverFactory::ClearBlockedClients() { |
364 blocked_clients_.clear(); | 368 blocked_clients_.clear(); |
365 } | 369 } |
366 | 370 |
367 void MockMojoProxyResolverFactory::CreateResolver( | 371 void MockMojoProxyResolverFactory::CreateResolver( |
368 const mojo::String& pac_script, | 372 const mojo::String& pac_script, |
369 mojo::InterfaceRequest<interfaces::ProxyResolver> request, | 373 mojo::InterfaceRequest<interfaces::ProxyResolver> request, |
370 interfaces::HostResolverPtr host_resolver, | 374 interfaces::HostResolverPtr host_resolver, |
| 375 interfaces::ProxyResolverErrorObserverPtr error_observer, |
371 interfaces::ProxyResolverFactoryRequestClientPtr client) { | 376 interfaces::ProxyResolverFactoryRequestClientPtr client) { |
372 ASSERT_FALSE(create_resolver_actions_.empty()); | 377 ASSERT_FALSE(create_resolver_actions_.empty()); |
373 CreateProxyResolverAction action = create_resolver_actions_.front(); | 378 CreateProxyResolverAction action = create_resolver_actions_.front(); |
374 create_resolver_actions_.pop(); | 379 create_resolver_actions_.pop(); |
375 | 380 |
376 EXPECT_EQ(action.expected_pac_script, pac_script.To<std::string>()); | 381 EXPECT_EQ(action.expected_pac_script, pac_script.To<std::string>()); |
377 switch (action.action) { | 382 switch (action.action) { |
378 case CreateProxyResolverAction::COMPLETE: | 383 case CreateProxyResolverAction::COMPLETE: |
379 if (action.error == OK) | 384 if (action.error == OK) |
380 resolver_->AddConnection(request.Pass()); | 385 resolver_->AddConnection(request.Pass()); |
(...skipping 21 matching lines...) Expand all Loading... |
402 } | 407 } |
403 | 408 |
404 } // namespace | 409 } // namespace |
405 | 410 |
406 class ProxyResolverMojoTest : public testing::Test, | 411 class ProxyResolverMojoTest : public testing::Test, |
407 public MojoProxyResolverFactory { | 412 public MojoProxyResolverFactory { |
408 public: | 413 public: |
409 void SetUp() override { | 414 void SetUp() override { |
410 mock_proxy_resolver_factory_.reset(new MockMojoProxyResolverFactory( | 415 mock_proxy_resolver_factory_.reset(new MockMojoProxyResolverFactory( |
411 &mock_proxy_resolver_, mojo::GetProxy(&factory_ptr_))); | 416 &mock_proxy_resolver_, mojo::GetProxy(&factory_ptr_))); |
412 proxy_resolver_factory_mojo_.reset( | 417 proxy_resolver_factory_mojo_.reset(new ProxyResolverFactoryMojo( |
413 new ProxyResolverFactoryMojo(this, nullptr)); | 418 this, nullptr, |
| 419 base::Callback<scoped_ptr<ProxyResolverErrorObserver>()>())); |
414 } | 420 } |
415 | 421 |
416 scoped_ptr<Request> MakeRequest(const GURL& url) { | 422 scoped_ptr<Request> MakeRequest(const GURL& url) { |
417 return make_scoped_ptr(new Request(proxy_resolver_mojo_.get(), url)); | 423 return make_scoped_ptr(new Request(proxy_resolver_mojo_.get(), url)); |
418 } | 424 } |
419 | 425 |
420 scoped_ptr<base::ScopedClosureRunner> CreateResolver( | 426 scoped_ptr<base::ScopedClosureRunner> CreateResolver( |
421 const mojo::String& pac_script, | 427 const mojo::String& pac_script, |
422 mojo::InterfaceRequest<interfaces::ProxyResolver> req, | 428 mojo::InterfaceRequest<interfaces::ProxyResolver> req, |
423 interfaces::HostResolverPtr host_resolver, | 429 interfaces::HostResolverPtr host_resolver, |
| 430 interfaces::ProxyResolverErrorObserverPtr error_observer, |
424 interfaces::ProxyResolverFactoryRequestClientPtr client) override { | 431 interfaces::ProxyResolverFactoryRequestClientPtr client) override { |
425 factory_ptr_->CreateResolver(pac_script, req.Pass(), host_resolver.Pass(), | 432 factory_ptr_->CreateResolver(pac_script, req.Pass(), host_resolver.Pass(), |
426 client.Pass()); | 433 error_observer.Pass(), client.Pass()); |
427 return make_scoped_ptr( | 434 return make_scoped_ptr( |
428 new base::ScopedClosureRunner(on_delete_callback_.closure())); | 435 new base::ScopedClosureRunner(on_delete_callback_.closure())); |
429 } | 436 } |
430 | 437 |
431 mojo::Array<interfaces::ProxyServerPtr> ProxyServersFromPacString( | 438 mojo::Array<interfaces::ProxyServerPtr> ProxyServersFromPacString( |
432 const std::string& pac_string) { | 439 const std::string& pac_string) { |
433 ProxyInfo proxy_info; | 440 ProxyInfo proxy_info; |
434 proxy_info.UsePacString(pac_string); | 441 proxy_info.UsePacString(pac_string); |
435 | 442 |
436 return mojo::Array<interfaces::ProxyServerPtr>::From( | 443 return mojo::Array<interfaces::ProxyServerPtr>::From( |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 &handle, net_log))); | 738 &handle, net_log))); |
732 on_delete_callback_.WaitForResult(); | 739 on_delete_callback_.WaitForResult(); |
733 } | 740 } |
734 | 741 |
735 TEST_F(ProxyResolverMojoTest, DeleteResolver) { | 742 TEST_F(ProxyResolverMojoTest, DeleteResolver) { |
736 CreateProxyResolver(); | 743 CreateProxyResolver(); |
737 proxy_resolver_mojo_.reset(); | 744 proxy_resolver_mojo_.reset(); |
738 on_delete_callback_.WaitForResult(); | 745 on_delete_callback_.WaitForResult(); |
739 } | 746 } |
740 } // namespace net | 747 } // namespace net |
OLD | NEW |