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

Side by Side Diff: net/dns/host_resolver_impl_unittest.cc

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 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 | Annotate | Revision Log
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | net/dns/host_resolver_proc.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/dns/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 return test->CreateRequest(hostname); 429 return test->CreateRequest(hostname);
430 } 430 }
431 ScopedVector<Request>& requests() { return test->requests_; } 431 ScopedVector<Request>& requests() { return test->requests_; }
432 432
433 void DeleteResolver() { test->resolver_.reset(); } 433 void DeleteResolver() { test->resolver_.reset(); }
434 434
435 HostResolverImplTest* test; 435 HostResolverImplTest* test;
436 }; 436 };
437 437
438 void CreateResolver() { 438 void CreateResolver() {
439 resolver_.reset(new HostResolverImpl( 439 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(),
440 HostCache::CreateDefaultCache(), 440 DefaultLimits(),
441 DefaultLimits(), 441 DefaultParams(proc_.get()),
442 DefaultParams(proc_), 442 NULL));
443 NULL));
444 } 443 }
445 444
446 // This HostResolverImpl will only allow 1 outstanding resolve at a time and 445 // This HostResolverImpl will only allow 1 outstanding resolve at a time and
447 // perform no retries. 446 // perform no retries.
448 void CreateSerialResolver() { 447 void CreateSerialResolver() {
449 HostResolverImpl::ProcTaskParams params = DefaultParams(proc_); 448 HostResolverImpl::ProcTaskParams params = DefaultParams(proc_.get());
450 params.max_retry_attempts = 0u; 449 params.max_retry_attempts = 0u;
451 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); 450 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1);
452 resolver_.reset(new HostResolverImpl( 451 resolver_.reset(new HostResolverImpl(
453 HostCache::CreateDefaultCache(), 452 HostCache::CreateDefaultCache(),
454 limits, 453 limits,
455 params, 454 params,
456 NULL)); 455 NULL));
457 } 456 }
458 457
459 // The Request will not be made until a call to |Resolve()|, and the Job will 458 // The Request will not be made until a call to |Resolve()|, and the Job will
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 if (req->index() == 0) { 773 if (req->index() == 0) {
775 // On completing the first request, start another request for "a". 774 // On completing the first request, start another request for "a".
776 // Since caching is disabled, this will result in another async request. 775 // Since caching is disabled, this will result in another async request.
777 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 70)->Resolve()); 776 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 70)->Resolve());
778 } 777 }
779 } 778 }
780 }; 779 };
781 set_handler(new MyHandler()); 780 set_handler(new MyHandler());
782 781
783 // Turn off caching for this host resolver. 782 // Turn off caching for this host resolver.
784 resolver_.reset(new HostResolverImpl( 783 resolver_.reset(new HostResolverImpl(scoped_ptr<HostCache>(),
785 scoped_ptr<HostCache>(), 784 DefaultLimits(),
786 DefaultLimits(), 785 DefaultParams(proc_.get()),
787 DefaultParams(proc_), 786 NULL));
788 NULL));
789 787
790 for (size_t i = 0; i < 4; ++i) { 788 for (size_t i = 0; i < 4; ++i) {
791 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; 789 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i;
792 } 790 }
793 791
794 proc_->SignalMultiple(2u); // One for "a". One for the second "a". 792 proc_->SignalMultiple(2u); // One for "a". One for the second "a".
795 793
796 EXPECT_EQ(OK, requests_[0]->WaitForResult()); 794 EXPECT_EQ(OK, requests_[0]->WaitForResult());
797 ASSERT_EQ(5u, requests_.size()); 795 ASSERT_EQ(5u, requests_.size());
798 EXPECT_EQ(OK, requests_.back()->WaitForResult()); 796 EXPECT_EQ(OK, requests_.back()->WaitForResult());
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 AddDnsRule("4ok", dns_protocol::kTypeA, MockDnsClientRule::OK); 1261 AddDnsRule("4ok", dns_protocol::kTypeA, MockDnsClientRule::OK);
1264 AddDnsRule("4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY); 1262 AddDnsRule("4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY);
1265 AddDnsRule("6ok", dns_protocol::kTypeA, MockDnsClientRule::EMPTY); 1263 AddDnsRule("6ok", dns_protocol::kTypeA, MockDnsClientRule::EMPTY);
1266 AddDnsRule("6ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK); 1264 AddDnsRule("6ok", dns_protocol::kTypeAAAA, MockDnsClientRule::OK);
1267 AddDnsRule("4nx", dns_protocol::kTypeA, MockDnsClientRule::OK); 1265 AddDnsRule("4nx", dns_protocol::kTypeA, MockDnsClientRule::OK);
1268 AddDnsRule("4nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL_ASYNC); 1266 AddDnsRule("4nx", dns_protocol::kTypeAAAA, MockDnsClientRule::FAIL_ASYNC);
1269 CreateResolver(); 1267 CreateResolver();
1270 } 1268 }
1271 1269
1272 void CreateResolver() { 1270 void CreateResolver() {
1273 resolver_.reset(new HostResolverImpl( 1271 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(),
1274 HostCache::CreateDefaultCache(), 1272 DefaultLimits(),
1275 DefaultLimits(), 1273 DefaultParams(proc_.get()),
1276 DefaultParams(proc_), 1274 NULL));
1277 NULL));
1278 resolver_->SetDnsClient(CreateMockDnsClient(DnsConfig(), dns_rules_)); 1275 resolver_->SetDnsClient(CreateMockDnsClient(DnsConfig(), dns_rules_));
1279 } 1276 }
1280 1277
1281 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply. 1278 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply.
1282 void AddDnsRule(const std::string& prefix, 1279 void AddDnsRule(const std::string& prefix,
1283 uint16 qtype, 1280 uint16 qtype,
1284 MockDnsClientRule::Result result) { 1281 MockDnsClientRule::Result result) {
1285 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result)); 1282 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result));
1286 } 1283 }
1287 1284
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 } 1504 }
1508 1505
1509 // Confirm that resolving "localhost" is unrestricted even if there are no 1506 // Confirm that resolving "localhost" is unrestricted even if there are no
1510 // global IPv6 address. See SystemHostResolverCall for rationale. 1507 // global IPv6 address. See SystemHostResolverCall for rationale.
1511 // Test both the DnsClient and system host resolver paths. 1508 // Test both the DnsClient and system host resolver paths.
1512 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) { 1509 TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) {
1513 // Use regular SystemHostResolverCall! 1510 // Use regular SystemHostResolverCall!
1514 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc()); 1511 scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc());
1515 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), 1512 resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(),
1516 DefaultLimits(), 1513 DefaultLimits(),
1517 DefaultParams(proc), 1514 DefaultParams(proc.get()),
1518 NULL)); 1515 NULL));
1519 resolver_->SetDnsClient(CreateMockDnsClient(DnsConfig(), dns_rules_)); 1516 resolver_->SetDnsClient(CreateMockDnsClient(DnsConfig(), dns_rules_));
1520 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); 1517 resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4);
1521 1518
1522 // Get the expected output. 1519 // Get the expected output.
1523 AddressList addrlist; 1520 AddressList addrlist;
1524 int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist, 1521 int rv = proc->Resolve("localhost", ADDRESS_FAMILY_UNSPECIFIED, 0, &addrlist,
1525 NULL); 1522 NULL);
1526 if (rv != OK) 1523 if (rv != OK)
1527 return; 1524 return;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 ChangeDnsConfig(config); 1560 ChangeDnsConfig(config);
1564 req = CreateRequest(info); 1561 req = CreateRequest(info);
1565 // Expect synchronous resolution from DnsHosts. 1562 // Expect synchronous resolution from DnsHosts.
1566 EXPECT_EQ(OK, req->Resolve()); 1563 EXPECT_EQ(OK, req->Resolve());
1567 1564
1568 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80)); 1565 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80));
1569 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80)); 1566 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80));
1570 } 1567 }
1571 1568
1572 } // namespace net 1569 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | net/dns/host_resolver_proc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698