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

Unified Diff: components/precache/core/precache_database_unittest.cc

Issue 2300703004: Fix precache issue with cancel and resume (Closed)
Patch Set: Addressed sclittle comments Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/precache/core/precache_fetcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/precache/core/precache_database_unittest.cc
diff --git a/components/precache/core/precache_database_unittest.cc b/components/precache/core/precache_database_unittest.cc
index c0408d39ee94f57c1453ed726f4e6dd4bbeb560b..6080b6b5faa9994441c30b3840a7c1ba7c4b6a8a 100644
--- a/components/precache/core/precache_database_unittest.cc
+++ b/components/precache/core/precache_database_unittest.cc
@@ -38,6 +38,8 @@ const base::Time kFetchTime = base::Time() + base::TimeDelta::FromHours(1000);
const base::Time kOldFetchTime = kFetchTime - base::TimeDelta::FromDays(1);
const base::Time kNewFetchTime =
base::Time() + base::TimeDelta::FromHours(2000);
+const base::Time kPrecacheTime =
+ base::Time() + base::TimeDelta::FromHours(3000);
const int64_t kSize = 5000;
const int64_t kFreshnessBucket10K = 9089;
// One of the possible CacheEntryStatus for when the fetch was served from the
@@ -525,6 +527,7 @@ TEST_F(PrecacheDatabaseTest, GetURLListForReferrerHost) {
struct test_resource_info {
std::string url;
+ bool is_user_browsed;
bool is_network_fetched;
bool is_cellular_fetched;
bool expected_in_used;
@@ -537,23 +540,27 @@ TEST_F(PrecacheDatabaseTest, GetURLListForReferrerHost) {
{
"foo.com",
{
- {"http://foo.com/from-cache.js", false, false, true},
- {"http://some-cdn.com/from-network.js", true, false, false},
- {"http://foo.com/from-cache-cellular.js", false, true, true},
- {"http://foo.com/from-network-cellular.js", true, true, false},
+ {"http://foo.com/from-cache.js", true, false, false, true},
+ {"http://some-cdn.com/from-network.js", true, true, false, false},
+ {"http://foo.com/from-cache-cellular.js", true, false, true,
+ true},
+ {"http://foo.com/from-network-cellular.js", true, true, true,
+ false},
+ {"http://foo.com/not-browsed.js", false, false, false, false},
},
},
{
"bar.com",
{
- {"http://bar.com/a.js", false, false, true},
- {"http://some-cdn.com/b.js", false, true, true},
+ {"http://bar.com/a.js", true, false, false, true},
+ {"http://some-cdn.com/b.js", true, false, true, true},
+ {"http://bar.com/not-browsed.js", false, false, false, false},
},
},
{
"foobar.com",
{
- {"http://some-cdn.com/not-used.js", true, true, false},
+ {"http://some-cdn.com/not-used.js", true, true, true, false},
},
},
{
@@ -564,12 +571,14 @@ TEST_F(PrecacheDatabaseTest, GetURLListForReferrerHost) {
for (const auto& test : tests) {
for (const auto& resource : test.resource_info) {
precache_database_->RecordURLPrefetch(GURL(resource.url), test.hostname,
- base::Time(), false, kSize);
+ kPrecacheTime, false, kSize);
}
}
// Update some resources as used due to user browsing.
for (const auto& test : tests) {
for (const auto& resource : test.resource_info) {
+ if (!resource.is_user_browsed)
+ continue;
if (!resource.is_network_fetched && !resource.is_cellular_fetched) {
RecordFetchFromCache(GURL(resource.url), kFetchTime, kSize);
} else if (!resource.is_network_fetched && resource.is_cellular_fetched) {
@@ -614,6 +623,16 @@ TEST_F(PrecacheDatabaseTest, GetURLListForReferrerHost) {
referrer_id, &actual_used_urls, &actual_unused_urls);
EXPECT_TRUE(actual_used_urls.empty());
}
+ // Resources that were precached previously and not seen in user browsing
+ // should be still marked as precached.
+ std::map<GURL, base::Time> expected_url_table_map;
+ for (const auto& test : tests) {
+ for (const auto& resource : test.resource_info) {
+ if (!resource.is_user_browsed)
+ expected_url_table_map[GURL(resource.url)] = kPrecacheTime;
+ }
+ }
+ EXPECT_EQ(expected_url_table_map, GetActualURLTableMap());
}
} // namespace
« no previous file with comments | « no previous file | components/precache/core/precache_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698