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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc

Issue 2831233004: predictors: Add resource type to manifest. (Closed)
Patch Set: Use the same resource type ordering. 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 unified diff | Download patch
OLDNEW
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 <memory> 5 #include <memory>
6 #include <set> 6 #include <set>
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 RedirectData microsoft = CreateRedirectData("microsoft.com", 21); 309 RedirectData microsoft = CreateRedirectData("microsoft.com", 21);
310 InitializeRedirectStat(microsoft.add_redirect_endpoints(), "m.microsoft.com", 310 InitializeRedirectStat(microsoft.add_redirect_endpoints(), "m.microsoft.com",
311 5, 7, 1); 311 5, 7, 1);
312 InitializeRedirectStat(microsoft.add_redirect_endpoints(), "microsoft.org", 7, 312 InitializeRedirectStat(microsoft.add_redirect_endpoints(), "microsoft.org", 7,
313 2, 0); 313 2, 0);
314 314
315 tables_->UpdateRedirectData(microsoft, PREFETCH_KEY_TYPE_HOST); 315 tables_->UpdateRedirectData(microsoft, PREFETCH_KEY_TYPE_HOST);
316 316
317 precache::PrecacheManifest theverge; 317 precache::PrecacheManifest theverge;
318 InitializePrecacheResource(theverge.add_resource(), 318 InitializePrecacheResource(theverge.add_resource(),
319 "https://www.theverge.com/main.js", 0.7); 319 "https://www.theverge.com/main.js", 0.7,
320 precache::PrecacheResource::RESOURCE_TYPE_SCRIPT);
320 321
321 tables_->UpdateManifestData("theverge.com", theverge); 322 tables_->UpdateManifestData("theverge.com", theverge);
322 323
323 OriginData twitter = CreateOriginData("twitter.com"); 324 OriginData twitter = CreateOriginData("twitter.com");
324 InitializeOriginStat(twitter.add_origins(), "https://dogs.twitter.com", 10, 1, 325 InitializeOriginStat(twitter.add_origins(), "https://dogs.twitter.com", 10, 1,
325 0, 12., false, true); 326 0, 12., false, true);
326 tables_->UpdateOriginData(twitter); 327 tables_->UpdateOriginData(twitter);
327 328
328 PrefetchDataMap actual_url_data, actual_host_data; 329 PrefetchDataMap actual_url_data, actual_host_data;
329 RedirectDataMap actual_url_redirect_data, actual_host_redirect_data; 330 RedirectDataMap actual_url_redirect_data, actual_host_redirect_data;
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 test_host_redirect_data_.insert(std::make_pair(bbc.primary_key(), bbc)); 719 test_host_redirect_data_.insert(std::make_pair(bbc.primary_key(), bbc));
719 test_host_redirect_data_.insert( 720 test_host_redirect_data_.insert(
720 std::make_pair(microsoft.primary_key(), microsoft)); 721 std::make_pair(microsoft.primary_key(), microsoft));
721 722
722 tables_->UpdateRedirectData(bbc, PREFETCH_KEY_TYPE_HOST); 723 tables_->UpdateRedirectData(bbc, PREFETCH_KEY_TYPE_HOST);
723 tables_->UpdateRedirectData(microsoft, PREFETCH_KEY_TYPE_HOST); 724 tables_->UpdateRedirectData(microsoft, PREFETCH_KEY_TYPE_HOST);
724 } 725 }
725 726
726 { // Manifest data. 727 { // Manifest data.
727 precache::PrecacheManifest wikipedia; 728 precache::PrecacheManifest wikipedia;
729 InitializePrecacheResource(
730 wikipedia.add_resource(), "https://en.wikipedia.org/script.js", 0.7,
731 precache::PrecacheResource::RESOURCE_TYPE_SCRIPT);
728 InitializePrecacheResource(wikipedia.add_resource(), 732 InitializePrecacheResource(wikipedia.add_resource(),
729 "https://en.wikipedia.org/script.js", 0.7); 733 "https://en.wikipedia.org/image.png", 0.3,
730 InitializePrecacheResource(wikipedia.add_resource(), 734 precache::PrecacheResource::RESOURCE_TYPE_IMAGE);
731 "https://en.wikipedia.org/image.png", 0.3);
732 735
733 precache::PrecacheManifest youtube; 736 precache::PrecacheManifest youtube;
734 InitializePrecacheResource(youtube.add_resource(), 737 InitializePrecacheResource(youtube.add_resource(),
735 "https://youtube.com/photo.jpg", 0.5); 738 "https://youtube.com/photo.jpg", 0.5,
736 InitializePrecacheResource(youtube.add_resource(), 739 precache::PrecacheResource::RESOURCE_TYPE_IMAGE);
737 "https://youtube.com/base.js", 0.2); 740 InitializePrecacheResource(
741 youtube.add_resource(), "https://youtube.com/base.js", 0.2,
742 precache::PrecacheResource::RESOURCE_TYPE_SCRIPT);
738 743
739 test_manifest_data_.clear(); 744 test_manifest_data_.clear();
740 test_manifest_data_.insert(std::make_pair("en.wikipedia.org", wikipedia)); 745 test_manifest_data_.insert(std::make_pair("en.wikipedia.org", wikipedia));
741 test_manifest_data_.insert(std::make_pair("youtube.com", youtube)); 746 test_manifest_data_.insert(std::make_pair("youtube.com", youtube));
742 tables_->UpdateManifestData("en.wikipedia.org", wikipedia); 747 tables_->UpdateManifestData("en.wikipedia.org", wikipedia);
743 tables_->UpdateManifestData("youtube.com", youtube); 748 tables_->UpdateManifestData("youtube.com", youtube);
744 } 749 }
745 750
746 { // Origin data. 751 { // Origin data.
747 OriginData twitter; 752 OriginData twitter;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 795
791 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.), 796 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.),
792 compute_score(net::MEDIUM, content::RESOURCE_TYPE_SCRIPT, 1.)); 797 compute_score(net::MEDIUM, content::RESOURCE_TYPE_SCRIPT, 1.));
793 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.), 798 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.),
794 compute_score(net::LOW, content::RESOURCE_TYPE_SCRIPT, 1.)); 799 compute_score(net::LOW, content::RESOURCE_TYPE_SCRIPT, 1.));
795 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.), 800 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.),
796 compute_score(net::LOWEST, content::RESOURCE_TYPE_SCRIPT, 1.)); 801 compute_score(net::LOWEST, content::RESOURCE_TYPE_SCRIPT, 1.));
797 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.), 802 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.),
798 compute_score(net::IDLE, content::RESOURCE_TYPE_SCRIPT, 1.)); 803 compute_score(net::IDLE, content::RESOURCE_TYPE_SCRIPT, 1.));
799 804
800 // Scripts and stylesheets are equivalent. 805 // Stylesheets are are more important than scripts, fonts and images, and the
801 EXPECT_NEAR( 806 // rest.
802 compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 42.), 807 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_STYLESHEET, 42.),
803 compute_score(net::HIGHEST, content::RESOURCE_TYPE_STYLESHEET, 42.), 808 compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 42.));
804 1e-4);
805
806 // Scripts are more important than fonts and images, and the rest.
807 EXPECT_GT( 809 EXPECT_GT(
808 compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 42.), 810 compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 42.),
809 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FONT_RESOURCE, 42.)); 811 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FONT_RESOURCE, 42.));
810 EXPECT_GT( 812 EXPECT_GT(
811 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FONT_RESOURCE, 42.), 813 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FONT_RESOURCE, 42.),
812 compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.)); 814 compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.));
813 EXPECT_GT( 815 EXPECT_GT(
814 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FONT_RESOURCE, 42.), 816 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FONT_RESOURCE, 42.),
815 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FAVICON, 42.)); 817 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FAVICON, 42.));
816 818
817 // All else being equal, position matters. 819 // All else being equal, position matters.
818 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 12.), 820 EXPECT_GT(compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 12.),
819 compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 42.)); 821 compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 42.));
820 } 822 }
821 823
824 TEST_F(ResourcePrefetchPredictorTablesTest, ComputePrecacheResourceScore) {
825 auto compute_score = [](precache::PrecacheResource::Type resource_type,
826 float weight_ratio) {
827 precache::PrecacheResource resource;
828 InitializePrecacheResource(&resource, "", weight_ratio, resource_type);
829 return ResourcePrefetchPredictorTables::ComputePrecacheResourceScore(
830 resource);
831 };
832
833 // Stylesheets are the most impotant followed by scripts, fonts and images in
834 // this order.
835 EXPECT_GT(
836 compute_score(precache::PrecacheResource::RESOURCE_TYPE_STYLESHEET, 0.1),
837 compute_score(precache::PrecacheResource::RESOURCE_TYPE_SCRIPT, 0.9));
838 EXPECT_GT(
839 compute_score(precache::PrecacheResource::RESOURCE_TYPE_SCRIPT, 0.1),
840 compute_score(precache::PrecacheResource::RESOURCE_TYPE_FONT, 0.9));
841 EXPECT_GT(
842 compute_score(precache::PrecacheResource::RESOURCE_TYPE_FONT, 0.1),
843 compute_score(precache::PrecacheResource::RESOURCE_TYPE_IMAGE, 0.9));
844
845 // If resource types are equal, weight ratio matters.
846 EXPECT_GT(
847 compute_score(precache::PrecacheResource::RESOURCE_TYPE_SCRIPT, 0.7),
848 compute_score(precache::PrecacheResource::RESOURCE_TYPE_SCRIPT, 0.6));
849 }
850
822 TEST_F(ResourcePrefetchPredictorTablesTest, ComputeOriginScore) { 851 TEST_F(ResourcePrefetchPredictorTablesTest, ComputeOriginScore) {
823 auto compute_score = [](int hits, int misses, double average_position, 852 auto compute_score = [](int hits, int misses, double average_position,
824 bool always_access_network, bool accessed_network) { 853 bool always_access_network, bool accessed_network) {
825 OriginStat origin; 854 OriginStat origin;
826 InitializeOriginStat(&origin, "", hits, misses, 0, average_position, 855 InitializeOriginStat(&origin, "", hits, misses, 0, average_position,
827 always_access_network, accessed_network); 856 always_access_network, accessed_network);
828 return ResourcePrefetchPredictorTables::ComputeOriginScore(origin); 857 return ResourcePrefetchPredictorTables::ComputeOriginScore(origin);
829 }; 858 };
830 859
831 // High-confidence is more important than the rest. 860 // High-confidence is more important than the rest.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 955
927 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteSingleDataPoint) { 956 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteSingleDataPoint) {
928 TestDeleteSingleDataPoint(); 957 TestDeleteSingleDataPoint();
929 } 958 }
930 959
931 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteAllData) { 960 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteAllData) {
932 TestDeleteAllData(); 961 TestDeleteAllData();
933 } 962 }
934 963
935 } // namespace predictors 964 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698