| 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 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 return m.ByteSize() == manifest_size; | 1174 return m.ByteSize() == manifest_size; |
| 1175 }; | 1175 }; |
| 1176 EXPECT_CALL( | 1176 EXPECT_CALL( |
| 1177 *mock_tables_.get(), | 1177 *mock_tables_.get(), |
| 1178 UpdateManifestData("google.com", | 1178 UpdateManifestData("google.com", |
| 1179 testing::AllOf(manifest, testing::Truly(match_size)))); | 1179 testing::AllOf(manifest, testing::Truly(match_size)))); |
| 1180 | 1180 |
| 1181 predictor_->OnManifestFetched("google.com", manifest_with_unknown_fields); | 1181 predictor_->OnManifestFetched("google.com", manifest_with_unknown_fields); |
| 1182 } | 1182 } |
| 1183 | 1183 |
| 1184 TEST_F(ResourcePrefetchPredictorTest, ManifestUnusedRemoved) { |
| 1185 const std::string& script_url = "http://cdn.google.com/script.js"; |
| 1186 const std::string& style_url = "http://cdn.google.com/style.css"; |
| 1187 PrefetchData google = CreatePrefetchData("www.google.com"); |
| 1188 InitializeResourceData(google.add_resources(), script_url, |
| 1189 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, |
| 1190 net::MEDIUM, false, false); |
| 1191 InitializeResourceData(google.add_resources(), style_url, |
| 1192 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, |
| 1193 net::MEDIUM, false, false); |
| 1194 predictor_->host_table_cache_->insert({google.primary_key(), google}); |
| 1195 |
| 1196 precache::PrecacheManifest manifest = CreateManifestData(1); |
| 1197 InitializePrecacheResource(manifest.add_resource(), script_url, 0.9); |
| 1198 InitializePrecacheResource(manifest.add_resource(), style_url, 0.75); |
| 1199 InitializeExperiment(&manifest, internal::kUnusedRemovedExperiment, |
| 1200 {true, false}); |
| 1201 |
| 1202 // style_url should be removed. |
| 1203 google.mutable_resources()->RemoveLast(); |
| 1204 EXPECT_CALL(*mock_tables_.get(), |
| 1205 UpdateResourceData(google, PREFETCH_KEY_TYPE_HOST)); |
| 1206 EXPECT_CALL(*mock_tables_.get(), UpdateManifestData("google.com", manifest)); |
| 1207 |
| 1208 predictor_->OnManifestFetched("google.com", manifest); |
| 1209 } |
| 1210 |
| 1184 TEST_F(ResourcePrefetchPredictorTest, DeleteUrls) { | 1211 TEST_F(ResourcePrefetchPredictorTest, DeleteUrls) { |
| 1185 // Add some dummy entries to cache. | 1212 // Add some dummy entries to cache. |
| 1186 predictor_->url_table_cache_->insert( | 1213 predictor_->url_table_cache_->insert( |
| 1187 std::make_pair("http://www.google.com/page1.html", | 1214 std::make_pair("http://www.google.com/page1.html", |
| 1188 CreatePrefetchData("http://www.google.com/page1.html"))); | 1215 CreatePrefetchData("http://www.google.com/page1.html"))); |
| 1189 predictor_->url_table_cache_->insert( | 1216 predictor_->url_table_cache_->insert( |
| 1190 std::make_pair("http://www.google.com/page2.html", | 1217 std::make_pair("http://www.google.com/page2.html", |
| 1191 CreatePrefetchData("http://www.google.com/page2.html"))); | 1218 CreatePrefetchData("http://www.google.com/page2.html"))); |
| 1192 predictor_->url_table_cache_->insert(std::make_pair( | 1219 predictor_->url_table_cache_->insert(std::make_pair( |
| 1193 "http://www.yahoo.com/", CreatePrefetchData("http://www.yahoo.com/"))); | 1220 "http://www.yahoo.com/", CreatePrefetchData("http://www.yahoo.com/"))); |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 predictor_->host_table_cache_->insert( | 2012 predictor_->host_table_cache_->insert( |
| 1986 std::make_pair(google.primary_key(), google)); | 2013 std::make_pair(google.primary_key(), google)); |
| 1987 | 2014 |
| 1988 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); | 2015 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); |
| 1989 predictor_->StopPrefetching(GURL(main_frame_url)); | 2016 predictor_->StopPrefetching(GURL(main_frame_url)); |
| 1990 histogram_tester_->ExpectTotalCount( | 2017 histogram_tester_->ExpectTotalCount( |
| 1991 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); | 2018 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); |
| 1992 } | 2019 } |
| 1993 | 2020 |
| 1994 } // namespace predictors | 2021 } // namespace predictors |
| OLD | NEW |