| 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_factory_mojo.h" | 5 #include "net/proxy/proxy_resolver_factory_mojo.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "mojo/common/common_type_converters.h" | 21 #include "mojo/common/common_type_converters.h" |
| 22 #include "mojo/public/cpp/bindings/binding.h" | 22 #include "mojo/public/cpp/bindings/binding.h" |
| 23 #include "net/base/load_states.h" | 23 #include "net/base/load_states.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 #include "net/base/test_completion_callback.h" | 25 #include "net/base/test_completion_callback.h" |
| 26 #include "net/dns/host_resolver.h" | 26 #include "net/dns/host_resolver.h" |
| 27 #include "net/log/net_log_event_type.h" | 27 #include "net/log/net_log_event_type.h" |
| 28 #include "net/log/net_log_with_source.h" | 28 #include "net/log/net_log_with_source.h" |
| 29 #include "net/log/test_net_log.h" | 29 #include "net/log/test_net_log.h" |
| 30 #include "net/proxy/mojo_proxy_resolver_factory.h" | 30 #include "net/proxy/mojo_proxy_resolver_factory.h" |
| 31 #include "net/proxy/mojo_proxy_type_converters.h" | |
| 32 #include "net/proxy/proxy_info.h" | 31 #include "net/proxy/proxy_info.h" |
| 33 #include "net/proxy/proxy_resolver.h" | 32 #include "net/proxy/proxy_resolver.h" |
| 34 #include "net/proxy/proxy_resolver_error_observer.h" | 33 #include "net/proxy/proxy_resolver_error_observer.h" |
| 35 #include "net/proxy/proxy_resolver_script_data.h" | 34 #include "net/proxy/proxy_resolver_script_data.h" |
| 36 #include "net/test/event_waiter.h" | 35 #include "net/test/event_waiter.h" |
| 37 #include "net/test/gtest_util.h" | 36 #include "net/test/gtest_util.h" |
| 38 #include "testing/gmock/include/gmock/gmock.h" | 37 #include "testing/gmock/include/gmock/gmock.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 40 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 41 | 40 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 DROP, | 119 DROP, |
| 121 // Disconnect the service. | 120 // Disconnect the service. |
| 122 DISCONNECT, | 121 DISCONNECT, |
| 123 // Wait for the client pipe to be disconnected. | 122 // Wait for the client pipe to be disconnected. |
| 124 WAIT_FOR_CLIENT_DISCONNECT, | 123 WAIT_FOR_CLIENT_DISCONNECT, |
| 125 // Make a DNS request. | 124 // Make a DNS request. |
| 126 MAKE_DNS_REQUEST, | 125 MAKE_DNS_REQUEST, |
| 127 }; | 126 }; |
| 128 | 127 |
| 129 GetProxyForUrlAction() {} | 128 GetProxyForUrlAction() {} |
| 130 GetProxyForUrlAction(const GetProxyForUrlAction& old) { | 129 GetProxyForUrlAction(const GetProxyForUrlAction& other) = default; |
| 131 action = old.action; | |
| 132 error = old.error; | |
| 133 expected_url = old.expected_url; | |
| 134 proxy_servers = old.proxy_servers.Clone(); | |
| 135 } | |
| 136 | 130 |
| 137 static GetProxyForUrlAction ReturnError(const GURL& url, Error error) { | 131 static GetProxyForUrlAction ReturnError(const GURL& url, Error error) { |
| 138 GetProxyForUrlAction result; | 132 GetProxyForUrlAction result; |
| 139 result.expected_url = url; | 133 result.expected_url = url; |
| 140 result.error = error; | 134 result.error = error; |
| 141 return result; | 135 return result; |
| 142 } | 136 } |
| 143 | 137 |
| 144 static GetProxyForUrlAction ReturnServers( | 138 static GetProxyForUrlAction ReturnServers(const GURL& url, |
| 145 const GURL& url, | 139 const ProxyInfo& proxy_info) { |
| 146 const mojo::Array<interfaces::ProxyServerPtr>& proxy_servers) { | |
| 147 GetProxyForUrlAction result; | 140 GetProxyForUrlAction result; |
| 148 result.expected_url = url; | 141 result.expected_url = url; |
| 149 result.proxy_servers = proxy_servers.Clone(); | 142 result.proxy_info = proxy_info; |
| 150 return result; | 143 return result; |
| 151 } | 144 } |
| 152 | 145 |
| 153 static GetProxyForUrlAction DropRequest(const GURL& url) { | 146 static GetProxyForUrlAction DropRequest(const GURL& url) { |
| 154 GetProxyForUrlAction result; | 147 GetProxyForUrlAction result; |
| 155 result.expected_url = url; | 148 result.expected_url = url; |
| 156 result.action = DROP; | 149 result.action = DROP; |
| 157 return result; | 150 return result; |
| 158 } | 151 } |
| 159 | 152 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 173 | 166 |
| 174 static GetProxyForUrlAction MakeDnsRequest(const GURL& url) { | 167 static GetProxyForUrlAction MakeDnsRequest(const GURL& url) { |
| 175 GetProxyForUrlAction result; | 168 GetProxyForUrlAction result; |
| 176 result.expected_url = url; | 169 result.expected_url = url; |
| 177 result.action = MAKE_DNS_REQUEST; | 170 result.action = MAKE_DNS_REQUEST; |
| 178 return result; | 171 return result; |
| 179 } | 172 } |
| 180 | 173 |
| 181 Action action = COMPLETE; | 174 Action action = COMPLETE; |
| 182 Error error = OK; | 175 Error error = OK; |
| 183 mojo::Array<interfaces::ProxyServerPtr> proxy_servers; | 176 ProxyInfo proxy_info; |
| 184 GURL expected_url; | 177 GURL expected_url; |
| 185 }; | 178 }; |
| 186 | 179 |
| 187 class MockMojoProxyResolver : public interfaces::ProxyResolver { | 180 class MockMojoProxyResolver : public interfaces::ProxyResolver { |
| 188 public: | 181 public: |
| 189 MockMojoProxyResolver(); | 182 MockMojoProxyResolver(); |
| 190 ~MockMojoProxyResolver() override; | 183 ~MockMojoProxyResolver() override; |
| 191 | 184 |
| 192 void AddGetProxyAction(GetProxyForUrlAction action); | 185 void AddGetProxyAction(GetProxyForUrlAction action); |
| 193 | 186 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 interfaces::ProxyResolverRequestClientPtr client) { | 249 interfaces::ProxyResolverRequestClientPtr client) { |
| 257 ASSERT_FALSE(get_proxy_actions_.empty()); | 250 ASSERT_FALSE(get_proxy_actions_.empty()); |
| 258 GetProxyForUrlAction action = get_proxy_actions_.front(); | 251 GetProxyForUrlAction action = get_proxy_actions_.front(); |
| 259 get_proxy_actions_.pop(); | 252 get_proxy_actions_.pop(); |
| 260 | 253 |
| 261 EXPECT_EQ(action.expected_url, url); | 254 EXPECT_EQ(action.expected_url, url); |
| 262 client->Alert(url.spec()); | 255 client->Alert(url.spec()); |
| 263 client->OnError(12345, url.spec()); | 256 client->OnError(12345, url.spec()); |
| 264 switch (action.action) { | 257 switch (action.action) { |
| 265 case GetProxyForUrlAction::COMPLETE: { | 258 case GetProxyForUrlAction::COMPLETE: { |
| 266 client->ReportResult(action.error, std::move(action.proxy_servers)); | 259 client->ReportResult(action.error, action.proxy_info); |
| 267 break; | 260 break; |
| 268 } | 261 } |
| 269 case GetProxyForUrlAction::DROP: { | 262 case GetProxyForUrlAction::DROP: { |
| 270 client.reset(); | 263 client.reset(); |
| 271 break; | 264 break; |
| 272 } | 265 } |
| 273 case GetProxyForUrlAction::DISCONNECT: { | 266 case GetProxyForUrlAction::DISCONNECT: { |
| 274 binding_.Close(); | 267 binding_.Close(); |
| 275 break; | 268 break; |
| 276 } | 269 } |
| 277 case GetProxyForUrlAction::WAIT_FOR_CLIENT_DISCONNECT: { | 270 case GetProxyForUrlAction::WAIT_FOR_CLIENT_DISCONNECT: { |
| 278 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( | 271 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( |
| 279 base::MessageLoop::current()); | 272 base::MessageLoop::current()); |
| 280 base::RunLoop run_loop; | 273 base::RunLoop run_loop; |
| 281 client.set_connection_error_handler(run_loop.QuitClosure()); | 274 client.set_connection_error_handler(run_loop.QuitClosure()); |
| 282 run_loop.Run(); | 275 run_loop.Run(); |
| 283 ASSERT_TRUE(client.encountered_error()); | 276 ASSERT_TRUE(client.encountered_error()); |
| 284 break; | 277 break; |
| 285 } | 278 } |
| 286 case GetProxyForUrlAction::MAKE_DNS_REQUEST: { | 279 case GetProxyForUrlAction::MAKE_DNS_REQUEST: { |
| 287 interfaces::HostResolverRequestInfoPtr request( | 280 auto request = base::MakeUnique<HostResolver::RequestInfo>( |
| 288 interfaces::HostResolverRequestInfo::New()); | 281 HostPortPair(url.spec(), 12345)); |
| 289 request->host = url.spec(); | |
| 290 request->port = 12345; | |
| 291 interfaces::HostResolverRequestClientPtr dns_client; | 282 interfaces::HostResolverRequestClientPtr dns_client; |
| 292 mojo::GetProxy(&dns_client); | 283 mojo::GetProxy(&dns_client); |
| 293 client->ResolveDns(std::move(request), std::move(dns_client)); | 284 client->ResolveDns(std::move(request), std::move(dns_client)); |
| 294 blocked_clients_.push_back( | 285 blocked_clients_.push_back( |
| 295 base::MakeUnique<interfaces::ProxyResolverRequestClientPtr>( | 286 base::MakeUnique<interfaces::ProxyResolverRequestClientPtr>( |
| 296 std::move(client))); | 287 std::move(client))); |
| 297 break; | 288 break; |
| 298 } | 289 } |
| 299 } | 290 } |
| 300 WakeWaiter(); | 291 WakeWaiter(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 case CreateProxyResolverAction::WAIT_FOR_CLIENT_DISCONNECT: { | 437 case CreateProxyResolverAction::WAIT_FOR_CLIENT_DISCONNECT: { |
| 447 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( | 438 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( |
| 448 base::MessageLoop::current()); | 439 base::MessageLoop::current()); |
| 449 base::RunLoop run_loop; | 440 base::RunLoop run_loop; |
| 450 client.set_connection_error_handler(run_loop.QuitClosure()); | 441 client.set_connection_error_handler(run_loop.QuitClosure()); |
| 451 run_loop.Run(); | 442 run_loop.Run(); |
| 452 ASSERT_TRUE(client.encountered_error()); | 443 ASSERT_TRUE(client.encountered_error()); |
| 453 break; | 444 break; |
| 454 } | 445 } |
| 455 case CreateProxyResolverAction::MAKE_DNS_REQUEST: { | 446 case CreateProxyResolverAction::MAKE_DNS_REQUEST: { |
| 456 interfaces::HostResolverRequestInfoPtr request( | 447 auto request = base::MakeUnique<HostResolver::RequestInfo>( |
| 457 interfaces::HostResolverRequestInfo::New()); | 448 HostPortPair(pac_script, 12345)); |
| 458 request->host = pac_script; | |
| 459 request->port = 12345; | |
| 460 interfaces::HostResolverRequestClientPtr dns_client; | 449 interfaces::HostResolverRequestClientPtr dns_client; |
| 461 mojo::GetProxy(&dns_client); | 450 mojo::GetProxy(&dns_client); |
| 462 client->ResolveDns(std::move(request), std::move(dns_client)); | 451 client->ResolveDns(std::move(request), std::move(dns_client)); |
| 463 blocked_clients_.push_back( | 452 blocked_clients_.push_back( |
| 464 base::MakeUnique<interfaces::ProxyResolverFactoryRequestClientPtr>( | 453 base::MakeUnique<interfaces::ProxyResolverFactoryRequestClientPtr>( |
| 465 std::move(client))); | 454 std::move(client))); |
| 466 break; | 455 break; |
| 467 } | 456 } |
| 468 } | 457 } |
| 469 WakeWaiter(); | 458 WakeWaiter(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 536 |
| 548 std::unique_ptr<base::ScopedClosureRunner> CreateResolver( | 537 std::unique_ptr<base::ScopedClosureRunner> CreateResolver( |
| 549 const mojo::String& pac_script, | 538 const mojo::String& pac_script, |
| 550 mojo::InterfaceRequest<interfaces::ProxyResolver> req, | 539 mojo::InterfaceRequest<interfaces::ProxyResolver> req, |
| 551 interfaces::ProxyResolverFactoryRequestClientPtr client) override { | 540 interfaces::ProxyResolverFactoryRequestClientPtr client) override { |
| 552 factory_ptr_->CreateResolver(pac_script, std::move(req), std::move(client)); | 541 factory_ptr_->CreateResolver(pac_script, std::move(req), std::move(client)); |
| 553 return base::MakeUnique<base::ScopedClosureRunner>( | 542 return base::MakeUnique<base::ScopedClosureRunner>( |
| 554 on_delete_callback_.closure()); | 543 on_delete_callback_.closure()); |
| 555 } | 544 } |
| 556 | 545 |
| 557 mojo::Array<interfaces::ProxyServerPtr> ProxyServersFromPacString( | 546 ProxyInfo ProxyServersFromPacString(const std::string& pac_string) { |
| 558 const std::string& pac_string) { | |
| 559 ProxyInfo proxy_info; | 547 ProxyInfo proxy_info; |
| 560 proxy_info.UsePacString(pac_string); | 548 proxy_info.UsePacString(pac_string); |
| 561 | 549 return proxy_info; |
| 562 return mojo::Array<interfaces::ProxyServerPtr>::From( | |
| 563 proxy_info.proxy_list().GetAll()); | |
| 564 } | 550 } |
| 565 | 551 |
| 566 void CreateProxyResolver() { | 552 void CreateProxyResolver() { |
| 567 mock_proxy_resolver_factory_->AddCreateProxyResolverAction( | 553 mock_proxy_resolver_factory_->AddCreateProxyResolverAction( |
| 568 CreateProxyResolverAction::ReturnResult(kScriptData, OK)); | 554 CreateProxyResolverAction::ReturnResult(kScriptData, OK)); |
| 569 TestCompletionCallback callback; | 555 TestCompletionCallback callback; |
| 570 scoped_refptr<ProxyResolverScriptData> pac_script( | 556 scoped_refptr<ProxyResolverScriptData> pac_script( |
| 571 ProxyResolverScriptData::FromUTF8(kScriptData)); | 557 ProxyResolverScriptData::FromUTF8(kScriptData)); |
| 572 std::unique_ptr<ProxyResolverFactory::Request> request; | 558 std::unique_ptr<ProxyResolverFactory::Request> request; |
| 573 ASSERT_EQ( | 559 ASSERT_EQ( |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 mock_proxy_resolver_.ClearBlockedClients(); | 897 mock_proxy_resolver_.ClearBlockedClients(); |
| 912 request->WaitForResult(); | 898 request->WaitForResult(); |
| 913 } | 899 } |
| 914 | 900 |
| 915 TEST_F(ProxyResolverFactoryMojoTest, DeleteResolver) { | 901 TEST_F(ProxyResolverFactoryMojoTest, DeleteResolver) { |
| 916 CreateProxyResolver(); | 902 CreateProxyResolver(); |
| 917 proxy_resolver_mojo_.reset(); | 903 proxy_resolver_mojo_.reset(); |
| 918 on_delete_callback_.WaitForResult(); | 904 on_delete_callback_.WaitForResult(); |
| 919 } | 905 } |
| 920 } // namespace net | 906 } // namespace net |
| OLD | NEW |