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

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

Issue 1545233002: Convert Pass()→std::move() in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
« no previous file with comments | « net/proxy/proxy_resolver_factory_mojo.cc ('k') | net/proxy/proxy_resolver_perftest.cc » ('j') | 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 <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 #include <utility>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/bind.h" 14 #include "base/bind.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "base/values.h" 18 #include "base/values.h"
18 #include "mojo/common/common_type_converters.h" 19 #include "mojo/common/common_type_converters.h"
19 #include "mojo/public/cpp/bindings/binding.h" 20 #include "mojo/public/cpp/bindings/binding.h"
20 #include "net/base/load_states.h" 21 #include "net/base/load_states.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 232 }
232 233
233 void MockMojoProxyResolver::ClearBlockedClients() { 234 void MockMojoProxyResolver::ClearBlockedClients() {
234 blocked_clients_.clear(); 235 blocked_clients_.clear();
235 } 236 }
236 237
237 void MockMojoProxyResolver::AddConnection( 238 void MockMojoProxyResolver::AddConnection(
238 mojo::InterfaceRequest<interfaces::ProxyResolver> req) { 239 mojo::InterfaceRequest<interfaces::ProxyResolver> req) {
239 if (binding_.is_bound()) 240 if (binding_.is_bound())
240 binding_.Close(); 241 binding_.Close();
241 binding_.Bind(req.Pass()); 242 binding_.Bind(std::move(req));
242 } 243 }
243 244
244 void MockMojoProxyResolver::GetProxyForUrl( 245 void MockMojoProxyResolver::GetProxyForUrl(
245 const mojo::String& url, 246 const mojo::String& url,
246 interfaces::ProxyResolverRequestClientPtr client) { 247 interfaces::ProxyResolverRequestClientPtr client) {
247 ASSERT_FALSE(get_proxy_actions_.empty()); 248 ASSERT_FALSE(get_proxy_actions_.empty());
248 GetProxyForUrlAction action = get_proxy_actions_.front(); 249 GetProxyForUrlAction action = get_proxy_actions_.front();
249 get_proxy_actions_.pop(); 250 get_proxy_actions_.pop();
250 251
251 EXPECT_EQ(action.expected_url.spec(), url.To<std::string>()); 252 EXPECT_EQ(action.expected_url.spec(), url.To<std::string>());
252 client->Alert(url); 253 client->Alert(url);
253 client->OnError(12345, url); 254 client->OnError(12345, url);
254 switch (action.action) { 255 switch (action.action) {
255 case GetProxyForUrlAction::COMPLETE: { 256 case GetProxyForUrlAction::COMPLETE: {
256 client->ReportResult(action.error, action.proxy_servers.Pass()); 257 client->ReportResult(action.error, std::move(action.proxy_servers));
257 break; 258 break;
258 } 259 }
259 case GetProxyForUrlAction::DROP: { 260 case GetProxyForUrlAction::DROP: {
260 client.reset(); 261 client.reset();
261 break; 262 break;
262 } 263 }
263 case GetProxyForUrlAction::DISCONNECT: { 264 case GetProxyForUrlAction::DISCONNECT: {
264 binding_.Close(); 265 binding_.Close();
265 break; 266 break;
266 } 267 }
267 case GetProxyForUrlAction::WAIT_FOR_CLIENT_DISCONNECT: { 268 case GetProxyForUrlAction::WAIT_FOR_CLIENT_DISCONNECT: {
268 ASSERT_FALSE(client.WaitForIncomingResponse()); 269 ASSERT_FALSE(client.WaitForIncomingResponse());
269 break; 270 break;
270 } 271 }
271 case GetProxyForUrlAction::MAKE_DNS_REQUEST: { 272 case GetProxyForUrlAction::MAKE_DNS_REQUEST: {
272 interfaces::HostResolverRequestInfoPtr request( 273 interfaces::HostResolverRequestInfoPtr request(
273 interfaces::HostResolverRequestInfo::New()); 274 interfaces::HostResolverRequestInfo::New());
274 request->host = url; 275 request->host = url;
275 request->port = 12345; 276 request->port = 12345;
276 interfaces::HostResolverRequestClientPtr dns_client; 277 interfaces::HostResolverRequestClientPtr dns_client;
277 mojo::GetProxy(&dns_client); 278 mojo::GetProxy(&dns_client);
278 client->ResolveDns(request.Pass(), dns_client.Pass()); 279 client->ResolveDns(std::move(request), std::move(dns_client));
279 blocked_clients_.push_back(make_scoped_ptr( 280 blocked_clients_.push_back(make_scoped_ptr(
280 new interfaces::ProxyResolverRequestClientPtr(std::move(client)))); 281 new interfaces::ProxyResolverRequestClientPtr(std::move(client))));
281 break; 282 break;
282 } 283 }
283 } 284 }
284 WakeWaiter(); 285 WakeWaiter();
285 } 286 }
286 287
287 class Request { 288 class Request {
288 public: 289 public:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 std::vector<scoped_ptr<interfaces::ProxyResolverFactoryRequestClientPtr>> 356 std::vector<scoped_ptr<interfaces::ProxyResolverFactoryRequestClientPtr>>
356 blocked_clients_; 357 blocked_clients_;
357 std::vector<scoped_ptr<mojo::InterfaceRequest<interfaces::ProxyResolver>>> 358 std::vector<scoped_ptr<mojo::InterfaceRequest<interfaces::ProxyResolver>>>
358 blocked_resolver_requests_; 359 blocked_resolver_requests_;
359 mojo::Binding<interfaces::ProxyResolverFactory> binding_; 360 mojo::Binding<interfaces::ProxyResolverFactory> binding_;
360 }; 361 };
361 362
362 MockMojoProxyResolverFactory::MockMojoProxyResolverFactory( 363 MockMojoProxyResolverFactory::MockMojoProxyResolverFactory(
363 MockMojoProxyResolver* resolver, 364 MockMojoProxyResolver* resolver,
364 mojo::InterfaceRequest<interfaces::ProxyResolverFactory> req) 365 mojo::InterfaceRequest<interfaces::ProxyResolverFactory> req)
365 : resolver_(resolver), binding_(this, req.Pass()) { 366 : resolver_(resolver), binding_(this, std::move(req)) {}
366 }
367 367
368 MockMojoProxyResolverFactory::~MockMojoProxyResolverFactory() { 368 MockMojoProxyResolverFactory::~MockMojoProxyResolverFactory() {
369 EXPECT_TRUE(create_resolver_actions_.empty()) 369 EXPECT_TRUE(create_resolver_actions_.empty())
370 << "Actions remaining: " << create_resolver_actions_.size(); 370 << "Actions remaining: " << create_resolver_actions_.size();
371 } 371 }
372 372
373 void MockMojoProxyResolverFactory::AddCreateProxyResolverAction( 373 void MockMojoProxyResolverFactory::AddCreateProxyResolverAction(
374 CreateProxyResolverAction action) { 374 CreateProxyResolverAction action) {
375 create_resolver_actions_.push(action); 375 create_resolver_actions_.push(action);
376 } 376 }
(...skipping 21 matching lines...) Expand all
398 ASSERT_FALSE(create_resolver_actions_.empty()); 398 ASSERT_FALSE(create_resolver_actions_.empty());
399 CreateProxyResolverAction action = create_resolver_actions_.front(); 399 CreateProxyResolverAction action = create_resolver_actions_.front();
400 create_resolver_actions_.pop(); 400 create_resolver_actions_.pop();
401 401
402 EXPECT_EQ(action.expected_pac_script, pac_script.To<std::string>()); 402 EXPECT_EQ(action.expected_pac_script, pac_script.To<std::string>());
403 client->Alert(pac_script); 403 client->Alert(pac_script);
404 client->OnError(12345, pac_script); 404 client->OnError(12345, pac_script);
405 switch (action.action) { 405 switch (action.action) {
406 case CreateProxyResolverAction::COMPLETE: { 406 case CreateProxyResolverAction::COMPLETE: {
407 if (action.error == OK) 407 if (action.error == OK)
408 resolver_->AddConnection(request.Pass()); 408 resolver_->AddConnection(std::move(request));
409 client->ReportResult(action.error); 409 client->ReportResult(action.error);
410 break; 410 break;
411 } 411 }
412 case CreateProxyResolverAction::DROP_CLIENT: { 412 case CreateProxyResolverAction::DROP_CLIENT: {
413 // Save |request| so its pipe isn't closed. 413 // Save |request| so its pipe isn't closed.
414 blocked_resolver_requests_.push_back( 414 blocked_resolver_requests_.push_back(
415 make_scoped_ptr(new mojo::InterfaceRequest<interfaces::ProxyResolver>( 415 make_scoped_ptr(new mojo::InterfaceRequest<interfaces::ProxyResolver>(
416 std::move(request)))); 416 std::move(request))));
417 break; 417 break;
418 } 418 }
(...skipping 12 matching lines...) Expand all
431 ASSERT_FALSE(client.WaitForIncomingResponse()); 431 ASSERT_FALSE(client.WaitForIncomingResponse());
432 break; 432 break;
433 } 433 }
434 case CreateProxyResolverAction::MAKE_DNS_REQUEST: { 434 case CreateProxyResolverAction::MAKE_DNS_REQUEST: {
435 interfaces::HostResolverRequestInfoPtr request( 435 interfaces::HostResolverRequestInfoPtr request(
436 interfaces::HostResolverRequestInfo::New()); 436 interfaces::HostResolverRequestInfo::New());
437 request->host = pac_script; 437 request->host = pac_script;
438 request->port = 12345; 438 request->port = 12345;
439 interfaces::HostResolverRequestClientPtr dns_client; 439 interfaces::HostResolverRequestClientPtr dns_client;
440 mojo::GetProxy(&dns_client); 440 mojo::GetProxy(&dns_client);
441 client->ResolveDns(request.Pass(), std::move(dns_client)); 441 client->ResolveDns(std::move(request), std::move(dns_client));
442 blocked_clients_.push_back( 442 blocked_clients_.push_back(
443 make_scoped_ptr(new interfaces::ProxyResolverFactoryRequestClientPtr( 443 make_scoped_ptr(new interfaces::ProxyResolverFactoryRequestClientPtr(
444 std::move(client)))); 444 std::move(client))));
445 break; 445 break;
446 } 446 }
447 } 447 }
448 WakeWaiter(); 448 WakeWaiter();
449 } 449 }
450 450
451 void DeleteResolverFactoryRequestCallback( 451 void DeleteResolverFactoryRequestCallback(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 519 }
520 520
521 scoped_ptr<Request> MakeRequest(const GURL& url) { 521 scoped_ptr<Request> MakeRequest(const GURL& url) {
522 return make_scoped_ptr(new Request(proxy_resolver_mojo_.get(), url)); 522 return make_scoped_ptr(new Request(proxy_resolver_mojo_.get(), url));
523 } 523 }
524 524
525 scoped_ptr<base::ScopedClosureRunner> CreateResolver( 525 scoped_ptr<base::ScopedClosureRunner> CreateResolver(
526 const mojo::String& pac_script, 526 const mojo::String& pac_script,
527 mojo::InterfaceRequest<interfaces::ProxyResolver> req, 527 mojo::InterfaceRequest<interfaces::ProxyResolver> req,
528 interfaces::ProxyResolverFactoryRequestClientPtr client) override { 528 interfaces::ProxyResolverFactoryRequestClientPtr client) override {
529 factory_ptr_->CreateResolver(pac_script, req.Pass(), client.Pass()); 529 factory_ptr_->CreateResolver(pac_script, std::move(req), std::move(client));
530 return make_scoped_ptr( 530 return make_scoped_ptr(
531 new base::ScopedClosureRunner(on_delete_callback_.closure())); 531 new base::ScopedClosureRunner(on_delete_callback_.closure()));
532 } 532 }
533 533
534 mojo::Array<interfaces::ProxyServerPtr> ProxyServersFromPacString( 534 mojo::Array<interfaces::ProxyServerPtr> ProxyServersFromPacString(
535 const std::string& pac_string) { 535 const std::string& pac_string) {
536 ProxyInfo proxy_info; 536 ProxyInfo proxy_info;
537 proxy_info.UsePacString(pac_string); 537 proxy_info.UsePacString(pac_string);
538 538
539 return mojo::Array<interfaces::ProxyServerPtr>::From( 539 return mojo::Array<interfaces::ProxyServerPtr>::From(
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_factory_mojo.cc ('k') | net/proxy/proxy_resolver_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698