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

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

Issue 2800783002: predictors: Several improvements for redirects database. (Closed)
Patch Set: Fix unittests. Created 3 years, 8 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_unittest.cc
diff --git a/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc b/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc
index 6e2e8cefc0b9c12ed866b32b18f652cb353f3e00..8bbd35e30317c5818ad3c5193a6fd8b9bb19b71e 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc
@@ -234,6 +234,7 @@ class ResourcePrefetchPredictorTest : public testing::Test {
config.min_url_visit_count = 2;
config.max_resources_per_entry = 4;
config.max_consecutive_misses = 2;
+ config.max_redirect_consecutive_misses = 2;
config.min_resource_confidence_to_trigger_prefetch = 0.5;
config.is_url_learning_enabled = true;
@@ -600,6 +601,13 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) {
UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
empty_redirect_data_));
+ RedirectData host_redirect_data = CreateRedirectData("www.google.com");
+ InitializeRedirectStat(host_redirect_data.add_redirect_endpoints(),
+ "www.google.com", 1, 0, 0);
+ EXPECT_CALL(*mock_tables_.get(),
+ UpdateData(empty_resource_data_, empty_resource_data_,
+ empty_redirect_data_, host_redirect_data));
+
predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
profile_->BlockUntilHistoryProcessesPendingRequests();
}
@@ -678,6 +686,20 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) {
UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
empty_redirect_data_));
+ RedirectData url_redirect_data = CreateRedirectData("http://www.google.com/");
+ InitializeRedirectStat(url_redirect_data.add_redirect_endpoints(),
+ "http://www.google.com/", 1, 0, 0);
+ EXPECT_CALL(*mock_tables_.get(),
+ UpdateData(empty_resource_data_, empty_resource_data_,
+ url_redirect_data, empty_redirect_data_));
+
+ RedirectData host_redirect_data = CreateRedirectData("www.google.com");
+ InitializeRedirectStat(host_redirect_data.add_redirect_endpoints(),
+ "www.google.com", 1, 0, 0);
+ EXPECT_CALL(*mock_tables_.get(),
+ UpdateData(empty_resource_data_, empty_resource_data_,
+ empty_redirect_data_, host_redirect_data));
+
predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
profile_->BlockUntilHistoryProcessesPendingRequests();
}
@@ -785,6 +807,20 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) {
UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
empty_redirect_data_));
+ RedirectData url_redirect_data = CreateRedirectData("http://www.google.com/");
+ InitializeRedirectStat(url_redirect_data.add_redirect_endpoints(),
+ "http://www.google.com/", 1, 0, 0);
+ EXPECT_CALL(*mock_tables_.get(),
+ UpdateData(empty_resource_data_, empty_resource_data_,
+ url_redirect_data, empty_redirect_data_));
+
+ RedirectData host_redirect_data = CreateRedirectData("www.google.com");
+ InitializeRedirectStat(host_redirect_data.add_redirect_endpoints(),
+ "www.google.com", 1, 0, 0);
+ EXPECT_CALL(*mock_tables_.get(),
+ UpdateData(empty_resource_data_, empty_resource_data_,
+ empty_redirect_data_, host_redirect_data));
+
predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
profile_->BlockUntilHistoryProcessesPendingRequests();
}
@@ -854,6 +890,20 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) {
UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
empty_redirect_data_));
+ RedirectData url_redirect_data = CreateRedirectData("http://www.nike.com/");
+ InitializeRedirectStat(url_redirect_data.add_redirect_endpoints(),
+ "http://www.nike.com/", 1, 0, 0);
+ EXPECT_CALL(*mock_tables_.get(),
+ UpdateData(empty_resource_data_, empty_resource_data_,
+ url_redirect_data, empty_redirect_data_));
+
+ RedirectData host_redirect_data = CreateRedirectData("www.nike.com");
+ InitializeRedirectStat(host_redirect_data.add_redirect_endpoints(),
+ "www.nike.com", 1, 0, 0);
+ EXPECT_CALL(*mock_tables_.get(),
+ UpdateData(empty_resource_data_, empty_resource_data_,
+ empty_redirect_data_, host_redirect_data));
+
predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
profile_->BlockUntilHistoryProcessesPendingRequests();
}
@@ -1633,39 +1683,49 @@ TEST_F(ResourcePrefetchPredictorTest, PopulatePrefetcherRequest) {
}
TEST_F(ResourcePrefetchPredictorTest, GetRedirectEndpoint) {
- // The data to be requested for the most confident endpoint.
- RedirectData google = CreateRedirectData("http://google.com/", 1);
- InitializeRedirectStat(google.add_redirect_endpoints(), "https://google.com",
- 10, 0, 0);
- InitializeRedirectStat(google.add_redirect_endpoints(), "https://google.fr",
- 10, 1, 0);
- InitializeRedirectStat(google.add_redirect_endpoints(), "https://google.ws",
- 20, 20, 0);
+ // The data to be requested for the confident endpoint.
+ RedirectData nyt = CreateRedirectData("http://nyt.com", 1);
+ InitializeRedirectStat(nyt.add_redirect_endpoints(),
+ "https://mobile.nytimes.com", 10, 0, 0);
// The data to be sure that other RedirectData won't be affected.
RedirectData gogle = CreateRedirectData("http://gogle.com", 2);
InitializeRedirectStat(gogle.add_redirect_endpoints(), "https://google.com",
100, 0, 0);
- // The data to check negative result.
- RedirectData facebook = CreateRedirectData("http://fb.com/", 3);
+ // The data to check negative result due not enough confidence.
+ RedirectData facebook = CreateRedirectData("http://fb.com", 3);
InitializeRedirectStat(facebook.add_redirect_endpoints(),
- "http://facebook.com", 5, 5,
- 0); // not enough confidence
+ "http://facebook.com", 5, 5, 0);
+
+ // The data to check negative result due ambiguity.
+ RedirectData google = CreateRedirectData("http://google.com", 4);
+ InitializeRedirectStat(google.add_redirect_endpoints(), "https://google.com",
+ 10, 0, 0);
+ InitializeRedirectStat(google.add_redirect_endpoints(), "https://google.fr",
+ 10, 1, 0);
+ InitializeRedirectStat(google.add_redirect_endpoints(), "https://google.ws",
+ 20, 20, 0);
RedirectDataMap data_map;
- data_map.insert(std::make_pair(google.primary_key(), google));
+ data_map.insert(std::make_pair(nyt.primary_key(), nyt));
data_map.insert(std::make_pair(gogle.primary_key(), gogle));
data_map.insert(std::make_pair(facebook.primary_key(), facebook));
+ data_map.insert(std::make_pair(google.primary_key(), google));
std::string redirect_endpoint;
- EXPECT_TRUE(predictor_->GetRedirectEndpoint("http://google.com/", data_map,
+ EXPECT_TRUE(predictor_->GetRedirectEndpoint("http://nyt.com", data_map,
+ &redirect_endpoint));
+ EXPECT_EQ(redirect_endpoint, "https://mobile.nytimes.com");
+
+ // Returns the initial url if data_map doesn't contain an entry for the url.
+ EXPECT_TRUE(predictor_->GetRedirectEndpoint("http://bbc.com", data_map,
&redirect_endpoint));
- EXPECT_EQ(redirect_endpoint, "https://google.com");
+ EXPECT_EQ(redirect_endpoint, "http://bbc.com");
EXPECT_FALSE(predictor_->GetRedirectEndpoint("http://fb.com", data_map,
&redirect_endpoint));
- EXPECT_FALSE(predictor_->GetRedirectEndpoint("http://404.com", data_map,
+ EXPECT_FALSE(predictor_->GetRedirectEndpoint("http://google.com", data_map,
&redirect_endpoint));
}
@@ -1689,20 +1749,6 @@ TEST_F(ResourcePrefetchPredictorTest, GetPrefetchData) {
EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction));
EXPECT_THAT(urls, UnorderedElementsAre(GURL(script_url)));
- // Add a resource associated with the main frame url.
- PrefetchData google_url =
- CreatePrefetchData("http://google.com/?query=cats", 2);
- const std::string image_url = "https://cdn.google.com/image.png";
- InitializeResourceData(google_url.add_resources(), image_url,
- content::RESOURCE_TYPE_IMAGE, 10, 0, 1, 2.1,
- net::MEDIUM, false, false);
- predictor_->url_table_cache_->insert(
- std::make_pair(google_url.primary_key(), google_url));
-
- urls.clear();
- EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction));
- EXPECT_THAT(urls, UnorderedElementsAre(GURL(image_url)));
-
// Add host-based redirect.
RedirectData host_redirect = CreateRedirectData("google.com", 3);
InitializeRedirectStat(host_redirect.add_redirect_endpoints(),
@@ -1710,11 +1756,9 @@ TEST_F(ResourcePrefetchPredictorTest, GetPrefetchData) {
predictor_->host_redirect_table_cache_->insert(
std::make_pair(host_redirect.primary_key(), host_redirect));
- // Nothing changed: new redirect endpoint doesn't have any associated
- // resources
+ // Prediction failed: no data associated with the host redirect endpoint.
urls.clear();
- EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction));
- EXPECT_THAT(urls, UnorderedElementsAre(GURL(image_url)));
+ EXPECT_FALSE(predictor_->GetPrefetchData(main_frame_url, &prediction));
// Add a resource associated with host redirect endpoint.
PrefetchData www_google_host = CreatePrefetchData("www.google.com", 4);
@@ -1729,6 +1773,20 @@ TEST_F(ResourcePrefetchPredictorTest, GetPrefetchData) {
EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction));
EXPECT_THAT(urls, UnorderedElementsAre(GURL(style_url)));
+ // Add a resource associated with the main frame url.
+ PrefetchData google_url =
+ CreatePrefetchData("http://google.com/?query=cats", 2);
+ const std::string image_url = "https://cdn.google.com/image.png";
+ InitializeResourceData(google_url.add_resources(), image_url,
+ content::RESOURCE_TYPE_IMAGE, 10, 0, 1, 2.1,
+ net::MEDIUM, false, false);
+ predictor_->url_table_cache_->insert(
+ std::make_pair(google_url.primary_key(), google_url));
+
+ urls.clear();
+ EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction));
+ EXPECT_THAT(urls, UnorderedElementsAre(GURL(image_url)));
+
// Add url-based redirect.
RedirectData url_redirect =
CreateRedirectData("http://google.com/?query=cats", 5);
@@ -1737,7 +1795,8 @@ TEST_F(ResourcePrefetchPredictorTest, GetPrefetchData) {
predictor_->url_redirect_table_cache_->insert(
std::make_pair(url_redirect.primary_key(), url_redirect));
- // Url redirect endpoint doesn't have associated resources.
+ // Url redirect endpoint doesn't have associated resources so we get
+ // host-based data.
urls.clear();
EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction));
EXPECT_THAT(urls, UnorderedElementsAre(GURL(style_url)));
@@ -1759,7 +1818,7 @@ TEST_F(ResourcePrefetchPredictorTest, GetPrefetchData) {
TEST_F(ResourcePrefetchPredictorTest, TestPrecisionRecallHistograms) {
using testing::_;
- EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _));
+ EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _)).Times(2);
// Fill the database with 3 resources: 1 useful, 2 useless.
const std::string main_frame_url = "http://google.com/?query=cats";

Powered by Google App Engine
This is Rietveld 408576698