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

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

Issue 1593015: HostResolver supports optional CNAME lookups. (Closed)
Patch Set: Addressing wtc's nits. Created 10 years, 8 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 explicit CapturingHostResolverProc(HostResolverProc* previous) 83 explicit CapturingHostResolverProc(HostResolverProc* previous)
84 : HostResolverProc(previous), event_(true, false) { 84 : HostResolverProc(previous), event_(true, false) {
85 } 85 }
86 86
87 void Signal() { 87 void Signal() {
88 event_.Signal(); 88 event_.Signal();
89 } 89 }
90 90
91 virtual int Resolve(const std::string& hostname, 91 virtual int Resolve(const std::string& hostname,
92 AddressFamily address_family, 92 AddressFamily address_family,
93 HostResolverFlags host_resolver_flags,
93 AddressList* addrlist) { 94 AddressList* addrlist) {
94 event_.Wait(); 95 event_.Wait();
95 { 96 {
96 AutoLock l(lock_); 97 AutoLock l(lock_);
97 capture_list_.push_back(CaptureEntry(hostname, address_family)); 98 capture_list_.push_back(CaptureEntry(hostname, address_family));
98 } 99 }
99 return ResolveUsingPrevious(hostname, address_family, addrlist); 100 return ResolveUsingPrevious(hostname, address_family,
101 host_resolver_flags, addrlist);
100 } 102 }
101 103
102 CaptureList GetCaptureList() const { 104 CaptureList GetCaptureList() const {
103 CaptureList copy; 105 CaptureList copy;
104 { 106 {
105 AutoLock l(lock_); 107 AutoLock l(lock_);
106 copy = capture_list_; 108 copy = capture_list_;
107 } 109 }
108 return copy; 110 return copy;
109 } 111 }
(...skipping 17 matching lines...) Expand all
127 // x = length of hostname 129 // x = length of hostname
128 // y = ASCII value of hostname[0] 130 // y = ASCII value of hostname[0]
129 // z = value of address_family 131 // z = value of address_family
130 // 132 //
131 class EchoingHostResolverProc : public HostResolverProc { 133 class EchoingHostResolverProc : public HostResolverProc {
132 public: 134 public:
133 EchoingHostResolverProc() : HostResolverProc(NULL) {} 135 EchoingHostResolverProc() : HostResolverProc(NULL) {}
134 136
135 virtual int Resolve(const std::string& hostname, 137 virtual int Resolve(const std::string& hostname,
136 AddressFamily address_family, 138 AddressFamily address_family,
139 HostResolverFlags host_resolver_flags,
137 AddressList* addrlist) { 140 AddressList* addrlist) {
138 // Encode the request's hostname and address_family in the output address. 141 // Encode the request's hostname and address_family in the output address.
139 std::string ip_literal = StringPrintf("192.%d.%d.%d", 142 std::string ip_literal = StringPrintf("192.%d.%d.%d",
140 static_cast<int>(hostname.size()), 143 static_cast<int>(hostname.size()),
141 static_cast<int>(hostname[0]), 144 static_cast<int>(hostname[0]),
142 static_cast<int>(address_family)); 145 static_cast<int>(address_family));
143 146
144 return SystemHostResolverProc(ip_literal, 147 return SystemHostResolverProc(ip_literal,
145 ADDRESS_FAMILY_UNSPECIFIED, 148 ADDRESS_FAMILY_UNSPECIFIED,
149 host_resolver_flags,
146 addrlist); 150 addrlist);
147 } 151 }
148 }; 152 };
149 153
150 // Helper that represents a single Resolve() result, used to inspect all the 154 // Helper that represents a single Resolve() result, used to inspect all the
151 // resolve results by forwarding them to Delegate. 155 // resolve results by forwarding them to Delegate.
152 class ResolveRequest { 156 class ResolveRequest {
153 public: 157 public:
154 // Delegate interface, for notification when the ResolveRequest completes. 158 // Delegate interface, for notification when the ResolveRequest completes.
155 class Delegate { 159 class Delegate {
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 // Addresses take the form: 192.x.y.z 1488 // Addresses take the form: 192.x.y.z
1485 // x = length of hostname 1489 // x = length of hostname
1486 // y = ASCII value of hostname[0] 1490 // y = ASCII value of hostname[0]
1487 // z = value of address family 1491 // z = value of address family
1488 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[0].head())); 1492 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[0].head()));
1489 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); 1493 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head()));
1490 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); 1494 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head()));
1491 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); 1495 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head()));
1492 } 1496 }
1493 1497
1498 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags.
1499
1494 } // namespace 1500 } // namespace
1495 1501
1496 } // namespace net 1502 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698