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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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/host_resolver_mojo.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/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 #include <tuple> 9 #include <tuple>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
18 #include "base/run_loop.h" 19 #include "base/run_loop.h"
19 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
22 #include "base/synchronization/condition_variable.h" 23 #include "base/synchronization/condition_variable.h"
23 #include "base/synchronization/lock.h" 24 #include "base/synchronization/lock.h"
24 #include "base/test/test_timeouts.h" 25 #include "base/test/test_timeouts.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 std::map<ResolveKey, AddressList> rules_; 180 std::map<ResolveKey, AddressList> rules_;
180 CaptureList capture_list_; 181 CaptureList capture_list_;
181 unsigned num_requests_waiting_; 182 unsigned num_requests_waiting_;
182 unsigned num_slots_available_; 183 unsigned num_slots_available_;
183 base::ConditionVariable requests_waiting_; 184 base::ConditionVariable requests_waiting_;
184 base::ConditionVariable slots_available_; 185 base::ConditionVariable slots_available_;
185 186
186 DISALLOW_COPY_AND_ASSIGN(MockHostResolverProc); 187 DISALLOW_COPY_AND_ASSIGN(MockHostResolverProc);
187 }; 188 };
188 189
189 bool AddressListContains(const AddressList& list, const std::string& address, 190 bool AddressListContains(const AddressList& list,
190 uint16 port) { 191 const std::string& address,
192 uint16_t port) {
191 IPAddressNumber ip; 193 IPAddressNumber ip;
192 bool rv = ParseIPLiteralToNumber(address, &ip); 194 bool rv = ParseIPLiteralToNumber(address, &ip);
193 DCHECK(rv); 195 DCHECK(rv);
194 return std::find(list.begin(), 196 return std::find(list.begin(),
195 list.end(), 197 list.end(),
196 IPEndPoint(ip, port)) != list.end(); 198 IPEndPoint(ip, port)) != list.end();
197 } 199 }
198 200
199 // A wrapper for requests to a HostResolver. 201 // A wrapper for requests to a HostResolver.
200 class Request { 202 class Request {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 handle_ = NULL; 250 handle_ = NULL;
249 } 251 }
250 252
251 const HostResolver::RequestInfo& info() const { return info_; } 253 const HostResolver::RequestInfo& info() const { return info_; }
252 size_t index() const { return index_; } 254 size_t index() const { return index_; }
253 const AddressList& list() const { return list_; } 255 const AddressList& list() const { return list_; }
254 int result() const { return result_; } 256 int result() const { return result_; }
255 bool completed() const { return result_ != ERR_IO_PENDING; } 257 bool completed() const { return result_ != ERR_IO_PENDING; }
256 bool pending() const { return handle_ != NULL; } 258 bool pending() const { return handle_ != NULL; }
257 259
258 bool HasAddress(const std::string& address, uint16 port) const { 260 bool HasAddress(const std::string& address, uint16_t port) const {
259 return AddressListContains(list_, address, port); 261 return AddressListContains(list_, address, port);
260 } 262 }
261 263
262 // Returns the number of addresses in |list_|. 264 // Returns the number of addresses in |list_|.
263 unsigned NumberOfAddresses() const { 265 unsigned NumberOfAddresses() const {
264 return list_.size(); 266 return list_.size();
265 } 267 }
266 268
267 bool HasOneAddress(const std::string& address, uint16 port) const { 269 bool HasOneAddress(const std::string& address, uint16_t port) const {
268 return HasAddress(address, port) && (NumberOfAddresses() == 1u); 270 return HasAddress(address, port) && (NumberOfAddresses() == 1u);
269 } 271 }
270 272
271 // Returns ERR_UNEXPECTED if timed out. 273 // Returns ERR_UNEXPECTED if timed out.
272 int WaitForResult() { 274 int WaitForResult() {
273 if (completed()) 275 if (completed())
274 return result_; 276 return result_;
275 base::CancelableClosure closure(base::MessageLoop::QuitWhenIdleClosure()); 277 base::CancelableClosure closure(base::MessageLoop::QuitWhenIdleClosure());
276 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 278 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
277 FROM_HERE, closure.callback(), TestTimeouts::action_max_timeout()); 279 FROM_HERE, closure.callback(), TestTimeouts::action_max_timeout());
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 HostResolverImpl::Options options = DefaultOptions(); 1469 HostResolverImpl::Options options = DefaultOptions();
1468 options.max_concurrent_resolves = max_concurrent_resolves; 1470 options.max_concurrent_resolves = max_concurrent_resolves;
1469 resolver_.reset(new TestHostResolverImpl(options, NULL)); 1471 resolver_.reset(new TestHostResolverImpl(options, NULL));
1470 resolver_->set_proc_params_for_test(params); 1472 resolver_->set_proc_params_for_test(params);
1471 dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_); 1473 dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_);
1472 resolver_->SetDnsClient(scoped_ptr<DnsClient>(dns_client_)); 1474 resolver_->SetDnsClient(scoped_ptr<DnsClient>(dns_client_));
1473 } 1475 }
1474 1476
1475 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply. 1477 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply.
1476 void AddDnsRule(const std::string& prefix, 1478 void AddDnsRule(const std::string& prefix,
1477 uint16 qtype, 1479 uint16_t qtype,
1478 MockDnsClientRule::Result result, 1480 MockDnsClientRule::Result result,
1479 bool delay) { 1481 bool delay) {
1480 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result, delay)); 1482 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result, delay));
1481 } 1483 }
1482 1484
1483 void ChangeDnsConfig(const DnsConfig& config) { 1485 void ChangeDnsConfig(const DnsConfig& config) {
1484 NetworkChangeNotifier::SetDnsConfig(config); 1486 NetworkChangeNotifier::SetDnsConfig(config);
1485 // Notification is delivered asynchronously. 1487 // Notification is delivered asynchronously.
1486 base::MessageLoop::current()->RunUntilIdle(); 1488 base::MessageLoop::current()->RunUntilIdle();
1487 } 1489 }
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
2170 2172
2171 EXPECT_EQ(OK, requests_[0]->WaitForResult()); 2173 EXPECT_EQ(OK, requests_[0]->WaitForResult());
2172 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); 2174 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80));
2173 EXPECT_EQ(OK, requests_[1]->WaitForResult()); 2175 EXPECT_EQ(OK, requests_[1]->WaitForResult());
2174 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); 2176 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80));
2175 EXPECT_EQ(OK, requests_[2]->WaitForResult()); 2177 EXPECT_EQ(OK, requests_[2]->WaitForResult());
2176 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); 2178 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80));
2177 } 2179 }
2178 2180
2179 } // namespace net 2181 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | net/dns/host_resolver_mojo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698