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

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

Issue 10831277: [net] Change factory methods for HostResolver and HostCache to return a scoped_ptr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unnecessary initialization; respond to review Created 8 years, 2 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/base/host_resolver_impl.cc ('k') | net/base/mapped_host_resolver.h » ('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/base/host_resolver_impl.h" 5 #include "net/base/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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 void DeleteResolver() { test->resolver_.reset(); } 428 void DeleteResolver() { test->resolver_.reset(); }
429 429
430 HostResolverImplTest* test; 430 HostResolverImplTest* test;
431 }; 431 };
432 432
433 void CreateResolver() { 433 void CreateResolver() {
434 resolver_.reset(new HostResolverImpl( 434 resolver_.reset(new HostResolverImpl(
435 HostCache::CreateDefaultCache(), 435 HostCache::CreateDefaultCache(),
436 DefaultLimits(), 436 DefaultLimits(),
437 DefaultParams(proc_), 437 DefaultParams(proc_),
438 scoped_ptr<DnsClient>(NULL), 438 scoped_ptr<DnsClient>(),
439 NULL)); 439 NULL));
440 } 440 }
441 441
442 // This HostResolverImpl will only allow 1 outstanding resolve at a time and 442 // This HostResolverImpl will only allow 1 outstanding resolve at a time and
443 // perform no retries. 443 // perform no retries.
444 void CreateSerialResolver() { 444 void CreateSerialResolver() {
445 HostResolverImpl::ProcTaskParams params = DefaultParams(proc_); 445 HostResolverImpl::ProcTaskParams params = DefaultParams(proc_);
446 params.max_retry_attempts = 0u; 446 params.max_retry_attempts = 0u;
447 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); 447 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1);
448 resolver_.reset(new HostResolverImpl( 448 resolver_.reset(new HostResolverImpl(
449 HostCache::CreateDefaultCache(), 449 HostCache::CreateDefaultCache(),
450 limits, 450 limits,
451 params, 451 params,
452 scoped_ptr<DnsClient>(NULL), 452 scoped_ptr<DnsClient>(),
453 NULL)); 453 NULL));
454 } 454 }
455 455
456 // The Request will not be made until a call to |Resolve()|, and the Job will 456 // The Request will not be made until a call to |Resolve()|, and the Job will
457 // not start until released by |proc_->SignalXXX|. 457 // not start until released by |proc_->SignalXXX|.
458 Request* CreateRequest(const HostResolver::RequestInfo& info) { 458 Request* CreateRequest(const HostResolver::RequestInfo& info) {
459 Request* req = new Request(info, requests_.size(), resolver_.get(), 459 Request* req = new Request(info, requests_.size(), resolver_.get(),
460 handler_.get()); 460 handler_.get());
461 requests_.push_back(req); 461 requests_.push_back(req);
462 return req; 462 return req;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 // On completing the first request, start another request for "a". 751 // On completing the first request, start another request for "a".
752 // Since caching is disabled, this will result in another async request. 752 // Since caching is disabled, this will result in another async request.
753 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 70)->Resolve()); 753 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 70)->Resolve());
754 } 754 }
755 } 755 }
756 }; 756 };
757 set_handler(new MyHandler()); 757 set_handler(new MyHandler());
758 758
759 // Turn off caching for this host resolver. 759 // Turn off caching for this host resolver.
760 resolver_.reset(new HostResolverImpl( 760 resolver_.reset(new HostResolverImpl(
761 NULL, 761 scoped_ptr<HostCache>(),
762 DefaultLimits(), 762 DefaultLimits(),
763 DefaultParams(proc_), 763 DefaultParams(proc_),
764 scoped_ptr<DnsClient>(NULL), 764 scoped_ptr<DnsClient>(),
765 NULL)); 765 NULL));
766 766
767 for (size_t i = 0; i < 4; ++i) { 767 for (size_t i = 0; i < 4; ++i) {
768 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; 768 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i;
769 } 769 }
770 770
771 proc_->SignalMultiple(2u); // One for "a". One for the second "a". 771 proc_->SignalMultiple(2u); // One for "a". One for the second "a".
772 772
773 EXPECT_EQ(OK, requests_[0]->WaitForResult()); 773 EXPECT_EQ(OK, requests_[0]->WaitForResult());
774 ASSERT_EQ(5u, requests_.size()); 774 ASSERT_EQ(5u, requests_.size());
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 1191
1192 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so 1192 // Specify smaller interval for unresponsive_delay_ for HostResolverImpl so
1193 // that unit test runs faster. For example, this test finishes in 1.5 secs 1193 // that unit test runs faster. For example, this test finishes in 1.5 secs
1194 // (500ms * 3). 1194 // (500ms * 3).
1195 params.unresponsive_delay = base::TimeDelta::FromMilliseconds(500); 1195 params.unresponsive_delay = base::TimeDelta::FromMilliseconds(500);
1196 1196
1197 resolver_.reset( 1197 resolver_.reset(
1198 new HostResolverImpl(HostCache::CreateDefaultCache(), 1198 new HostResolverImpl(HostCache::CreateDefaultCache(),
1199 DefaultLimits(), 1199 DefaultLimits(),
1200 params, 1200 params,
1201 scoped_ptr<DnsClient>(NULL), 1201 scoped_ptr<DnsClient>(),
1202 NULL)); 1202 NULL));
1203 1203
1204 // Resolve "host1". 1204 // Resolve "host1".
1205 HostResolver::RequestInfo info(HostPortPair("host1", 70)); 1205 HostResolver::RequestInfo info(HostPortPair("host1", 70));
1206 Request* req = CreateRequest(info); 1206 Request* req = CreateRequest(info);
1207 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); 1207 EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
1208 1208
1209 // Resolve returns -4 to indicate that 3rd attempt has resolved the host. 1209 // Resolve returns -4 to indicate that 3rd attempt has resolved the host.
1210 EXPECT_EQ(-4, req->WaitForResult()); 1210 EXPECT_EQ(-4, req->WaitForResult());
1211 1211
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 proc_->SignalMultiple(requests_.size()); 1410 proc_->SignalMultiple(requests_.size());
1411 1411
1412 for (size_t i = 0; i < 2; ++i) 1412 for (size_t i = 0; i < 2; ++i)
1413 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[i]->WaitForResult()) << i; 1413 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, requests_[i]->WaitForResult()) << i;
1414 1414
1415 for (size_t i = 2; i < requests_.size(); ++i) 1415 for (size_t i = 2; i < requests_.size(); ++i)
1416 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i; 1416 EXPECT_EQ(OK, requests_[i]->WaitForResult()) << i;
1417 } 1417 }
1418 1418
1419 } // namespace net 1419 } // namespace net
OLDNEW
« no previous file with comments | « net/base/host_resolver_impl.cc ('k') | net/base/mapped_host_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698