| 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 5cc1100a572538527de7102ff425a2c20446ea48..af63d510cc9286cd9a8cb2f59f5119d2053d5eeb 100644
|
| --- a/chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc
|
| +++ b/chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc
|
| @@ -13,6 +13,7 @@
|
| #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "content/public/test/test_browser_thread.h"
|
| +#include "net/base/request_priority.h"
|
| #include "sql/statement.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -64,9 +65,9 @@ class ResourcePrefetchPredictorTablesTest : public testing::Test {
|
| it != data.resources.end(); ++it) {
|
| LOG(ERROR) << "\t\t" << it->resource_url << "\t" << it->resource_type
|
| << "\t" << it->number_of_hits << "\t" << it->number_of_misses
|
| - << "\t" << it->consecutive_misses
|
| - << "\t" << it->average_position
|
| - << "\t" << it->score;
|
| + << "\t" << it->consecutive_misses << "\t"
|
| + << it->average_position << "\t" << it->priority << "\t"
|
| + << it->score;
|
| }
|
| }
|
|
|
| @@ -168,45 +169,24 @@ 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));
|
| - google.resources.push_back(ResourceRow(std::string(),
|
| - "http://www.google.com/image.png",
|
| - content::RESOURCE_TYPE_IMAGE,
|
| - 6,
|
| - 4,
|
| - 1,
|
| - 4.2));
|
| - google.resources.push_back(ResourceRow(std::string(),
|
| - "http://www.google.com/a.xml",
|
| - content::RESOURCE_TYPE_LAST_TYPE,
|
| - 1,
|
| - 0,
|
| - 0,
|
| - 6.1));
|
| - google.resources
|
| - .push_back(ResourceRow(std::string(),
|
| - "http://www.resources.google.com/script.js",
|
| - content::RESOURCE_TYPE_SCRIPT,
|
| - 12,
|
| - 0,
|
| - 0,
|
| - 8.5));
|
| + 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));
|
|
|
| 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));
|
| + yahoo.resources.push_back(
|
| + ResourceRow(std::string(), "http://www.yahoo.com/image.png",
|
| + content::RESOURCE_TYPE_IMAGE, 120, 1, 1, 10.0, net::MEDIUM));
|
|
|
| tables_->UpdateData(google, yahoo);
|
|
|
| @@ -288,71 +268,36 @@ 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));
|
| - google.resources.push_back(ResourceRow(std::string(),
|
| - "http://www.google.com/script.js",
|
| - content::RESOURCE_TYPE_SCRIPT,
|
| - 4,
|
| - 0,
|
| - 1,
|
| - 2.1));
|
| - google.resources.push_back(ResourceRow(std::string(),
|
| - "http://www.google.com/image.png",
|
| - content::RESOURCE_TYPE_IMAGE,
|
| - 6,
|
| - 3,
|
| - 0,
|
| - 2.2));
|
| - google.resources.push_back(ResourceRow(std::string(),
|
| - "http://www.google.com/a.font",
|
| - content::RESOURCE_TYPE_LAST_TYPE,
|
| - 2,
|
| - 0,
|
| - 0,
|
| - 5.1));
|
| - google.resources
|
| - .push_back(ResourceRow(std::string(),
|
| - "http://www.resources.google.com/script.js",
|
| - content::RESOURCE_TYPE_SCRIPT,
|
| - 11,
|
| - 0,
|
| - 0,
|
| - 8.5));
|
| + 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));
|
| + 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));
|
| + 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));
|
|
|
| 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));
|
| - reddit.resources
|
| - .push_back(ResourceRow(std::string(),
|
| - "http://reddit-resource.com/script2.js",
|
| - content::RESOURCE_TYPE_SCRIPT,
|
| - 2,
|
| - 0,
|
| - 0,
|
| - 2.1));
|
| + reddit.resources.push_back(
|
| + ResourceRow(std::string(), "http://reddit-resource.com/script1.js",
|
| + content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 1.0, net::MEDIUM));
|
| + reddit.resources.push_back(
|
| + ResourceRow(std::string(), "http://reddit-resource.com/script2.js",
|
| + content::RESOURCE_TYPE_SCRIPT, 2, 0, 0, 2.1, net::MEDIUM));
|
|
|
| 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));
|
| + yahoo.resources.push_back(
|
| + ResourceRow(std::string(), "http://www.google.com/image.png",
|
| + content::RESOURCE_TYPE_IMAGE, 20, 1, 0, 10.0, net::MEDIUM));
|
|
|
| test_url_data_.clear();
|
| test_url_data_.insert(std::make_pair("http://www.google.com", google));
|
| @@ -368,55 +313,27 @@ 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));
|
| - facebook.resources
|
| - .push_back(ResourceRow(std::string(),
|
| - "http://www.facebook.com/script.js",
|
| - content::RESOURCE_TYPE_SCRIPT,
|
| - 4,
|
| - 0,
|
| - 1,
|
| - 2.1));
|
| - facebook.resources
|
| - .push_back(ResourceRow(std::string(),
|
| - "http://www.facebook.com/image.png",
|
| - content::RESOURCE_TYPE_IMAGE,
|
| - 6,
|
| - 3,
|
| - 0,
|
| - 2.2));
|
| - facebook.resources.push_back(ResourceRow(std::string(),
|
| - "http://www.facebook.com/a.font",
|
| - content::RESOURCE_TYPE_LAST_TYPE,
|
| - 2,
|
| - 0,
|
| - 0,
|
| - 5.1));
|
| - facebook.resources
|
| - .push_back(ResourceRow(std::string(),
|
| - "http://www.resources.facebook.com/script.js",
|
| - content::RESOURCE_TYPE_SCRIPT,
|
| - 11,
|
| - 0,
|
| - 0,
|
| - 8.5));
|
| + 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));
|
| + facebook.resources.push_back(
|
| + ResourceRow(std::string(), "http://www.facebook.com/image.png",
|
| + content::RESOURCE_TYPE_IMAGE, 6, 3, 0, 2.2, net::MEDIUM));
|
| + 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));
|
| + 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));
|
|
|
| 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));
|
| + yahoo.resources.push_back(
|
| + ResourceRow(std::string(), "http://www.google.com/image.png",
|
| + content::RESOURCE_TYPE_IMAGE, 20, 1, 0, 10.0, net::MEDIUM));
|
|
|
| test_host_data_.clear();
|
| test_host_data_.insert(std::make_pair("www.facebook.com", facebook));
|
| @@ -432,18 +349,18 @@ void ResourcePrefetchPredictorTablesTest::InitializeSampleData() {
|
|
|
| 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.);
|
| - ResourceRow image_resource(std::string(),
|
| - "http://www.resources.google.com/image.jpg",
|
| - content::RESOURCE_TYPE_IMAGE, 11, 0, 0, 1.);
|
| - ResourceRow css_resource(std::string(),
|
| - "http://www.resources.google.com/stylesheet.css",
|
| - content::RESOURCE_TYPE_STYLESHEET, 11, 0, 0, 1.);
|
| - ResourceRow font_resource(std::string(),
|
| - "http://www.resources.google.com/font.woff",
|
| - content::RESOURCE_TYPE_FONT_RESOURCE, 11, 0, 0, 1.);
|
| + ResourceRow js_resource(
|
| + std::string(), "http://www.resources.google.com/script.js",
|
| + content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 1., net::MEDIUM);
|
| + 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);
|
| EXPECT_TRUE(js_resource.score == css_resource.score);
|
| EXPECT_TRUE(js_resource.score == font_resource.score);
|
| EXPECT_NEAR(199., js_resource.score, 1e-4);
|
|
|