| OLD | NEW |
| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 EXPECT_EQ(OK, result_); | 237 EXPECT_EQ(OK, result_); |
| 238 return result_; | 238 return result_; |
| 239 } | 239 } |
| 240 | 240 |
| 241 int ResolveFromCache() { | 241 int ResolveFromCache() { |
| 242 DCHECK(resolver_); | 242 DCHECK(resolver_); |
| 243 DCHECK(!handle_); | 243 DCHECK(!handle_); |
| 244 return resolver_->ResolveFromCache(info_, &list_, BoundNetLog()); | 244 return resolver_->ResolveFromCache(info_, &list_, BoundNetLog()); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void ChangePriority(RequestPriority priority) { |
| 248 DCHECK(resolver_); |
| 249 DCHECK(handle_); |
| 250 resolver_->ChangeRequestPriority(handle_, priority); |
| 251 priority_ = priority; |
| 252 } |
| 253 |
| 247 void Cancel() { | 254 void Cancel() { |
| 248 DCHECK(resolver_); | 255 DCHECK(resolver_); |
| 249 DCHECK(handle_); | 256 DCHECK(handle_); |
| 250 resolver_->CancelRequest(handle_); | 257 resolver_->CancelRequest(handle_); |
| 251 handle_ = NULL; | 258 handle_ = NULL; |
| 252 } | 259 } |
| 253 | 260 |
| 254 const HostResolver::RequestInfo& info() const { return info_; } | 261 const HostResolver::RequestInfo& info() const { return info_; } |
| 255 size_t index() const { return index_; } | 262 size_t index() const { return index_; } |
| 256 const AddressList& list() const { return list_; } | 263 const AddressList& list() const { return list_; } |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 | 1191 |
| 1185 EXPECT_EQ("req0", capture_list[0].hostname); | 1192 EXPECT_EQ("req0", capture_list[0].hostname); |
| 1186 EXPECT_EQ("req4", capture_list[1].hostname); | 1193 EXPECT_EQ("req4", capture_list[1].hostname); |
| 1187 EXPECT_EQ("req5", capture_list[2].hostname); | 1194 EXPECT_EQ("req5", capture_list[2].hostname); |
| 1188 EXPECT_EQ("req1", capture_list[3].hostname); | 1195 EXPECT_EQ("req1", capture_list[3].hostname); |
| 1189 EXPECT_EQ("req2", capture_list[4].hostname); | 1196 EXPECT_EQ("req2", capture_list[4].hostname); |
| 1190 EXPECT_EQ("req3", capture_list[5].hostname); | 1197 EXPECT_EQ("req3", capture_list[5].hostname); |
| 1191 EXPECT_EQ("req6", capture_list[6].hostname); | 1198 EXPECT_EQ("req6", capture_list[6].hostname); |
| 1192 } | 1199 } |
| 1193 | 1200 |
| 1201 // Test that changing a job's priority affects the dequeueing order. |
| 1202 TEST_F(HostResolverImplTest, ChangePriority) { |
| 1203 CreateSerialResolver(); |
| 1204 |
| 1205 CreateRequest("req0", 80, MEDIUM); |
| 1206 CreateRequest("req1", 80, LOW); |
| 1207 CreateRequest("req2", 80, LOWEST); |
| 1208 |
| 1209 ASSERT_EQ(3u, requests_.size()); |
| 1210 |
| 1211 // req0 starts immediately; without ChangePriority, req1 and then req2 should |
| 1212 // run. |
| 1213 EXPECT_EQ(ERR_IO_PENDING, requests_[0]->Resolve()); |
| 1214 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->Resolve()); |
| 1215 EXPECT_EQ(ERR_IO_PENDING, requests_[2]->Resolve()); |
| 1216 |
| 1217 // Changing req2 to HIGH should make it run before req1. |
| 1218 // (It can't run before req0, since req0 started immediately.) |
| 1219 requests_[2]->ChangePriority(HIGHEST); |
| 1220 |
| 1221 // Let all 3 requests finish. |
| 1222 proc_->SignalMultiple(3u); |
| 1223 |
| 1224 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
| 1225 EXPECT_EQ(OK, requests_[1]->WaitForResult()); |
| 1226 EXPECT_EQ(OK, requests_[2]->WaitForResult()); |
| 1227 |
| 1228 MockHostResolverProc::CaptureList capture_list = proc_->GetCaptureList(); |
| 1229 ASSERT_EQ(3u, capture_list.size()); |
| 1230 |
| 1231 EXPECT_EQ("req0", capture_list[0].hostname); |
| 1232 EXPECT_EQ("req2", capture_list[1].hostname); |
| 1233 EXPECT_EQ("req1", capture_list[2].hostname); |
| 1234 } |
| 1235 |
| 1194 // Try cancelling a job which has not started yet. | 1236 // Try cancelling a job which has not started yet. |
| 1195 TEST_F(HostResolverImplTest, CancelPendingRequest) { | 1237 TEST_F(HostResolverImplTest, CancelPendingRequest) { |
| 1196 CreateSerialResolver(); | 1238 CreateSerialResolver(); |
| 1197 | 1239 |
| 1198 CreateRequest("req0", 80, LOWEST); | 1240 CreateRequest("req0", 80, LOWEST); |
| 1199 CreateRequest("req1", 80, HIGHEST); // Will cancel. | 1241 CreateRequest("req1", 80, HIGHEST); // Will cancel. |
| 1200 CreateRequest("req2", 80, MEDIUM); | 1242 CreateRequest("req2", 80, MEDIUM); |
| 1201 CreateRequest("req3", 80, LOW); | 1243 CreateRequest("req3", 80, LOW); |
| 1202 CreateRequest("req4", 80, HIGHEST); // Will cancel. | 1244 CreateRequest("req4", 80, HIGHEST); // Will cancel. |
| 1203 CreateRequest("req5", 80, LOWEST); // Will cancel. | 1245 CreateRequest("req5", 80, LOWEST); // Will cancel. |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2274 EXPECT_FALSE(ResolveLocalHostname("::1:1", kLocalhostLookupPort, &addresses)); | 2316 EXPECT_FALSE(ResolveLocalHostname("::1:1", kLocalhostLookupPort, &addresses)); |
| 2275 EXPECT_FALSE(ResolveLocalHostname("0:0:0:0:0:0:0:0:1", kLocalhostLookupPort, | 2317 EXPECT_FALSE(ResolveLocalHostname("0:0:0:0:0:0:0:0:1", kLocalhostLookupPort, |
| 2276 &addresses)); | 2318 &addresses)); |
| 2277 EXPECT_FALSE(ResolveLocalHostname("foo.localhost.com", kLocalhostLookupPort, | 2319 EXPECT_FALSE(ResolveLocalHostname("foo.localhost.com", kLocalhostLookupPort, |
| 2278 &addresses)); | 2320 &addresses)); |
| 2279 EXPECT_FALSE( | 2321 EXPECT_FALSE( |
| 2280 ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses)); | 2322 ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses)); |
| 2281 } | 2323 } |
| 2282 | 2324 |
| 2283 } // namespace net | 2325 } // namespace net |
| OLD | NEW |