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

Side by Side Diff: components/history/core/browser/history_backend_unittest.cc

Issue 2796343003: Remove preferences among favicon types when choosing large icons
Patch Set: Rebased. 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 (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 "components/history/core/browser/history_backend.h" 5 #include "components/history/core/browser/history_backend.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 2787 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 std::vector<GURL>(1u, icon_url), 2798 std::vector<GURL>(1u, icon_url),
2799 favicon_base::FAVICON, 2799 favicon_base::FAVICON,
2800 GetEdgeSizesSmallAndLarge(), 2800 GetEdgeSizesSmallAndLarge(),
2801 &bitmap_results); 2801 &bitmap_results);
2802 } 2802 }
2803 2803
2804 EXPECT_EQ(0u, favicon_changed_notifications_page_urls().size()); 2804 EXPECT_EQ(0u, favicon_changed_notifications_page_urls().size());
2805 EXPECT_EQ(0u, favicon_changed_notifications_icon_urls().size()); 2805 EXPECT_EQ(0u, favicon_changed_notifications_icon_urls().size());
2806 } 2806 }
2807 2807
2808 // Tests GetFaviconsForURL with icon_types priority, 2808 // Test the favicon is returned if its size is smaller than minimal size,
2809 TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) { 2809 // because it is only one available.
2810 TEST_F(HistoryBackendTest, TestGetLargestFaviconsForURL) {
2810 GURL page_url("http://www.google.com"); 2811 GURL page_url("http://www.google.com");
2811 GURL icon_url("http://www.google.com/favicon.ico"); 2812 GURL icon_url("http://www.google.com/favicon.ico");
2812 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico"); 2813 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
2813 2814
2814 std::vector<SkBitmap> favicon_bitmaps; 2815 // Set preexisting favicons for |page_url|.
2815 favicon_bitmaps.push_back(CreateBitmap(SK_ColorBLUE, 16)); 2816 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url,
2816 favicon_bitmaps.push_back(CreateBitmap(SK_ColorRED, 32)); 2817 {CreateBitmap(SK_ColorBLUE, 16)});
2817 2818 backend_->SetFavicons(page_url, favicon_base::TOUCH_ICON, touch_icon_url,
2818 std::vector<SkBitmap> touch_bitmaps; 2819 {CreateBitmap(SK_ColorGREEN, 64)});
2819 touch_bitmaps.push_back(CreateBitmap(SK_ColorWHITE, 64));
2820
2821 // Set some preexisting favicons for |page_url|.
2822 backend_->SetFavicons(
2823 page_url, favicon_base::FAVICON, icon_url, favicon_bitmaps);
2824 backend_->SetFavicons(
2825 page_url, favicon_base::TOUCH_ICON, touch_icon_url, touch_bitmaps);
2826 2820
2827 favicon_base::FaviconRawBitmapResult result; 2821 favicon_base::FaviconRawBitmapResult result;
2828 std::vector<int> icon_types; 2822 backend_->GetLargestFaviconForURL(page_url, &result);
2829 icon_types.push_back(favicon_base::FAVICON);
2830 icon_types.push_back(favicon_base::TOUCH_ICON);
2831
2832 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result);
2833
2834 // Verify the result icon is 32x32 favicon.
2835 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
2836 EXPECT_EQ(favicon_base::FAVICON, result.icon_type);
2837
2838 // Change Minimal size to 32x32 and verify the 64x64 touch icon returned.
2839 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result);
2840 EXPECT_EQ(gfx::Size(64, 64), result.pixel_size); 2823 EXPECT_EQ(gfx::Size(64, 64), result.pixel_size);
2841 EXPECT_EQ(favicon_base::TOUCH_ICON, result.icon_type); 2824 EXPECT_EQ(favicon_base::TOUCH_ICON, result.icon_type);
2842 } 2825 }
2843 2826
2844 // Test the the first types of icon is returned if its size equal to the
2845 // second types icon.
2846 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) {
2847 GURL page_url("http://www.google.com");
2848 GURL icon_url("http://www.google.com/favicon.ico");
2849 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
2850
2851 std::vector<SkBitmap> favicon_bitmaps;
2852 favicon_bitmaps.push_back(CreateBitmap(SK_ColorBLUE, 16));
2853 favicon_bitmaps.push_back(CreateBitmap(SK_ColorRED, 32));
2854
2855 std::vector<SkBitmap> touch_bitmaps;
2856 touch_bitmaps.push_back(CreateBitmap(SK_ColorWHITE, 32));
2857
2858 // Set some preexisting favicons for |page_url|.
2859 backend_->SetFavicons(
2860 page_url, favicon_base::FAVICON, icon_url, favicon_bitmaps);
2861 backend_->SetFavicons(
2862 page_url, favicon_base::TOUCH_ICON, touch_icon_url, touch_bitmaps);
2863
2864 favicon_base::FaviconRawBitmapResult result;
2865 std::vector<int> icon_types;
2866 icon_types.push_back(favicon_base::FAVICON);
2867 icon_types.push_back(favicon_base::TOUCH_ICON);
2868
2869 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result);
2870
2871 // Verify the result icon is 32x32 favicon.
2872 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
2873 EXPECT_EQ(favicon_base::FAVICON, result.icon_type);
2874
2875 // Change minimal size to 32x32 and verify the 32x32 favicon returned.
2876 favicon_base::FaviconRawBitmapResult result1;
2877 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result1);
2878 EXPECT_EQ(gfx::Size(32, 32), result1.pixel_size);
2879 EXPECT_EQ(favicon_base::FAVICON, result1.icon_type);
2880 }
2881
2882 // Test the favicon is returned if its size is smaller than minimal size,
2883 // because it is only one available.
2884 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) {
2885 GURL page_url("http://www.google.com");
2886 GURL icon_url("http://www.google.com/favicon.ico");
2887
2888 std::vector<SkBitmap> bitmaps;
2889 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, 16));
2890
2891 // Set preexisting favicons for |page_url|.
2892 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url, bitmaps);
2893
2894 favicon_base::FaviconRawBitmapResult result;
2895 std::vector<int> icon_types;
2896 icon_types.push_back(favicon_base::FAVICON);
2897 icon_types.push_back(favicon_base::TOUCH_ICON);
2898
2899 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result);
2900
2901 // Verify 16x16 icon is returned, even it small than minimal_size.
2902 EXPECT_EQ(gfx::Size(16, 16), result.pixel_size);
2903 EXPECT_EQ(favicon_base::FAVICON, result.icon_type);
2904 }
2905
2906 // Test UpdateFaviconMappingsAndFetch() when multiple icon types are passed in. 2827 // Test UpdateFaviconMappingsAndFetch() when multiple icon types are passed in.
2907 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) { 2828 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
2908 GURL page_url1("http://www.google.com"); 2829 GURL page_url1("http://www.google.com");
2909 GURL page_url2("http://news.google.com"); 2830 GURL page_url2("http://news.google.com");
2910 GURL page_url3("http://mail.google.com"); 2831 GURL page_url3("http://mail.google.com");
2911 GURL icon_urla("http://www.google.com/favicon1.ico"); 2832 GURL icon_urla("http://www.google.com/favicon1.ico");
2912 GURL icon_urlb("http://www.google.com/favicon2.ico"); 2833 GURL icon_urlb("http://www.google.com/favicon2.ico");
2913 std::vector<SkBitmap> bitmaps; 2834 std::vector<SkBitmap> bitmaps;
2914 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); 2835 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize));
2915 2836
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after
3922 backend_->QueryMostVisitedURLs(100, 100, &most_visited); 3843 backend_->QueryMostVisitedURLs(100, 100, &most_visited);
3923 3844
3924 const base::string16 kSomeTitle; // Ignored by equality operator. 3845 const base::string16 kSomeTitle; // Ignored by equality operator.
3925 EXPECT_THAT( 3846 EXPECT_THAT(
3926 most_visited, 3847 most_visited,
3927 ElementsAre(MostVisitedURL(GURL("http://example1.com"), kSomeTitle), 3848 ElementsAre(MostVisitedURL(GURL("http://example1.com"), kSomeTitle),
3928 MostVisitedURL(GURL("http://example5.com"), kSomeTitle))); 3849 MostVisitedURL(GURL("http://example5.com"), kSomeTitle)));
3929 } 3850 }
3930 3851
3931 } // namespace history 3852 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend.cc ('k') | components/history/core/browser/history_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698