| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 base::TimeTicks now; | 312 base::TimeTicks now; |
| 313 | 313 |
| 314 // Lookup and Set should have no effect. | 314 // Lookup and Set should have no effect. |
| 315 EXPECT_TRUE(cache.Lookup(Key("foobar.com"), base::TimeTicks()) == NULL); | 315 EXPECT_TRUE(cache.Lookup(Key("foobar.com"), base::TimeTicks()) == NULL); |
| 316 cache.Set(Key("foobar.com"), OK, AddressList(), now); | 316 cache.Set(Key("foobar.com"), OK, AddressList(), now); |
| 317 EXPECT_TRUE(cache.Lookup(Key("foobar.com"), base::TimeTicks()) == NULL); | 317 EXPECT_TRUE(cache.Lookup(Key("foobar.com"), base::TimeTicks()) == NULL); |
| 318 | 318 |
| 319 EXPECT_EQ(0U, cache.size()); | 319 EXPECT_EQ(0U, cache.size()); |
| 320 } | 320 } |
| 321 | 321 |
| 322 TEST(HostCacheTest, Clear) { |
| 323 HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL); |
| 324 |
| 325 // Set t=0. |
| 326 base::TimeTicks now; |
| 327 |
| 328 EXPECT_EQ(0u, cache.size()); |
| 329 |
| 330 // Add three entries. |
| 331 cache.Set(Key("foobar1.com"), OK, AddressList(), now); |
| 332 cache.Set(Key("foobar2.com"), OK, AddressList(), now); |
| 333 cache.Set(Key("foobar3.com"), OK, AddressList(), now); |
| 334 |
| 335 EXPECT_EQ(3u, cache.size()); |
| 336 |
| 337 cache.clear(); |
| 338 |
| 339 EXPECT_EQ(0u, cache.size()); |
| 340 } |
| 341 |
| 322 // Tests the less than and equal operators for HostCache::Key work. | 342 // Tests the less than and equal operators for HostCache::Key work. |
| 323 TEST(HostCacheTest, KeyComparators) { | 343 TEST(HostCacheTest, KeyComparators) { |
| 324 struct { | 344 struct { |
| 325 // Inputs. | 345 // Inputs. |
| 326 HostCache::Key key1; | 346 HostCache::Key key1; |
| 327 HostCache::Key key2; | 347 HostCache::Key key2; |
| 328 | 348 |
| 329 // Expectation. | 349 // Expectation. |
| 330 // -1 means key1 is less than key2 | 350 // -1 means key1 is less than key2 |
| 331 // 0 means key1 equals key2 | 351 // 0 means key1 equals key2 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 EXPECT_TRUE(key2 < key1); | 406 EXPECT_TRUE(key2 < key1); |
| 387 EXPECT_FALSE(key2 == key1); | 407 EXPECT_FALSE(key2 == key1); |
| 388 break; | 408 break; |
| 389 default: | 409 default: |
| 390 FAIL() << "Invalid expectation. Can be only -1, 0, 1"; | 410 FAIL() << "Invalid expectation. Can be only -1, 0, 1"; |
| 391 } | 411 } |
| 392 } | 412 } |
| 393 } | 413 } |
| 394 | 414 |
| 395 } // namespace net | 415 } // namespace net |
| OLD | NEW |