| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/base/host_cache.h" | 5 #include "net/base/host_cache.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 // the HostResolverFlags differ. | 307 // the HostResolverFlags differ. |
| 308 TEST(HostCacheTest, HostResolverFlagsArePartOfKey) { | 308 TEST(HostCacheTest, HostResolverFlagsArePartOfKey) { |
| 309 HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL); | 309 HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL); |
| 310 | 310 |
| 311 // t=0. | 311 // t=0. |
| 312 base::TimeTicks now; | 312 base::TimeTicks now; |
| 313 | 313 |
| 314 HostCache::Key key1("foobar.com", ADDRESS_FAMILY_IPV4, 0); | 314 HostCache::Key key1("foobar.com", ADDRESS_FAMILY_IPV4, 0); |
| 315 HostCache::Key key2("foobar.com", ADDRESS_FAMILY_IPV4, | 315 HostCache::Key key2("foobar.com", ADDRESS_FAMILY_IPV4, |
| 316 HOST_RESOLVER_CANONNAME); | 316 HOST_RESOLVER_CANONNAME); |
| 317 HostCache::Key key3("foobar.com", ADDRESS_FAMILY_IPV4, |
| 318 HOST_RESOLVER_LOOPBACK_ONLY); |
| 317 | 319 |
| 318 const HostCache::Entry* entry1 = NULL; // Entry for key1 | 320 const HostCache::Entry* entry1 = NULL; // Entry for key1 |
| 319 const HostCache::Entry* entry2 = NULL; // Entry for key2 | 321 const HostCache::Entry* entry2 = NULL; // Entry for key2 |
| 322 const HostCache::Entry* entry3 = NULL; // Entry for key3 |
| 320 | 323 |
| 321 EXPECT_EQ(0U, cache.size()); | 324 EXPECT_EQ(0U, cache.size()); |
| 322 | 325 |
| 323 // Add an entry for ("foobar.com", IPV4, NONE) at t=0. | 326 // Add an entry for ("foobar.com", IPV4, NONE) at t=0. |
| 324 EXPECT_TRUE(cache.Lookup(key1, base::TimeTicks()) == NULL); | 327 EXPECT_TRUE(cache.Lookup(key1, base::TimeTicks()) == NULL); |
| 325 cache.Set(key1, OK, AddressList(), now); | 328 cache.Set(key1, OK, AddressList(), now); |
| 326 entry1 = cache.Lookup(key1, base::TimeTicks()); | 329 entry1 = cache.Lookup(key1, base::TimeTicks()); |
| 327 EXPECT_FALSE(entry1 == NULL); | 330 EXPECT_FALSE(entry1 == NULL); |
| 328 EXPECT_EQ(1U, cache.size()); | 331 EXPECT_EQ(1U, cache.size()); |
| 329 | 332 |
| 330 // Add an entry for ("foobar.com", IPV4, CANONNAME) at t=0. | 333 // Add an entry for ("foobar.com", IPV4, CANONNAME) at t=0. |
| 331 EXPECT_TRUE(cache.Lookup(key2, base::TimeTicks()) == NULL); | 334 EXPECT_TRUE(cache.Lookup(key2, base::TimeTicks()) == NULL); |
| 332 cache.Set(key2, OK, AddressList(), now); | 335 cache.Set(key2, OK, AddressList(), now); |
| 333 entry2 = cache.Lookup(key2, base::TimeTicks()); | 336 entry2 = cache.Lookup(key2, base::TimeTicks()); |
| 334 EXPECT_FALSE(entry2 == NULL); | 337 EXPECT_FALSE(entry2 == NULL); |
| 335 EXPECT_EQ(2U, cache.size()); | 338 EXPECT_EQ(2U, cache.size()); |
| 336 | 339 |
| 340 // Add an entry for ("foobar.com", IPV4, LOOPBACK_ONLY) at t=0. |
| 341 EXPECT_TRUE(cache.Lookup(key3, base::TimeTicks()) == NULL); |
| 342 cache.Set(key3, OK, AddressList(), now); |
| 343 entry3 = cache.Lookup(key3, base::TimeTicks()); |
| 344 EXPECT_FALSE(entry3 == NULL); |
| 345 EXPECT_EQ(3U, cache.size()); |
| 346 |
| 337 // Even though the hostnames were the same, we should have two unique | 347 // Even though the hostnames were the same, we should have two unique |
| 338 // entries (because the HostResolverFlags differ). | 348 // entries (because the HostResolverFlags differ). |
| 339 EXPECT_NE(entry1, entry2); | 349 EXPECT_NE(entry1, entry2); |
| 350 EXPECT_NE(entry1, entry3); |
| 351 EXPECT_NE(entry2, entry3); |
| 340 } | 352 } |
| 341 | 353 |
| 342 TEST(HostCacheTest, NoCache) { | 354 TEST(HostCacheTest, NoCache) { |
| 343 // Disable caching. | 355 // Disable caching. |
| 344 HostCache cache(0, kSuccessEntryTTL, kFailureEntryTTL); | 356 HostCache cache(0, kSuccessEntryTTL, kFailureEntryTTL); |
| 345 EXPECT_TRUE(cache.caching_is_disabled()); | 357 EXPECT_TRUE(cache.caching_is_disabled()); |
| 346 | 358 |
| 347 // Set t=0. | 359 // Set t=0. |
| 348 base::TimeTicks now; | 360 base::TimeTicks now; |
| 349 | 361 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 EXPECT_TRUE(key2 < key1); | 473 EXPECT_TRUE(key2 < key1); |
| 462 EXPECT_FALSE(key2 == key1); | 474 EXPECT_FALSE(key2 == key1); |
| 463 break; | 475 break; |
| 464 default: | 476 default: |
| 465 FAIL() << "Invalid expectation. Can be only -1, 0, 1"; | 477 FAIL() << "Invalid expectation. Can be only -1, 0, 1"; |
| 466 } | 478 } |
| 467 } | 479 } |
| 468 } | 480 } |
| 469 | 481 |
| 470 } // namespace net | 482 } // namespace net |
| OLD | NEW |