Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: net/proxy/proxy_resolver_factory_mojo_unittest.cc

Issue 2083463002: Replace //net TypeConverters with StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@type-converter-cleanup--gurl
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« net/proxy/OWNERS ('K') | « net/proxy/proxy_resolver_factory_mojo.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "mojo/common/common_type_converters.h" 20 #include "mojo/common/common_type_converters.h"
21 #include "mojo/public/cpp/bindings/binding.h" 21 #include "mojo/public/cpp/bindings/binding.h"
22 #include "net/base/load_states.h" 22 #include "net/base/load_states.h"
23 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
24 #include "net/base/test_completion_callback.h" 24 #include "net/base/test_completion_callback.h"
25 #include "net/dns/host_resolver.h" 25 #include "net/dns/host_resolver.h"
26 #include "net/log/test_net_log.h" 26 #include "net/log/test_net_log.h"
27 #include "net/proxy/mojo_proxy_resolver_factory.h" 27 #include "net/proxy/mojo_proxy_resolver_factory.h"
28 #include "net/proxy/mojo_proxy_type_converters.h"
29 #include "net/proxy/proxy_info.h" 28 #include "net/proxy/proxy_info.h"
30 #include "net/proxy/proxy_resolver.h" 29 #include "net/proxy/proxy_resolver.h"
31 #include "net/proxy/proxy_resolver_error_observer.h" 30 #include "net/proxy/proxy_resolver_error_observer.h"
32 #include "net/proxy/proxy_resolver_script_data.h" 31 #include "net/proxy/proxy_resolver_script_data.h"
33 #include "net/test/event_waiter.h" 32 #include "net/test/event_waiter.h"
34 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
35 #include "url/gurl.h" 34 #include "url/gurl.h"
36 35
37 namespace net { 36 namespace net {
38 37
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 DROP, 111 DROP,
113 // Disconnect the service. 112 // Disconnect the service.
114 DISCONNECT, 113 DISCONNECT,
115 // Wait for the client pipe to be disconnected. 114 // Wait for the client pipe to be disconnected.
116 WAIT_FOR_CLIENT_DISCONNECT, 115 WAIT_FOR_CLIENT_DISCONNECT,
117 // Make a DNS request. 116 // Make a DNS request.
118 MAKE_DNS_REQUEST, 117 MAKE_DNS_REQUEST,
119 }; 118 };
120 119
121 GetProxyForUrlAction() {} 120 GetProxyForUrlAction() {}
122 GetProxyForUrlAction(const GetProxyForUrlAction& old) { 121 GetProxyForUrlAction(const GetProxyForUrlAction& other) = default;
123 action = old.action;
124 error = old.error;
125 expected_url = old.expected_url;
126 proxy_servers = old.proxy_servers.Clone();
127 }
128 122
129 static GetProxyForUrlAction ReturnError(const GURL& url, Error error) { 123 static GetProxyForUrlAction ReturnError(const GURL& url, Error error) {
130 GetProxyForUrlAction result; 124 GetProxyForUrlAction result;
131 result.expected_url = url; 125 result.expected_url = url;
132 result.error = error; 126 result.error = error;
133 return result; 127 return result;
134 } 128 }
135 129
136 static GetProxyForUrlAction ReturnServers( 130 static GetProxyForUrlAction ReturnServers(const GURL& url,
137 const GURL& url, 131 const ProxyInfo& proxy_info) {
138 const mojo::Array<interfaces::ProxyServerPtr>& proxy_servers) {
139 GetProxyForUrlAction result; 132 GetProxyForUrlAction result;
140 result.expected_url = url; 133 result.expected_url = url;
141 result.proxy_servers = proxy_servers.Clone(); 134 result.proxy_info = proxy_info;
142 return result; 135 return result;
143 } 136 }
144 137
145 static GetProxyForUrlAction DropRequest(const GURL& url) { 138 static GetProxyForUrlAction DropRequest(const GURL& url) {
146 GetProxyForUrlAction result; 139 GetProxyForUrlAction result;
147 result.expected_url = url; 140 result.expected_url = url;
148 result.action = DROP; 141 result.action = DROP;
149 return result; 142 return result;
150 } 143 }
151 144
(...skipping 13 matching lines...) Expand all
165 158
166 static GetProxyForUrlAction MakeDnsRequest(const GURL& url) { 159 static GetProxyForUrlAction MakeDnsRequest(const GURL& url) {
167 GetProxyForUrlAction result; 160 GetProxyForUrlAction result;
168 result.expected_url = url; 161 result.expected_url = url;
169 result.action = MAKE_DNS_REQUEST; 162 result.action = MAKE_DNS_REQUEST;
170 return result; 163 return result;
171 } 164 }
172 165
173 Action action = COMPLETE; 166 Action action = COMPLETE;
174 Error error = OK; 167 Error error = OK;
175 mojo::Array<interfaces::ProxyServerPtr> proxy_servers; 168 ProxyInfo proxy_info;
176 GURL expected_url; 169 GURL expected_url;
177 }; 170 };
178 171
179 class MockMojoProxyResolver : public interfaces::ProxyResolver { 172 class MockMojoProxyResolver : public interfaces::ProxyResolver {
180 public: 173 public:
181 MockMojoProxyResolver(); 174 MockMojoProxyResolver();
182 ~MockMojoProxyResolver() override; 175 ~MockMojoProxyResolver() override;
183 176
184 void AddGetProxyAction(GetProxyForUrlAction action); 177 void AddGetProxyAction(GetProxyForUrlAction action);
185 178
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 interfaces::ProxyResolverRequestClientPtr client) { 241 interfaces::ProxyResolverRequestClientPtr client) {
249 ASSERT_FALSE(get_proxy_actions_.empty()); 242 ASSERT_FALSE(get_proxy_actions_.empty());
250 GetProxyForUrlAction action = get_proxy_actions_.front(); 243 GetProxyForUrlAction action = get_proxy_actions_.front();
251 get_proxy_actions_.pop(); 244 get_proxy_actions_.pop();
252 245
253 EXPECT_EQ(action.expected_url, url); 246 EXPECT_EQ(action.expected_url, url);
254 client->Alert(url.spec()); 247 client->Alert(url.spec());
255 client->OnError(12345, url.spec()); 248 client->OnError(12345, url.spec());
256 switch (action.action) { 249 switch (action.action) {
257 case GetProxyForUrlAction::COMPLETE: { 250 case GetProxyForUrlAction::COMPLETE: {
258 client->ReportResult(action.error, std::move(action.proxy_servers)); 251 client->ReportResult(action.error, action.proxy_info);
259 break; 252 break;
260 } 253 }
261 case GetProxyForUrlAction::DROP: { 254 case GetProxyForUrlAction::DROP: {
262 client.reset(); 255 client.reset();
263 break; 256 break;
264 } 257 }
265 case GetProxyForUrlAction::DISCONNECT: { 258 case GetProxyForUrlAction::DISCONNECT: {
266 binding_.Close(); 259 binding_.Close();
267 break; 260 break;
268 } 261 }
269 case GetProxyForUrlAction::WAIT_FOR_CLIENT_DISCONNECT: { 262 case GetProxyForUrlAction::WAIT_FOR_CLIENT_DISCONNECT: {
270 ASSERT_FALSE(client.WaitForIncomingResponse()); 263 ASSERT_FALSE(client.WaitForIncomingResponse());
271 break; 264 break;
272 } 265 }
273 case GetProxyForUrlAction::MAKE_DNS_REQUEST: { 266 case GetProxyForUrlAction::MAKE_DNS_REQUEST: {
274 interfaces::HostResolverRequestInfoPtr request( 267 auto request = base::MakeUnique<HostResolver::RequestInfo>(
275 interfaces::HostResolverRequestInfo::New()); 268 HostPortPair(url.spec(), 12345));
276 request->host = url.spec();
277 request->port = 12345;
278 interfaces::HostResolverRequestClientPtr dns_client; 269 interfaces::HostResolverRequestClientPtr dns_client;
279 mojo::GetProxy(&dns_client); 270 mojo::GetProxy(&dns_client);
280 client->ResolveDns(std::move(request), std::move(dns_client)); 271 client->ResolveDns(std::move(request), std::move(dns_client));
281 blocked_clients_.push_back(base::WrapUnique( 272 blocked_clients_.push_back(base::WrapUnique(
282 new interfaces::ProxyResolverRequestClientPtr(std::move(client)))); 273 new interfaces::ProxyResolverRequestClientPtr(std::move(client))));
283 break; 274 break;
284 } 275 }
285 } 276 }
286 WakeWaiter(); 277 WakeWaiter();
287 } 278 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 418 }
428 case CreateProxyResolverAction::DROP_BOTH: { 419 case CreateProxyResolverAction::DROP_BOTH: {
429 // Both |request| and |client| will be closed. 420 // Both |request| and |client| will be closed.
430 break; 421 break;
431 } 422 }
432 case CreateProxyResolverAction::WAIT_FOR_CLIENT_DISCONNECT: { 423 case CreateProxyResolverAction::WAIT_FOR_CLIENT_DISCONNECT: {
433 ASSERT_FALSE(client.WaitForIncomingResponse()); 424 ASSERT_FALSE(client.WaitForIncomingResponse());
434 break; 425 break;
435 } 426 }
436 case CreateProxyResolverAction::MAKE_DNS_REQUEST: { 427 case CreateProxyResolverAction::MAKE_DNS_REQUEST: {
437 interfaces::HostResolverRequestInfoPtr request( 428 auto request = base::MakeUnique<HostResolver::RequestInfo>(
438 interfaces::HostResolverRequestInfo::New()); 429 HostPortPair(pac_script, 12345));
439 request->host = pac_script;
440 request->port = 12345;
441 interfaces::HostResolverRequestClientPtr dns_client; 430 interfaces::HostResolverRequestClientPtr dns_client;
442 mojo::GetProxy(&dns_client); 431 mojo::GetProxy(&dns_client);
443 client->ResolveDns(std::move(request), std::move(dns_client)); 432 client->ResolveDns(std::move(request), std::move(dns_client));
444 blocked_clients_.push_back( 433 blocked_clients_.push_back(
445 base::WrapUnique(new interfaces::ProxyResolverFactoryRequestClientPtr( 434 base::WrapUnique(new interfaces::ProxyResolverFactoryRequestClientPtr(
446 std::move(client)))); 435 std::move(client))));
447 break; 436 break;
448 } 437 }
449 } 438 }
450 WakeWaiter(); 439 WakeWaiter();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 516
528 std::unique_ptr<base::ScopedClosureRunner> CreateResolver( 517 std::unique_ptr<base::ScopedClosureRunner> CreateResolver(
529 const mojo::String& pac_script, 518 const mojo::String& pac_script,
530 mojo::InterfaceRequest<interfaces::ProxyResolver> req, 519 mojo::InterfaceRequest<interfaces::ProxyResolver> req,
531 interfaces::ProxyResolverFactoryRequestClientPtr client) override { 520 interfaces::ProxyResolverFactoryRequestClientPtr client) override {
532 factory_ptr_->CreateResolver(pac_script, std::move(req), std::move(client)); 521 factory_ptr_->CreateResolver(pac_script, std::move(req), std::move(client));
533 return base::WrapUnique( 522 return base::WrapUnique(
534 new base::ScopedClosureRunner(on_delete_callback_.closure())); 523 new base::ScopedClosureRunner(on_delete_callback_.closure()));
535 } 524 }
536 525
537 mojo::Array<interfaces::ProxyServerPtr> ProxyServersFromPacString( 526 ProxyInfo ProxyServersFromPacString(const std::string& pac_string) {
538 const std::string& pac_string) {
539 ProxyInfo proxy_info; 527 ProxyInfo proxy_info;
540 proxy_info.UsePacString(pac_string); 528 proxy_info.UsePacString(pac_string);
541 529 return proxy_info;
542 return mojo::Array<interfaces::ProxyServerPtr>::From(
543 proxy_info.proxy_list().GetAll());
544 } 530 }
545 531
546 void CreateProxyResolver() { 532 void CreateProxyResolver() {
547 mock_proxy_resolver_factory_->AddCreateProxyResolverAction( 533 mock_proxy_resolver_factory_->AddCreateProxyResolverAction(
548 CreateProxyResolverAction::ReturnResult(kScriptData, OK)); 534 CreateProxyResolverAction::ReturnResult(kScriptData, OK));
549 TestCompletionCallback callback; 535 TestCompletionCallback callback;
550 scoped_refptr<ProxyResolverScriptData> pac_script( 536 scoped_refptr<ProxyResolverScriptData> pac_script(
551 ProxyResolverScriptData::FromUTF8(kScriptData)); 537 ProxyResolverScriptData::FromUTF8(kScriptData));
552 std::unique_ptr<ProxyResolverFactory::Request> request; 538 std::unique_ptr<ProxyResolverFactory::Request> request;
553 ASSERT_EQ( 539 ASSERT_EQ(
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 mock_proxy_resolver_.ClearBlockedClients(); 877 mock_proxy_resolver_.ClearBlockedClients();
892 request->WaitForResult(); 878 request->WaitForResult();
893 } 879 }
894 880
895 TEST_F(ProxyResolverFactoryMojoTest, DeleteResolver) { 881 TEST_F(ProxyResolverFactoryMojoTest, DeleteResolver) {
896 CreateProxyResolver(); 882 CreateProxyResolver();
897 proxy_resolver_mojo_.reset(); 883 proxy_resolver_mojo_.reset();
898 on_delete_callback_.WaitForResult(); 884 on_delete_callback_.WaitForResult();
899 } 885 }
900 } // namespace net 886 } // namespace net
OLDNEW
« net/proxy/OWNERS ('K') | « net/proxy/proxy_resolver_factory_mojo.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698