Lines Matching +full:cache +full:- +full:base
2 // Use of this source code is governed by a BSD-style license that can be
13 #include "base/format_macros.h"
14 #include "base/functional/bind.h"
15 #include "base/functional/callback.h"
16 #include "base/functional/callback_helpers.h"
17 #include "base/json/json_reader.h"
18 #include "base/json/json_writer.h"
19 #include "base/ranges/algorithm.h"
20 #include "base/strings/strcat.h"
21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_piece.h"
23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h"
25 #include "base/time/time.h"
26 #include "base/values.h"
27 #include "net/base/connection_endpoint_metadata.h"
28 #include "net/base/host_port_pair.h"
29 #include "net/base/ip_address.h"
30 #include "net/base/ip_endpoint.h"
31 #include "net/base/network_anonymization_key.h"
32 #include "net/base/schemeful_site.h"
67 return (foobarx_com[6] - '0') % 2 == 1; in FoobarIndexIsOdd()
82 base::StrCat({"contents ", negation ? "!=" : "==", " contents of ",
87 IPAddress MakeIP(base::StringPiece literal) { in MakeIP()
95 base::ranges::transform(my_addresses, out.begin(), in MakeEndpoints()
103 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
105 HostCache cache(kMaxCacheEntries); in TEST() local
108 base::TimeTicks now; in TEST()
116 EXPECT_EQ(0U, cache.size()); in TEST()
119 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
120 cache.Set(key1, entry, now, kTTL); in TEST()
121 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
122 EXPECT_TRUE(cache.Lookup(key1, now)->second.error() == entry.error()); in TEST()
124 EXPECT_EQ(1U, cache.size()); in TEST()
127 now += base::Seconds(5); in TEST()
130 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
131 cache.Set(key2, entry, now, kTTL); in TEST()
132 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
133 EXPECT_EQ(2U, cache.size()); in TEST()
136 now += base::Seconds(4); in TEST()
139 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
140 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
141 EXPECT_NE(cache.Lookup(key1, now), cache.Lookup(key2, now)); in TEST()
144 now += base::Seconds(1); in TEST()
146 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
147 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
150 cache.Set(key1, entry, now, kTTL); in TEST()
151 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
152 EXPECT_EQ(2U, cache.size()); in TEST()
155 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
156 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
159 now += base::Seconds(10); in TEST()
161 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
162 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
185 // Merge in non-empty metadata. in TEST()
208 // Merge in non-empty metadata. in TEST()
226 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
228 HostCache cache(kMaxCacheEntries); in TEST() local
231 base::TimeTicks now; in TEST()
244 ASSERT_EQ(0U, cache.size()); in TEST()
245 ASSERT_FALSE(cache.Lookup(key, now)); in TEST()
246 ASSERT_FALSE(cache.Lookup(key_with_scheme, now)); in TEST()
249 cache.Set(key, entry, now, kTTL); in TEST()
250 EXPECT_EQ(1U, cache.size()); in TEST()
251 EXPECT_TRUE(cache.Lookup(key, now)); in TEST()
252 EXPECT_FALSE(cache.Lookup(key_with_scheme, now)); in TEST()
255 cache.Set(key_with_scheme, entry, now, kTTL); in TEST()
256 EXPECT_EQ(2U, cache.size()); in TEST()
257 EXPECT_TRUE(cache.Lookup(key, now)); in TEST()
258 EXPECT_TRUE(cache.Lookup(key_with_scheme, now)); in TEST()
260 // Clear the cache and try adding in reverse order. in TEST()
261 cache.clear(); in TEST()
262 ASSERT_EQ(0U, cache.size()); in TEST()
263 ASSERT_FALSE(cache.Lookup(key, now)); in TEST()
264 ASSERT_FALSE(cache.Lookup(key_with_scheme, now)); in TEST()
267 cache.Set(key_with_scheme, entry, now, kTTL); in TEST()
268 EXPECT_EQ(1U, cache.size()); in TEST()
269 EXPECT_FALSE(cache.Lookup(key, now)); in TEST()
270 EXPECT_TRUE(cache.Lookup(key_with_scheme, now)); in TEST()
273 cache.Set(key, entry, now, kTTL); in TEST()
274 EXPECT_EQ(2U, cache.size()); in TEST()
275 EXPECT_TRUE(cache.Lookup(key, now)); in TEST()
276 EXPECT_TRUE(cache.Lookup(key_with_scheme, now)); in TEST()
282 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
302 HostCache cache(kMaxCacheEntries); in TEST() local
305 base::TimeTicks now; in TEST()
307 EXPECT_EQ(0U, cache.size()); in TEST()
310 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
311 cache.Set(key1, entry1, now, kTTL); in TEST()
314 cache.Lookup(key1, now); in TEST()
316 EXPECT_EQ(kNetworkAnonymizationKey1, result->first.network_anonymization_key); in TEST()
317 EXPECT_EQ(OK, result->second.error()); in TEST()
318 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
319 EXPECT_EQ(1U, cache.size()); in TEST()
322 cache.Set(key2, entry2, now, 3 * kTTL); in TEST()
323 result = cache.Lookup(key1, now); in TEST()
325 EXPECT_EQ(kNetworkAnonymizationKey1, result->first.network_anonymization_key); in TEST()
326 EXPECT_EQ(OK, result->second.error()); in TEST()
327 result = cache.Lookup(key2, now); in TEST()
329 EXPECT_EQ(kNetworkAnonymizationKey2, result->first.network_anonymization_key); in TEST()
330 EXPECT_EQ(ERR_FAILED, result->second.error()); in TEST()
331 EXPECT_EQ(2U, cache.size()); in TEST()
335 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
336 result = cache.Lookup(key2, now); in TEST()
338 EXPECT_EQ(kNetworkAnonymizationKey2, result->first.network_anonymization_key); in TEST()
339 EXPECT_EQ(ERR_FAILED, result->second.error()); in TEST()
342 // Try caching entries for a failed resolve attempt -- since we set the TTL of
345 const base::TimeDelta kSuccessEntryTTL = base::Seconds(10); in TEST()
346 const base::TimeDelta kFailureEntryTTL = base::Seconds(0); in TEST()
348 HostCache cache(kMaxCacheEntries); in TEST() local
351 base::TimeTicks now; in TEST()
359 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
360 cache.Set(key1, entry, now, kFailureEntryTTL); in TEST()
361 EXPECT_EQ(1U, cache.size()); in TEST()
364 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
367 // again -- the valid entry should be kicked out. in TEST()
368 cache.Set(key1, entry, now, kSuccessEntryTTL); in TEST()
369 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
370 cache.Set(key1, entry, now, kFailureEntryTTL); in TEST()
371 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
376 const base::TimeDelta kFailureEntryTTL = base::Seconds(10); in TEST()
378 HostCache cache(kMaxCacheEntries); in TEST() local
381 base::TimeTicks now; in TEST()
389 EXPECT_EQ(0U, cache.size()); in TEST()
392 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
393 cache.Set(key1, entry, now, kFailureEntryTTL); in TEST()
394 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
395 EXPECT_EQ(1U, cache.size()); in TEST()
398 now += base::Seconds(5); in TEST()
401 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
402 cache.Set(key2, entry, now, kFailureEntryTTL); in TEST()
403 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
404 EXPECT_EQ(2U, cache.size()); in TEST()
407 now += base::Seconds(4); in TEST()
410 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
411 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
414 now += base::Seconds(1); in TEST()
416 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
417 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
420 cache.Set(key1, entry, now, kFailureEntryTTL); in TEST()
421 // Re-uses existing entry storage. in TEST()
422 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
423 EXPECT_EQ(2U, cache.size()); in TEST()
426 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
427 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
430 now += base::Seconds(10); in TEST()
432 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
433 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
436 // Tests that the same hostname can be duplicated in the cache, so long as
439 const base::TimeDelta kSuccessEntryTTL = base::Seconds(10); in TEST()
441 HostCache cache(kMaxCacheEntries); in TEST() local
444 base::TimeTicks now; in TEST()
456 EXPECT_EQ(0U, cache.size()); in TEST()
459 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
460 cache.Set(key1, entry, now, kSuccessEntryTTL); in TEST()
461 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
462 EXPECT_EQ(1U, cache.size()); in TEST()
465 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
466 cache.Set(key2, entry, now, kSuccessEntryTTL); in TEST()
467 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
468 EXPECT_EQ(2U, cache.size()); in TEST()
472 EXPECT_NE(cache.Lookup(key1, now), cache.Lookup(key2, now)); in TEST()
475 // Tests that the same hostname can be duplicated in the cache, so long as
479 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
481 HostCache cache(kMaxCacheEntries); in TEST() local
484 base::TimeTicks now; in TEST()
496 EXPECT_EQ(0U, cache.size()); in TEST()
499 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
500 cache.Set(key1, entry, now, kTTL); in TEST()
501 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
502 EXPECT_EQ(1U, cache.size()); in TEST()
505 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
506 cache.Set(key2, entry, now, kTTL); in TEST()
507 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
508 EXPECT_EQ(2U, cache.size()); in TEST()
511 EXPECT_FALSE(cache.Lookup(key3, now)); in TEST()
512 cache.Set(key3, entry, now, kTTL); in TEST()
513 EXPECT_TRUE(cache.Lookup(key3, now)); in TEST()
514 EXPECT_EQ(3U, cache.size()); in TEST()
518 EXPECT_NE(cache.Lookup(key1, now), cache.Lookup(key2, now)); in TEST()
519 EXPECT_NE(cache.Lookup(key1, now), cache.Lookup(key3, now)); in TEST()
520 EXPECT_NE(cache.Lookup(key2, now), cache.Lookup(key3, now)); in TEST()
523 // Tests that the same hostname can be duplicated in the cache, so long as
527 const base::TimeDelta kSuccessEntryTTL = base::Seconds(10); in TEST()
529 HostCache cache(kMaxCacheEntries); in TEST() local
532 base::TimeTicks now; in TEST()
542 EXPECT_EQ(0U, cache.size()); in TEST()
545 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
546 cache.Set(key1, entry, now, kSuccessEntryTTL); in TEST()
547 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
548 EXPECT_EQ(1U, cache.size()); in TEST()
551 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
552 cache.Set(key2, entry, now, kSuccessEntryTTL); in TEST()
553 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
554 EXPECT_EQ(2U, cache.size()); in TEST()
558 EXPECT_NE(cache.Lookup(key1, now), cache.Lookup(key2, now)); in TEST()
561 // Tests that the same hostname can be duplicated in the cache, so long as
565 const base::TimeDelta kSuccessEntryTTL = base::Seconds(10); in TEST()
567 HostCache cache(kMaxCacheEntries); in TEST() local
570 base::TimeTicks now; in TEST()
583 EXPECT_EQ(0U, cache.size()); in TEST()
586 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
587 cache.Set(key1, entry, now, kSuccessEntryTTL); in TEST()
588 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
589 EXPECT_EQ(1U, cache.size()); in TEST()
593 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
594 EXPECT_FALSE(cache.LookupStale(key2, now, &stale)); in TEST()
596 result = cache.Lookup(key2, now, true /* ignore_secure */); in TEST()
598 EXPECT_TRUE(result->first.secure); in TEST()
599 result = cache.LookupStale(key2, now, &stale, true /* ignore_secure */); in TEST()
601 EXPECT_TRUE(result->first.secure); in TEST()
604 cache.Set(key2, entry, now, kSuccessEntryTTL); in TEST()
605 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
606 EXPECT_TRUE(cache.LookupStale(key2, now, &stale)); in TEST()
607 EXPECT_EQ(2U, cache.size()); in TEST()
612 const base::TimeDelta kSuccessEntryTTL = base::Seconds(10); in TEST()
614 HostCache cache(kMaxCacheEntries); in TEST() local
617 base::TimeTicks now; in TEST()
630 EXPECT_EQ(0U, cache.size()); in TEST()
633 cache.Set(insecure_key, entry, now, kSuccessEntryTTL); in TEST()
634 cache.Set(secure_key, entry, now, kSuccessEntryTTL); in TEST()
635 EXPECT_EQ(insecure_key, cache.Lookup(insecure_key, now)->first); in TEST()
636 EXPECT_EQ(secure_key, cache.Lookup(secure_key, now)->first); in TEST()
639 cache.Lookup(insecure_key, now, true /* ignore_secure */)->first); in TEST()
641 cache.Lookup(insecure_key, now, true /* ignore_secure */)->first); in TEST()
644 cache.Invalidate(); in TEST()
646 // Re-add insecure entry. in TEST()
647 cache.Set(insecure_key, entry, now, kSuccessEntryTTL); in TEST()
648 EXPECT_EQ(insecure_key, cache.Lookup(insecure_key, now)->first); in TEST()
649 EXPECT_FALSE(cache.Lookup(secure_key, now)); in TEST()
650 EXPECT_EQ(secure_key, cache.LookupStale(secure_key, now, &stale)->first); in TEST()
654 cache.LookupStale(secure_key, now, &stale, true /* ignore-secure */) in TEST()
655 ->first); in TEST()
657 // Add both insecure and secure entries to a cleared cache, still at t=0. in TEST()
658 cache.clear(); in TEST()
659 cache.Set(insecure_key, entry, now, base::Seconds(20)); in TEST()
660 cache.Set(secure_key, entry, now, kSuccessEntryTTL); in TEST()
663 now += base::Seconds(15); in TEST()
664 EXPECT_EQ(insecure_key, cache.Lookup(insecure_key, now)->first); in TEST()
665 EXPECT_FALSE(cache.Lookup(secure_key, now)); in TEST()
666 EXPECT_EQ(secure_key, cache.LookupStale(secure_key, now, &stale)->first); in TEST()
667 // Non-expired result is preferred. in TEST()
670 cache.LookupStale(secure_key, now, &stale, true /* ignore-secure */) in TEST()
671 ->first); in TEST()
675 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
678 HostCache cache(0); in TEST() local
679 EXPECT_TRUE(cache.caching_is_disabled()); in TEST()
682 base::TimeTicks now; in TEST()
689 EXPECT_FALSE(cache.Lookup(Key("foobar.com"), now)); in TEST()
690 cache.Set(Key("foobar.com"), entry, now, kTTL); in TEST()
691 EXPECT_FALSE(cache.Lookup(Key("foobar.com"), now)); in TEST()
693 EXPECT_EQ(0U, cache.size()); in TEST()
697 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
699 HostCache cache(kMaxCacheEntries); in TEST() local
702 base::TimeTicks now; in TEST()
708 EXPECT_EQ(0u, cache.size()); in TEST()
711 cache.Set(Key("foobar1.com"), entry, now, kTTL); in TEST()
712 cache.Set(Key("foobar2.com"), entry, now, kTTL); in TEST()
713 cache.Set(Key("foobar3.com"), entry, now, kTTL); in TEST()
715 EXPECT_EQ(3u, cache.size()); in TEST()
717 cache.clear(); in TEST()
719 EXPECT_EQ(0u, cache.size()); in TEST()
723 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
725 HostCache cache(kMaxCacheEntries); in TEST() local
728 base::TimeTicks now; in TEST()
734 EXPECT_EQ(0u, cache.size()); in TEST()
737 cache.Set(Key("foobar1.com"), entry, now, kTTL); in TEST()
738 cache.Set(Key("foobar2.com"), entry, now, kTTL); in TEST()
739 cache.Set(Key("foobar3.com"), entry, now, kTTL); in TEST()
740 cache.Set(Key("foobar4.com"), entry, now, kTTL); in TEST()
741 cache.Set(Key("foobar5.com"), entry, now, kTTL); in TEST()
743 EXPECT_EQ(5u, cache.size()); in TEST()
746 cache.ClearForHosts(base::BindRepeating(&FoobarIndexIsOdd)); in TEST()
748 EXPECT_EQ(2u, cache.size()); in TEST()
749 EXPECT_TRUE(cache.Lookup(Key("foobar2.com"), now)); in TEST()
750 EXPECT_TRUE(cache.Lookup(Key("foobar4.com"), now)); in TEST()
753 cache.ClearForHosts(base::NullCallback()); in TEST()
755 EXPECT_EQ(0u, cache.size()); in TEST()
758 // Try to add too many entries to cache; it should evict the one with the oldest
761 HostCache cache(2); in TEST() local
763 base::TimeTicks now; in TEST()
772 EXPECT_EQ(0u, cache.size()); in TEST()
773 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
774 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
775 EXPECT_FALSE(cache.Lookup(key3, now)); in TEST()
778 cache.Set(key1, entry, now, base::Seconds(10)); in TEST()
779 cache.Set(key2, entry, now, base::Seconds(5)); in TEST()
780 EXPECT_EQ(2u, cache.size()); in TEST()
781 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
782 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
783 EXPECT_FALSE(cache.Lookup(key3, now)); in TEST()
786 cache.Set(key3, entry, now, base::Seconds(10)); in TEST()
787 EXPECT_EQ(2u, cache.size()); in TEST()
788 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
789 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
790 EXPECT_TRUE(cache.Lookup(key3, now)); in TEST()
793 // Try to retrieve stale entries from the cache. They should be returned by
796 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
798 HostCache cache(kMaxCacheEntries); in TEST() local
801 base::TimeTicks now; in TEST()
809 EXPECT_EQ(0U, cache.size()); in TEST()
812 EXPECT_FALSE(cache.Lookup(key, now)); in TEST()
813 EXPECT_FALSE(cache.LookupStale(key, now, &stale)); in TEST()
814 cache.Set(key, entry, now, kTTL); in TEST()
815 EXPECT_TRUE(cache.Lookup(key, now)); in TEST()
816 EXPECT_TRUE(cache.LookupStale(key, now, &stale)); in TEST()
820 EXPECT_EQ(1U, cache.size()); in TEST()
823 now += base::Seconds(5); in TEST()
825 EXPECT_TRUE(cache.Lookup(key, now)); in TEST()
826 EXPECT_TRUE(cache.LookupStale(key, now, &stale)); in TEST()
831 now += base::Seconds(10); in TEST()
833 EXPECT_FALSE(cache.Lookup(key, now)); in TEST()
834 EXPECT_TRUE(cache.LookupStale(key, now, &stale)); in TEST()
836 EXPECT_EQ(base::Seconds(5), stale.expired_by); in TEST()
841 now += base::Seconds(5); in TEST()
843 EXPECT_FALSE(cache.Lookup(key, now)); in TEST()
844 EXPECT_TRUE(cache.LookupStale(key, now, &stale)); in TEST()
846 EXPECT_EQ(base::Seconds(10), stale.expired_by); in TEST()
851 cache.Invalidate(); in TEST()
853 EXPECT_FALSE(cache.Lookup(key, now)); in TEST()
854 EXPECT_TRUE(cache.LookupStale(key, now, &stale)); in TEST()
856 EXPECT_EQ(base::Seconds(10), stale.expired_by); in TEST()
862 HostCache cache(2); in TEST() local
864 base::TimeTicks now; in TEST()
874 EXPECT_EQ(0u, cache.size()); in TEST()
875 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
876 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
877 EXPECT_FALSE(cache.Lookup(key3, now)); in TEST()
880 cache.Set(key1, entry, now, base::Seconds(10)); in TEST()
881 EXPECT_EQ(1u, cache.size()); in TEST()
882 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
883 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
884 EXPECT_FALSE(cache.Lookup(key3, now)); in TEST()
886 // Simulate network change, expiring the cache. in TEST()
887 cache.Invalidate(); in TEST()
889 EXPECT_EQ(1u, cache.size()); in TEST()
890 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
891 EXPECT_TRUE(cache.LookupStale(key1, now, &stale)); in TEST()
895 now += base::Seconds(1); in TEST()
898 cache.Set(key2, entry, now, base::Seconds(5)); in TEST()
899 EXPECT_EQ(2u, cache.size()); in TEST()
900 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
901 EXPECT_TRUE(cache.LookupStale(key1, now, &stale)); in TEST()
902 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
903 EXPECT_FALSE(cache.Lookup(key3, now)); in TEST()
906 cache.Set(key3, entry, now, base::Seconds(1)); in TEST()
907 EXPECT_EQ(2u, cache.size()); in TEST()
908 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
909 EXPECT_FALSE(cache.LookupStale(key1, now, &stale)); in TEST()
910 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
911 EXPECT_TRUE(cache.Lookup(key3, now)); in TEST()
914 now += base::Seconds(5); in TEST()
917 cache.Set(key1, entry, now, base::Seconds(10)); in TEST()
918 EXPECT_EQ(2u, cache.size()); in TEST()
919 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
920 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
921 EXPECT_TRUE(cache.LookupStale(key2, now, &stale)); in TEST()
922 EXPECT_FALSE(cache.Lookup(key3, now)); in TEST()
923 EXPECT_FALSE(cache.LookupStale(key3, now, &stale)); in TEST()
926 // Pinned entries should not be evicted, even if the cache is full and the Entry
929 HostCache cache(2); in TEST() local
931 base::TimeTicks now; in TEST()
941 cache.Set(key1, entry, now, base::Seconds(5)); in TEST()
942 now += base::Seconds(10); in TEST()
943 cache.Set(key2, entry, now, base::Seconds(5)); in TEST()
944 now += base::Seconds(10); in TEST()
945 cache.Set(key3, entry, now, base::Seconds(5)); in TEST()
947 // There are 3 entries in this cache whose nominal max size is 2. in TEST()
948 EXPECT_EQ(3u, cache.size()); in TEST()
949 EXPECT_TRUE(cache.LookupStale(key1, now, nullptr)); in TEST()
950 EXPECT_TRUE(cache.LookupStale(key2, now, nullptr)); in TEST()
951 EXPECT_TRUE(cache.Lookup(key3, now)); in TEST()
956 HostCache cache(2); in TEST() local
958 base::TimeTicks now; in TEST()
970 cache.Set(key1, entry, now, base::Seconds(5)); in TEST()
971 cache.Set(key2, entry, now, base::Seconds(10)); in TEST()
972 cache.Set(key3, entry, now, base::Seconds(5)); in TEST()
973 // There are 3 entries in this cache whose nominal max size is 2. in TEST()
974 EXPECT_EQ(3u, cache.size()); in TEST()
976 cache.Invalidate(); in TEST()
978 EXPECT_EQ(3u, cache.size()); in TEST()
980 // |Set()| triggers an eviction, leaving only |key2| in cache, in TEST()
982 cache.Set(key4, entry, now, base::Seconds(2)); in TEST()
983 EXPECT_EQ(2u, cache.size()); in TEST()
984 EXPECT_FALSE(cache.LookupStale(key1, now, nullptr)); in TEST()
985 EXPECT_TRUE(cache.LookupStale(key2, now, nullptr)); in TEST()
986 EXPECT_FALSE(cache.LookupStale(key3, now, nullptr)); in TEST()
987 EXPECT_TRUE(cache.LookupStale(key4, now, nullptr)); in TEST()
993 HostCache cache(2); in TEST() local
995 base::TimeTicks now; in TEST()
1010 cache.Set(key, entry1, now, base::Seconds(10)); in TEST()
1011 const auto* pair1 = cache.Lookup(key, now); in TEST()
1013 const HostCache::Entry& result1 = pair1->second; in TEST()
1020 cache.Set(key, entry2, now, base::Seconds(10)); in TEST()
1021 const auto* pair2 = cache.Lookup(key, now); in TEST()
1023 const HostCache::Entry& result2 = pair2->second; in TEST()
1029 // An obsolete cache pin is not preserved if the record is replaced.
1031 HostCache cache(2); in TEST() local
1033 base::TimeTicks now; in TEST()
1048 cache.Set(key, entry1, now, base::Seconds(10)); in TEST()
1049 const auto* pair1 = cache.Lookup(key, now); in TEST()
1051 const HostCache::Entry& result1 = pair1->second; in TEST()
1057 cache.Invalidate(); in TEST()
1061 cache.Set(key, entry2, now, base::Seconds(10)); in TEST()
1062 const auto* pair2 = cache.Lookup(key, now); in TEST()
1064 const HostCache::Entry& result2 = pair2->second; in TEST()
1073 HostCache cache(2); in TEST() local
1075 base::TimeTicks now; in TEST()
1091 cache.Set(key, entry1, now, base::Seconds(10)); in TEST()
1092 const auto* pair1 = cache.Lookup(key, now); in TEST()
1094 const HostCache::Entry& result1 = pair1->second; in TEST()
1101 cache.Set(key, entry2, now, base::Seconds(10)); in TEST()
1102 const auto* pair2 = cache.Lookup(key, now); in TEST()
1104 const HostCache::Entry& result2 = pair2->second; in TEST()
1123 // -1 means key1 is less than key2 in TEST()
1149 -1}, in TEST()
1156 -1}, in TEST()
1170 -1}, in TEST()
1177 -1}, in TEST()
1191 -1}, in TEST()
1207 -1}, in TEST()
1219 -1}, in TEST()
1226 -1}, in TEST()
1237 tests.emplace_back(insecure_key, secure_key, -1); in TEST()
1240 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]", i)); in TEST()
1246 case -1: in TEST()
1259 FAIL() << "Invalid expectation. Can be only -1, 0, 1"; in TEST()
1265 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
1267 HostCache cache(kMaxCacheEntries); in TEST() local
1270 base::TimeTicks now; in TEST()
1279 EXPECT_EQ(0u, cache.size()); in TEST()
1282 EXPECT_FALSE(cache.Lookup(expire_by_time_key, now)); in TEST()
1283 cache.Set(expire_by_time_key, entry, now, kTTL); in TEST()
1284 EXPECT_THAT(cache.Lookup(expire_by_time_key, now), in TEST()
1287 EXPECT_EQ(1u, cache.size()); in TEST()
1290 now += base::Seconds(5); in TEST()
1293 EXPECT_FALSE(cache.Lookup(expire_by_changes_key, now)); in TEST()
1294 cache.Set(expire_by_changes_key, entry, now, kTTL); in TEST()
1295 EXPECT_TRUE(cache.Lookup(expire_by_changes_key, now)); in TEST()
1296 EXPECT_EQ(2u, cache.size()); in TEST()
1298 EXPECT_EQ(0u, cache.last_restore_size()); in TEST()
1300 // Advance to t=12, and serialize/deserialize the cache. in TEST()
1301 now += base::Seconds(7); in TEST()
1303 base::Value::List serialized_cache; in TEST()
1304 cache.GetList(serialized_cache, false /* include_staleness */, in TEST()
1320 EXPECT_GT(base::Milliseconds(100), in TEST()
1321 (base::Seconds(2) - stale.expired_by).magnitude()); in TEST()
1328 EXPECT_GT(base::Milliseconds(100), in TEST()
1329 (base::Seconds(-3) - stale.expired_by).magnitude()); in TEST()
1337 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
1339 HostCache cache(kMaxCacheEntries); in TEST() local
1342 base::TimeTicks now; in TEST()
1361 EXPECT_EQ(0u, cache.size()); in TEST()
1364 EXPECT_FALSE(cache.Lookup(to_serialize_key1, now)); in TEST()
1365 cache.Set(to_serialize_key1, serialized_entry, now, kTTL); in TEST()
1367 cache.Lookup(to_serialize_key1, now), in TEST()
1369 EXPECT_FALSE(cache.Lookup(to_serialize_key2, now)); in TEST()
1370 cache.Set(to_serialize_key2, serialized_entry, now, kTTL); in TEST()
1372 cache.Lookup(to_serialize_key2, now), in TEST()
1374 EXPECT_EQ(2u, cache.size()); in TEST()
1376 // Serialize the cache. in TEST()
1377 base::Value::List serialized_cache; in TEST()
1378 cache.GetList(serialized_cache, false /* include_staleness */, in TEST()
1382 // Add entries for `to_serialize_key1` and `other_key` to the new cache in TEST()
1421 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
1423 HostCache cache(kMaxCacheEntries); in TEST() local
1426 base::TimeTicks now; in TEST()
1449 EXPECT_EQ(0u, cache.size()); in TEST()
1452 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
1453 cache.Set(key1, entry1, now, kTTL); in TEST()
1454 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
1455 EXPECT_TRUE(cache.Lookup(key1, now)->second.error() == entry1.error()); in TEST()
1457 EXPECT_EQ(1u, cache.size()); in TEST()
1460 now += base::Seconds(5); in TEST()
1463 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
1464 cache.Set(key2, entry2, now, kTTL); in TEST()
1465 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
1466 EXPECT_EQ(2u, cache.size()); in TEST()
1468 EXPECT_FALSE(cache.Lookup(key3, now)); in TEST()
1469 cache.Set(key3, entry3, now, kTTL); in TEST()
1470 EXPECT_TRUE(cache.Lookup(key3, now)); in TEST()
1471 EXPECT_EQ(3u, cache.size()); in TEST()
1473 EXPECT_EQ(0u, cache.last_restore_size()); in TEST()
1475 // Advance to t=12, ansd serialize the cache. in TEST()
1476 now += base::Seconds(7); in TEST()
1478 base::Value::List serialized_cache; in TEST()
1479 cache.GetList(serialized_cache, false /* include_staleness */, in TEST()
1483 // Add entries for "foobar3.com" and "foobar4.com" to the cache before in TEST()
1507 EXPECT_TRUE(result1->first.secure); in TEST()
1508 EXPECT_THAT(result1->second.text_records(), IsEmpty()); in TEST()
1509 EXPECT_THAT(result1->second.hostnames(), IsEmpty()); in TEST()
1510 EXPECT_EQ(1u, result1->second.ip_endpoints().size()); in TEST()
1511 EXPECT_EQ(endpoint_ipv4, result1->second.ip_endpoints().front()); in TEST()
1515 EXPECT_GT(base::Milliseconds(100), in TEST()
1516 (base::Seconds(2) - stale.expired_by).magnitude()); in TEST()
1523 EXPECT_FALSE(result2->first.secure); in TEST()
1524 EXPECT_EQ(2u, result2->second.ip_endpoints().size()); in TEST()
1525 EXPECT_EQ(endpoint_ipv6, result2->second.ip_endpoints().front()); in TEST()
1526 EXPECT_EQ(endpoint_ipv4, result2->second.ip_endpoints().back()); in TEST()
1528 EXPECT_GT(base::Milliseconds(100), in TEST()
1529 (base::Seconds(-3) - stale.expired_by).magnitude()); in TEST()
1535 EXPECT_EQ(1u, result3->second.ip_endpoints().size()); in TEST()
1536 EXPECT_EQ(endpoint_ipv4, result3->second.ip_endpoints().front()); in TEST()
1542 EXPECT_EQ(1u, result4->second.ip_endpoints().size()); in TEST()
1543 EXPECT_EQ(endpoint_ipv4, result4->second.ip_endpoints().front()); in TEST()
1549 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
1557 base::TimeTicks now; in TEST()
1558 HostCache cache(kMaxCacheEntries); in TEST() local
1560 cache.Set(key, entry, now, kTTL); in TEST()
1561 ASSERT_TRUE(cache.Lookup(key, now)); in TEST()
1562 ASSERT_EQ(cache.size(), 1u); in TEST()
1564 base::Value::List serialized_cache; in TEST()
1565 cache.GetList(serialized_cache, /*include_staleness=*/false, in TEST()
1579 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
1596 base::TimeTicks now; in TEST()
1597 HostCache cache(kMaxCacheEntries); in TEST() local
1599 cache.Set(key1, entry, now, kTTL); in TEST()
1600 cache.Set(key2, entry, now, kTTL); in TEST()
1602 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
1604 cache.Lookup(key1, now)->first.network_anonymization_key); in TEST()
1605 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
1607 cache.Lookup(key2, now)->first.network_anonymization_key); in TEST()
1608 EXPECT_EQ(2u, cache.size()); in TEST()
1610 base::Value::List serialized_cache; in TEST()
1611 cache.GetList(serialized_cache, false /* include_staleness */, in TEST()
1625 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
1636 base::TimeTicks now; in TEST()
1637 HostCache cache(kMaxCacheEntries); in TEST() local
1639 cache.Set(key, entry, now, kTTL); in TEST()
1641 EXPECT_TRUE(cache.Lookup(key, now)); in TEST()
1643 cache.Lookup(key, now)->first.network_anonymization_key); in TEST()
1644 EXPECT_EQ(1u, cache.size()); in TEST()
1646 base::Value::List serialized_cache; in TEST()
1647 cache.GetList(serialized_cache, false /* include_staleness */, in TEST()
1661 base::TimeTicks now; in TEST()
1663 base::TimeDelta ttl = base::Seconds(99); in TEST()
1672 HostCache cache(kMaxCacheEntries); in TEST() local
1673 cache.Set(key, entry, now, ttl); in TEST()
1674 EXPECT_EQ(1u, cache.size()); in TEST()
1676 base::Value::List serialized_cache; in TEST()
1677 cache.GetList(serialized_cache, false /* include_staleness */, in TEST()
1688 EXPECT_THAT(result->second.text_records(), text_records); in TEST()
1692 base::TimeTicks now; in TEST()
1694 base::TimeDelta ttl = base::Seconds(99); in TEST()
1703 HostCache cache(kMaxCacheEntries); in TEST() local
1704 cache.Set(key, entry, now, ttl); in TEST()
1705 EXPECT_EQ(1u, cache.size()); in TEST()
1707 base::Value::List serialized_cache; in TEST()
1708 cache.GetList(serialized_cache, false /* include_staleness */, in TEST()
1718 EXPECT_THAT(result->second.hostnames(), hostnames); in TEST()
1722 base::TimeTicks now; in TEST()
1724 base::TimeDelta ttl = base::Seconds(99); in TEST()
1775 HostCache cache(kMaxCacheEntries); in TEST() local
1776 cache.Set(key, merged_entry, now, ttl); in TEST()
1777 EXPECT_EQ(1u, cache.size()); in TEST()
1779 base::Value::List serialized_cache; in TEST()
1780 cache.GetList(serialized_cache, false /* include_staleness */, in TEST()
1788 EXPECT_TRUE(base::JSONWriter::Write(serialized_cache, &json)); in TEST()
1797 EXPECT_THAT(result->second.GetEndpoints(), in TEST()
1800 result->second.GetMetadatas(), in TEST()
1807 EXPECT_THAT(result->second.canonical_names(), in TEST()
1810 EXPECT_EQ(result->second.aliases(), aliases); in TEST()
1814 base::TimeDelta ttl = base::Seconds(99); in TEST()
1815 std::string expiration_time_str = base::NumberToString( in TEST()
1816 (base::Time::Now() + ttl).since_origin().InMicroseconds()); in TEST()
1818 auto dict = base::JSONReader::Read(base::StringPrintf( in TEST()
1836 ASSERT_TRUE(dict->is_list()); in TEST()
1837 EXPECT_TRUE(restored_cache.RestoreFromListValue(dict->GetList())); in TEST()
1847 restored_cache.LookupStale(key, base::TimeTicks::Now(), &stale); in TEST()
1850 EXPECT_THAT(result->second.aliases(), ElementsAre()); in TEST()
1851 EXPECT_THAT(result->second.ip_endpoints(), ElementsAre()); in TEST()
1855 base::TimeDelta ttl = base::Seconds(99); in TEST()
1856 std::string expiration_time_str = base::NumberToString( in TEST()
1857 (base::Time::Now() + ttl).since_origin().InMicroseconds()); in TEST()
1859 auto dict = base::JSONReader::Read(base::StringPrintf( in TEST()
1878 ASSERT_TRUE(dict->is_list()); in TEST()
1879 EXPECT_TRUE(restored_cache.RestoreFromListValue(dict->GetList())); in TEST()
1889 restored_cache.LookupStale(key, base::TimeTicks::Now(), &stale); in TEST()
1892 EXPECT_THAT(result->second.ip_endpoints(), in TEST()
1894 EXPECT_THAT(result->second.aliases(), ElementsAre()); in TEST()
1898 base::TimeDelta ttl = base::Seconds(99); in TEST()
1899 std::string expiration_time_str = base::NumberToString( in TEST()
1900 (base::Time::Now() + ttl).since_origin().InMicroseconds()); in TEST()
1903 auto dict = base::JSONReader::Read(base::StringPrintf( in TEST()
1922 ASSERT_TRUE(dict->is_list()); in TEST()
1923 EXPECT_FALSE(restored_cache.RestoreFromListValue(dict->GetList())); in TEST()
1929 base::TimeDelta ttl = base::Seconds(99); in TEST()
1930 std::string expiration_time_str = base::NumberToString( in TEST()
1931 (base::Time::Now() + ttl).since_origin().InMicroseconds()); in TEST()
1934 auto dict = base::JSONReader::Read(base::StringPrintf( in TEST()
1953 ASSERT_TRUE(dict->is_list()); in TEST()
1954 EXPECT_FALSE(restored_cache.RestoreFromListValue(dict->GetList())); in TEST()
1960 const base::TimeDelta kTTL = base::Seconds(10); in TEST()
1961 HostCache cache(kMaxCacheEntries); in TEST() local
1963 cache.set_persistence_delegate(&delegate); in TEST()
1980 base::TimeTicks now; in TEST()
1981 EXPECT_EQ(0u, cache.size()); in TEST()
1984 EXPECT_FALSE(cache.Lookup(key1, now)); in TEST()
1985 cache.Set(key1, ok_entry, now, kTTL); in TEST()
1986 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
1987 EXPECT_EQ(1u, cache.size()); in TEST()
1990 EXPECT_FALSE(cache.Lookup(key2, now)); in TEST()
1991 cache.Set(key2, error_entry, now, kTTL); in TEST()
1992 EXPECT_TRUE(cache.Lookup(key2, now)); in TEST()
1993 EXPECT_EQ(2u, cache.size()); in TEST()
1997 now += base::Seconds(5); in TEST()
2001 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
2002 cache.Set(key1, ok_entry, now, kTTL); in TEST()
2003 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
2004 EXPECT_EQ(2u, cache.size()); in TEST()
2008 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
2009 cache.Set(key1, ok_entry, now, kTTL - base::Seconds(5)); in TEST()
2010 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
2011 EXPECT_EQ(2u, cache.size()); in TEST()
2016 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
2017 cache.Set(key1, other_entry, now, kTTL); in TEST()
2018 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
2019 EXPECT_EQ(2u, cache.size()); in TEST()
2023 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
2024 cache.Set(key2, ok_entry, now, kTTL); in TEST()
2025 EXPECT_TRUE(cache.Lookup(key1, now)); in TEST()
2026 EXPECT_EQ(2u, cache.size()); in TEST()
2262 HostCache::Entry::SOURCE_DNS, base::Hours(4)); in TEST()
2277 EXPECT_EQ(base::Hours(4), result.ttl()); in TEST()
2287 HostCache::Entry::SOURCE_DNS, base::Minutes(5)); in TEST()
2304 EXPECT_EQ(base::Minutes(5), result.ttl()); in TEST()
2335 HostCache::Entry::SOURCE_DNS, base::Hours(4)); in TEST()
2345 EXPECT_EQ(base::Hours(4), result.ttl()); in TEST()
2360 HostCache::Entry::SOURCE_DNS, base::Hours(4)); in TEST()
2370 EXPECT_EQ(base::Hours(4), result.ttl()); in TEST()
2380 HostCache::Entry::SOURCE_DNS, base::Hours(4)); in TEST()
2386 HostCache::Entry::SOURCE_DNS, base::Hours(4)); in TEST()
2396 EXPECT_EQ(base::Hours(4), result.ttl()); in TEST()
2406 HostCache::Entry::SOURCE_DNS, base::Hours(4)); in TEST()
2411 HostCache::Entry::SOURCE_DNS, base::Hours(4)); in TEST()
2422 EXPECT_EQ(base::Hours(4), result.ttl()); in TEST()
2430 base::Days(12)); in TEST()
2432 base::Seconds(42)); in TEST()
2437 EXPECT_EQ(base::Seconds(42), result.ttl()); in TEST()
2470 constexpr base::TimeDelta kTtl1 = base::Minutes(45); in TEST()
2471 constexpr base::TimeDelta kTtl2 = base::Minutes(40); in TEST()
2472 constexpr base::TimeDelta kTtl3 = base::Minutes(55); in TEST()
2476 "endpoint.test", DnsQueryType::AAAA, base::TimeTicks() + kTtl1, in TEST()
2477 base::Time() + kTtl1, HostResolverInternalResult::Source::kDns, in TEST()
2480 "domain1.test", DnsQueryType::AAAA, base::TimeTicks() + kTtl2, in TEST()
2481 base::Time() + kTtl2, HostResolverInternalResult::Source::kDns, in TEST()
2484 "domain2.test", DnsQueryType::AAAA, base::TimeTicks() + kTtl3, in TEST()
2485 base::Time() + kTtl3, HostResolverInternalResult::Source::kDns, in TEST()
2488 HostCache::Entry converted(std::move(results), base::Time(), in TEST()
2489 base::TimeTicks()); in TEST()
2499 // between empty and no-data for the various data types, so need to set empty in TEST()
2512 constexpr base::TimeDelta kTtl1 = base::Minutes(45); in TEST()
2513 constexpr base::TimeDelta kTtl2 = base::Minutes(40); in TEST()
2514 constexpr base::TimeDelta kTtl3 = base::Minutes(55); in TEST()
2518 "endpoint.test", DnsQueryType::HTTPS, base::TimeTicks() + kTtl1, in TEST()
2519 base::Time() + kTtl1, HostResolverInternalResult::Source::kDns, in TEST()
2522 "domain1.test", DnsQueryType::HTTPS, base::TimeTicks() + kTtl2, in TEST()
2523 base::Time() + kTtl2, HostResolverInternalResult::Source::kDns, in TEST()
2526 "domain2.test", DnsQueryType::HTTPS, base::TimeTicks() + kTtl3, in TEST()
2527 base::Time() + kTtl3, HostResolverInternalResult::Source::kDns, in TEST()
2530 HostCache::Entry converted(std::move(results), base::Time(), in TEST()
2531 base::TimeTicks()); in TEST()
2548 constexpr base::TimeDelta kTtl1 = base::Minutes(45); in TEST()
2549 constexpr base::TimeDelta kTtl2 = base::Minutes(40); in TEST()
2550 constexpr base::TimeDelta kTtl3 = base::Minutes(55); in TEST()
2554 "endpoint.test", DnsQueryType::HTTPS, base::TimeTicks() + kTtl1, in TEST()
2555 base::Time() + kTtl1, HostResolverInternalResult::Source::kDns, in TEST()
2558 "domain1.test", DnsQueryType::HTTPS, base::TimeTicks() + kTtl2, in TEST()
2559 base::Time() + kTtl2, HostResolverInternalResult::Source::kDns, in TEST()
2562 "domain2.test", DnsQueryType::HTTPS, base::TimeTicks() + kTtl3, in TEST()
2563 base::Time() + kTtl3, HostResolverInternalResult::Source::kDns, in TEST()
2566 HostCache::Entry converted(std::move(results), base::Time(), in TEST()
2567 base::TimeTicks()); in TEST()
2578 constexpr base::TimeDelta kTtl1 = base::Minutes(45); in TEST()
2579 constexpr base::TimeDelta kTtl2 = base::Minutes(40); in TEST()
2580 constexpr base::TimeDelta kTtl3 = base::Minutes(55); in TEST()
2584 "endpoint.test", DnsQueryType::A, base::TimeTicks() + kTtl1, in TEST()
2585 base::Time() + kTtl1, HostResolverInternalResult::Source::kDns, in TEST()
2588 "domain1.test", DnsQueryType::A, base::TimeTicks() + kTtl2, in TEST()
2589 base::Time() + kTtl2, HostResolverInternalResult::Source::kDns, in TEST()
2592 "domain2.test", DnsQueryType::A, base::TimeTicks() + kTtl3, in TEST()
2593 base::Time() + kTtl3, HostResolverInternalResult::Source::kDns, in TEST()
2596 HostCache::Entry converted(std::move(results), base::Time(), in TEST()
2597 base::TimeTicks()); in TEST()
2607 constexpr base::TimeDelta kTtl1 = base::Minutes(45); in TEST()
2608 constexpr base::TimeDelta kTtl2 = base::Minutes(40); in TEST()
2616 "domain1.test", DnsQueryType::AAAA, base::TimeTicks() + kTtl1, in TEST()
2617 base::Time() + kTtl1, HostResolverInternalResult::Source::kDns, in TEST()
2620 "domain2.test", DnsQueryType::AAAA, base::TimeTicks() + kTtl2, in TEST()
2621 base::Time() + kTtl2, HostResolverInternalResult::Source::kDns, in TEST()
2624 HostCache::Entry converted(std::move(results), base::Time(), in TEST()
2625 base::TimeTicks()); in TEST()
2627 // Expect no TTL because error is non-cachable (has no TTL itself). in TEST()
2635 constexpr base::TimeDelta kTtl1 = base::Minutes(45); in TEST()
2636 constexpr base::TimeDelta kTtl2 = base::Minutes(40); in TEST()
2640 "domain1.test", DnsQueryType::A, base::TimeTicks() + kTtl1, in TEST()
2641 base::Time() + kTtl1, HostResolverInternalResult::Source::kDns, in TEST()
2644 "domain2.test", DnsQueryType::A, base::TimeTicks() + kTtl2, in TEST()
2645 base::Time() + kTtl2, HostResolverInternalResult::Source::kDns, in TEST()
2648 HostCache::Entry converted(std::move(results), base::Time(), in TEST()
2649 base::TimeTicks()); in TEST()
2651 // Expect no TTL because alias-only results are not cacheable. in TEST()
2659 HostCache::Entry converted({}, base::Time(), base::TimeTicks()); in TEST()