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

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

Issue 2116983002: Change HostResolver::Resolve() to take an std::unique_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 size_t index, 218 size_t index,
219 HostResolverImpl* resolver, 219 HostResolverImpl* resolver,
220 Handler* handler) 220 Handler* handler)
221 : info_(info), 221 : info_(info),
222 priority_(priority), 222 priority_(priority),
223 index_(index), 223 index_(index),
224 resolver_(resolver), 224 resolver_(resolver),
225 handler_(handler), 225 handler_(handler),
226 quit_on_complete_(false), 226 quit_on_complete_(false),
227 result_(ERR_UNEXPECTED), 227 result_(ERR_UNEXPECTED),
228 handle_(NULL) {} 228 handle_(nullptr) {}
229 229
230 int Resolve() { 230 int Resolve() {
231 DCHECK(resolver_); 231 DCHECK(resolver_);
232 DCHECK(!handle_); 232 DCHECK(!handle_);
233 list_ = AddressList(); 233 list_ = AddressList();
234 result_ = resolver_->Resolve( 234 result_ = resolver_->Resolve(
235 info_, 235 info_,
236 priority_, 236 priority_,
237 &list_, 237 &list_,
238 base::Bind(&Request::OnComplete, base::Unretained(this)), 238 base::Bind(&Request::OnComplete, base::Unretained(this)),
(...skipping 13 matching lines...) Expand all
252 int ResolveStaleFromCache() { 252 int ResolveStaleFromCache() {
253 DCHECK(resolver_); 253 DCHECK(resolver_);
254 DCHECK(!handle_); 254 DCHECK(!handle_);
255 return resolver_->ResolveStaleFromCache(info_, &list_, &staleness_, 255 return resolver_->ResolveStaleFromCache(info_, &list_, &staleness_,
256 BoundNetLog()); 256 BoundNetLog());
257 } 257 }
258 258
259 void ChangePriority(RequestPriority priority) { 259 void ChangePriority(RequestPriority priority) {
260 DCHECK(resolver_); 260 DCHECK(resolver_);
261 DCHECK(handle_); 261 DCHECK(handle_);
262 resolver_->ChangeRequestPriority(handle_, priority); 262 handle_->ChangeRequestPriority(priority);
263 priority_ = priority; 263 priority_ = priority;
264 } 264 }
265 265
266 void Cancel() { 266 void Cancel() {
267 DCHECK(resolver_); 267 DCHECK(resolver_);
268 DCHECK(handle_); 268 DCHECK(handle_);
269 resolver_->CancelRequest(handle_); 269 handle_.reset();
270 handle_ = NULL;
271 } 270 }
272 271
273 const HostResolver::RequestInfo& info() const { return info_; } 272 const HostResolver::RequestInfo& info() const { return info_; }
274 size_t index() const { return index_; } 273 size_t index() const { return index_; }
275 const AddressList& list() const { return list_; } 274 const AddressList& list() const { return list_; }
276 int result() const { return result_; } 275 int result() const { return result_; }
277 const HostCache::EntryStaleness staleness() const { return staleness_; } 276 const HostCache::EntryStaleness staleness() const { return staleness_; }
278 bool completed() const { return result_ != ERR_IO_PENDING; } 277 bool completed() const { return result_ != ERR_IO_PENDING; }
279 bool pending() const { return handle_ != NULL; } 278 bool pending() const { return handle_ != NULL; }
280 279
(...skipping 27 matching lines...) Expand all
308 else 307 else
309 return ERR_UNEXPECTED; 308 return ERR_UNEXPECTED;
310 } 309 }
311 310
312 private: 311 private:
313 void OnComplete(int rv) { 312 void OnComplete(int rv) {
314 EXPECT_TRUE(pending()); 313 EXPECT_TRUE(pending());
315 EXPECT_THAT(result_, IsError(ERR_IO_PENDING)); 314 EXPECT_THAT(result_, IsError(ERR_IO_PENDING));
316 EXPECT_NE(ERR_IO_PENDING, rv); 315 EXPECT_NE(ERR_IO_PENDING, rv);
317 result_ = rv; 316 result_ = rv;
318 handle_ = NULL; 317 handle_.reset();
319 if (!list_.empty()) { 318 if (!list_.empty()) {
320 EXPECT_THAT(result_, IsOk()); 319 EXPECT_THAT(result_, IsOk());
321 EXPECT_EQ(info_.port(), list_.front().port()); 320 EXPECT_EQ(info_.port(), list_.front().port());
322 } 321 }
323 if (handler_) 322 if (handler_)
324 handler_->Handle(this); 323 handler_->Handle(this);
325 if (quit_on_complete_) { 324 if (quit_on_complete_) {
326 base::MessageLoop::current()->QuitWhenIdle(); 325 base::MessageLoop::current()->QuitWhenIdle();
327 quit_on_complete_ = false; 326 quit_on_complete_ = false;
328 } 327 }
329 } 328 }
330 329
331 HostResolver::RequestInfo info_; 330 HostResolver::RequestInfo info_;
332 RequestPriority priority_; 331 RequestPriority priority_;
333 size_t index_; 332 size_t index_;
334 HostResolverImpl* resolver_; 333 HostResolverImpl* resolver_;
335 Handler* handler_; 334 Handler* handler_;
336 bool quit_on_complete_; 335 bool quit_on_complete_;
337 336
338 AddressList list_; 337 AddressList list_;
339 int result_; 338 int result_;
340 HostResolver::RequestHandle handle_; 339 std::unique_ptr<HostResolver::Request> handle_;
341 HostCache::EntryStaleness staleness_; 340 HostCache::EntryStaleness staleness_;
342 341
343 DISALLOW_COPY_AND_ASSIGN(Request); 342 DISALLOW_COPY_AND_ASSIGN(Request);
344 }; 343 };
345 344
346 // Using LookupAttemptHostResolverProc simulate very long lookups, and control 345 // Using LookupAttemptHostResolverProc simulate very long lookups, and control
347 // which attempt resolves the host. 346 // which attempt resolves the host.
348 class LookupAttemptHostResolverProc : public HostResolverProc { 347 class LookupAttemptHostResolverProc : public HostResolverProc {
349 public: 348 public:
350 LookupAttemptHostResolverProc(HostResolverProc* previous, 349 LookupAttemptHostResolverProc(HostResolverProc* previous,
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 632
634 TEST_F(HostResolverImplTest, AsynchronousLookup) { 633 TEST_F(HostResolverImplTest, AsynchronousLookup) {
635 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42"); 634 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42");
636 proc_->SignalMultiple(1u); 635 proc_->SignalMultiple(1u);
637 636
638 Request* req = CreateRequest("just.testing", 80); 637 Request* req = CreateRequest("just.testing", 80);
639 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING)); 638 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING));
640 EXPECT_THAT(req->WaitForResult(), IsOk()); 639 EXPECT_THAT(req->WaitForResult(), IsOk());
641 640
642 EXPECT_TRUE(req->HasOneAddress("192.168.1.42", 80)); 641 EXPECT_TRUE(req->HasOneAddress("192.168.1.42", 80));
643
644 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname); 642 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname);
645 } 643 }
646 644
647 // RFC 6761 localhost names should always resolve to loopback. 645 // RFC 6761 localhost names should always resolve to loopback.
648 TEST_F(HostResolverImplTest, LocalhostLookup) { 646 TEST_F(HostResolverImplTest, LocalhostLookup) {
649 // Add a rule resolving localhost names to a non-loopback IP and test 647 // Add a rule resolving localhost names to a non-loopback IP and test
650 // that they still resolves to loopback. 648 // that they still resolves to loopback.
651 proc_->AddRuleForAllFamilies("foo.localhost", "192.168.1.42"); 649 proc_->AddRuleForAllFamilies("foo.localhost", "192.168.1.42");
652 proc_->AddRuleForAllFamilies("localhost", "192.168.1.42"); 650 proc_->AddRuleForAllFamilies("localhost", "192.168.1.42");
653 proc_->AddRuleForAllFamilies("localhost.", "192.168.1.42"); 651 proc_->AddRuleForAllFamilies("localhost.", "192.168.1.42");
(...skipping 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 EXPECT_FALSE(ResolveLocalHostname("::1:1", kLocalhostLookupPort, &addresses)); 2396 EXPECT_FALSE(ResolveLocalHostname("::1:1", kLocalhostLookupPort, &addresses));
2399 EXPECT_FALSE(ResolveLocalHostname("0:0:0:0:0:0:0:0:1", kLocalhostLookupPort, 2397 EXPECT_FALSE(ResolveLocalHostname("0:0:0:0:0:0:0:0:1", kLocalhostLookupPort,
2400 &addresses)); 2398 &addresses));
2401 EXPECT_FALSE(ResolveLocalHostname("foo.localhost.com", kLocalhostLookupPort, 2399 EXPECT_FALSE(ResolveLocalHostname("foo.localhost.com", kLocalhostLookupPort,
2402 &addresses)); 2400 &addresses));
2403 EXPECT_FALSE( 2401 EXPECT_FALSE(
2404 ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses)); 2402 ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses));
2405 } 2403 }
2406 2404
2407 } // namespace net 2405 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698