| 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/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 19 #include "net/base/net_log.h" | 19 #include "net/base/net_log.h" |
| 20 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
| 21 #include "net/dns/mock_host_resolver.h" | 21 #include "net/dns/mock_host_resolver.h" |
| 22 #include "net/proxy/mojo_proxy_resolver_factory.h" | 22 #include "net/proxy/mojo_proxy_resolver_factory.h" |
| 23 #include "net/proxy/mojo_proxy_type_converters.h" | 23 #include "net/proxy/mojo_proxy_type_converters.h" |
| 24 #include "net/proxy/proxy_info.h" | 24 #include "net/proxy/proxy_info.h" |
| 25 #include "net/proxy/proxy_resolver_error_observer.h" |
| 25 #include "net/proxy/proxy_resolver_script_data.h" | 26 #include "net/proxy/proxy_resolver_script_data.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 28 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
| 28 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" | 29 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" |
| 29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 30 | 31 |
| 31 namespace net { | 32 namespace net { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 WakeWaiter(); | 253 WakeWaiter(); |
| 253 } | 254 } |
| 254 | 255 |
| 255 class TestMojoProxyResolverFactory : public MojoProxyResolverFactory { | 256 class TestMojoProxyResolverFactory : public MojoProxyResolverFactory { |
| 256 public: | 257 public: |
| 257 TestMojoProxyResolverFactory(); | 258 TestMojoProxyResolverFactory(); |
| 258 ~TestMojoProxyResolverFactory() override; | 259 ~TestMojoProxyResolverFactory() override; |
| 259 | 260 |
| 260 // Overridden from MojoProxyResolverFactory: | 261 // Overridden from MojoProxyResolverFactory: |
| 261 void Create(mojo::InterfaceRequest<interfaces::ProxyResolver> req, | 262 void Create(mojo::InterfaceRequest<interfaces::ProxyResolver> req, |
| 262 interfaces::HostResolverPtr host_resolver) override; | 263 interfaces::HostResolverPtr host_resolver, |
| 264 interfaces::ProxyResolverErrorObserverPtr error_handler) override; |
| 263 | 265 |
| 264 MockMojoProxyResolver& GetMockResolver() { return *mock_proxy_resolver_; } | 266 MockMojoProxyResolver& GetMockResolver() { return *mock_proxy_resolver_; } |
| 265 | 267 |
| 266 void AddFuturePacScriptAction(int creation, SetPacScriptAction action); | 268 void AddFuturePacScriptAction(int creation, SetPacScriptAction action); |
| 267 void AddFutureGetProxyAction(int creation, GetProxyForUrlAction action); | 269 void AddFutureGetProxyAction(int creation, GetProxyForUrlAction action); |
| 268 | 270 |
| 269 int num_create_calls() const { return num_create_calls_; } | 271 int num_create_calls() const { return num_create_calls_; } |
| 270 void FailNextCreate() { fail_next_create_ = true; } | 272 void FailNextCreate() { fail_next_create_ = true; } |
| 271 | 273 |
| 272 private: | 274 private: |
| 273 int num_create_calls_; | 275 int num_create_calls_; |
| 274 std::map<int, std::list<SetPacScriptAction>> pac_script_actions_; | 276 std::map<int, std::list<SetPacScriptAction>> pac_script_actions_; |
| 275 std::map<int, std::list<GetProxyForUrlAction>> get_proxy_actions_; | 277 std::map<int, std::list<GetProxyForUrlAction>> get_proxy_actions_; |
| 276 bool fail_next_create_; | 278 bool fail_next_create_; |
| 277 | 279 |
| 278 scoped_ptr<MockMojoProxyResolver> mock_proxy_resolver_; | 280 scoped_ptr<MockMojoProxyResolver> mock_proxy_resolver_; |
| 279 }; | 281 }; |
| 280 | 282 |
| 281 TestMojoProxyResolverFactory::TestMojoProxyResolverFactory() | 283 TestMojoProxyResolverFactory::TestMojoProxyResolverFactory() |
| 282 : num_create_calls_(0), fail_next_create_(false) { | 284 : num_create_calls_(0), fail_next_create_(false) { |
| 283 } | 285 } |
| 284 | 286 |
| 285 TestMojoProxyResolverFactory::~TestMojoProxyResolverFactory() { | 287 TestMojoProxyResolverFactory::~TestMojoProxyResolverFactory() { |
| 286 } | 288 } |
| 287 | 289 |
| 288 void TestMojoProxyResolverFactory::Create( | 290 void TestMojoProxyResolverFactory::Create( |
| 289 mojo::InterfaceRequest<interfaces::ProxyResolver> req, | 291 mojo::InterfaceRequest<interfaces::ProxyResolver> req, |
| 290 interfaces::HostResolverPtr host_resolver) { | 292 interfaces::HostResolverPtr host_resolver, |
| 293 interfaces::ProxyResolverErrorObserverPtr error_handler) { |
| 291 if (fail_next_create_) { | 294 if (fail_next_create_) { |
| 292 req = nullptr; | 295 req = nullptr; |
| 293 fail_next_create_ = false; | 296 fail_next_create_ = false; |
| 294 } else { | 297 } else { |
| 295 mock_proxy_resolver_.reset(new MockMojoProxyResolver(req.Pass())); | 298 mock_proxy_resolver_.reset(new MockMojoProxyResolver(req.Pass())); |
| 296 | 299 |
| 297 for (const auto& action : pac_script_actions_[num_create_calls_]) | 300 for (const auto& action : pac_script_actions_[num_create_calls_]) |
| 298 mock_proxy_resolver_->AddPacScriptAction(action); | 301 mock_proxy_resolver_->AddPacScriptAction(action); |
| 299 | 302 |
| 300 for (const auto& action : get_proxy_actions_[num_create_calls_]) | 303 for (const auto& action : get_proxy_actions_[num_create_calls_]) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 error_ = callback_.WaitForResult(); | 358 error_ = callback_.WaitForResult(); |
| 356 return error_; | 359 return error_; |
| 357 } | 360 } |
| 358 | 361 |
| 359 } // namespace | 362 } // namespace |
| 360 | 363 |
| 361 class ProxyResolverMojoTest : public testing::Test { | 364 class ProxyResolverMojoTest : public testing::Test { |
| 362 public: | 365 public: |
| 363 void SetUp() override { | 366 void SetUp() override { |
| 364 proxy_resolver_mojo_.reset(new ProxyResolverMojo( | 367 proxy_resolver_mojo_.reset(new ProxyResolverMojo( |
| 365 &mojo_proxy_resolver_factory_, &mock_host_resolver_)); | 368 &mojo_proxy_resolver_factory_, &mock_host_resolver_, nullptr)); |
| 366 } | 369 } |
| 367 | 370 |
| 368 scoped_ptr<Request> MakeRequest(const GURL& url) { | 371 scoped_ptr<Request> MakeRequest(const GURL& url) { |
| 369 return make_scoped_ptr(new Request(proxy_resolver_mojo_.get(), url)); | 372 return make_scoped_ptr(new Request(proxy_resolver_mojo_.get(), url)); |
| 370 } | 373 } |
| 371 | 374 |
| 372 mojo::Array<interfaces::ProxyServerPtr> ProxyServersFromPacString( | 375 mojo::Array<interfaces::ProxyServerPtr> ProxyServersFromPacString( |
| 373 const std::string& pac_string) { | 376 const std::string& pac_string) { |
| 374 ProxyInfo proxy_info; | 377 ProxyInfo proxy_info; |
| 375 proxy_info.UsePacString(pac_string); | 378 proxy_info.UsePacString(pac_string); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 // resolve request. | 729 // resolve request. |
| 727 scoped_ptr<Request> request(MakeRequest(GURL(kExampleUrl))); | 730 scoped_ptr<Request> request(MakeRequest(GURL(kExampleUrl))); |
| 728 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | 731 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); |
| 729 EXPECT_EQ(OK, request->WaitForResult()); | 732 EXPECT_EQ(OK, request->WaitForResult()); |
| 730 EXPECT_EQ("DIRECT", request->results().ToPacString()); | 733 EXPECT_EQ("DIRECT", request->results().ToPacString()); |
| 731 | 734 |
| 732 EXPECT_EQ(2, mojo_proxy_resolver_factory_.num_create_calls()); | 735 EXPECT_EQ(2, mojo_proxy_resolver_factory_.num_create_calls()); |
| 733 } | 736 } |
| 734 | 737 |
| 735 } // namespace net | 738 } // namespace net |
| OLD | NEW |