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

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

Issue 16296002: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <iostream> 5 #include <iostream>
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 InitializeSampleData(); 188 InitializeSampleData();
189 189
190 profile_->CreateHistoryService(true, false); 190 profile_->CreateHistoryService(true, false);
191 profile_->BlockUntilHistoryProcessesPendingRequests(); 191 profile_->BlockUntilHistoryProcessesPendingRequests();
192 EXPECT_TRUE(HistoryServiceFactory::GetForProfile(profile_.get(), 192 EXPECT_TRUE(HistoryServiceFactory::GetForProfile(profile_.get(),
193 Profile::EXPLICIT_ACCESS)); 193 Profile::EXPLICIT_ACCESS));
194 // Initialize the predictor with empty data. 194 // Initialize the predictor with empty data.
195 ResetPredictor(); 195 ResetPredictor();
196 EXPECT_EQ(predictor_->initialization_state_, 196 EXPECT_EQ(predictor_->initialization_state_,
197 ResourcePrefetchPredictor::NOT_INITIALIZED); 197 ResourcePrefetchPredictor::NOT_INITIALIZED);
198 EXPECT_CALL(*mock_tables_, 198 EXPECT_CALL(*mock_tables_.get(),
199 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 199 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
200 Pointee(ContainerEq(PrefetchDataMap())))); 200 Pointee(ContainerEq(PrefetchDataMap()))));
201 InitializePredictor(); 201 InitializePredictor();
202 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); 202 EXPECT_TRUE(predictor_->inflight_navigations_.empty());
203 EXPECT_EQ(predictor_->initialization_state_, 203 EXPECT_EQ(predictor_->initialization_state_,
204 ResourcePrefetchPredictor::INITIALIZED); 204 ResourcePrefetchPredictor::INITIALIZED);
205 } 205 }
206 206
207 void ResourcePrefetchPredictorTest::TearDown() { 207 void ResourcePrefetchPredictorTest::TearDown() {
208 predictor_.reset(NULL); 208 predictor_.reset(NULL);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // Tests that the predictor initializes correctly without any data. 347 // Tests that the predictor initializes correctly without any data.
348 EXPECT_TRUE(predictor_->url_table_cache_->empty()); 348 EXPECT_TRUE(predictor_->url_table_cache_->empty());
349 EXPECT_TRUE(predictor_->host_table_cache_->empty()); 349 EXPECT_TRUE(predictor_->host_table_cache_->empty());
350 } 350 }
351 351
352 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeWithData) { 352 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeWithData) {
353 // Tests that the history and the db tables data are loaded correctly. 353 // Tests that the history and the db tables data are loaded correctly.
354 AddUrlToHistory("http://www.google.com/", 4); 354 AddUrlToHistory("http://www.google.com/", 4);
355 AddUrlToHistory("http://www.yahoo.com/", 2); 355 AddUrlToHistory("http://www.yahoo.com/", 2);
356 356
357 EXPECT_CALL(*mock_tables_, 357 EXPECT_CALL(*mock_tables_.get(),
358 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 358 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
359 Pointee(ContainerEq(PrefetchDataMap())))) 359 Pointee(ContainerEq(PrefetchDataMap()))))
360 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), 360 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_),
361 SetArgPointee<1>(test_host_data_))); 361 SetArgPointee<1>(test_host_data_)));
362 362
363 ResetPredictor(); 363 ResetPredictor();
364 InitializePredictor(); 364 InitializePredictor();
365 365
366 // Test that the internal variables correctly initialized. 366 // Test that the internal variables correctly initialized.
367 EXPECT_EQ(predictor_->initialization_state_, 367 EXPECT_EQ(predictor_->initialization_state_,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 0, 416 0,
417 0, 417 0,
418 2.0)); 418 2.0));
419 host_data.resources.push_back(ResourceRow(std::string(), 419 host_data.resources.push_back(ResourceRow(std::string(),
420 "http://google.com/script2.js", 420 "http://google.com/script2.js",
421 ResourceType::SCRIPT, 421 ResourceType::SCRIPT,
422 1, 422 1,
423 0, 423 0,
424 0, 424 0,
425 3.0)); 425 3.0));
426 EXPECT_CALL(*mock_tables_, UpdateData(empty_url_data_, host_data)); 426 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data));
427 427
428 predictor_->OnNavigationComplete(main_frame.navigation_id); 428 predictor_->OnNavigationComplete(main_frame.navigation_id);
429 profile_->BlockUntilHistoryProcessesPendingRequests(); 429 profile_->BlockUntilHistoryProcessesPendingRequests();
430 } 430 }
431 431
432 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { 432 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) {
433 // Single navigation that will be recorded. Will check for duplicate 433 // Single navigation that will be recorded. Will check for duplicate
434 // resources and also for number of resources saved. 434 // resources and also for number of resources saved.
435 AddUrlToHistory("http://www.google.com", 4); 435 AddUrlToHistory("http://www.google.com", 4);
436 436
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 0, 500 0,
501 0, 501 0,
502 3.0)); 502 3.0));
503 url_data.resources.push_back(ResourceRow(std::string(), 503 url_data.resources.push_back(ResourceRow(std::string(),
504 "http://google.com/style2.css", 504 "http://google.com/style2.css",
505 ResourceType::STYLESHEET, 505 ResourceType::STYLESHEET,
506 1, 506 1,
507 0, 507 0,
508 0, 508 0,
509 7.0)); 509 7.0));
510 EXPECT_CALL(*mock_tables_, UpdateData(url_data, empty_host_data_)); 510 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_));
511 511
512 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); 512 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com");
513 host_data.resources = url_data.resources; 513 host_data.resources = url_data.resources;
514 EXPECT_CALL(*mock_tables_, UpdateData(empty_url_data_, host_data)); 514 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data));
515 515
516 predictor_->OnNavigationComplete(main_frame.navigation_id); 516 predictor_->OnNavigationComplete(main_frame.navigation_id);
517 profile_->BlockUntilHistoryProcessesPendingRequests(); 517 profile_->BlockUntilHistoryProcessesPendingRequests();
518 } 518 }
519 519
520 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) { 520 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) {
521 // Tests that navigation is recorded correctly for URL already present in 521 // Tests that navigation is recorded correctly for URL already present in
522 // the database cache. 522 // the database cache.
523 AddUrlToHistory("http://www.google.com", 4); 523 AddUrlToHistory("http://www.google.com", 4);
524 524
525 EXPECT_CALL(*mock_tables_, 525 EXPECT_CALL(*mock_tables_.get(),
526 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 526 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
527 Pointee(ContainerEq(PrefetchDataMap())))) 527 Pointee(ContainerEq(PrefetchDataMap()))))
528 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), 528 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_),
529 SetArgPointee<1>(test_host_data_))); 529 SetArgPointee<1>(test_host_data_)));
530 ResetPredictor(); 530 ResetPredictor();
531 InitializePredictor(); 531 InitializePredictor();
532 EXPECT_EQ(3, static_cast<int>(predictor_->url_table_cache_->size())); 532 EXPECT_EQ(3, static_cast<int>(predictor_->url_table_cache_->size()));
533 EXPECT_EQ(2, static_cast<int>(predictor_->host_table_cache_->size())); 533 EXPECT_EQ(2, static_cast<int>(predictor_->host_table_cache_->size()));
534 534
535 URLRequestSummary main_frame = 535 URLRequestSummary main_frame =
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 1, 598 1,
599 1, 599 1,
600 2.1)); 600 2.1));
601 url_data.resources.push_back(ResourceRow(std::string(), 601 url_data.resources.push_back(ResourceRow(std::string(),
602 "http://google.com/script2.js", 602 "http://google.com/script2.js",
603 ResourceType::SCRIPT, 603 ResourceType::SCRIPT,
604 1, 604 1,
605 0, 605 0,
606 0, 606 0,
607 3.0)); 607 3.0));
608 EXPECT_CALL(*mock_tables_, UpdateData(url_data, empty_host_data_)); 608 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_));
609 609
610 EXPECT_CALL(*mock_tables_, 610 EXPECT_CALL(
611 DeleteSingleDataPoint("www.facebook.com", 611 *mock_tables_.get(),
612 PREFETCH_KEY_TYPE_HOST)); 612 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST));
613 613
614 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); 614 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com");
615 host_data.resources.push_back(ResourceRow(std::string(), 615 host_data.resources.push_back(ResourceRow(std::string(),
616 "http://google.com/style1.css", 616 "http://google.com/style1.css",
617 ResourceType::STYLESHEET, 617 ResourceType::STYLESHEET,
618 1, 618 1,
619 0, 619 0,
620 0, 620 0,
621 1.0)); 621 1.0));
622 host_data.resources.push_back(ResourceRow(std::string(), 622 host_data.resources.push_back(ResourceRow(std::string(),
(...skipping 10 matching lines...) Expand all
633 0, 633 0,
634 0, 634 0,
635 3.0)); 635 3.0));
636 host_data.resources.push_back(ResourceRow(std::string(), 636 host_data.resources.push_back(ResourceRow(std::string(),
637 "http://google.com/style2.css", 637 "http://google.com/style2.css",
638 ResourceType::STYLESHEET, 638 ResourceType::STYLESHEET,
639 1, 639 1,
640 0, 640 0,
641 0, 641 0,
642 7.0)); 642 7.0));
643 EXPECT_CALL(*mock_tables_, UpdateData(empty_url_data_, host_data)); 643 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data));
644 644
645 predictor_->OnNavigationComplete(main_frame.navigation_id); 645 predictor_->OnNavigationComplete(main_frame.navigation_id);
646 profile_->BlockUntilHistoryProcessesPendingRequests(); 646 profile_->BlockUntilHistoryProcessesPendingRequests();
647 } 647 }
648 648
649 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { 649 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) {
650 // Tests that a URL is deleted before another is added if the cache is full. 650 // Tests that a URL is deleted before another is added if the cache is full.
651 AddUrlToHistory("http://www.nike.com/", 4); 651 AddUrlToHistory("http://www.nike.com/", 4);
652 652
653 EXPECT_CALL(*mock_tables_, 653 EXPECT_CALL(*mock_tables_.get(),
654 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 654 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
655 Pointee(ContainerEq(PrefetchDataMap())))) 655 Pointee(ContainerEq(PrefetchDataMap()))))
656 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), 656 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_),
657 SetArgPointee<1>(test_host_data_))); 657 SetArgPointee<1>(test_host_data_)));
658 ResetPredictor(); 658 ResetPredictor();
659 InitializePredictor(); 659 InitializePredictor();
660 EXPECT_EQ(3, static_cast<int>(predictor_->url_table_cache_->size())); 660 EXPECT_EQ(3, static_cast<int>(predictor_->url_table_cache_->size()));
661 EXPECT_EQ(2, static_cast<int>(predictor_->host_table_cache_->size())); 661 EXPECT_EQ(2, static_cast<int>(predictor_->host_table_cache_->size()));
662 662
663 URLRequestSummary main_frame = 663 URLRequestSummary main_frame =
664 CreateURLRequestSummary(1, 664 CreateURLRequestSummary(1,
665 1, 665 1,
666 "http://www.nike.com", 666 "http://www.nike.com",
667 "http://www.nike.com", 667 "http://www.nike.com",
668 ResourceType::MAIN_FRAME, 668 ResourceType::MAIN_FRAME,
669 std::string(), 669 std::string(),
670 false); 670 false);
671 predictor_->RecordURLRequest(main_frame); 671 predictor_->RecordURLRequest(main_frame);
672 EXPECT_EQ(1, static_cast<int>(predictor_->inflight_navigations_.size())); 672 EXPECT_EQ(1, static_cast<int>(predictor_->inflight_navigations_.size()));
673 673
674 URLRequestSummary resource1 = CreateURLRequestSummary( 674 URLRequestSummary resource1 = CreateURLRequestSummary(
675 1, 1, "http://www.nike.com", "http://nike.com/style1.css", 675 1, 1, "http://www.nike.com", "http://nike.com/style1.css",
676 ResourceType::STYLESHEET, "text/css", false); 676 ResourceType::STYLESHEET, "text/css", false);
677 predictor_->RecordUrlResponse(resource1); 677 predictor_->RecordUrlResponse(resource1);
678 URLRequestSummary resource2 = CreateURLRequestSummary( 678 URLRequestSummary resource2 = CreateURLRequestSummary(
679 1, 1, "http://www.nike.com", "http://nike.com/image2.png", 679 1, 1, "http://www.nike.com", "http://nike.com/image2.png",
680 ResourceType::IMAGE, "image/png", false); 680 ResourceType::IMAGE, "image/png", false);
681 predictor_->RecordUrlResponse(resource2); 681 predictor_->RecordUrlResponse(resource2);
682 682
683 EXPECT_CALL(*mock_tables_, 683 EXPECT_CALL(
684 DeleteSingleDataPoint("http://www.google.com/", 684 *mock_tables_.get(),
685 PREFETCH_KEY_TYPE_URL)); 685 DeleteSingleDataPoint("http://www.google.com/", PREFETCH_KEY_TYPE_URL));
686 EXPECT_CALL(*mock_tables_, 686 EXPECT_CALL(
687 DeleteSingleDataPoint("www.facebook.com", 687 *mock_tables_.get(),
688 PREFETCH_KEY_TYPE_HOST)); 688 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST));
689 689
690 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/"); 690 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/");
691 url_data.resources.push_back(ResourceRow(std::string(), 691 url_data.resources.push_back(ResourceRow(std::string(),
692 "http://nike.com/style1.css", 692 "http://nike.com/style1.css",
693 ResourceType::STYLESHEET, 693 ResourceType::STYLESHEET,
694 1, 694 1,
695 0, 695 0,
696 0, 696 0,
697 1.0)); 697 1.0));
698 url_data.resources.push_back(ResourceRow(std::string(), 698 url_data.resources.push_back(ResourceRow(std::string(),
699 "http://nike.com/image2.png", 699 "http://nike.com/image2.png",
700 ResourceType::IMAGE, 700 ResourceType::IMAGE,
701 1, 701 1,
702 0, 702 0,
703 0, 703 0,
704 2.0)); 704 2.0));
705 EXPECT_CALL(*mock_tables_, UpdateData(url_data, empty_host_data_)); 705 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_));
706 706
707 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com"); 707 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com");
708 host_data.resources = url_data.resources; 708 host_data.resources = url_data.resources;
709 EXPECT_CALL(*mock_tables_, UpdateData(empty_url_data_, host_data)); 709 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data));
710 710
711 predictor_->OnNavigationComplete(main_frame.navigation_id); 711 predictor_->OnNavigationComplete(main_frame.navigation_id);
712 profile_->BlockUntilHistoryProcessesPendingRequests(); 712 profile_->BlockUntilHistoryProcessesPendingRequests();
713 } 713 }
714 714
715 TEST_F(ResourcePrefetchPredictorTest, DeleteUrls) { 715 TEST_F(ResourcePrefetchPredictorTest, DeleteUrls) {
716 // Add some dummy entries to cache. 716 // Add some dummy entries to cache.
717 predictor_->url_table_cache_->insert(std::make_pair( 717 predictor_->url_table_cache_->insert(std::make_pair(
718 "http://www.google.com/page1.html", 718 "http://www.google.com/page1.html",
719 PrefetchData(PREFETCH_KEY_TYPE_URL, "http://www.google.com/page1.html"))); 719 PrefetchData(PREFETCH_KEY_TYPE_URL, "http://www.google.com/page1.html")));
(...skipping 25 matching lines...) Expand all
745 rows.push_back(history::URLRow(GURL("http://www.apple.com"))); 745 rows.push_back(history::URLRow(GURL("http://www.apple.com")));
746 rows.push_back(history::URLRow(GURL("http://www.nike.com"))); 746 rows.push_back(history::URLRow(GURL("http://www.nike.com")));
747 747
748 std::vector<std::string> urls_to_delete, hosts_to_delete; 748 std::vector<std::string> urls_to_delete, hosts_to_delete;
749 urls_to_delete.push_back("http://www.google.com/page2.html"); 749 urls_to_delete.push_back("http://www.google.com/page2.html");
750 urls_to_delete.push_back("http://www.apple.com/"); 750 urls_to_delete.push_back("http://www.apple.com/");
751 urls_to_delete.push_back("http://www.nike.com/"); 751 urls_to_delete.push_back("http://www.nike.com/");
752 hosts_to_delete.push_back("www.google.com"); 752 hosts_to_delete.push_back("www.google.com");
753 hosts_to_delete.push_back("www.apple.com"); 753 hosts_to_delete.push_back("www.apple.com");
754 754
755 EXPECT_CALL(*mock_tables_, 755 EXPECT_CALL(
756 DeleteData(ContainerEq(urls_to_delete), 756 *mock_tables_.get(),
757 ContainerEq(hosts_to_delete))); 757 DeleteData(ContainerEq(urls_to_delete), ContainerEq(hosts_to_delete)));
758 758
759 predictor_->DeleteUrls(rows); 759 predictor_->DeleteUrls(rows);
760 EXPECT_EQ(2, static_cast<int>(predictor_->url_table_cache_->size())); 760 EXPECT_EQ(2, static_cast<int>(predictor_->url_table_cache_->size()));
761 EXPECT_EQ(1, static_cast<int>(predictor_->host_table_cache_->size())); 761 EXPECT_EQ(1, static_cast<int>(predictor_->host_table_cache_->size()));
762 762
763 EXPECT_CALL(*mock_tables_, DeleteAllData()); 763 EXPECT_CALL(*mock_tables_.get(), DeleteAllData());
764 764
765 predictor_->DeleteAllUrls(); 765 predictor_->DeleteAllUrls();
766 EXPECT_TRUE(predictor_->url_table_cache_->empty()); 766 EXPECT_TRUE(predictor_->url_table_cache_->empty());
767 EXPECT_TRUE(predictor_->host_table_cache_->empty()); 767 EXPECT_TRUE(predictor_->host_table_cache_->empty());
768 } 768 }
769 769
770 TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRequest) { 770 TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRequest) {
771 URLRequestSummary summary1 = CreateURLRequestSummary(1, 771 URLRequestSummary summary1 = CreateURLRequestSummary(1,
772 1, 772 1,
773 "http://www.google.com", 773 "http://www.google.com",
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(0))); 918 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(0)));
919 EXPECT_TRUE(URLRequestSummaryAreEqual( 919 EXPECT_TRUE(URLRequestSummaryAreEqual(
920 resource2, 920 resource2,
921 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(1))); 921 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(1)));
922 EXPECT_TRUE(URLRequestSummaryAreEqual( 922 EXPECT_TRUE(URLRequestSummaryAreEqual(
923 resource3, 923 resource3,
924 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(2))); 924 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(2)));
925 } 925 }
926 926
927 } // namespace predictors 927 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor.cc ('k') | chrome/browser/predictors/resource_prefetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698