| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 223 } |
| 224 | 224 |
| 225 void InitializePredictor() { | 225 void InitializePredictor() { |
| 226 predictor_->StartInitialization(); | 226 predictor_->StartInitialization(); |
| 227 base::RunLoop loop; | 227 base::RunLoop loop; |
| 228 loop.RunUntilIdle(); // Runs the DB lookup. | 228 loop.RunUntilIdle(); // Runs the DB lookup. |
| 229 profile_->BlockUntilHistoryProcessesPendingRequests(); | 229 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void ResetPredictor() { | 232 void ResetPredictor() { |
| 233 ResourcePrefetchPredictorConfig config; | 233 GlowplugPredictorConfig config; |
| 234 config.max_urls_to_track = 3; | 234 config.max_urls_to_track = 3; |
| 235 config.max_hosts_to_track = 2; | 235 config.max_hosts_to_track = 2; |
| 236 config.min_url_visit_count = 2; | 236 config.min_url_visit_count = 2; |
| 237 config.max_resources_per_entry = 4; | 237 config.max_resources_per_entry = 4; |
| 238 config.max_consecutive_misses = 2; | 238 config.max_consecutive_misses = 2; |
| 239 config.max_redirect_consecutive_misses = 2; | 239 config.max_redirect_consecutive_misses = 2; |
| 240 config.min_resource_confidence_to_trigger_prefetch = 0.5; | 240 config.min_resource_confidence_to_trigger_prefetch = 0.5; |
| 241 config.is_url_learning_enabled = true; | 241 config.is_url_learning_enabled = true; |
| 242 config.is_manifests_enabled = true; | 242 config.is_manifests_enabled = true; |
| 243 config.is_origin_learning_enabled = true; | 243 config.is_origin_learning_enabled = true; |
| 244 | 244 |
| 245 config.mode |= ResourcePrefetchPredictorConfig::LEARNING; | 245 config.mode |= GlowplugPredictorConfig::LEARNING; |
| 246 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); | 246 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); |
| 247 predictor_->set_mock_tables(mock_tables_); | 247 predictor_->set_mock_tables(mock_tables_); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void InitializeSampleData(); | 250 void InitializeSampleData(); |
| 251 void TestRedirectStatusHistogram( | 251 void TestRedirectStatusHistogram( |
| 252 const std::string& predictor_initial_key, | 252 const std::string& predictor_initial_key, |
| 253 const std::string& predictor_key, | 253 const std::string& predictor_key, |
| 254 const std::string& navigation_initial_url, | 254 const std::string& navigation_initial_url, |
| 255 const std::string& navigation_url, | 255 const std::string& navigation_url, |
| (...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2091 TestRedirectStatusHistogram( | 2091 TestRedirectStatusHistogram( |
| 2092 "google.com", "www.google.com", "http://google.com?query=cats", | 2092 "google.com", "www.google.com", "http://google.com?query=cats", |
| 2093 "http://www.google.com?query=cats", | 2093 "http://www.google.com?query=cats", |
| 2094 ResourcePrefetchPredictor::RedirectStatus::REDIRECT_CORRECTLY_PREDICTED); | 2094 ResourcePrefetchPredictor::RedirectStatus::REDIRECT_CORRECTLY_PREDICTED); |
| 2095 } | 2095 } |
| 2096 | 2096 |
| 2097 TEST_F(ResourcePrefetchPredictorTest, TestPrefetchingDurationHistogram) { | 2097 TEST_F(ResourcePrefetchPredictorTest, TestPrefetchingDurationHistogram) { |
| 2098 // Prefetching duration for an url without resources in the database | 2098 // Prefetching duration for an url without resources in the database |
| 2099 // shouldn't be recorded. | 2099 // shouldn't be recorded. |
| 2100 const std::string main_frame_url = "http://google.com/?query=cats"; | 2100 const std::string main_frame_url = "http://google.com/?query=cats"; |
| 2101 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); | 2101 predictor_->StartPrefetching(GURL(main_frame_url), HintOrigin::EXTERNAL); |
| 2102 predictor_->StopPrefetching(GURL(main_frame_url)); | 2102 predictor_->StopPrefetching(GURL(main_frame_url)); |
| 2103 histogram_tester_->ExpectTotalCount( | 2103 histogram_tester_->ExpectTotalCount( |
| 2104 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 0); | 2104 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 0); |
| 2105 | 2105 |
| 2106 // Fill the database to record a duration. | 2106 // Fill the database to record a duration. |
| 2107 PrefetchData google = CreatePrefetchData("google.com", 1); | 2107 PrefetchData google = CreatePrefetchData("google.com", 1); |
| 2108 InitializeResourceData( | 2108 InitializeResourceData( |
| 2109 google.add_resources(), "https://cdn.google.com/script.js", | 2109 google.add_resources(), "https://cdn.google.com/script.js", |
| 2110 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, net::MEDIUM, false, false); | 2110 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, net::MEDIUM, false, false); |
| 2111 predictor_->host_table_cache_->insert( | 2111 predictor_->host_table_cache_->insert( |
| 2112 std::make_pair(google.primary_key(), google)); | 2112 std::make_pair(google.primary_key(), google)); |
| 2113 | 2113 |
| 2114 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); | 2114 predictor_->StartPrefetching(GURL(main_frame_url), HintOrigin::EXTERNAL); |
| 2115 predictor_->StopPrefetching(GURL(main_frame_url)); | 2115 predictor_->StopPrefetching(GURL(main_frame_url)); |
| 2116 histogram_tester_->ExpectTotalCount( | 2116 histogram_tester_->ExpectTotalCount( |
| 2117 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); | 2117 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); |
| 2118 } | 2118 } |
| 2119 | 2119 |
| 2120 TEST_F(ResourcePrefetchPredictorTest, TestRecordFirstContentfulPaint) { | 2120 TEST_F(ResourcePrefetchPredictorTest, TestRecordFirstContentfulPaint) { |
| 2121 using testing::_; | 2121 using testing::_; |
| 2122 EXPECT_CALL(*mock_tables_.get(), UpdateRedirectData(_, _)); | 2122 EXPECT_CALL(*mock_tables_.get(), UpdateRedirectData(_, _)); |
| 2123 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_)); | 2123 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_)); |
| 2124 | 2124 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2164 net::MEDIUM, false, false); | 2164 net::MEDIUM, false, false); |
| 2165 resource3_rd->set_before_first_contentful_paint(false); | 2165 resource3_rd->set_before_first_contentful_paint(false); |
| 2166 EXPECT_CALL(*mock_tables_.get(), | 2166 EXPECT_CALL(*mock_tables_.get(), |
| 2167 UpdateResourceData(host_data, PREFETCH_KEY_TYPE_HOST)); | 2167 UpdateResourceData(host_data, PREFETCH_KEY_TYPE_HOST)); |
| 2168 | 2168 |
| 2169 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 2169 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 2170 profile_->BlockUntilHistoryProcessesPendingRequests(); | 2170 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 2171 } | 2171 } |
| 2172 | 2172 |
| 2173 } // namespace predictors | 2173 } // namespace predictors |
| OLD | NEW |