| 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 <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 285 |
| 286 class Request { | 286 class Request { |
| 287 public: | 287 public: |
| 288 Request(ProxyResolver* resolver, const GURL& url); | 288 Request(ProxyResolver* resolver, const GURL& url); |
| 289 | 289 |
| 290 int Resolve(); | 290 int Resolve(); |
| 291 void Cancel(); | 291 void Cancel(); |
| 292 int WaitForResult(); | 292 int WaitForResult(); |
| 293 | 293 |
| 294 const ProxyInfo& results() const { return results_; } | 294 const ProxyInfo& results() const { return results_; } |
| 295 LoadState load_state() { return resolver_->GetLoadState(handle_); } | 295 LoadState load_state() { return handle_->GetLoadState(); } |
| 296 BoundTestNetLog& net_log() { return net_log_; } | 296 BoundTestNetLog& net_log() { return net_log_; } |
| 297 | 297 |
| 298 private: | 298 private: |
| 299 ProxyResolver* resolver_; | 299 ProxyResolver* resolver_; |
| 300 const GURL url_; | 300 const GURL url_; |
| 301 ProxyInfo results_; | 301 ProxyInfo results_; |
| 302 ProxyResolver::RequestHandle handle_; | 302 scoped_ptr<ProxyResolver::Request> handle_; |
| 303 int error_; | 303 int error_; |
| 304 TestCompletionCallback callback_; | 304 TestCompletionCallback callback_; |
| 305 BoundTestNetLog net_log_; | 305 BoundTestNetLog net_log_; |
| 306 }; | 306 }; |
| 307 | 307 |
| 308 Request::Request(ProxyResolver* resolver, const GURL& url) | 308 Request::Request(ProxyResolver* resolver, const GURL& url) |
| 309 : resolver_(resolver), url_(url), error_(0) { | 309 : resolver_(resolver), url_(url), error_(0) { |
| 310 } | 310 } |
| 311 | 311 |
| 312 int Request::Resolve() { | 312 int Request::Resolve() { |
| 313 error_ = resolver_->GetProxyForURL(url_, &results_, callback_.callback(), | 313 error_ = resolver_->GetProxyForURL(url_, &results_, callback_.callback(), |
| 314 &handle_, net_log_.bound()); | 314 &handle_, net_log_.bound()); |
| 315 return error_; | 315 return error_; |
| 316 } | 316 } |
| 317 | 317 |
| 318 void Request::Cancel() { | 318 void Request::Cancel() { |
| 319 resolver_->CancelRequest(handle_); | 319 handle_.reset(); |
| 320 } | 320 } |
| 321 | 321 |
| 322 int Request::WaitForResult() { | 322 int Request::WaitForResult() { |
| 323 error_ = callback_.WaitForResult(); | 323 error_ = callback_.WaitForResult(); |
| 324 return error_; | 324 return error_; |
| 325 } | 325 } |
| 326 | 326 |
| 327 class MockMojoProxyResolverFactory : public interfaces::ProxyResolverFactory { | 327 class MockMojoProxyResolverFactory : public interfaces::ProxyResolverFactory { |
| 328 public: | 328 public: |
| 329 MockMojoProxyResolverFactory( | 329 MockMojoProxyResolverFactory( |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 EXPECT_EQ(ERR_PAC_SCRIPT_TERMINATED, request1->WaitForResult()); | 831 EXPECT_EQ(ERR_PAC_SCRIPT_TERMINATED, request1->WaitForResult()); |
| 832 } | 832 } |
| 833 | 833 |
| 834 TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_DeleteInCallback) { | 834 TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_DeleteInCallback) { |
| 835 mock_proxy_resolver_.AddGetProxyAction(GetProxyForUrlAction::ReturnServers( | 835 mock_proxy_resolver_.AddGetProxyAction(GetProxyForUrlAction::ReturnServers( |
| 836 GURL(kExampleUrl), ProxyServersFromPacString("DIRECT"))); | 836 GURL(kExampleUrl), ProxyServersFromPacString("DIRECT"))); |
| 837 CreateProxyResolver(); | 837 CreateProxyResolver(); |
| 838 | 838 |
| 839 ProxyInfo results; | 839 ProxyInfo results; |
| 840 TestCompletionCallback callback; | 840 TestCompletionCallback callback; |
| 841 ProxyResolver::RequestHandle handle; | 841 scoped_ptr<ProxyResolver::Request> request; |
| 842 BoundNetLog net_log; | 842 BoundNetLog net_log; |
| 843 EXPECT_EQ( | 843 EXPECT_EQ( |
| 844 OK, | 844 OK, |
| 845 callback.GetResult(proxy_resolver_mojo_->GetProxyForURL( | 845 callback.GetResult(proxy_resolver_mojo_->GetProxyForURL( |
| 846 GURL(kExampleUrl), &results, | 846 GURL(kExampleUrl), &results, |
| 847 base::Bind(&ProxyResolverFactoryMojoTest::DeleteProxyResolverCallback, | 847 base::Bind(&ProxyResolverFactoryMojoTest::DeleteProxyResolverCallback, |
| 848 base::Unretained(this), callback.callback()), | 848 base::Unretained(this), callback.callback()), |
| 849 &handle, net_log))); | 849 &request, net_log))); |
| 850 on_delete_callback_.WaitForResult(); | 850 on_delete_callback_.WaitForResult(); |
| 851 } | 851 } |
| 852 | 852 |
| 853 TEST_F(ProxyResolverFactoryMojoTest, | 853 TEST_F(ProxyResolverFactoryMojoTest, |
| 854 GetProxyForURL_DeleteInCallbackFromDisconnect) { | 854 GetProxyForURL_DeleteInCallbackFromDisconnect) { |
| 855 mock_proxy_resolver_.AddGetProxyAction( | 855 mock_proxy_resolver_.AddGetProxyAction( |
| 856 GetProxyForUrlAction::Disconnect(GURL(kExampleUrl))); | 856 GetProxyForUrlAction::Disconnect(GURL(kExampleUrl))); |
| 857 CreateProxyResolver(); | 857 CreateProxyResolver(); |
| 858 | 858 |
| 859 ProxyInfo results; | 859 ProxyInfo results; |
| 860 TestCompletionCallback callback; | 860 TestCompletionCallback callback; |
| 861 ProxyResolver::RequestHandle handle; | 861 scoped_ptr<ProxyResolver::Request> request; |
| 862 BoundNetLog net_log; | 862 BoundNetLog net_log; |
| 863 EXPECT_EQ( | 863 EXPECT_EQ( |
| 864 ERR_PAC_SCRIPT_TERMINATED, | 864 ERR_PAC_SCRIPT_TERMINATED, |
| 865 callback.GetResult(proxy_resolver_mojo_->GetProxyForURL( | 865 callback.GetResult(proxy_resolver_mojo_->GetProxyForURL( |
| 866 GURL(kExampleUrl), &results, | 866 GURL(kExampleUrl), &results, |
| 867 base::Bind(&ProxyResolverFactoryMojoTest::DeleteProxyResolverCallback, | 867 base::Bind(&ProxyResolverFactoryMojoTest::DeleteProxyResolverCallback, |
| 868 base::Unretained(this), callback.callback()), | 868 base::Unretained(this), callback.callback()), |
| 869 &handle, net_log))); | 869 &request, net_log))); |
| 870 on_delete_callback_.WaitForResult(); | 870 on_delete_callback_.WaitForResult(); |
| 871 } | 871 } |
| 872 | 872 |
| 873 TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_DnsRequest) { | 873 TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_DnsRequest) { |
| 874 mock_proxy_resolver_.AddGetProxyAction( | 874 mock_proxy_resolver_.AddGetProxyAction( |
| 875 GetProxyForUrlAction::MakeDnsRequest(GURL(kExampleUrl))); | 875 GetProxyForUrlAction::MakeDnsRequest(GURL(kExampleUrl))); |
| 876 CreateProxyResolver(); | 876 CreateProxyResolver(); |
| 877 | 877 |
| 878 scoped_ptr<Request> request(MakeRequest(GURL(kExampleUrl))); | 878 scoped_ptr<Request> request(MakeRequest(GURL(kExampleUrl))); |
| 879 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | 879 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); |
| 880 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, request->load_state()); | 880 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, request->load_state()); |
| 881 | 881 |
| 882 host_resolver_.waiter().WaitForEvent(MockHostResolver::DNS_REQUEST); | 882 host_resolver_.waiter().WaitForEvent(MockHostResolver::DNS_REQUEST); |
| 883 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT, request->load_state()); | 883 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT, request->load_state()); |
| 884 mock_proxy_resolver_.ClearBlockedClients(); | 884 mock_proxy_resolver_.ClearBlockedClients(); |
| 885 request->WaitForResult(); | 885 request->WaitForResult(); |
| 886 } | 886 } |
| 887 | 887 |
| 888 TEST_F(ProxyResolverFactoryMojoTest, DeleteResolver) { | 888 TEST_F(ProxyResolverFactoryMojoTest, DeleteResolver) { |
| 889 CreateProxyResolver(); | 889 CreateProxyResolver(); |
| 890 proxy_resolver_mojo_.reset(); | 890 proxy_resolver_mojo_.reset(); |
| 891 on_delete_callback_.WaitForResult(); | 891 on_delete_callback_.WaitForResult(); |
| 892 } | 892 } |
| 893 } // namespace net | 893 } // namespace net |
| OLD | NEW |