OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <time.h> | 5 #include <time.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/string_util.h" |
13 #include "base/timer.h" | 14 #include "base/timer.h" |
14 #include "chrome/browser/net/dns_global.h" | 15 #include "chrome/browser/net/dns_global.h" |
15 #include "chrome/browser/net/dns_host_info.h" | 16 #include "chrome/browser/net/dns_host_info.h" |
16 #include "chrome/common/net/dns.h" | 17 #include "chrome/common/net/dns.h" |
17 #include "net/base/address_list.h" | 18 #include "net/base/address_list.h" |
18 #include "net/base/host_resolver.h" | 19 #include "net/base/mock_host_resolver.h" |
19 #include "net/base/host_resolver_unittest.h" | |
20 #include "net/base/winsock_init.h" | 20 #include "net/base/winsock_init.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 using base::Time; | 23 using base::Time; |
24 using base::TimeDelta; | 24 using base::TimeDelta; |
25 | 25 |
26 namespace chrome_browser_net { | 26 namespace chrome_browser_net { |
27 | 27 |
28 class WaitForResolutionHelper; | 28 class WaitForResolutionHelper; |
29 | 29 |
(...skipping 22 matching lines...) Expand all Loading... |
52 | 52 |
53 private: | 53 private: |
54 DnsMaster* master_; | 54 DnsMaster* master_; |
55 const NameList hosts_; | 55 const NameList hosts_; |
56 HelperTimer* timer_; | 56 HelperTimer* timer_; |
57 }; | 57 }; |
58 | 58 |
59 class DnsMasterTest : public testing::Test { | 59 class DnsMasterTest : public testing::Test { |
60 public: | 60 public: |
61 DnsMasterTest() | 61 DnsMasterTest() |
62 : mapper_(new net::RuleBasedHostMapper()), | 62 : host_resolver_(new net::MockHostResolver()), |
63 default_max_queueing_delay_(TimeDelta::FromMilliseconds( | 63 default_max_queueing_delay_(TimeDelta::FromMilliseconds( |
64 DnsPrefetcherInit::kMaxQueueingDelayMs)), | 64 DnsPrefetcherInit::kMaxQueueingDelayMs)) { |
65 scoped_mapper_(mapper_.get()) { | |
66 } | 65 } |
67 | 66 |
68 protected: | 67 protected: |
69 virtual void SetUp() { | 68 virtual void SetUp() { |
70 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
71 net::EnsureWinsockInit(); | 70 net::EnsureWinsockInit(); |
72 #endif | 71 #endif |
73 mapper_->AddRuleWithLatency("www.google.com", "127.0.0.1", 50); | 72 net::RuleBasedHostResolverProc* rules = host_resolver_->rules(); |
74 mapper_->AddRuleWithLatency("gmail.google.com.com", "127.0.0.1", 70); | 73 rules->AddRuleWithLatency("www.google.com", "127.0.0.1", 50); |
75 mapper_->AddRuleWithLatency("mail.google.com", "127.0.0.1", 44); | 74 rules->AddRuleWithLatency("gmail.google.com.com", "127.0.0.1", 70); |
76 mapper_->AddRuleWithLatency("gmail.com", "127.0.0.1", 63); | 75 rules->AddRuleWithLatency("mail.google.com", "127.0.0.1", 44); |
| 76 rules->AddRuleWithLatency("gmail.com", "127.0.0.1", 63); |
77 } | 77 } |
78 | 78 |
79 void WaitForResolution(DnsMaster* master, const NameList& hosts) { | 79 void WaitForResolution(DnsMaster* master, const NameList& hosts) { |
80 HelperTimer* timer = new HelperTimer(); | 80 HelperTimer* timer = new HelperTimer(); |
81 timer->Start(TimeDelta::FromMilliseconds(100), | 81 timer->Start(TimeDelta::FromMilliseconds(100), |
82 new WaitForResolutionHelper(master, hosts, timer), | 82 new WaitForResolutionHelper(master, hosts, timer), |
83 &WaitForResolutionHelper::Run); | 83 &WaitForResolutionHelper::Run); |
84 MessageLoop::current()->Run(); | 84 MessageLoop::current()->Run(); |
85 } | 85 } |
86 | 86 |
87 scoped_refptr<net::RuleBasedHostMapper> mapper_; | 87 private: |
| 88 // IMPORTANT: do not move this below |host_resolver_|; the host resolver |
| 89 // must not outlive the message loop, otherwise bad things can happen |
| 90 // (like posting to a deleted message loop). |
| 91 MessageLoop loop; |
| 92 |
| 93 protected: |
| 94 scoped_refptr<net::MockHostResolver> host_resolver_; |
88 | 95 |
89 // Shorthand to access TimeDelta of DnsPrefetcherInit::kMaxQueueingDelayMs. | 96 // Shorthand to access TimeDelta of DnsPrefetcherInit::kMaxQueueingDelayMs. |
90 // (It would be a static constant... except style rules preclude that :-/ ). | 97 // (It would be a static constant... except style rules preclude that :-/ ). |
91 const TimeDelta default_max_queueing_delay_; | 98 const TimeDelta default_max_queueing_delay_; |
92 | |
93 private: | |
94 MessageLoop loop; | |
95 net::ScopedHostMapper scoped_mapper_; | |
96 }; | 99 }; |
97 | 100 |
98 //------------------------------------------------------------------------------ | 101 //------------------------------------------------------------------------------ |
99 // Provide a function to create unique (nonexistant) domains at *every* call. | 102 // Provide a function to create unique (nonexistant) domains at *every* call. |
100 //------------------------------------------------------------------------------ | 103 //------------------------------------------------------------------------------ |
101 static std::string GetNonexistantDomain() { | 104 static std::string GetNonexistantDomain() { |
102 static std::string postfix = ".google.com"; | 105 static std::string postfix = ".google.com"; |
103 static std::string prefix = "www."; | 106 static std::string prefix = "www."; |
104 static std::string mid = "datecount"; | 107 static std::string mid = "datecount"; |
105 | 108 |
106 static int counter = 0; // Make sure its unique. | 109 static int counter = 0; // Make sure its unique. |
107 time_t number = time(NULL); | 110 time_t number = time(NULL); |
108 std::ostringstream result; | 111 std::ostringstream result; |
109 result << prefix << number << mid << ++counter << postfix; | 112 result << prefix << number << mid << ++counter << postfix; |
110 return result.str(); | 113 return result.str(); |
111 } | 114 } |
112 | 115 |
113 //------------------------------------------------------------------------------ | 116 //------------------------------------------------------------------------------ |
114 // Use a blocking function to contrast results we get via async services. | 117 // Use a blocking function to contrast results we get via async services. |
115 //------------------------------------------------------------------------------ | 118 //------------------------------------------------------------------------------ |
116 TimeDelta BlockingDnsLookup(const std::string& hostname) { | 119 TimeDelta BlockingDnsLookup(net::HostResolver* resolver, |
117 Time start = Time::Now(); | 120 const std::string& hostname) { |
| 121 Time start = Time::Now(); |
118 | 122 |
119 scoped_refptr<net::HostResolver> resolver(new net::HostResolver); | 123 net::AddressList addresses; |
120 net::AddressList addresses; | 124 net::HostResolver::RequestInfo info(hostname, 80); |
121 net::HostResolver::RequestInfo info(hostname, 80); | 125 resolver->Resolve(info, &addresses, NULL, NULL); |
122 resolver->Resolve(info, &addresses, NULL, NULL); | |
123 | 126 |
124 return Time::Now() - start; | 127 return Time::Now() - start; |
125 } | 128 } |
126 | 129 |
127 //------------------------------------------------------------------------------ | 130 //------------------------------------------------------------------------------ |
128 | 131 |
129 // First test to be sure the OS is caching lookups, which is the whole premise | 132 // First test to be sure the OS is caching lookups, which is the whole premise |
130 // of DNS prefetching. | 133 // of DNS prefetching. |
131 TEST_F(DnsMasterTest, OsCachesLookupsTest) { | 134 TEST_F(DnsMasterTest, OsCachesLookupsTest) { |
132 mapper_->AllowDirectLookup("*.google.com"); | 135 // Make sure caching is disabled in the mock host resolver. |
| 136 host_resolver_->Reset(NULL, 0, 0); |
| 137 host_resolver_->rules()->AllowDirectLookup("*.google.com"); |
133 | 138 |
134 const Time start = Time::Now(); | 139 const Time start = Time::Now(); |
135 int all_lookups = 0; | 140 int all_lookups = 0; |
136 int lookups_with_improvement = 0; | 141 int lookups_with_improvement = 0; |
137 // This test can be really flaky on Linux. It should run in much shorter time, | 142 // This test can be really flaky on Linux. It should run in much shorter time, |
138 // but sometimes it won't and we don't like bogus failures. | 143 // but sometimes it won't and we don't like bogus failures. |
139 while (Time::Now() - start < TimeDelta::FromMinutes(1)) { | 144 while (Time::Now() - start < TimeDelta::FromMinutes(1)) { |
140 std::string badname; | 145 std::string badname; |
141 badname = GetNonexistantDomain(); | 146 badname = GetNonexistantDomain(); |
142 | 147 |
143 TimeDelta duration = BlockingDnsLookup(badname); | 148 TimeDelta duration = BlockingDnsLookup(host_resolver_, badname); |
144 | 149 |
145 // Produce more than one result and remove the largest one | 150 // Produce more than one result and remove the largest one |
146 // to reduce flakiness. | 151 // to reduce flakiness. |
147 std::vector<TimeDelta> cached_results; | 152 std::vector<TimeDelta> cached_results; |
148 for (int j = 0; j < 3; j++) | 153 for (int j = 0; j < 3; j++) |
149 cached_results.push_back(BlockingDnsLookup(badname)); | 154 cached_results.push_back(BlockingDnsLookup(host_resolver_, badname)); |
150 std::sort(cached_results.begin(), cached_results.end()); | 155 std::sort(cached_results.begin(), cached_results.end()); |
151 cached_results.pop_back(); | 156 cached_results.pop_back(); |
152 | 157 |
153 TimeDelta cached_sum = TimeDelta::FromSeconds(0); | 158 TimeDelta cached_sum = TimeDelta::FromSeconds(0); |
154 for (std::vector<TimeDelta>::const_iterator j = cached_results.begin(); | 159 for (std::vector<TimeDelta>::const_iterator j = cached_results.begin(); |
155 j != cached_results.end(); ++j) | 160 j != cached_results.end(); ++j) |
156 cached_sum += *j; | 161 cached_sum += *j; |
157 TimeDelta cached_duration = cached_sum / cached_results.size(); | 162 TimeDelta cached_duration = cached_sum / cached_results.size(); |
158 | 163 |
159 all_lookups++; | 164 all_lookups++; |
160 if (cached_duration < duration) | 165 if (cached_duration < duration) |
161 lookups_with_improvement++; | 166 lookups_with_improvement++; |
162 if (all_lookups >= 10) | 167 if (all_lookups >= 10) |
163 if (lookups_with_improvement * 100 > all_lookups * 75) | 168 if (lookups_with_improvement * 100 > all_lookups * 75) |
164 // Okay, we see the improvement for more than 75% of all lookups. | 169 // Okay, we see the improvement for more than 75% of all lookups. |
165 return; | 170 return; |
166 } | 171 } |
167 FAIL() << "No substantial improvement in lookup time."; | 172 FAIL() << "No substantial improvement in lookup time."; |
168 } | 173 } |
169 | 174 |
170 TEST_F(DnsMasterTest, StartupShutdownTest) { | 175 TEST_F(DnsMasterTest, StartupShutdownTest) { |
171 scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, | 176 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
172 MessageLoop::current(), default_max_queueing_delay_, | 177 MessageLoop::current(), default_max_queueing_delay_, |
173 DnsPrefetcherInit::kMaxConcurrentLookups); | 178 DnsPrefetcherInit::kMaxConcurrentLookups); |
174 testing_master->Shutdown(); | 179 testing_master->Shutdown(); |
175 } | 180 } |
176 | 181 |
177 TEST_F(DnsMasterTest, BenefitLookupTest) { | 182 TEST_F(DnsMasterTest, BenefitLookupTest) { |
178 scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, | 183 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
179 MessageLoop::current(), default_max_queueing_delay_, | 184 MessageLoop::current(), default_max_queueing_delay_, |
180 DnsPrefetcherInit::kMaxConcurrentLookups); | 185 DnsPrefetcherInit::kMaxConcurrentLookups); |
181 | 186 |
182 std::string goog("www.google.com"), | 187 std::string goog("www.google.com"), |
183 goog2("gmail.google.com.com"), | 188 goog2("gmail.google.com.com"), |
184 goog3("mail.google.com"), | 189 goog3("mail.google.com"), |
185 goog4("gmail.com"); | 190 goog4("gmail.com"); |
186 DnsHostInfo goog_info, goog2_info, goog3_info, goog4_info; | 191 DnsHostInfo goog_info, goog2_info, goog3_info, goog4_info; |
187 | 192 |
188 // Simulate getting similar names from a network observer | 193 // Simulate getting similar names from a network observer |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // Benefits can ONLY be reported once (for the first navigation). | 234 // Benefits can ONLY be reported once (for the first navigation). |
230 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(GURL(), &goog_info)); | 235 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(GURL(), &goog_info)); |
231 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(GURL(), &goog2_info)); | 236 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(GURL(), &goog2_info)); |
232 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(GURL(), &goog3_info)); | 237 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(GURL(), &goog3_info)); |
233 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(GURL(), &goog4_info)); | 238 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(GURL(), &goog4_info)); |
234 | 239 |
235 testing_master->Shutdown(); | 240 testing_master->Shutdown(); |
236 } | 241 } |
237 | 242 |
238 TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { | 243 TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { |
239 scoped_refptr<net::WaitingHostMapper> mapper = new net::WaitingHostMapper(); | 244 scoped_refptr<net::WaitingHostResolverProc> resolver_proc = |
240 net::ScopedHostMapper scoped_mapper(mapper.get()); | 245 new net::WaitingHostResolverProc(NULL); |
| 246 host_resolver_->Reset(resolver_proc, 0, 0); |
241 | 247 |
242 scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, | 248 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
243 MessageLoop::current(), default_max_queueing_delay_, | 249 MessageLoop::current(), default_max_queueing_delay_, |
244 DnsPrefetcherInit::kMaxConcurrentLookups); | 250 DnsPrefetcherInit::kMaxConcurrentLookups); |
245 | 251 |
246 std::string localhost("127.0.0.1"); | 252 std::string localhost("127.0.0.1"); |
247 NameList names; | 253 NameList names; |
248 names.insert(names.end(), localhost); | 254 names.insert(names.end(), localhost); |
249 | 255 |
250 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); | 256 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); |
251 | 257 |
252 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 258 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
253 new MessageLoop::QuitTask(), 500); | 259 new MessageLoop::QuitTask(), 500); |
254 MessageLoop::current()->Run(); | 260 MessageLoop::current()->Run(); |
255 | 261 |
256 EXPECT_FALSE(testing_master->WasFound(localhost)); | 262 EXPECT_FALSE(testing_master->WasFound(localhost)); |
257 | 263 |
258 testing_master->Shutdown(); | 264 testing_master->Shutdown(); |
259 | 265 |
260 // Clean up after ourselves. | 266 // Clean up after ourselves. |
261 mapper->Signal(); | 267 resolver_proc->Signal(); |
262 MessageLoop::current()->RunAllPending(); | 268 MessageLoop::current()->RunAllPending(); |
263 } | 269 } |
264 | 270 |
265 TEST_F(DnsMasterTest, SingleLookupTest) { | 271 TEST_F(DnsMasterTest, SingleLookupTest) { |
266 scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, | 272 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
267 MessageLoop::current(), default_max_queueing_delay_, | 273 MessageLoop::current(), default_max_queueing_delay_, |
268 DnsPrefetcherInit::kMaxConcurrentLookups); | 274 DnsPrefetcherInit::kMaxConcurrentLookups); |
269 | 275 |
270 std::string goog("www.google.com"); | 276 std::string goog("www.google.com"); |
271 | 277 |
272 NameList names; | 278 NameList names; |
273 names.insert(names.end(), goog); | 279 names.insert(names.end(), goog); |
274 | 280 |
275 // Try to flood the master with many concurrent requests. | 281 // Try to flood the master with many concurrent requests. |
276 for (int i = 0; i < 10; i++) | 282 for (int i = 0; i < 10; i++) |
277 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); | 283 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); |
278 | 284 |
279 WaitForResolution(testing_master, names); | 285 WaitForResolution(testing_master, names); |
280 | 286 |
281 EXPECT_TRUE(testing_master->WasFound(goog)); | 287 EXPECT_TRUE(testing_master->WasFound(goog)); |
282 | 288 |
283 MessageLoop::current()->RunAllPending(); | 289 MessageLoop::current()->RunAllPending(); |
284 | 290 |
285 EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2); | 291 EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2); |
286 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); | 292 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); |
287 EXPECT_LE(testing_master->peak_pending_lookups(), | 293 EXPECT_LE(testing_master->peak_pending_lookups(), |
288 testing_master->max_concurrent_lookups()); | 294 testing_master->max_concurrent_lookups()); |
289 | 295 |
290 testing_master->Shutdown(); | 296 testing_master->Shutdown(); |
291 } | 297 } |
292 | 298 |
293 TEST_F(DnsMasterTest, ConcurrentLookupTest) { | 299 TEST_F(DnsMasterTest, ConcurrentLookupTest) { |
294 mapper_->AddSimulatedFailure("*.notfound"); | 300 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); |
295 | 301 |
296 scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, | 302 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
297 MessageLoop::current(), default_max_queueing_delay_, | 303 MessageLoop::current(), default_max_queueing_delay_, |
298 DnsPrefetcherInit::kMaxConcurrentLookups); | 304 DnsPrefetcherInit::kMaxConcurrentLookups); |
299 | 305 |
300 std::string goog("www.google.com"), | 306 std::string goog("www.google.com"), |
301 goog2("gmail.google.com.com"), | 307 goog2("gmail.google.com.com"), |
302 goog3("mail.google.com"), | 308 goog3("mail.google.com"), |
303 goog4("gmail.com"); | 309 goog4("gmail.com"); |
304 std::string bad1("bad1.notfound"), | 310 std::string bad1("bad1.notfound"), |
305 bad2("bad2.notfound"); | 311 bad2("bad2.notfound"); |
306 | 312 |
307 NameList names; | 313 NameList names; |
308 names.insert(names.end(), goog); | 314 names.insert(names.end(), goog); |
309 names.insert(names.end(), goog3); | 315 names.insert(names.end(), goog3); |
310 names.insert(names.end(), bad1); | 316 names.insert(names.end(), bad1); |
311 names.insert(names.end(), goog2); | 317 names.insert(names.end(), goog2); |
312 names.insert(names.end(), bad2); | 318 names.insert(names.end(), bad2); |
313 names.insert(names.end(), goog4); | 319 names.insert(names.end(), goog4); |
314 names.insert(names.end(), goog); | 320 names.insert(names.end(), goog); |
315 | 321 |
316 // Warm up the *OS* cache for all the goog domains. | |
317 BlockingDnsLookup(goog); | |
318 BlockingDnsLookup(goog2); | |
319 BlockingDnsLookup(goog3); | |
320 BlockingDnsLookup(goog4); | |
321 | |
322 // Try to flood the master with many concurrent requests. | 322 // Try to flood the master with many concurrent requests. |
323 for (int i = 0; i < 10; i++) | 323 for (int i = 0; i < 10; i++) |
324 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); | 324 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); |
325 | 325 |
326 WaitForResolution(testing_master, names); | 326 WaitForResolution(testing_master, names); |
327 | 327 |
328 EXPECT_TRUE(testing_master->WasFound(goog)); | 328 EXPECT_TRUE(testing_master->WasFound(goog)); |
329 EXPECT_TRUE(testing_master->WasFound(goog3)); | 329 EXPECT_TRUE(testing_master->WasFound(goog3)); |
330 EXPECT_TRUE(testing_master->WasFound(goog2)); | 330 EXPECT_TRUE(testing_master->WasFound(goog2)); |
331 EXPECT_TRUE(testing_master->WasFound(goog4)); | 331 EXPECT_TRUE(testing_master->WasFound(goog4)); |
332 EXPECT_FALSE(testing_master->WasFound(bad1)); | 332 EXPECT_FALSE(testing_master->WasFound(bad1)); |
333 EXPECT_FALSE(testing_master->WasFound(bad2)); | 333 EXPECT_FALSE(testing_master->WasFound(bad2)); |
334 | 334 |
335 MessageLoop::current()->RunAllPending(); | 335 MessageLoop::current()->RunAllPending(); |
336 | 336 |
337 EXPECT_FALSE(testing_master->WasFound(bad1)); | 337 EXPECT_FALSE(testing_master->WasFound(bad1)); |
338 EXPECT_FALSE(testing_master->WasFound(bad2)); | 338 EXPECT_FALSE(testing_master->WasFound(bad2)); |
339 | 339 |
340 EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2); | 340 EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2); |
341 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); | 341 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); |
342 EXPECT_LE(testing_master->peak_pending_lookups(), | 342 EXPECT_LE(testing_master->peak_pending_lookups(), |
343 testing_master->max_concurrent_lookups()); | 343 testing_master->max_concurrent_lookups()); |
344 | 344 |
345 testing_master->Shutdown(); | 345 testing_master->Shutdown(); |
346 } | 346 } |
347 | 347 |
348 TEST_F(DnsMasterTest, DISABLED_MassiveConcurrentLookupTest) { | 348 TEST_F(DnsMasterTest, DISABLED_MassiveConcurrentLookupTest) { |
349 mapper_->AddSimulatedFailure("*.notfound"); | 349 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); |
350 | 350 |
351 scoped_refptr<DnsMaster> testing_master = new DnsMaster(new net::HostResolver, | 351 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
352 MessageLoop::current(), default_max_queueing_delay_, | 352 MessageLoop::current(), default_max_queueing_delay_, |
353 DnsPrefetcherInit::kMaxConcurrentLookups); | 353 DnsPrefetcherInit::kMaxConcurrentLookups); |
354 | 354 |
355 NameList names; | 355 NameList names; |
356 for (int i = 0; i < 100; i++) | 356 for (int i = 0; i < 100; i++) |
357 names.push_back("host" + IntToString(i) + ".notfound"); | 357 names.push_back("host" + IntToString(i) + ".notfound"); |
358 | 358 |
359 // Try to flood the master with many concurrent requests. | 359 // Try to flood the master with many concurrent requests. |
360 for (int i = 0; i < 10; i++) | 360 for (int i = 0; i < 10; i++) |
361 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); | 361 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 } | 446 } |
447 ++i; // Skip latency value. | 447 ++i; // Skip latency value. |
448 } | 448 } |
449 return kLatencyNotFound; | 449 return kLatencyNotFound; |
450 } | 450 } |
451 | 451 |
452 //------------------------------------------------------------------------------ | 452 //------------------------------------------------------------------------------ |
453 | 453 |
454 // Make sure nil referral lists really have no entries, and no latency listed. | 454 // Make sure nil referral lists really have no entries, and no latency listed. |
455 TEST_F(DnsMasterTest, ReferrerSerializationNilTest) { | 455 TEST_F(DnsMasterTest, ReferrerSerializationNilTest) { |
456 scoped_refptr<DnsMaster> master = new DnsMaster(new net::HostResolver, | 456 scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, |
457 MessageLoop::current(), default_max_queueing_delay_, | 457 MessageLoop::current(), default_max_queueing_delay_, |
458 DnsPrefetcherInit::kMaxConcurrentLookups); | 458 DnsPrefetcherInit::kMaxConcurrentLookups); |
459 ListValue referral_list; | 459 ListValue referral_list; |
460 master->SerializeReferrers(&referral_list); | 460 master->SerializeReferrers(&referral_list); |
461 EXPECT_EQ(0U, referral_list.GetSize()); | 461 EXPECT_EQ(0U, referral_list.GetSize()); |
462 EXPECT_EQ(kLatencyNotFound, GetLatencyFromSerialization("a.com", "b.com", | 462 EXPECT_EQ(kLatencyNotFound, GetLatencyFromSerialization("a.com", "b.com", |
463 referral_list)); | 463 referral_list)); |
464 | 464 |
465 master->Shutdown(); | 465 master->Shutdown(); |
466 } | 466 } |
467 | 467 |
468 // Make sure that when a serialization list includes a value, that it can be | 468 // Make sure that when a serialization list includes a value, that it can be |
469 // deserialized into the database, and can be extracted back out via | 469 // deserialized into the database, and can be extracted back out via |
470 // serialization without being changed. | 470 // serialization without being changed. |
471 TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { | 471 TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { |
472 scoped_refptr<DnsMaster> master = new DnsMaster(new net::HostResolver, | 472 scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, |
473 MessageLoop::current(), default_max_queueing_delay_, | 473 MessageLoop::current(), default_max_queueing_delay_, |
474 DnsPrefetcherInit::kMaxConcurrentLookups); | 474 DnsPrefetcherInit::kMaxConcurrentLookups); |
475 std::string motivation_hostname = "www.google.com"; | 475 std::string motivation_hostname = "www.google.com"; |
476 std::string subresource_hostname = "icons.google.com"; | 476 std::string subresource_hostname = "icons.google.com"; |
477 const int kLatency = 3; | 477 const int kLatency = 3; |
478 ListValue referral_list; | 478 ListValue referral_list; |
479 | 479 |
480 AddToSerializedList(motivation_hostname, subresource_hostname, kLatency, | 480 AddToSerializedList(motivation_hostname, subresource_hostname, kLatency, |
481 &referral_list); | 481 &referral_list); |
482 | 482 |
483 master->DeserializeReferrers(referral_list); | 483 master->DeserializeReferrers(referral_list); |
484 | 484 |
485 ListValue recovered_referral_list; | 485 ListValue recovered_referral_list; |
486 master->SerializeReferrers(&recovered_referral_list); | 486 master->SerializeReferrers(&recovered_referral_list); |
487 EXPECT_EQ(1U, recovered_referral_list.GetSize()); | 487 EXPECT_EQ(1U, recovered_referral_list.GetSize()); |
488 EXPECT_EQ(kLatency, GetLatencyFromSerialization(motivation_hostname, | 488 EXPECT_EQ(kLatency, GetLatencyFromSerialization(motivation_hostname, |
489 subresource_hostname, | 489 subresource_hostname, |
490 recovered_referral_list)); | 490 recovered_referral_list)); |
491 | 491 |
492 master->Shutdown(); | 492 master->Shutdown(); |
493 } | 493 } |
494 | 494 |
495 // Make sure the Trim() functionality works as expected. | 495 // Make sure the Trim() functionality works as expected. |
496 TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { | 496 TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { |
497 scoped_refptr<DnsMaster> master = new DnsMaster(new net::HostResolver, | 497 scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, |
498 MessageLoop::current(), default_max_queueing_delay_, | 498 MessageLoop::current(), default_max_queueing_delay_, |
499 DnsPrefetcherInit::kMaxConcurrentLookups); | 499 DnsPrefetcherInit::kMaxConcurrentLookups); |
500 std::string motivation_hostname = "www.google.com"; | 500 std::string motivation_hostname = "www.google.com"; |
501 std::string icon_subresource_hostname = "icons.google.com"; | 501 std::string icon_subresource_hostname = "icons.google.com"; |
502 std::string img_subresource_hostname = "img.google.com"; | 502 std::string img_subresource_hostname = "img.google.com"; |
503 ListValue referral_list; | 503 ListValue referral_list; |
504 | 504 |
505 AddToSerializedList(motivation_hostname, icon_subresource_hostname, 10, | 505 AddToSerializedList(motivation_hostname, icon_subresource_hostname, 10, |
506 &referral_list); | 506 &referral_list); |
507 AddToSerializedList(motivation_hostname, img_subresource_hostname, 3, | 507 AddToSerializedList(motivation_hostname, img_subresource_hostname, 3, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 EXPECT_EQ(queue.Pop(), "startup"); | 622 EXPECT_EQ(queue.Pop(), "startup"); |
623 EXPECT_EQ(queue.Pop(), "omni"); | 623 EXPECT_EQ(queue.Pop(), "omni"); |
624 | 624 |
625 EXPECT_TRUE(queue.IsEmpty()); | 625 EXPECT_TRUE(queue.IsEmpty()); |
626 } | 626 } |
627 | 627 |
628 | 628 |
629 | 629 |
630 | 630 |
631 } // namespace chrome_browser_net | 631 } // namespace chrome_browser_net |
OLD | NEW |