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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 const NameList hosts_; | 56 const NameList hosts_; |
57 HelperTimer* timer_; | 57 HelperTimer* timer_; |
58 }; | 58 }; |
59 | 59 |
60 class DnsMasterTest : public testing::Test { | 60 class DnsMasterTest : public testing::Test { |
61 public: | 61 public: |
62 DnsMasterTest() | 62 DnsMasterTest() |
63 : io_thread_(ChromeThread::IO, &loop_), | 63 : io_thread_(ChromeThread::IO, &loop_), |
64 host_resolver_(new net::MockCachingHostResolver()), | 64 host_resolver_(new net::MockCachingHostResolver()), |
65 default_max_queueing_delay_(TimeDelta::FromMilliseconds( | 65 default_max_queueing_delay_(TimeDelta::FromMilliseconds( |
66 DnsPrefetcherInit::kMaxQueueingDelayMs)) { | 66 DnsGlobalInit::kMaxPrefetchQueueingDelayMs)) { |
67 } | 67 } |
68 | 68 |
69 protected: | 69 protected: |
70 virtual void SetUp() { | 70 virtual void SetUp() { |
71 #if defined(OS_WIN) | 71 #if defined(OS_WIN) |
72 net::EnsureWinsockInit(); | 72 net::EnsureWinsockInit(); |
73 #endif | 73 #endif |
74 // Since we are using a caching HostResolver, the following latencies will | 74 // Since we are using a caching HostResolver, the following latencies will |
75 // only be incurred by the first request, after which the result will be | 75 // only be incurred by the first request, after which the result will be |
76 // cached internally by |host_resolver_|. | 76 // cached internally by |host_resolver_|. |
(...skipping 15 matching lines...) Expand all Loading... |
92 private: | 92 private: |
93 // IMPORTANT: do not move this below |host_resolver_|; the host resolver | 93 // IMPORTANT: do not move this below |host_resolver_|; the host resolver |
94 // must not outlive the message loop, otherwise bad things can happen | 94 // must not outlive the message loop, otherwise bad things can happen |
95 // (like posting to a deleted message loop). | 95 // (like posting to a deleted message loop). |
96 MessageLoop loop_; | 96 MessageLoop loop_; |
97 ChromeThread io_thread_; | 97 ChromeThread io_thread_; |
98 | 98 |
99 protected: | 99 protected: |
100 scoped_refptr<net::MockCachingHostResolver> host_resolver_; | 100 scoped_refptr<net::MockCachingHostResolver> host_resolver_; |
101 | 101 |
102 // Shorthand to access TimeDelta of DnsPrefetcherInit::kMaxQueueingDelayMs. | 102 // Shorthand to access TimeDelta of DnsGlobalInit::kMaxQueueingDelayMs. |
103 // (It would be a static constant... except style rules preclude that :-/ ). | 103 // (It would be a static constant... except style rules preclude that :-/ ). |
104 const TimeDelta default_max_queueing_delay_; | 104 const TimeDelta default_max_queueing_delay_; |
105 }; | 105 }; |
106 | 106 |
107 //------------------------------------------------------------------------------ | 107 //------------------------------------------------------------------------------ |
108 | 108 |
109 TEST_F(DnsMasterTest, StartupShutdownTest) { | 109 TEST_F(DnsMasterTest, StartupShutdownTest) { |
110 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, | 110 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
111 default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); | 111 default_max_queueing_delay_, |
| 112 DnsGlobalInit::kMaxPrefetchConcurrentLookups); |
112 testing_master->Shutdown(); | 113 testing_master->Shutdown(); |
113 } | 114 } |
114 | 115 |
115 TEST_F(DnsMasterTest, BenefitLookupTest) { | 116 TEST_F(DnsMasterTest, BenefitLookupTest) { |
116 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, | 117 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
117 default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); | 118 default_max_queueing_delay_, |
| 119 DnsGlobalInit::kMaxPrefetchConcurrentLookups); |
118 | 120 |
119 std::string goog("www.google.com"), | 121 std::string goog("www.google.com"), |
120 goog2("gmail.google.com.com"), | 122 goog2("gmail.google.com.com"), |
121 goog3("mail.google.com"), | 123 goog3("mail.google.com"), |
122 goog4("gmail.com"); | 124 goog4("gmail.com"); |
123 DnsHostInfo goog_info, goog2_info, goog3_info, goog4_info; | 125 DnsHostInfo goog_info, goog2_info, goog3_info, goog4_info; |
124 | 126 |
125 // Simulate getting similar names from a network observer | 127 // Simulate getting similar names from a network observer |
126 goog_info.SetHostname(goog); | 128 goog_info.SetHostname(goog); |
127 goog2_info.SetHostname(goog2); | 129 goog2_info.SetHostname(goog2); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 173 |
172 testing_master->Shutdown(); | 174 testing_master->Shutdown(); |
173 } | 175 } |
174 | 176 |
175 TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { | 177 TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) { |
176 scoped_refptr<net::WaitingHostResolverProc> resolver_proc = | 178 scoped_refptr<net::WaitingHostResolverProc> resolver_proc = |
177 new net::WaitingHostResolverProc(NULL); | 179 new net::WaitingHostResolverProc(NULL); |
178 host_resolver_->Reset(resolver_proc); | 180 host_resolver_->Reset(resolver_proc); |
179 | 181 |
180 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, | 182 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
181 default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); | 183 default_max_queueing_delay_, |
| 184 DnsGlobalInit::kMaxPrefetchConcurrentLookups); |
182 | 185 |
183 std::string localhost("127.0.0.1"); | 186 std::string localhost("127.0.0.1"); |
184 NameList names; | 187 NameList names; |
185 names.insert(names.end(), localhost); | 188 names.insert(names.end(), localhost); |
186 | 189 |
187 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); | 190 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); |
188 | 191 |
189 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 192 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
190 new MessageLoop::QuitTask(), 500); | 193 new MessageLoop::QuitTask(), 500); |
191 MessageLoop::current()->Run(); | 194 MessageLoop::current()->Run(); |
192 | 195 |
193 EXPECT_FALSE(testing_master->WasFound(localhost)); | 196 EXPECT_FALSE(testing_master->WasFound(localhost)); |
194 | 197 |
195 testing_master->Shutdown(); | 198 testing_master->Shutdown(); |
196 | 199 |
197 // Clean up after ourselves. | 200 // Clean up after ourselves. |
198 resolver_proc->Signal(); | 201 resolver_proc->Signal(); |
199 MessageLoop::current()->RunAllPending(); | 202 MessageLoop::current()->RunAllPending(); |
200 } | 203 } |
201 | 204 |
202 TEST_F(DnsMasterTest, SingleLookupTest) { | 205 TEST_F(DnsMasterTest, SingleLookupTest) { |
203 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, | 206 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
204 default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); | 207 default_max_queueing_delay_, |
| 208 DnsGlobalInit::kMaxPrefetchConcurrentLookups); |
205 | 209 |
206 std::string goog("www.google.com"); | 210 std::string goog("www.google.com"); |
207 | 211 |
208 NameList names; | 212 NameList names; |
209 names.insert(names.end(), goog); | 213 names.insert(names.end(), goog); |
210 | 214 |
211 // Try to flood the master with many concurrent requests. | 215 // Try to flood the master with many concurrent requests. |
212 for (int i = 0; i < 10; i++) | 216 for (int i = 0; i < 10; i++) |
213 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); | 217 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); |
214 | 218 |
215 WaitForResolution(testing_master, names); | 219 WaitForResolution(testing_master, names); |
216 | 220 |
217 EXPECT_TRUE(testing_master->WasFound(goog)); | 221 EXPECT_TRUE(testing_master->WasFound(goog)); |
218 | 222 |
219 MessageLoop::current()->RunAllPending(); | 223 MessageLoop::current()->RunAllPending(); |
220 | 224 |
221 EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2); | 225 EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2); |
222 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); | 226 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); |
223 EXPECT_LE(testing_master->peak_pending_lookups(), | 227 EXPECT_LE(testing_master->peak_pending_lookups(), |
224 testing_master->max_concurrent_lookups()); | 228 testing_master->max_concurrent_lookups()); |
225 | 229 |
226 testing_master->Shutdown(); | 230 testing_master->Shutdown(); |
227 } | 231 } |
228 | 232 |
229 TEST_F(DnsMasterTest, ConcurrentLookupTest) { | 233 TEST_F(DnsMasterTest, ConcurrentLookupTest) { |
230 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); | 234 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); |
231 | 235 |
232 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, | 236 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
233 default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); | 237 default_max_queueing_delay_, |
| 238 DnsGlobalInit::kMaxPrefetchConcurrentLookups); |
234 | 239 |
235 std::string goog("www.google.com"), | 240 std::string goog("www.google.com"), |
236 goog2("gmail.google.com.com"), | 241 goog2("gmail.google.com.com"), |
237 goog3("mail.google.com"), | 242 goog3("mail.google.com"), |
238 goog4("gmail.com"); | 243 goog4("gmail.com"); |
239 std::string bad1("bad1.notfound"), | 244 std::string bad1("bad1.notfound"), |
240 bad2("bad2.notfound"); | 245 bad2("bad2.notfound"); |
241 | 246 |
242 NameList names; | 247 NameList names; |
243 names.insert(names.end(), goog); | 248 names.insert(names.end(), goog); |
(...skipping 27 matching lines...) Expand all Loading... |
271 EXPECT_LE(testing_master->peak_pending_lookups(), | 276 EXPECT_LE(testing_master->peak_pending_lookups(), |
272 testing_master->max_concurrent_lookups()); | 277 testing_master->max_concurrent_lookups()); |
273 | 278 |
274 testing_master->Shutdown(); | 279 testing_master->Shutdown(); |
275 } | 280 } |
276 | 281 |
277 TEST_F(DnsMasterTest, MassiveConcurrentLookupTest) { | 282 TEST_F(DnsMasterTest, MassiveConcurrentLookupTest) { |
278 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); | 283 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); |
279 | 284 |
280 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, | 285 scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_, |
281 default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); | 286 default_max_queueing_delay_, |
| 287 DnsGlobalInit::kMaxPrefetchConcurrentLookups); |
282 | 288 |
283 NameList names; | 289 NameList names; |
284 for (int i = 0; i < 100; i++) | 290 for (int i = 0; i < 100; i++) |
285 names.push_back("host" + IntToString(i) + ".notfound"); | 291 names.push_back("host" + IntToString(i) + ".notfound"); |
286 | 292 |
287 // Try to flood the master with many concurrent requests. | 293 // Try to flood the master with many concurrent requests. |
288 for (int i = 0; i < 10; i++) | 294 for (int i = 0; i < 10; i++) |
289 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); | 295 testing_master->ResolveList(names, DnsHostInfo::PAGE_SCAN_MOTIVATED); |
290 | 296 |
291 WaitForResolution(testing_master, names); | 297 WaitForResolution(testing_master, names); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 ++i; // Skip latency value. | 381 ++i; // Skip latency value. |
376 } | 382 } |
377 return kLatencyNotFound; | 383 return kLatencyNotFound; |
378 } | 384 } |
379 | 385 |
380 //------------------------------------------------------------------------------ | 386 //------------------------------------------------------------------------------ |
381 | 387 |
382 // Make sure nil referral lists really have no entries, and no latency listed. | 388 // Make sure nil referral lists really have no entries, and no latency listed. |
383 TEST_F(DnsMasterTest, ReferrerSerializationNilTest) { | 389 TEST_F(DnsMasterTest, ReferrerSerializationNilTest) { |
384 scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, | 390 scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, |
385 default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); | 391 default_max_queueing_delay_, |
| 392 DnsGlobalInit::kMaxPrefetchConcurrentLookups); |
386 ListValue referral_list; | 393 ListValue referral_list; |
387 master->SerializeReferrers(&referral_list); | 394 master->SerializeReferrers(&referral_list); |
388 EXPECT_EQ(0U, referral_list.GetSize()); | 395 EXPECT_EQ(0U, referral_list.GetSize()); |
389 EXPECT_EQ(kLatencyNotFound, GetLatencyFromSerialization("a.com", "b.com", | 396 EXPECT_EQ(kLatencyNotFound, GetLatencyFromSerialization("a.com", "b.com", |
390 referral_list)); | 397 referral_list)); |
391 | 398 |
392 master->Shutdown(); | 399 master->Shutdown(); |
393 } | 400 } |
394 | 401 |
395 // Make sure that when a serialization list includes a value, that it can be | 402 // Make sure that when a serialization list includes a value, that it can be |
396 // deserialized into the database, and can be extracted back out via | 403 // deserialized into the database, and can be extracted back out via |
397 // serialization without being changed. | 404 // serialization without being changed. |
398 TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { | 405 TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) { |
399 scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, | 406 scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, |
400 default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); | 407 default_max_queueing_delay_, |
| 408 DnsGlobalInit::kMaxPrefetchConcurrentLookups); |
401 std::string motivation_hostname = "www.google.com"; | 409 std::string motivation_hostname = "www.google.com"; |
402 std::string subresource_hostname = "icons.google.com"; | 410 std::string subresource_hostname = "icons.google.com"; |
403 const int kLatency = 3; | 411 const int kLatency = 3; |
404 ListValue referral_list; | 412 ListValue referral_list; |
405 | 413 |
406 AddToSerializedList(motivation_hostname, subresource_hostname, kLatency, | 414 AddToSerializedList(motivation_hostname, subresource_hostname, kLatency, |
407 &referral_list); | 415 &referral_list); |
408 | 416 |
409 master->DeserializeReferrers(referral_list); | 417 master->DeserializeReferrers(referral_list); |
410 | 418 |
411 ListValue recovered_referral_list; | 419 ListValue recovered_referral_list; |
412 master->SerializeReferrers(&recovered_referral_list); | 420 master->SerializeReferrers(&recovered_referral_list); |
413 EXPECT_EQ(1U, recovered_referral_list.GetSize()); | 421 EXPECT_EQ(1U, recovered_referral_list.GetSize()); |
414 EXPECT_EQ(kLatency, GetLatencyFromSerialization(motivation_hostname, | 422 EXPECT_EQ(kLatency, GetLatencyFromSerialization(motivation_hostname, |
415 subresource_hostname, | 423 subresource_hostname, |
416 recovered_referral_list)); | 424 recovered_referral_list)); |
417 | 425 |
418 master->Shutdown(); | 426 master->Shutdown(); |
419 } | 427 } |
420 | 428 |
421 // Make sure the Trim() functionality works as expected. | 429 // Make sure the Trim() functionality works as expected. |
422 TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { | 430 TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) { |
423 scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, | 431 scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_, |
424 default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups); | 432 default_max_queueing_delay_, |
| 433 DnsGlobalInit::kMaxPrefetchConcurrentLookups); |
425 std::string motivation_hostname = "www.google.com"; | 434 std::string motivation_hostname = "www.google.com"; |
426 std::string icon_subresource_hostname = "icons.google.com"; | 435 std::string icon_subresource_hostname = "icons.google.com"; |
427 std::string img_subresource_hostname = "img.google.com"; | 436 std::string img_subresource_hostname = "img.google.com"; |
428 ListValue referral_list; | 437 ListValue referral_list; |
429 | 438 |
430 AddToSerializedList(motivation_hostname, icon_subresource_hostname, 10, | 439 AddToSerializedList(motivation_hostname, icon_subresource_hostname, 10, |
431 &referral_list); | 440 &referral_list); |
432 AddToSerializedList(motivation_hostname, img_subresource_hostname, 3, | 441 AddToSerializedList(motivation_hostname, img_subresource_hostname, 3, |
433 &referral_list); | 442 &referral_list); |
434 | 443 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 EXPECT_EQ(queue.Pop(), "unit"); | 553 EXPECT_EQ(queue.Pop(), "unit"); |
545 EXPECT_EQ(queue.Pop(), "lmax"); | 554 EXPECT_EQ(queue.Pop(), "lmax"); |
546 EXPECT_EQ(queue.Pop(), "omni"); | 555 EXPECT_EQ(queue.Pop(), "omni"); |
547 EXPECT_EQ(queue.Pop(), "startup"); | 556 EXPECT_EQ(queue.Pop(), "startup"); |
548 EXPECT_EQ(queue.Pop(), "omni"); | 557 EXPECT_EQ(queue.Pop(), "omni"); |
549 | 558 |
550 EXPECT_TRUE(queue.IsEmpty()); | 559 EXPECT_TRUE(queue.IsEmpty()); |
551 } | 560 } |
552 | 561 |
553 } // namespace chrome_browser_net | 562 } // namespace chrome_browser_net |
OLD | NEW |