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

Side by Side Diff: chrome/browser/history/top_sites_impl_unittest.cc

Issue 23477033: Implementing URL prefix match for history thumbnail cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replacing ASSERT_TRUE() << ... to NOTREACHED() << ... Created 7 years, 3 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
« no previous file with comments | « chrome/browser/history/top_sites_impl.cc ('k') | chrome/browser/history/url_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/history/history_db_task.h" 10 #include "chrome/browser/history/history_db_task.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 141 }
142 142
143 // Returns true if history and top sites should be created in SetUp. 143 // Returns true if history and top sites should be created in SetUp.
144 virtual bool CreateHistoryAndTopSites() { 144 virtual bool CreateHistoryAndTopSites() {
145 return true; 145 return true;
146 } 146 }
147 147
148 // Gets the thumbnail for |url| from TopSites. 148 // Gets the thumbnail for |url| from TopSites.
149 SkBitmap GetThumbnail(const GURL& url) { 149 SkBitmap GetThumbnail(const GURL& url) {
150 scoped_refptr<base::RefCountedMemory> data; 150 scoped_refptr<base::RefCountedMemory> data;
151 return top_sites()->GetPageThumbnail(url, &data) ? 151 return top_sites()->GetPageThumbnail(url, false, &data) ?
152 ExtractThumbnail(*data.get()) : SkBitmap(); 152 ExtractThumbnail(*data.get()) : SkBitmap();
153 } 153 }
154 154
155 // Creates a bitmap of the specified color. Caller takes ownership. 155 // Creates a bitmap of the specified color. Caller takes ownership.
156 gfx::Image CreateBitmap(SkColor color) { 156 gfx::Image CreateBitmap(SkColor color) {
157 SkBitmap thumbnail; 157 SkBitmap thumbnail;
158 thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); 158 thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4);
159 thumbnail.allocPixels(); 159 thumbnail.allocPixels();
160 thumbnail.eraseColor(color); 160 thumbnail.eraseColor(color);
161 return gfx::Image::CreateFrom1xBitmap(thumbnail); // adds ref. 161 return gfx::Image::CreateFrom1xBitmap(thumbnail); // adds ref.
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 base::Time now = base::Time::Now(); 471 base::Time now = base::Time::Now();
472 ThumbnailScore low_score(1.0, true, true, now); 472 ThumbnailScore low_score(1.0, true, true, now);
473 ThumbnailScore medium_score(0.5, true, true, now); 473 ThumbnailScore medium_score(0.5, true, true, now);
474 ThumbnailScore high_score(0.0, true, true, now); 474 ThumbnailScore high_score(0.0, true, true, now);
475 475
476 // Set the thumbnail. 476 // Set the thumbnail.
477 EXPECT_TRUE(top_sites()->SetPageThumbnail(url, thumbnail, medium_score)); 477 EXPECT_TRUE(top_sites()->SetPageThumbnail(url, thumbnail, medium_score));
478 478
479 // Make sure the thumbnail was actually set. 479 // Make sure the thumbnail was actually set.
480 scoped_refptr<base::RefCountedMemory> result; 480 scoped_refptr<base::RefCountedMemory> result;
481 EXPECT_TRUE(top_sites()->GetPageThumbnail(url, &result)); 481 EXPECT_TRUE(top_sites()->GetPageThumbnail(url, false, &result));
482 EXPECT_TRUE(ThumbnailEqualsBytes(thumbnail, result.get())); 482 EXPECT_TRUE(ThumbnailEqualsBytes(thumbnail, result.get()));
483 483
484 // Reset the thumbnails and make sure we don't get it back. 484 // Reset the thumbnails and make sure we don't get it back.
485 SetTopSites(MostVisitedURLList()); 485 SetTopSites(MostVisitedURLList());
486 RefreshTopSitesAndRecreate(); 486 RefreshTopSitesAndRecreate();
487 EXPECT_FALSE(top_sites()->GetPageThumbnail(url, &result)); 487 EXPECT_FALSE(top_sites()->GetPageThumbnail(url, false, &result));
488 } 488 }
489 489
490 // Tests GetPageThumbnail. 490 // Tests GetPageThumbnail.
491 TEST_F(TopSitesImplTest, GetPageThumbnail) { 491 TEST_F(TopSitesImplTest, GetPageThumbnail) {
492 MostVisitedURLList url_list; 492 MostVisitedURLList url_list;
493 MostVisitedURL url1; 493 MostVisitedURL url1;
494 url1.url = GURL("http://asdf.com"); 494 url1.url = GURL("http://asdf.com");
495 url1.redirects.push_back(url1.url); 495 url1.redirects.push_back(url1.url);
496 url_list.push_back(url1); 496 url_list.push_back(url1);
497 497
498 MostVisitedURL url2; 498 MostVisitedURL url2;
499 url2.url = GURL("http://gmail.com"); 499 url2.url = GURL("http://gmail.com");
500 url2.redirects.push_back(url2.url); 500 url2.redirects.push_back(url2.url);
501 url2.redirects.push_back(GURL("http://mail.google.com")); 501 url2.redirects.push_back(GURL("http://mail.google.com"));
502 url_list.push_back(url2); 502 url_list.push_back(url2);
503 503
504 SetTopSites(url_list); 504 SetTopSites(url_list);
505 505
506 // Create a dummy thumbnail. 506 // Create a dummy thumbnail.
507 gfx::Image thumbnail(CreateBitmap(SK_ColorWHITE)); 507 gfx::Image thumbnail(CreateBitmap(SK_ColorWHITE));
508 ThumbnailScore score(0.5, true, true, base::Time::Now()); 508 ThumbnailScore score(0.5, true, true, base::Time::Now());
509 509
510 scoped_refptr<base::RefCountedMemory> result; 510 scoped_refptr<base::RefCountedMemory> result;
511 EXPECT_TRUE(top_sites()->SetPageThumbnail(url1.url, thumbnail, score)); 511 EXPECT_TRUE(top_sites()->SetPageThumbnail(url1.url, thumbnail, score));
512 EXPECT_TRUE(top_sites()->GetPageThumbnail(url1.url, &result)); 512 EXPECT_TRUE(top_sites()->GetPageThumbnail(url1.url, false, &result));
513 513
514 EXPECT_TRUE(top_sites()->SetPageThumbnail(GURL("http://gmail.com"), 514 EXPECT_TRUE(top_sites()->SetPageThumbnail(GURL("http://gmail.com"),
515 thumbnail, score)); 515 thumbnail, score));
516 EXPECT_TRUE(top_sites()->GetPageThumbnail(GURL("http://gmail.com"), 516 EXPECT_TRUE(top_sites()->GetPageThumbnail(GURL("http://gmail.com"),
517 false,
517 &result)); 518 &result));
518 // Get a thumbnail via a redirect. 519 // Get a thumbnail via a redirect.
519 EXPECT_TRUE(top_sites()->GetPageThumbnail(GURL("http://mail.google.com"), 520 EXPECT_TRUE(top_sites()->GetPageThumbnail(GURL("http://mail.google.com"),
521 false,
520 &result)); 522 &result));
521 523
522 EXPECT_TRUE(top_sites()->SetPageThumbnail(GURL("http://mail.google.com"), 524 EXPECT_TRUE(top_sites()->SetPageThumbnail(GURL("http://mail.google.com"),
523 thumbnail, score)); 525 thumbnail, score));
524 EXPECT_TRUE(top_sites()->GetPageThumbnail(url2.url, &result)); 526 EXPECT_TRUE(top_sites()->GetPageThumbnail(url2.url, false, &result));
525 527
526 EXPECT_TRUE(ThumbnailEqualsBytes(thumbnail, result.get())); 528 EXPECT_TRUE(ThumbnailEqualsBytes(thumbnail, result.get()));
527 } 529 }
528 530
529 // Tests GetMostVisitedURLs. 531 // Tests GetMostVisitedURLs.
530 TEST_F(TopSitesImplTest, GetMostVisited) { 532 TEST_F(TopSitesImplTest, GetMostVisited) {
531 GURL news("http://news.google.com/"); 533 GURL news("http://news.google.com/");
532 GURL google("http://google.com/"); 534 GURL google("http://google.com/");
533 535
534 AddPageToHistory(news); 536 AddPageToHistory(news);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 577
576 { 578 {
577 TopSitesQuerier querier; 579 TopSitesQuerier querier;
578 querier.QueryTopSites(top_sites(), false); 580 querier.QueryTopSites(top_sites(), false);
579 ASSERT_EQ(1u + GetPrepopulatePages().size(), querier.urls().size()); 581 ASSERT_EQ(1u + GetPrepopulatePages().size(), querier.urls().size());
580 EXPECT_EQ(asdf_url, querier.urls()[0].url); 582 EXPECT_EQ(asdf_url, querier.urls()[0].url);
581 EXPECT_EQ(asdf_title, querier.urls()[0].title); 583 EXPECT_EQ(asdf_title, querier.urls()[0].title);
582 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(querier, 1)); 584 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(querier, 1));
583 585
584 scoped_refptr<base::RefCountedMemory> read_data; 586 scoped_refptr<base::RefCountedMemory> read_data;
585 EXPECT_TRUE(top_sites()->GetPageThumbnail(asdf_url, &read_data)); 587 EXPECT_TRUE(top_sites()->GetPageThumbnail(asdf_url, false, &read_data));
586 EXPECT_TRUE(ThumbnailEqualsBytes(tmp_bitmap, read_data.get())); 588 EXPECT_TRUE(ThumbnailEqualsBytes(tmp_bitmap, read_data.get()));
587 } 589 }
588 590
589 MostVisitedURL url2; 591 MostVisitedURL url2;
590 url2.url = google_url; 592 url2.url = google_url;
591 url2.title = google_title; 593 url2.title = google_title;
592 url2.redirects.push_back(url2.url); 594 url2.redirects.push_back(url2.url);
593 595
594 AddPageToHistory(url2.url, url2.title); 596 AddPageToHistory(url2.url, url2.title);
595 597
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 { 642 {
641 TopSitesQuerier querier; 643 TopSitesQuerier querier;
642 querier.QueryTopSites(top_sites(), false); 644 querier.QueryTopSites(top_sites(), false);
643 645
644 ASSERT_EQ(1u + GetPrepopulatePages().size(), querier.urls().size()); 646 ASSERT_EQ(1u + GetPrepopulatePages().size(), querier.urls().size());
645 EXPECT_EQ(asdf_url, querier.urls()[0].url); 647 EXPECT_EQ(asdf_url, querier.urls()[0].url);
646 EXPECT_EQ(asdf_title, querier.urls()[0].title); 648 EXPECT_EQ(asdf_title, querier.urls()[0].title);
647 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(querier, 1)); 649 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(querier, 1));
648 650
649 scoped_refptr<base::RefCountedMemory> read_data; 651 scoped_refptr<base::RefCountedMemory> read_data;
650 EXPECT_TRUE(top_sites()->GetPageThumbnail(asdf_url, &read_data)); 652 EXPECT_TRUE(top_sites()->GetPageThumbnail(asdf_url, false, &read_data));
651 EXPECT_TRUE(ThumbnailEqualsBytes(asdf_thumbnail, read_data.get())); 653 EXPECT_TRUE(ThumbnailEqualsBytes(asdf_thumbnail, read_data.get()));
652 } 654 }
653 655
654 MostVisitedURL url2; 656 MostVisitedURL url2;
655 url2.url = google3_url; 657 url2.url = google3_url;
656 url2.title = google_title; 658 url2.title = google_title;
657 url2.redirects.push_back(google1_url); 659 url2.redirects.push_back(google1_url);
658 url2.redirects.push_back(google2_url); 660 url2.redirects.push_back(google2_url);
659 url2.redirects.push_back(google3_url); 661 url2.redirects.push_back(google3_url);
660 662
(...skipping 11 matching lines...) Expand all
672 674
673 { 675 {
674 scoped_refptr<base::RefCountedMemory> read_data; 676 scoped_refptr<base::RefCountedMemory> read_data;
675 TopSitesQuerier querier; 677 TopSitesQuerier querier;
676 querier.QueryTopSites(top_sites(), false); 678 querier.QueryTopSites(top_sites(), false);
677 679
678 ASSERT_EQ(2u + GetPrepopulatePages().size(), querier.urls().size()); 680 ASSERT_EQ(2u + GetPrepopulatePages().size(), querier.urls().size());
679 EXPECT_EQ(google1_url, querier.urls()[0].url); 681 EXPECT_EQ(google1_url, querier.urls()[0].url);
680 EXPECT_EQ(google_title, querier.urls()[0].title); 682 EXPECT_EQ(google_title, querier.urls()[0].title);
681 ASSERT_EQ(3u, querier.urls()[0].redirects.size()); 683 ASSERT_EQ(3u, querier.urls()[0].redirects.size());
682 EXPECT_TRUE(top_sites()->GetPageThumbnail(google3_url, &read_data)); 684 EXPECT_TRUE(top_sites()->GetPageThumbnail(google3_url, false, &read_data));
683 EXPECT_TRUE(ThumbnailEqualsBytes(google_thumbnail, read_data.get())); 685 EXPECT_TRUE(ThumbnailEqualsBytes(google_thumbnail, read_data.get()));
684 686
685 EXPECT_EQ(asdf_url, querier.urls()[1].url); 687 EXPECT_EQ(asdf_url, querier.urls()[1].url);
686 EXPECT_EQ(asdf_title, querier.urls()[1].title); 688 EXPECT_EQ(asdf_title, querier.urls()[1].title);
687 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(querier, 2)); 689 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(querier, 2));
688 } 690 }
689 691
690 gfx::Image weewar_bitmap(CreateBitmap(SK_ColorYELLOW)); 692 gfx::Image weewar_bitmap(CreateBitmap(SK_ColorYELLOW));
691 693
692 base::Time thumbnail_time(base::Time::Now()); 694 base::Time thumbnail_time(base::Time::Now());
693 ThumbnailScore low_score(1.0, true, true, thumbnail_time); 695 ThumbnailScore low_score(1.0, true, true, thumbnail_time);
694 ThumbnailScore medium_score(0.5, true, true, thumbnail_time); 696 ThumbnailScore medium_score(0.5, true, true, thumbnail_time);
695 ThumbnailScore high_score(0.0, true, true, thumbnail_time); 697 ThumbnailScore high_score(0.0, true, true, thumbnail_time);
696 698
697 // 1. Set to weewar. (Writes the thumbnail to the DB.) 699 // 1. Set to weewar. (Writes the thumbnail to the DB.)
698 EXPECT_TRUE(top_sites()->SetPageThumbnail(google3_url, 700 EXPECT_TRUE(top_sites()->SetPageThumbnail(google3_url,
699 weewar_bitmap, 701 weewar_bitmap,
700 medium_score)); 702 medium_score));
701 RefreshTopSitesAndRecreate(); 703 RefreshTopSitesAndRecreate();
702 { 704 {
703 scoped_refptr<base::RefCountedMemory> read_data; 705 scoped_refptr<base::RefCountedMemory> read_data;
704 EXPECT_TRUE(top_sites()->GetPageThumbnail(google3_url, &read_data)); 706 EXPECT_TRUE(top_sites()->GetPageThumbnail(google3_url, false, &read_data));
705 EXPECT_TRUE(ThumbnailEqualsBytes(weewar_bitmap, read_data.get())); 707 EXPECT_TRUE(ThumbnailEqualsBytes(weewar_bitmap, read_data.get()));
706 } 708 }
707 709
708 gfx::Image green_bitmap(CreateBitmap(SK_ColorGREEN)); 710 gfx::Image green_bitmap(CreateBitmap(SK_ColorGREEN));
709 711
710 // 2. Set to google - low score. 712 // 2. Set to google - low score.
711 EXPECT_FALSE(top_sites()->SetPageThumbnail(google3_url, 713 EXPECT_FALSE(top_sites()->SetPageThumbnail(google3_url,
712 green_bitmap, 714 green_bitmap,
713 low_score)); 715 low_score));
714 716
715 // 3. Set to google - high score. 717 // 3. Set to google - high score.
716 EXPECT_TRUE(top_sites()->SetPageThumbnail(google1_url, 718 EXPECT_TRUE(top_sites()->SetPageThumbnail(google1_url,
717 green_bitmap, 719 green_bitmap,
718 high_score)); 720 high_score));
719 721
720 // Check that the thumbnail was updated. 722 // Check that the thumbnail was updated.
721 RefreshTopSitesAndRecreate(); 723 RefreshTopSitesAndRecreate();
722 { 724 {
723 scoped_refptr<base::RefCountedMemory> read_data; 725 scoped_refptr<base::RefCountedMemory> read_data;
724 EXPECT_TRUE(top_sites()->GetPageThumbnail(google3_url, &read_data)); 726 EXPECT_TRUE(top_sites()->GetPageThumbnail(google3_url, false, &read_data));
725 EXPECT_FALSE(ThumbnailEqualsBytes(weewar_bitmap, read_data.get())); 727 EXPECT_FALSE(ThumbnailEqualsBytes(weewar_bitmap, read_data.get()));
726 EXPECT_TRUE(ThumbnailEqualsBytes(green_bitmap, read_data.get())); 728 EXPECT_TRUE(ThumbnailEqualsBytes(green_bitmap, read_data.get()));
727 } 729 }
728 } 730 }
729 731
730 TEST_F(TopSitesImplTest, DeleteNotifications) { 732 TEST_F(TopSitesImplTest, DeleteNotifications) {
731 GURL google1_url("http://google.com"); 733 GURL google1_url("http://google.com");
732 GURL google2_url("http://google.com/redirect"); 734 GURL google2_url("http://google.com/redirect");
733 GURL google3_url("http://www.google.com"); 735 GURL google3_url("http://www.google.com");
734 string16 google_title(ASCIIToUTF16("Google")); 736 string16 google_title(ASCIIToUTF16("Google"));
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 thumbnail, 959 thumbnail,
958 medium_score)); 960 medium_score));
959 // Store thumbnails for unknown (but valid) URLs temporarily - calls 961 // Store thumbnails for unknown (but valid) URLs temporarily - calls
960 // AddTemporaryThumbnail. 962 // AddTemporaryThumbnail.
961 EXPECT_TRUE(top_sites()->SetPageThumbnail(unknown_url, 963 EXPECT_TRUE(top_sites()->SetPageThumbnail(unknown_url,
962 thumbnail, 964 thumbnail,
963 medium_score)); 965 medium_score));
964 966
965 // We shouldn't get the thumnail back though (the url isn't in to sites yet). 967 // We shouldn't get the thumnail back though (the url isn't in to sites yet).
966 scoped_refptr<base::RefCountedMemory> out; 968 scoped_refptr<base::RefCountedMemory> out;
967 EXPECT_FALSE(top_sites()->GetPageThumbnail(unknown_url, &out)); 969 EXPECT_FALSE(top_sites()->GetPageThumbnail(unknown_url, false, &out));
968 // But we should be able to get the temporary page thumbnail score. 970 // But we should be able to get the temporary page thumbnail score.
969 ThumbnailScore out_score; 971 ThumbnailScore out_score;
970 EXPECT_TRUE(top_sites()->GetTemporaryPageThumbnailScore(unknown_url, 972 EXPECT_TRUE(top_sites()->GetTemporaryPageThumbnailScore(unknown_url,
971 &out_score)); 973 &out_score));
972 EXPECT_TRUE(medium_score.Equals(out_score)); 974 EXPECT_TRUE(medium_score.Equals(out_score));
973 975
974 std::vector<MostVisitedURL> list; 976 std::vector<MostVisitedURL> list;
975 977
976 MostVisitedURL mv; 978 MostVisitedURL mv;
977 mv.url = unknown_url; 979 mv.url = unknown_url;
978 mv.redirects.push_back(mv.url); 980 mv.redirects.push_back(mv.url);
979 mv.redirects.push_back(url1a); 981 mv.redirects.push_back(url1a);
980 mv.redirects.push_back(url1b); 982 mv.redirects.push_back(url1b);
981 list.push_back(mv); 983 list.push_back(mv);
982 984
983 // Update URLs. This should result in using thumbnail. 985 // Update URLs. This should result in using thumbnail.
984 SetTopSites(list); 986 SetTopSites(list);
985 987
986 ASSERT_TRUE(top_sites()->GetPageThumbnail(unknown_url, &out)); 988 ASSERT_TRUE(top_sites()->GetPageThumbnail(unknown_url, false, &out));
987 EXPECT_TRUE(ThumbnailEqualsBytes(thumbnail, out.get())); 989 EXPECT_TRUE(ThumbnailEqualsBytes(thumbnail, out.get()));
988 } 990 }
989 991
990 // Tests variations of blacklisting. 992 // Tests variations of blacklisting.
991 TEST_F(TopSitesImplTest, Blacklisting) { 993 TEST_F(TopSitesImplTest, Blacklisting) {
992 MostVisitedURLList pages; 994 MostVisitedURLList pages;
993 MostVisitedURL url, url1; 995 MostVisitedURL url, url1;
994 url.url = GURL("http://bbc.com/"); 996 url.url = GURL("http://bbc.com/");
995 url.redirects.push_back(url.url); 997 url.redirects.push_back(url.url);
996 pages.push_back(url); 998 pages.push_back(url);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 1089
1088 MostVisitedURLList pages = q.urls(); 1090 MostVisitedURLList pages = q.urls();
1089 EXPECT_FALSE(AddPrepopulatedPages(&pages)); 1091 EXPECT_FALSE(AddPrepopulatedPages(&pages));
1090 1092
1091 EXPECT_EQ(GetPrepopulatePages().size(), pages.size()); 1093 EXPECT_EQ(GetPrepopulatePages().size(), pages.size());
1092 q.set_urls(pages); 1094 q.set_urls(pages);
1093 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 0)); 1095 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 0));
1094 } 1096 }
1095 1097
1096 } // namespace history 1098 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites_impl.cc ('k') | chrome/browser/history/url_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698