| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 struct GetProxyForUrlAction { | 95 struct GetProxyForUrlAction { |
| 96 enum Action { | 96 enum Action { |
| 97 COMPLETE, | 97 COMPLETE, |
| 98 // Drop the request by closing the reply channel. | 98 // Drop the request by closing the reply channel. |
| 99 DROP, | 99 DROP, |
| 100 // Disconnect the service. | 100 // Disconnect the service. |
| 101 DISCONNECT, | 101 DISCONNECT, |
| 102 // Wait for the client pipe to be disconnected. | 102 // Wait for the client pipe to be disconnected. |
| 103 WAIT_FOR_CLIENT_DISCONNECT, | 103 WAIT_FOR_CLIENT_DISCONNECT, |
| 104 // Send a LoadStateChanged message and keep the client pipe open. | |
| 105 SEND_LOAD_STATE_AND_BLOCK, | |
| 106 }; | 104 }; |
| 107 | 105 |
| 108 GetProxyForUrlAction() {} | 106 GetProxyForUrlAction() {} |
| 109 GetProxyForUrlAction(const GetProxyForUrlAction& old) { | 107 GetProxyForUrlAction(const GetProxyForUrlAction& old) { |
| 110 action = old.action; | 108 action = old.action; |
| 111 error = old.error; | 109 error = old.error; |
| 112 expected_url = old.expected_url; | 110 expected_url = old.expected_url; |
| 113 proxy_servers = old.proxy_servers.Clone(); | 111 proxy_servers = old.proxy_servers.Clone(); |
| 114 } | 112 } |
| 115 | 113 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 143 return result; | 141 return result; |
| 144 } | 142 } |
| 145 | 143 |
| 146 static GetProxyForUrlAction WaitForClientDisconnect(const GURL& url) { | 144 static GetProxyForUrlAction WaitForClientDisconnect(const GURL& url) { |
| 147 GetProxyForUrlAction result; | 145 GetProxyForUrlAction result; |
| 148 result.expected_url = url; | 146 result.expected_url = url; |
| 149 result.action = WAIT_FOR_CLIENT_DISCONNECT; | 147 result.action = WAIT_FOR_CLIENT_DISCONNECT; |
| 150 return result; | 148 return result; |
| 151 } | 149 } |
| 152 | 150 |
| 153 static GetProxyForUrlAction SendLoadStateChanged(const GURL& url) { | |
| 154 GetProxyForUrlAction result; | |
| 155 result.expected_url = url; | |
| 156 result.action = SEND_LOAD_STATE_AND_BLOCK; | |
| 157 return result; | |
| 158 } | |
| 159 | |
| 160 Action action = COMPLETE; | 151 Action action = COMPLETE; |
| 161 Error error = OK; | 152 Error error = OK; |
| 162 mojo::Array<interfaces::ProxyServerPtr> proxy_servers; | 153 mojo::Array<interfaces::ProxyServerPtr> proxy_servers; |
| 163 GURL expected_url; | 154 GURL expected_url; |
| 164 }; | 155 }; |
| 165 | 156 |
| 166 class MockMojoProxyResolver : public interfaces::ProxyResolver { | 157 class MockMojoProxyResolver : public interfaces::ProxyResolver { |
| 167 public: | 158 public: |
| 168 MockMojoProxyResolver(); | 159 MockMojoProxyResolver(); |
| 169 ~MockMojoProxyResolver() override; | 160 ~MockMojoProxyResolver() override; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 break; | 234 break; |
| 244 case GetProxyForUrlAction::DROP: | 235 case GetProxyForUrlAction::DROP: |
| 245 client.reset(); | 236 client.reset(); |
| 246 break; | 237 break; |
| 247 case GetProxyForUrlAction::DISCONNECT: | 238 case GetProxyForUrlAction::DISCONNECT: |
| 248 binding_.Close(); | 239 binding_.Close(); |
| 249 break; | 240 break; |
| 250 case GetProxyForUrlAction::WAIT_FOR_CLIENT_DISCONNECT: | 241 case GetProxyForUrlAction::WAIT_FOR_CLIENT_DISCONNECT: |
| 251 ASSERT_FALSE(client.WaitForIncomingResponse()); | 242 ASSERT_FALSE(client.WaitForIncomingResponse()); |
| 252 break; | 243 break; |
| 253 case GetProxyForUrlAction::SEND_LOAD_STATE_AND_BLOCK: | |
| 254 client->LoadStateChanged(LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT); | |
| 255 blocked_clients_.push_back( | |
| 256 new interfaces::ProxyResolverRequestClientPtr(client.Pass())); | |
| 257 break; | |
| 258 } | 244 } |
| 259 WakeWaiter(); | 245 WakeWaiter(); |
| 260 } | 246 } |
| 261 | 247 |
| 262 class Request { | 248 class Request { |
| 263 public: | 249 public: |
| 264 Request(ProxyResolver* resolver, const GURL& url); | 250 Request(ProxyResolver* resolver, const GURL& url); |
| 265 | 251 |
| 266 int Resolve(); | 252 int Resolve(); |
| 267 void Cancel(); | 253 void Cancel(); |
| 268 int WaitForResult(); | 254 int WaitForResult(); |
| 269 | 255 |
| 270 int error() const { return error_; } | 256 int error() const { return error_; } |
| 271 const ProxyInfo& results() const { return results_; } | 257 const ProxyInfo& results() const { return results_; } |
| 272 LoadState load_state() { return resolver_->GetLoadState(handle_); } | |
| 273 | 258 |
| 274 private: | 259 private: |
| 275 ProxyResolver* resolver_; | 260 ProxyResolver* resolver_; |
| 276 const GURL url_; | 261 const GURL url_; |
| 277 ProxyInfo results_; | 262 ProxyInfo results_; |
| 278 ProxyResolver::RequestHandle handle_; | 263 ProxyResolver::RequestHandle handle_; |
| 279 int error_; | 264 int error_; |
| 280 TestCompletionCallback callback_; | 265 TestCompletionCallback callback_; |
| 281 }; | 266 }; |
| 282 | 267 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 GURL(kExampleUrl), ProxyServersFromPacString("DIRECT"))); | 577 GURL(kExampleUrl), ProxyServersFromPacString("DIRECT"))); |
| 593 CreateProxyResolver(); | 578 CreateProxyResolver(); |
| 594 | 579 |
| 595 scoped_ptr<Request> request(MakeRequest(GURL(kExampleUrl))); | 580 scoped_ptr<Request> request(MakeRequest(GURL(kExampleUrl))); |
| 596 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | 581 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); |
| 597 EXPECT_EQ(OK, request->WaitForResult()); | 582 EXPECT_EQ(OK, request->WaitForResult()); |
| 598 | 583 |
| 599 EXPECT_EQ("DIRECT", request->results().ToPacString()); | 584 EXPECT_EQ("DIRECT", request->results().ToPacString()); |
| 600 } | 585 } |
| 601 | 586 |
| 602 TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_LoadState) { | |
| 603 mock_proxy_resolver_.AddGetProxyAction( | |
| 604 GetProxyForUrlAction::SendLoadStateChanged(GURL(kExampleUrl))); | |
| 605 CreateProxyResolver(); | |
| 606 | |
| 607 scoped_ptr<Request> request(MakeRequest(GURL(kExampleUrl))); | |
| 608 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | |
| 609 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, request->load_state()); | |
| 610 while (request->load_state() == LOAD_STATE_RESOLVING_PROXY_FOR_URL) | |
| 611 base::RunLoop().RunUntilIdle(); | |
| 612 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT, request->load_state()); | |
| 613 mock_proxy_resolver_.ClearBlockedClients(); | |
| 614 EXPECT_EQ(ERR_PAC_SCRIPT_TERMINATED, request->WaitForResult()); | |
| 615 } | |
| 616 | |
| 617 TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_MultipleResults) { | 587 TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_MultipleResults) { |
| 618 static const char kPacString[] = | 588 static const char kPacString[] = |
| 619 "PROXY foo1:80;DIRECT;SOCKS foo2:1234;" | 589 "PROXY foo1:80;DIRECT;SOCKS foo2:1234;" |
| 620 "SOCKS5 foo3:1080;HTTPS foo4:443;QUIC foo6:8888"; | 590 "SOCKS5 foo3:1080;HTTPS foo4:443;QUIC foo6:8888"; |
| 621 mock_proxy_resolver_.AddGetProxyAction(GetProxyForUrlAction::ReturnServers( | 591 mock_proxy_resolver_.AddGetProxyAction(GetProxyForUrlAction::ReturnServers( |
| 622 GURL(kExampleUrl), ProxyServersFromPacString(kPacString))); | 592 GURL(kExampleUrl), ProxyServersFromPacString(kPacString))); |
| 623 CreateProxyResolver(); | 593 CreateProxyResolver(); |
| 624 | 594 |
| 625 scoped_ptr<Request> request(MakeRequest(GURL(kExampleUrl))); | 595 scoped_ptr<Request> request(MakeRequest(GURL(kExampleUrl))); |
| 626 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); | 596 EXPECT_EQ(ERR_IO_PENDING, request->Resolve()); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 &handle, net_log))); | 711 &handle, net_log))); |
| 742 on_delete_callback_.WaitForResult(); | 712 on_delete_callback_.WaitForResult(); |
| 743 } | 713 } |
| 744 | 714 |
| 745 TEST_F(ProxyResolverFactoryMojoTest, DeleteResolver) { | 715 TEST_F(ProxyResolverFactoryMojoTest, DeleteResolver) { |
| 746 CreateProxyResolver(); | 716 CreateProxyResolver(); |
| 747 proxy_resolver_mojo_.reset(); | 717 proxy_resolver_mojo_.reset(); |
| 748 on_delete_callback_.WaitForResult(); | 718 on_delete_callback_.WaitForResult(); |
| 749 } | 719 } |
| 750 } // namespace net | 720 } // namespace net |
| OLD | NEW |