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

Side by Side Diff: components/cronet/host_cache_persistence_manager_unittest.cc

Issue 2958023002: Add histograms and NetLog for host cache persistence (Closed)
Patch Set: use scoped timer 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 | « components/cronet/host_cache_persistence_manager.cc ('k') | net/dns/host_cache.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/cronet/host_cache_persistence_manager.h" 5 #include "components/cronet/host_cache_persistence_manager.h"
6 6
7 #include "base/test/scoped_mock_time_message_loop_task_runner.h" 7 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
8 #include "base/test/scoped_task_environment.h" 8 #include "base/test/scoped_task_environment.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/prefs/pref_registry_simple.h" 10 #include "components/prefs/pref_registry_simple.h"
11 #include "components/prefs/testing_pref_service.h" 11 #include "components/prefs/testing_pref_service.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/dns/host_cache.h" 13 #include "net/dns/host_cache.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace cronet { 16 namespace cronet {
17 17
18 class HostCachePersistenceManagerTest : public testing::Test { 18 class HostCachePersistenceManagerTest : public testing::Test {
19 protected: 19 protected:
20 void SetUp() override { 20 void SetUp() override {
21 cache_ = net::HostCache::CreateDefaultCache(); 21 cache_ = net::HostCache::CreateDefaultCache();
22 pref_service_ = base::MakeUnique<TestingPrefServiceSimple>(); 22 pref_service_ = base::MakeUnique<TestingPrefServiceSimple>();
23 pref_service_->registry()->RegisterListPref(kPrefName); 23 pref_service_->registry()->RegisterListPref(kPrefName);
24 } 24 }
25 25
26 void MakePersistenceManager(base::TimeDelta delay) { 26 void MakePersistenceManager(base::TimeDelta delay) {
27 persistence_manager_ = base::MakeUnique<HostCachePersistenceManager>( 27 persistence_manager_ = base::MakeUnique<HostCachePersistenceManager>(
28 cache_.get(), pref_service_.get(), kPrefName, delay); 28 cache_.get(), pref_service_.get(), kPrefName, delay, nullptr);
29 } 29 }
30 30
31 // Sets an entry in the HostCache in order to trigger a pref write. The 31 // Sets an entry in the HostCache in order to trigger a pref write. The
32 // caller is responsible for making sure this is a change that will trigger 32 // caller is responsible for making sure this is a change that will trigger
33 // a write, and the HostCache's interaction with its PersistenceDelegate is 33 // a write, and the HostCache's interaction with its PersistenceDelegate is
34 // assumed to work (it's tested in net/dns/host_cache_unittest.cc). 34 // assumed to work (it's tested in net/dns/host_cache_unittest.cc).
35 void WriteToCache(const std::string& host) { 35 void WriteToCache(const std::string& host) {
36 net::HostCache::Key key(host, net::ADDRESS_FAMILY_UNSPECIFIED, 0); 36 net::HostCache::Key key(host, net::ADDRESS_FAMILY_UNSPECIFIED, 0);
37 net::HostCache::Entry entry(net::OK, net::AddressList()); 37 net::HostCache::Entry entry(net::OK, net::AddressList());
38 cache_->Set(key, entry, base::TimeTicks::Now(), 38 cache_->Set(key, entry, base::TimeTicks::Now(),
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 MakePersistenceManager(base::TimeDelta::FromSeconds(1)); 173 MakePersistenceManager(base::TimeDelta::FromSeconds(1));
174 ASSERT_EQ(0u, cache_->size()); 174 ASSERT_EQ(0u, cache_->size());
175 175
176 CheckPref(0); 176 CheckPref(0);
177 InitializePref(); 177 InitializePref();
178 CheckPref(3); 178 CheckPref(3);
179 ASSERT_EQ(3u, cache_->size()); 179 ASSERT_EQ(3u, cache_->size());
180 } 180 }
181 181
182 } // namespace cronet 182 } // namespace cronet
OLDNEW
« no previous file with comments | « components/cronet/host_cache_persistence_manager.cc ('k') | net/dns/host_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698