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 <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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 568 |
569 void ResourcePrefetchPredictorTablesTest::ReopenDatabase() { | 569 void ResourcePrefetchPredictorTablesTest::ReopenDatabase() { |
570 db_.reset(new PredictorDatabase(&profile_)); | 570 db_.reset(new PredictorDatabase(&profile_)); |
571 base::RunLoop().RunUntilIdle(); | 571 base::RunLoop().RunUntilIdle(); |
572 tables_ = db_->resource_prefetch_tables(); | 572 tables_ = db_->resource_prefetch_tables(); |
573 } | 573 } |
574 | 574 |
575 // Test cases. | 575 // Test cases. |
576 | 576 |
577 TEST_F(ResourcePrefetchPredictorTablesTest, ComputeResourceScore) { | 577 TEST_F(ResourcePrefetchPredictorTablesTest, ComputeResourceScore) { |
578 ResourceData js_resource = CreateResourceData( | 578 auto compute_score = [](net::RequestPriority priority, |
579 "http://www.resources.google.com/script.js", | 579 content::ResourceType resource_type, |
580 content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 1., net::MEDIUM, false, false); | 580 double average_position) { |
581 ResourceData image_resource = CreateResourceData( | 581 return ResourcePrefetchPredictorTables::ComputeResourceScore( |
582 "http://www.resources.google.com/image.jpg", content::RESOURCE_TYPE_IMAGE, | 582 CreateResourceData("", resource_type, 0, 0, 0, average_position, |
583 11, 0, 0, 1., net::MEDIUM, false, false); | 583 priority, false, false)); |
584 ResourceData css_resource = | 584 }; |
585 CreateResourceData("http://www.resources.google.com/stylesheet.css", | |
586 content::RESOURCE_TYPE_STYLESHEET, 11, 0, 0, 1., | |
587 net::MEDIUM, false, false); | |
588 ResourceData font_resource = | |
589 CreateResourceData("http://www.resources.google.com/font.woff", | |
590 content::RESOURCE_TYPE_FONT_RESOURCE, 11, 0, 0, 1., | |
591 net::MEDIUM, false, false); | |
592 float js_resource_score = | |
593 ResourcePrefetchPredictorTables::ComputeResourceScore(js_resource); | |
594 float css_resource_score = | |
595 ResourcePrefetchPredictorTables::ComputeResourceScore(css_resource); | |
596 float font_resource_score = | |
597 ResourcePrefetchPredictorTables::ComputeResourceScore(font_resource); | |
598 float image_resource_score = | |
599 ResourcePrefetchPredictorTables::ComputeResourceScore(image_resource); | |
600 | 585 |
601 EXPECT_TRUE(js_resource_score == css_resource_score); | 586 // Priority is more important than the rest. |
602 EXPECT_TRUE(js_resource_score == font_resource_score); | 587 EXPECT_TRUE(compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 1.) > |
603 EXPECT_NEAR(199., js_resource_score, 1e-4); | 588 compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.)); |
604 EXPECT_NEAR(99., image_resource_score, 1e-4); | 589 |
| 590 EXPECT_TRUE(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.) > |
| 591 compute_score(net::MEDIUM, content::RESOURCE_TYPE_SCRIPT, 1.)); |
| 592 EXPECT_TRUE(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.) > |
| 593 compute_score(net::LOW, content::RESOURCE_TYPE_SCRIPT, 1.)); |
| 594 EXPECT_TRUE(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.) > |
| 595 compute_score(net::LOWEST, content::RESOURCE_TYPE_SCRIPT, 1.)); |
| 596 EXPECT_TRUE(compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.) > |
| 597 compute_score(net::IDLE, content::RESOURCE_TYPE_SCRIPT, 1.)); |
| 598 |
| 599 // Scripts and stylesheets are equivalent. |
| 600 EXPECT_NEAR( |
| 601 compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 42.), |
| 602 compute_score(net::HIGHEST, content::RESOURCE_TYPE_STYLESHEET, 42.), |
| 603 1e-4); |
| 604 |
| 605 // Scripts are more important than fonts and images, and the rest. |
| 606 EXPECT_TRUE( |
| 607 compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 42.) > |
| 608 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FONT_RESOURCE, 42.)); |
| 609 EXPECT_TRUE( |
| 610 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FONT_RESOURCE, 42.) > |
| 611 compute_score(net::HIGHEST, content::RESOURCE_TYPE_IMAGE, 42.)); |
| 612 EXPECT_TRUE( |
| 613 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FONT_RESOURCE, 42.) > |
| 614 compute_score(net::HIGHEST, content::RESOURCE_TYPE_FAVICON, 42.)); |
| 615 |
| 616 // All else being equal, position matters. |
| 617 EXPECT_TRUE(compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 12.) > |
| 618 compute_score(net::HIGHEST, content::RESOURCE_TYPE_SCRIPT, 42.)); |
605 } | 619 } |
606 | 620 |
607 TEST_F(ResourcePrefetchPredictorTablesTest, GetAllData) { | 621 TEST_F(ResourcePrefetchPredictorTablesTest, GetAllData) { |
608 TestGetAllData(); | 622 TestGetAllData(); |
609 } | 623 } |
610 | 624 |
611 TEST_F(ResourcePrefetchPredictorTablesTest, UpdateData) { | 625 TEST_F(ResourcePrefetchPredictorTablesTest, UpdateData) { |
612 TestUpdateData(); | 626 TestUpdateData(); |
613 } | 627 } |
614 | 628 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 | 679 |
666 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteSingleDataPoint) { | 680 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteSingleDataPoint) { |
667 TestDeleteSingleDataPoint(); | 681 TestDeleteSingleDataPoint(); |
668 } | 682 } |
669 | 683 |
670 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteAllData) { | 684 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteAllData) { |
671 TestDeleteAllData(); | 685 TestDeleteAllData(); |
672 } | 686 } |
673 | 687 |
674 } // namespace predictors | 688 } // namespace predictors |
OLD | NEW |