Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: net/dns/host_cache_unittest.cc

Issue 2953483003: Add HostCachePersistenceManager for Cronet (Closed)
Patch Set: move constant Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/dns/host_cache.cc ('k') | net/log/net_log_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/dns/host_cache.h" 5 #include "net/dns/host_cache.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 EXPECT_EQ(2u, cache.size()); 697 EXPECT_EQ(2u, cache.size());
698 698
699 EXPECT_FALSE(cache.Lookup(key3, now)); 699 EXPECT_FALSE(cache.Lookup(key3, now));
700 cache.Set(key3, entry3, now, kTTL); 700 cache.Set(key3, entry3, now, kTTL);
701 EXPECT_TRUE(cache.Lookup(key3, now)); 701 EXPECT_TRUE(cache.Lookup(key3, now));
702 EXPECT_EQ(3u, cache.size()); 702 EXPECT_EQ(3u, cache.size());
703 703
704 // Advance to t=12, ansd serialize the cache. 704 // Advance to t=12, ansd serialize the cache.
705 now += base::TimeDelta::FromSeconds(7); 705 now += base::TimeDelta::FromSeconds(7);
706 706
707 std::unique_ptr<base::ListValue> serialized_cache = 707 base::ListValue serialized_cache;
708 cache.GetAsListValue(/*include_staleness=*/false); 708 cache.GetAsListValue(&serialized_cache, /*include_staleness=*/false);
709 HostCache restored_cache(kMaxCacheEntries); 709 HostCache restored_cache(kMaxCacheEntries);
710 710
711 // Add entries for "foobar3.com" and "foobar4.com" to the cache before 711 // Add entries for "foobar3.com" and "foobar4.com" to the cache before
712 // restoring it. The "foobar3.com" result is different from the original. 712 // restoring it. The "foobar3.com" result is different from the original.
713 EXPECT_FALSE(restored_cache.Lookup(key3, now)); 713 EXPECT_FALSE(restored_cache.Lookup(key3, now));
714 restored_cache.Set(key3, entry1, now, kTTL); 714 restored_cache.Set(key3, entry1, now, kTTL);
715 EXPECT_TRUE(restored_cache.Lookup(key3, now)); 715 EXPECT_TRUE(restored_cache.Lookup(key3, now));
716 EXPECT_EQ(1u, restored_cache.size()); 716 EXPECT_EQ(1u, restored_cache.size());
717 717
718 EXPECT_FALSE(restored_cache.Lookup(key4, now)); 718 EXPECT_FALSE(restored_cache.Lookup(key4, now));
719 restored_cache.Set(key4, entry4, now, kTTL); 719 restored_cache.Set(key4, entry4, now, kTTL);
720 EXPECT_TRUE(restored_cache.Lookup(key4, now)); 720 EXPECT_TRUE(restored_cache.Lookup(key4, now));
721 EXPECT_EQ(2u, restored_cache.size()); 721 EXPECT_EQ(2u, restored_cache.size());
722 722
723 restored_cache.RestoreFromListValue(*serialized_cache); 723 restored_cache.RestoreFromListValue(serialized_cache);
724 724
725 HostCache::EntryStaleness stale; 725 HostCache::EntryStaleness stale;
726 726
727 // The "foobar.com" entry is stale due to both network changes and expiration 727 // The "foobar.com" entry is stale due to both network changes and expiration
728 // time. 728 // time.
729 EXPECT_FALSE(restored_cache.Lookup(key1, now)); 729 EXPECT_FALSE(restored_cache.Lookup(key1, now));
730 const HostCache::Entry* result1 = 730 const HostCache::Entry* result1 =
731 restored_cache.LookupStale(key1, now, &stale); 731 restored_cache.LookupStale(key1, now, &stale);
732 EXPECT_TRUE(result1); 732 EXPECT_TRUE(result1);
733 EXPECT_EQ(1u, result1->addresses().size()); 733 EXPECT_EQ(1u, result1->addresses().size());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 830
831 // Add an entry for "foobar2.com" with different error. 831 // Add an entry for "foobar2.com" with different error.
832 EXPECT_TRUE(cache.Lookup(key1, now)); 832 EXPECT_TRUE(cache.Lookup(key1, now));
833 cache.Set(key2, entry4, now, kTTL); 833 cache.Set(key2, entry4, now, kTTL);
834 EXPECT_TRUE(cache.Lookup(key1, now)); 834 EXPECT_TRUE(cache.Lookup(key1, now));
835 EXPECT_EQ(2u, cache.size()); 835 EXPECT_EQ(2u, cache.size());
836 EXPECT_EQ(4, delegate.num_changes()); 836 EXPECT_EQ(4, delegate.num_changes());
837 } 837 }
838 838
839 } // namespace net 839 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_cache.cc ('k') | net/log/net_log_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698