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