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

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

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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/dns/host_resolver_impl.cc ('k') | net/dns/mock_host_resolver.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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 CaptureList capture_list_; 174 CaptureList capture_list_;
175 unsigned num_requests_waiting_; 175 unsigned num_requests_waiting_;
176 unsigned num_slots_available_; 176 unsigned num_slots_available_;
177 base::ConditionVariable requests_waiting_; 177 base::ConditionVariable requests_waiting_;
178 base::ConditionVariable slots_available_; 178 base::ConditionVariable slots_available_;
179 179
180 DISALLOW_COPY_AND_ASSIGN(MockHostResolverProc); 180 DISALLOW_COPY_AND_ASSIGN(MockHostResolverProc);
181 }; 181 };
182 182
183 bool AddressListContains(const AddressList& list, const std::string& address, 183 bool AddressListContains(const AddressList& list, const std::string& address,
184 int port) { 184 uint16 port) {
185 IPAddressNumber ip; 185 IPAddressNumber ip;
186 bool rv = ParseIPLiteralToNumber(address, &ip); 186 bool rv = ParseIPLiteralToNumber(address, &ip);
187 DCHECK(rv); 187 DCHECK(rv);
188 return std::find(list.begin(), 188 return std::find(list.begin(),
189 list.end(), 189 list.end(),
190 IPEndPoint(ip, port)) != list.end(); 190 IPEndPoint(ip, port)) != list.end();
191 } 191 }
192 192
193 // A wrapper for requests to a HostResolver. 193 // A wrapper for requests to a HostResolver.
194 class Request { 194 class Request {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 handle_ = NULL; 242 handle_ = NULL;
243 } 243 }
244 244
245 const HostResolver::RequestInfo& info() const { return info_; } 245 const HostResolver::RequestInfo& info() const { return info_; }
246 size_t index() const { return index_; } 246 size_t index() const { return index_; }
247 const AddressList& list() const { return list_; } 247 const AddressList& list() const { return list_; }
248 int result() const { return result_; } 248 int result() const { return result_; }
249 bool completed() const { return result_ != ERR_IO_PENDING; } 249 bool completed() const { return result_ != ERR_IO_PENDING; }
250 bool pending() const { return handle_ != NULL; } 250 bool pending() const { return handle_ != NULL; }
251 251
252 bool HasAddress(const std::string& address, int port) const { 252 bool HasAddress(const std::string& address, uint16 port) const {
253 return AddressListContains(list_, address, port); 253 return AddressListContains(list_, address, port);
254 } 254 }
255 255
256 // Returns the number of addresses in |list_|. 256 // Returns the number of addresses in |list_|.
257 unsigned NumberOfAddresses() const { 257 unsigned NumberOfAddresses() const {
258 return list_.size(); 258 return list_.size();
259 } 259 }
260 260
261 bool HasOneAddress(const std::string& address, int port) const { 261 bool HasOneAddress(const std::string& address, uint16 port) const {
262 return HasAddress(address, port) && (NumberOfAddresses() == 1u); 262 return HasAddress(address, port) && (NumberOfAddresses() == 1u);
263 } 263 }
264 264
265 // Returns ERR_UNEXPECTED if timed out. 265 // Returns ERR_UNEXPECTED if timed out.
266 int WaitForResult() { 266 int WaitForResult() {
267 if (completed()) 267 if (completed())
268 return result_; 268 return result_;
269 base::CancelableClosure closure(base::MessageLoop::QuitClosure()); 269 base::CancelableClosure closure(base::MessageLoop::QuitClosure());
270 base::MessageLoop::current()->PostDelayedTask( 270 base::MessageLoop::current()->PostDelayedTask(
271 FROM_HERE, closure.callback(), TestTimeouts::action_max_timeout()); 271 FROM_HERE, closure.callback(), TestTimeouts::action_max_timeout());
(...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 2096
2097 EXPECT_EQ(OK, requests_[0]->WaitForResult()); 2097 EXPECT_EQ(OK, requests_[0]->WaitForResult());
2098 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); 2098 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80));
2099 EXPECT_EQ(OK, requests_[1]->WaitForResult()); 2099 EXPECT_EQ(OK, requests_[1]->WaitForResult());
2100 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); 2100 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80));
2101 EXPECT_EQ(OK, requests_[2]->WaitForResult()); 2101 EXPECT_EQ(OK, requests_[2]->WaitForResult());
2102 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); 2102 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80));
2103 } 2103 }
2104 2104
2105 } // namespace net 2105 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | net/dns/mock_host_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698