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

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

Issue 2804283002: predictors: Refactor UpdateData() function. (Closed)
Patch Set: Oops fix. 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 InitializeResourceData( 284 InitializeResourceData(
285 google.add_resources(), "http://www.google.com/image.png", 285 google.add_resources(), "http://www.google.com/image.png",
286 content::RESOURCE_TYPE_IMAGE, 6, 4, 1, 4.2, net::MEDIUM, false, false); 286 content::RESOURCE_TYPE_IMAGE, 6, 4, 1, 4.2, net::MEDIUM, false, false);
287 InitializeResourceData(google.add_resources(), "http://www.google.com/a.xml", 287 InitializeResourceData(google.add_resources(), "http://www.google.com/a.xml",
288 content::RESOURCE_TYPE_LAST_TYPE, 1, 0, 0, 6.1, 288 content::RESOURCE_TYPE_LAST_TYPE, 1, 0, 0, 6.1,
289 net::MEDIUM, false, false); 289 net::MEDIUM, false, false);
290 InitializeResourceData( 290 InitializeResourceData(
291 google.add_resources(), "http://www.resources.google.com/script.js", 291 google.add_resources(), "http://www.resources.google.com/script.js",
292 content::RESOURCE_TYPE_SCRIPT, 12, 0, 0, 8.5, net::MEDIUM, true, true); 292 content::RESOURCE_TYPE_SCRIPT, 12, 0, 0, 8.5, net::MEDIUM, true, true);
293 293
294 tables_->UpdateResourceData(google, PREFETCH_KEY_TYPE_URL);
295
294 PrefetchData yahoo = CreatePrefetchData("www.yahoo.com", 7); 296 PrefetchData yahoo = CreatePrefetchData("www.yahoo.com", 7);
295 InitializeResourceData( 297 InitializeResourceData(
296 yahoo.add_resources(), "http://www.yahoo.com/image.png", 298 yahoo.add_resources(), "http://www.yahoo.com/image.png",
297 content::RESOURCE_TYPE_IMAGE, 120, 1, 1, 10.0, net::MEDIUM, true, false); 299 content::RESOURCE_TYPE_IMAGE, 120, 1, 1, 10.0, net::MEDIUM, true, false);
298 300
301 tables_->UpdateResourceData(yahoo, PREFETCH_KEY_TYPE_HOST);
302
299 RedirectData facebook = CreateRedirectData("http://fb.com/google", 20); 303 RedirectData facebook = CreateRedirectData("http://fb.com/google", 20);
300 InitializeRedirectStat(facebook.add_redirect_endpoints(), 304 InitializeRedirectStat(facebook.add_redirect_endpoints(),
301 "https://facebook.fr/google", 4, 2, 1); 305 "https://facebook.fr/google", 4, 2, 1);
302 306
307 tables_->UpdateRedirectData(facebook, PREFETCH_KEY_TYPE_URL);
308
303 RedirectData microsoft = CreateRedirectData("microsoft.com", 21); 309 RedirectData microsoft = CreateRedirectData("microsoft.com", 21);
304 InitializeRedirectStat(microsoft.add_redirect_endpoints(), "m.microsoft.com", 310 InitializeRedirectStat(microsoft.add_redirect_endpoints(), "m.microsoft.com",
305 5, 7, 1); 311 5, 7, 1);
306 InitializeRedirectStat(microsoft.add_redirect_endpoints(), "microsoft.org", 7, 312 InitializeRedirectStat(microsoft.add_redirect_endpoints(), "microsoft.org", 7,
307 2, 0); 313 2, 0);
308 314
309 tables_->UpdateData(google, yahoo, facebook, microsoft); 315 tables_->UpdateRedirectData(microsoft, PREFETCH_KEY_TYPE_HOST);
310 316
311 precache::PrecacheManifest theverge; 317 precache::PrecacheManifest theverge;
312 InitializePrecacheResource(theverge.add_resource(), 318 InitializePrecacheResource(theverge.add_resource(),
313 "https://www.theverge.com/main.js", 0.7); 319 "https://www.theverge.com/main.js", 0.7);
314 320
315 tables_->UpdateManifestData("theverge.com", theverge); 321 tables_->UpdateManifestData("theverge.com", theverge);
316 322
317 OriginData twitter = CreateOriginData("twitter.com"); 323 OriginData twitter = CreateOriginData("twitter.com");
318 InitializeOriginStat(twitter.add_origins(), "https://dogs.twitter.com", 10, 1, 324 InitializeOriginStat(twitter.add_origins(), "https://dogs.twitter.com", 10, 1,
319 0, 12., false, true); 325 0, 12., false, true);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 } 588 }
583 589
584 void ResourcePrefetchPredictorTablesTest::AddKey(OriginDataMap* m, 590 void ResourcePrefetchPredictorTablesTest::AddKey(OriginDataMap* m,
585 const std::string& key) const { 591 const std::string& key) const {
586 auto it = test_origin_data_.find(key); 592 auto it = test_origin_data_.find(key);
587 ASSERT_TRUE(it != test_origin_data_.end()); 593 ASSERT_TRUE(it != test_origin_data_.end());
588 m->insert(*it); 594 m->insert(*it);
589 } 595 }
590 596
591 void ResourcePrefetchPredictorTablesTest::InitializeSampleData() { 597 void ResourcePrefetchPredictorTablesTest::InitializeSampleData() {
592 PrefetchData empty_resource_data;
593 RedirectData empty_redirect_data;
594
595 { // Url data. 598 { // Url data.
596 PrefetchData google = CreatePrefetchData("http://www.google.com", 1); 599 PrefetchData google = CreatePrefetchData("http://www.google.com", 1);
597 InitializeResourceData(google.add_resources(), 600 InitializeResourceData(google.add_resources(),
598 "http://www.google.com/style.css", 601 "http://www.google.com/style.css",
599 content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1, 602 content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1,
600 net::MEDIUM, false, false); 603 net::MEDIUM, false, false);
601 InitializeResourceData( 604 InitializeResourceData(
602 google.add_resources(), "http://www.google.com/script.js", 605 google.add_resources(), "http://www.google.com/script.js",
603 content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 2.1, net::MEDIUM, false, false); 606 content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 2.1, net::MEDIUM, false, false);
604 InitializeResourceData( 607 InitializeResourceData(
(...skipping 20 matching lines...) Expand all
625 InitializeResourceData(yahoo.add_resources(), 628 InitializeResourceData(yahoo.add_resources(),
626 "http://www.google.com/image.png", 629 "http://www.google.com/image.png",
627 content::RESOURCE_TYPE_IMAGE, 20, 1, 0, 10.0, 630 content::RESOURCE_TYPE_IMAGE, 20, 1, 0, 10.0,
628 net::MEDIUM, false, false); 631 net::MEDIUM, false, false);
629 632
630 test_url_data_.clear(); 633 test_url_data_.clear();
631 test_url_data_.insert(std::make_pair(google.primary_key(), google)); 634 test_url_data_.insert(std::make_pair(google.primary_key(), google));
632 test_url_data_.insert(std::make_pair(reddit.primary_key(), reddit)); 635 test_url_data_.insert(std::make_pair(reddit.primary_key(), reddit));
633 test_url_data_.insert(std::make_pair(yahoo.primary_key(), yahoo)); 636 test_url_data_.insert(std::make_pair(yahoo.primary_key(), yahoo));
634 637
635 tables_->UpdateData(google, empty_resource_data, empty_redirect_data, 638 tables_->UpdateResourceData(google, PREFETCH_KEY_TYPE_URL);
636 empty_redirect_data); 639 tables_->UpdateResourceData(reddit, PREFETCH_KEY_TYPE_URL);
637 tables_->UpdateData(reddit, empty_resource_data, empty_redirect_data, 640 tables_->UpdateResourceData(yahoo, PREFETCH_KEY_TYPE_URL);
638 empty_redirect_data);
639 tables_->UpdateData(yahoo, empty_resource_data, empty_redirect_data,
640 empty_redirect_data);
641 } 641 }
642 642
643 { // Host data. 643 { // Host data.
644 PrefetchData facebook = CreatePrefetchData("www.facebook.com", 4); 644 PrefetchData facebook = CreatePrefetchData("www.facebook.com", 4);
645 InitializeResourceData(facebook.add_resources(), 645 InitializeResourceData(facebook.add_resources(),
646 "http://www.facebook.com/style.css", 646 "http://www.facebook.com/style.css",
647 content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1, 647 content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1,
648 net::MEDIUM, false, false); 648 net::MEDIUM, false, false);
649 InitializeResourceData( 649 InitializeResourceData(
650 facebook.add_resources(), "http://www.facebook.com/script.js", 650 facebook.add_resources(), "http://www.facebook.com/script.js",
(...skipping 13 matching lines...) Expand all
664 PrefetchData yahoo = CreatePrefetchData("www.yahoo.com", 5); 664 PrefetchData yahoo = CreatePrefetchData("www.yahoo.com", 5);
665 InitializeResourceData(yahoo.add_resources(), 665 InitializeResourceData(yahoo.add_resources(),
666 "http://www.google.com/image.png", 666 "http://www.google.com/image.png",
667 content::RESOURCE_TYPE_IMAGE, 20, 1, 0, 10.0, 667 content::RESOURCE_TYPE_IMAGE, 20, 1, 0, 10.0,
668 net::MEDIUM, false, false); 668 net::MEDIUM, false, false);
669 669
670 test_host_data_.clear(); 670 test_host_data_.clear();
671 test_host_data_.insert(std::make_pair(facebook.primary_key(), facebook)); 671 test_host_data_.insert(std::make_pair(facebook.primary_key(), facebook));
672 test_host_data_.insert(std::make_pair(yahoo.primary_key(), yahoo)); 672 test_host_data_.insert(std::make_pair(yahoo.primary_key(), yahoo));
673 673
674 tables_->UpdateData(empty_resource_data, facebook, empty_redirect_data, 674 tables_->UpdateResourceData(facebook, PREFETCH_KEY_TYPE_HOST);
675 empty_redirect_data); 675 tables_->UpdateResourceData(yahoo, PREFETCH_KEY_TYPE_HOST);
676 tables_->UpdateData(empty_resource_data, yahoo, empty_redirect_data,
677 empty_redirect_data);
678 } 676 }
679 677
680 { // Url redirect data. 678 { // Url redirect data.
681 RedirectData facebook = CreateRedirectData("http://fb.com/google", 6); 679 RedirectData facebook = CreateRedirectData("http://fb.com/google", 6);
682 InitializeRedirectStat(facebook.add_redirect_endpoints(), 680 InitializeRedirectStat(facebook.add_redirect_endpoints(),
683 "https://facebook.com/google", 5, 1, 0); 681 "https://facebook.com/google", 5, 1, 0);
684 InitializeRedirectStat(facebook.add_redirect_endpoints(), 682 InitializeRedirectStat(facebook.add_redirect_endpoints(),
685 "https://facebook.com/login", 3, 5, 1); 683 "https://facebook.com/login", 3, 5, 1);
686 684
687 RedirectData nytimes = CreateRedirectData("http://nyt.com", 7); 685 RedirectData nytimes = CreateRedirectData("http://nyt.com", 7);
688 InitializeRedirectStat(nytimes.add_redirect_endpoints(), 686 InitializeRedirectStat(nytimes.add_redirect_endpoints(),
689 "https://nytimes.com", 2, 0, 0); 687 "https://nytimes.com", 2, 0, 0);
690 688
691 RedirectData google = CreateRedirectData("http://google.com", 8); 689 RedirectData google = CreateRedirectData("http://google.com", 8);
692 InitializeRedirectStat(google.add_redirect_endpoints(), 690 InitializeRedirectStat(google.add_redirect_endpoints(),
693 "https://google.com", 3, 0, 0); 691 "https://google.com", 3, 0, 0);
694 692
695 test_url_redirect_data_.clear(); 693 test_url_redirect_data_.clear();
696 test_url_redirect_data_.insert( 694 test_url_redirect_data_.insert(
697 std::make_pair(facebook.primary_key(), facebook)); 695 std::make_pair(facebook.primary_key(), facebook));
698 test_url_redirect_data_.insert( 696 test_url_redirect_data_.insert(
699 std::make_pair(nytimes.primary_key(), nytimes)); 697 std::make_pair(nytimes.primary_key(), nytimes));
700 test_url_redirect_data_.insert( 698 test_url_redirect_data_.insert(
701 std::make_pair(google.primary_key(), google)); 699 std::make_pair(google.primary_key(), google));
702 700
703 tables_->UpdateData(empty_resource_data, empty_resource_data, facebook, 701 tables_->UpdateRedirectData(facebook, PREFETCH_KEY_TYPE_URL);
704 empty_redirect_data); 702 tables_->UpdateRedirectData(nytimes, PREFETCH_KEY_TYPE_URL);
705 tables_->UpdateData(empty_resource_data, empty_resource_data, nytimes, 703 tables_->UpdateRedirectData(google, PREFETCH_KEY_TYPE_URL);
706 empty_redirect_data);
707 tables_->UpdateData(empty_resource_data, empty_resource_data, google,
708 empty_redirect_data);
709 } 704 }
710 705
711 { // Host redirect data. 706 { // Host redirect data.
712 RedirectData bbc = CreateRedirectData("bbc.com", 9); 707 RedirectData bbc = CreateRedirectData("bbc.com", 9);
713 InitializeRedirectStat(bbc.add_redirect_endpoints(), "www.bbc.com", 8, 4, 708 InitializeRedirectStat(bbc.add_redirect_endpoints(), "www.bbc.com", 8, 4,
714 1); 709 1);
715 InitializeRedirectStat(bbc.add_redirect_endpoints(), "m.bbc.com", 5, 8, 0); 710 InitializeRedirectStat(bbc.add_redirect_endpoints(), "m.bbc.com", 5, 8, 0);
716 InitializeRedirectStat(bbc.add_redirect_endpoints(), "bbc.co.uk", 1, 3, 0); 711 InitializeRedirectStat(bbc.add_redirect_endpoints(), "bbc.co.uk", 1, 3, 0);
717 712
718 RedirectData microsoft = CreateRedirectData("microsoft.com", 10); 713 RedirectData microsoft = CreateRedirectData("microsoft.com", 10);
719 InitializeRedirectStat(microsoft.add_redirect_endpoints(), 714 InitializeRedirectStat(microsoft.add_redirect_endpoints(),
720 "www.microsoft.com", 10, 0, 0); 715 "www.microsoft.com", 10, 0, 0);
721 716
722 test_host_redirect_data_.clear(); 717 test_host_redirect_data_.clear();
723 test_host_redirect_data_.insert(std::make_pair(bbc.primary_key(), bbc)); 718 test_host_redirect_data_.insert(std::make_pair(bbc.primary_key(), bbc));
724 test_host_redirect_data_.insert( 719 test_host_redirect_data_.insert(
725 std::make_pair(microsoft.primary_key(), microsoft)); 720 std::make_pair(microsoft.primary_key(), microsoft));
726 tables_->UpdateData(empty_resource_data, empty_resource_data, 721
727 empty_redirect_data, bbc); 722 tables_->UpdateRedirectData(bbc, PREFETCH_KEY_TYPE_HOST);
728 tables_->UpdateData(empty_resource_data, empty_resource_data, 723 tables_->UpdateRedirectData(microsoft, PREFETCH_KEY_TYPE_HOST);
729 empty_redirect_data, microsoft);
730 } 724 }
731 725
732 { // Manifest data. 726 { // Manifest data.
733 precache::PrecacheManifest wikipedia; 727 precache::PrecacheManifest wikipedia;
734 InitializePrecacheResource(wikipedia.add_resource(), 728 InitializePrecacheResource(wikipedia.add_resource(),
735 "https://en.wikipedia.org/script.js", 0.7); 729 "https://en.wikipedia.org/script.js", 0.7);
736 InitializePrecacheResource(wikipedia.add_resource(), 730 InitializePrecacheResource(wikipedia.add_resource(),
737 "https://en.wikipedia.org/image.png", 0.3); 731 "https://en.wikipedia.org/image.png", 0.3);
738 732
739 precache::PrecacheManifest youtube; 733 precache::PrecacheManifest youtube;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 926
933 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteSingleDataPoint) { 927 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteSingleDataPoint) {
934 TestDeleteSingleDataPoint(); 928 TestDeleteSingleDataPoint();
935 } 929 }
936 930
937 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteAllData) { 931 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteAllData) {
938 TestDeleteAllData(); 932 TestDeleteAllData();
939 } 933 }
940 934
941 } // namespace predictors 935 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698