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

Unified Diff: chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc

Issue 2260573002: predictors: Track whether resources have validators, and require validation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make Visual Studio happy. Created 4 years, 4 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
Index: chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc
diff --git a/chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc b/chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc
index 5146ab313c45858a4404de725a9f8506e5608af0..ed74da914ef17d0395d3042bd4d2938dd81b41e6 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc
@@ -67,6 +67,7 @@ class ResourcePrefetchPredictorTablesTest : public testing::Test {
<< "\t" << it->number_of_hits << "\t" << it->number_of_misses
<< "\t" << it->consecutive_misses << "\t"
<< it->average_position << "\t" << it->priority << "\t"
+ << it->has_validators << "\t" << it->always_revalidate << "\t"
<< it->score;
}
}
@@ -169,24 +170,26 @@ void ResourcePrefetchPredictorTablesTest::TestDeleteSingleDataPoint() {
void ResourcePrefetchPredictorTablesTest::TestUpdateData() {
PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com");
google.last_visit = base::Time::FromInternalValue(10);
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/style.css",
+ content::RESOURCE_TYPE_STYLESHEET, 6,
+ 2, 0, 1.0, net::MEDIUM, true, false));
google.resources.push_back(ResourceRow(
- std::string(), "http://www.google.com/style.css",
- content::RESOURCE_TYPE_STYLESHEET, 6, 2, 0, 1.0, net::MEDIUM));
- google.resources.push_back(
- ResourceRow(std::string(), "http://www.google.com/image.png",
- content::RESOURCE_TYPE_IMAGE, 6, 4, 1, 4.2, net::MEDIUM));
- google.resources.push_back(
- ResourceRow(std::string(), "http://www.google.com/a.xml",
- content::RESOURCE_TYPE_LAST_TYPE, 1, 0, 0, 6.1, net::MEDIUM));
- google.resources.push_back(
- ResourceRow(std::string(), "http://www.resources.google.com/script.js",
- content::RESOURCE_TYPE_SCRIPT, 12, 0, 0, 8.5, net::MEDIUM));
+ std::string(), "http://www.google.com/image.png",
+ content::RESOURCE_TYPE_IMAGE, 6, 4, 1, 4.2, net::MEDIUM, false, false));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/a.xml",
+ content::RESOURCE_TYPE_LAST_TYPE, 1, 0,
+ 0, 6.1, net::MEDIUM, false, false));
+ google.resources.push_back(ResourceRow(
+ std::string(), "http://www.resources.google.com/script.js",
+ content::RESOURCE_TYPE_SCRIPT, 12, 0, 0, 8.5, net::MEDIUM, true, true));
PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com");
yahoo.last_visit = base::Time::FromInternalValue(7);
- yahoo.resources.push_back(
- ResourceRow(std::string(), "http://www.yahoo.com/image.png",
- content::RESOURCE_TYPE_IMAGE, 120, 1, 1, 10.0, net::MEDIUM));
+ yahoo.resources.push_back(ResourceRow(
+ std::string(), "http://www.yahoo.com/image.png",
+ content::RESOURCE_TYPE_IMAGE, 120, 1, 1, 10.0, net::MEDIUM, true, false));
tables_->UpdateData(google, yahoo);
@@ -268,36 +271,43 @@ void ResourcePrefetchPredictorTablesTest::InitializeSampleData() {
{ // Url data.
PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com");
google.last_visit = base::Time::FromInternalValue(1);
- google.resources.push_back(ResourceRow(
- std::string(), "http://www.google.com/style.css",
- content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1, net::MEDIUM));
google.resources.push_back(
- ResourceRow(std::string(), "http://www.google.com/script.js",
- content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 2.1, net::MEDIUM));
- google.resources.push_back(
- ResourceRow(std::string(), "http://www.google.com/image.png",
- content::RESOURCE_TYPE_IMAGE, 6, 3, 0, 2.2, net::MEDIUM));
+ ResourceRow(std::string(), "http://www.google.com/style.css",
+ content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1,
+ net::MEDIUM, false, false));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/script.js",
+ content::RESOURCE_TYPE_SCRIPT, 4, 0,
+ 1, 2.1, net::MEDIUM, false, false));
google.resources.push_back(ResourceRow(
- std::string(), "http://www.google.com/a.font",
- content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, 5.1, net::MEDIUM));
+ std::string(), "http://www.google.com/image.png",
+ content::RESOURCE_TYPE_IMAGE, 6, 3, 0, 2.2, net::MEDIUM, false, false));
+ google.resources.push_back(
+ ResourceRow(std::string(), "http://www.google.com/a.font",
+ content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, 5.1, net::MEDIUM,
+ false, false));
google.resources.push_back(
ResourceRow(std::string(), "http://www.resources.google.com/script.js",
- content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 8.5, net::MEDIUM));
+ content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 8.5, net::MEDIUM,
+ false, false));
PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com");
reddit.last_visit = base::Time::FromInternalValue(2);
reddit.resources.push_back(
ResourceRow(std::string(), "http://reddit-resource.com/script1.js",
- content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 1.0, net::MEDIUM));
+ content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 1.0, net::MEDIUM,
+ false, false));
reddit.resources.push_back(
ResourceRow(std::string(), "http://reddit-resource.com/script2.js",
- content::RESOURCE_TYPE_SCRIPT, 2, 0, 0, 2.1, net::MEDIUM));
+ content::RESOURCE_TYPE_SCRIPT, 2, 0, 0, 2.1, net::MEDIUM,
+ false, false));
PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com");
yahoo.last_visit = base::Time::FromInternalValue(3);
- yahoo.resources.push_back(
- ResourceRow(std::string(), "http://www.google.com/image.png",
- content::RESOURCE_TYPE_IMAGE, 20, 1, 0, 10.0, net::MEDIUM));
+ yahoo.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/image.png",
+ content::RESOURCE_TYPE_IMAGE, 20, 1,
+ 0, 10.0, net::MEDIUM, false, false));
test_url_data_.clear();
test_url_data_.insert(std::make_pair("http://www.google.com", google));
@@ -313,27 +323,32 @@ void ResourcePrefetchPredictorTablesTest::InitializeSampleData() {
{ // Host data.
PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com");
facebook.last_visit = base::Time::FromInternalValue(4);
- facebook.resources.push_back(ResourceRow(
- std::string(), "http://www.facebook.com/style.css",
- content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1, net::MEDIUM));
facebook.resources.push_back(
- ResourceRow(std::string(), "http://www.facebook.com/script.js",
- content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 2.1, net::MEDIUM));
+ ResourceRow(std::string(), "http://www.facebook.com/style.css",
+ content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1,
+ net::MEDIUM, false, false));
facebook.resources.push_back(
- ResourceRow(std::string(), "http://www.facebook.com/image.png",
- content::RESOURCE_TYPE_IMAGE, 6, 3, 0, 2.2, net::MEDIUM));
+ ResourceRow(std::string(), "http://www.facebook.com/script.js",
+ content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 2.1, net::MEDIUM,
+ false, false));
facebook.resources.push_back(ResourceRow(
- std::string(), "http://www.facebook.com/a.font",
- content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, 5.1, net::MEDIUM));
+ std::string(), "http://www.facebook.com/image.png",
+ content::RESOURCE_TYPE_IMAGE, 6, 3, 0, 2.2, net::MEDIUM, false, false));
+ facebook.resources.push_back(
+ ResourceRow(std::string(), "http://www.facebook.com/a.font",
+ content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, 5.1, net::MEDIUM,
+ false, false));
facebook.resources.push_back(ResourceRow(
std::string(), "http://www.resources.facebook.com/script.js",
- content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 8.5, net::MEDIUM));
+ content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 8.5, net::MEDIUM, false,
+ false));
PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com");
yahoo.last_visit = base::Time::FromInternalValue(5);
- yahoo.resources.push_back(
- ResourceRow(std::string(), "http://www.google.com/image.png",
- content::RESOURCE_TYPE_IMAGE, 20, 1, 0, 10.0, net::MEDIUM));
+ yahoo.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/image.png",
+ content::RESOURCE_TYPE_IMAGE, 20, 1,
+ 0, 10.0, net::MEDIUM, false, false));
test_host_data_.clear();
test_host_data_.insert(std::make_pair("www.facebook.com", facebook));
@@ -351,16 +366,18 @@ TEST_F(ResourcePrefetchPredictorTablesTest, ComputeScore) {
typedef ResourcePrefetchPredictorTables::ResourceRow ResourceRow;
ResourceRow js_resource(
std::string(), "http://www.resources.google.com/script.js",
- content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 1., net::MEDIUM);
+ content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 1., net::MEDIUM, false, false);
ResourceRow image_resource(
std::string(), "http://www.resources.google.com/image.jpg",
- content::RESOURCE_TYPE_IMAGE, 11, 0, 0, 1., net::MEDIUM);
- ResourceRow css_resource(
- std::string(), "http://www.resources.google.com/stylesheet.css",
- content::RESOURCE_TYPE_STYLESHEET, 11, 0, 0, 1., net::MEDIUM);
- ResourceRow font_resource(
- std::string(), "http://www.resources.google.com/font.woff",
- content::RESOURCE_TYPE_FONT_RESOURCE, 11, 0, 0, 1., net::MEDIUM);
+ content::RESOURCE_TYPE_IMAGE, 11, 0, 0, 1., net::MEDIUM, false, false);
+ ResourceRow css_resource(std::string(),
+ "http://www.resources.google.com/stylesheet.css",
+ content::RESOURCE_TYPE_STYLESHEET, 11, 0, 0, 1.,
+ net::MEDIUM, false, false);
+ ResourceRow font_resource(std::string(),
+ "http://www.resources.google.com/font.woff",
+ content::RESOURCE_TYPE_FONT_RESOURCE, 11, 0, 0, 1.,
+ net::MEDIUM, false, false);
EXPECT_TRUE(js_resource.score == css_resource.score);
EXPECT_TRUE(js_resource.score == font_resource.score);
EXPECT_NEAR(199., js_resource.score, 1e-4);

Powered by Google App Engine
This is Rietveld 408576698