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

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

Issue 26563004: Find Favicon in priority of icon_type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 2 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 "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 std::vector<unsigned char> data; 1904 std::vector<unsigned char> data;
1905 data.push_back('c'); 1905 data.push_back('c');
1906 scoped_refptr<base::RefCountedBytes> bitmap_data( 1906 scoped_refptr<base::RefCountedBytes> bitmap_data(
1907 new base::RefCountedBytes(data)); 1907 new base::RefCountedBytes(data));
1908 backend_->MergeFavicon( 1908 backend_->MergeFavicon(
1909 page_url, merged_icon_url, chrome::FAVICON, bitmap_data, kSmallSize); 1909 page_url, merged_icon_url, chrome::FAVICON, bitmap_data, kSmallSize);
1910 1910
1911 // Request favicon bitmaps for both 1x and 2x to simulate request done by 1911 // Request favicon bitmaps for both 1x and 2x to simulate request done by
1912 // BookmarkModel::GetFavicon(). 1912 // BookmarkModel::GetFavicon().
1913 std::vector<chrome::FaviconBitmapResult> bitmap_results; 1913 std::vector<chrome::FaviconBitmapResult> bitmap_results;
1914 backend_->GetFaviconsForURL(page_url, chrome::FAVICON, kSmallSize.width(), 1914 std::vector<int> icon_types_priority;
1915 GetScaleFactors1x2x(), &bitmap_results); 1915 icon_types_priority.push_back(chrome::FAVICON);
1916 backend_->GetFaviconsForURL(page_url, icon_types_priority, kSmallSize.width(),
1917 GetScaleFactors1x2x(), 0, &bitmap_results);
1916 1918
1917 EXPECT_EQ(2u, bitmap_results.size()); 1919 EXPECT_EQ(2u, bitmap_results.size());
1918 const chrome::FaviconBitmapResult& first_result = bitmap_results[0]; 1920 const chrome::FaviconBitmapResult& first_result = bitmap_results[0];
1919 const chrome::FaviconBitmapResult& result = 1921 const chrome::FaviconBitmapResult& result =
1920 (first_result.pixel_size == kSmallSize) ? first_result 1922 (first_result.pixel_size == kSmallSize) ? first_result
1921 : bitmap_results[1]; 1923 : bitmap_results[1];
1922 EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data)); 1924 EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data));
1923 } 1925 }
1924 1926
1927 // Tests GetFaviconsForURL with icon_types priority,
1928 TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) {
1929 GURL page_url("http://www.google.com");
1930 GURL icon_url("http://www.google.com/favicon.ico");
1931 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
1932
1933 std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
1934 std::vector<gfx::Size> favicon_size;
1935 favicon_size.push_back(gfx::Size(16, 16));
1936 favicon_size.push_back(gfx::Size(32, 32));
1937 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
1938 ASSERT_EQ(2u, favicon_bitmap_data.size());
1939
1940 std::vector<chrome::FaviconBitmapData> touch_icon_bitmap_data;
1941 std::vector<gfx::Size> touch_icon_size;
1942 touch_icon_size.push_back(gfx::Size(64, 64));
1943 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data);
1944 ASSERT_EQ(1u, touch_icon_bitmap_data.size());
1945
1946 // Set some preexisting favicons for |page_url|.
1947 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
1948 backend_->SetFavicons(page_url, chrome::TOUCH_ICON, touch_icon_bitmap_data);
1949
1950 std::vector<chrome::FaviconBitmapResult> bitmap_results;
1951 std::vector<int> icon_types_priority;
1952 icon_types_priority.push_back(chrome::FAVICON);
1953 icon_types_priority.push_back(chrome::TOUCH_ICON);
1954
1955 backend_->GetFaviconsForURL(page_url, icon_types_priority, kSmallSize.width(),
1956 GetScaleFactors1x2x(), 16, &bitmap_results);
1957
1958 // Verify the result icon is 32x32 favicon.
1959 EXPECT_EQ(1u, bitmap_results.size());
1960 chrome::FaviconBitmapResult& result = bitmap_results[0];
1961 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
1962 EXPECT_EQ(chrome::FAVICON, result.icon_type);
1963
1964 // Change Minimal size to 32x32 and verify the 64x64 touch icon returned.
1965 bitmap_results.clear();
1966 backend_->GetFaviconsForURL(page_url, icon_types_priority, kSmallSize.width(),
1967 GetScaleFactors1x2x(), 32, &bitmap_results);
1968 EXPECT_EQ(1u, bitmap_results.size());
1969 result = bitmap_results[0];
1970 EXPECT_EQ(gfx::Size(64, 64), result.pixel_size);
1971 EXPECT_EQ(chrome::TOUCH_ICON, result.icon_type);
1972 }
1973
1974 // Test the the first types of icon is returned if its size equal to the
1975 // second types icon.
1976 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) {
1977 GURL page_url("http://www.google.com");
1978 GURL icon_url("http://www.google.com/favicon.ico");
1979 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
1980
1981 std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
1982 std::vector<gfx::Size> favicon_size;
1983 favicon_size.push_back(gfx::Size(16, 16));
1984 favicon_size.push_back(gfx::Size(32, 32));
1985 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
1986 ASSERT_EQ(2u, favicon_bitmap_data.size());
1987
1988 std::vector<chrome::FaviconBitmapData> touch_icon_bitmap_data;
1989 std::vector<gfx::Size> touch_icon_size;
1990 touch_icon_size.push_back(gfx::Size(32, 32));
1991 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data);
1992 ASSERT_EQ(1u, touch_icon_bitmap_data.size());
1993
1994 // Set some preexisting favicons for |page_url|.
1995 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
1996 backend_->SetFavicons(page_url, chrome::TOUCH_ICON, touch_icon_bitmap_data);
1997
1998 std::vector<chrome::FaviconBitmapResult> bitmap_results;
1999 std::vector<int> icon_types_priority;
2000 icon_types_priority.push_back(chrome::FAVICON);
2001 icon_types_priority.push_back(chrome::TOUCH_ICON);
2002
2003 backend_->GetFaviconsForURL(page_url, icon_types_priority, kSmallSize.width(),
2004 GetScaleFactors1x2x(), 16, &bitmap_results);
2005
2006 // Verify the result icon is 32x32 favicon.
2007 EXPECT_EQ(1u, bitmap_results.size());
2008 chrome::FaviconBitmapResult& result = bitmap_results[0];
2009 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
2010 EXPECT_EQ(chrome::FAVICON, result.icon_type);
2011
2012 // Change minimal size to 32x32 and verify the 32x32 favicon returned.
2013 bitmap_results.clear();
2014 backend_->GetFaviconsForURL(page_url, icon_types_priority, kSmallSize.width(),
2015 GetScaleFactors1x2x(), 32, &bitmap_results);
2016 EXPECT_EQ(1u, bitmap_results.size());
2017 result = bitmap_results[0];
2018 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
2019 EXPECT_EQ(chrome::FAVICON, result.icon_type);
2020 }
2021
2022 // Test the favicon is returned if its size is smaller than minimal size,
2023 // because it is only one available.
2024 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) {
2025 GURL page_url("http://www.google.com");
2026 GURL icon_url("http://www.google.com/favicon.ico");
2027
2028 std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
2029 std::vector<gfx::Size> favicon_size;
2030 favicon_size.push_back(gfx::Size(16, 16));
2031 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
2032 ASSERT_EQ(1u, favicon_bitmap_data.size());
2033
2034 // Set preexisting favicons for |page_url|.
2035 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
2036
2037 std::vector<chrome::FaviconBitmapResult> bitmap_results;
2038 std::vector<int> icon_types_priority;
2039 icon_types_priority.push_back(chrome::FAVICON);
2040 icon_types_priority.push_back(chrome::TOUCH_ICON);
2041
2042 backend_->GetFaviconsForURL(page_url, icon_types_priority, kSmallSize.width(),
2043 GetScaleFactors1x2x(), 32, &bitmap_results);
2044
2045 // Verify 16x16 icon is returned, even it small than minimal_size.
2046 EXPECT_EQ(1u, bitmap_results.size());
2047 chrome::FaviconBitmapResult& result = bitmap_results[0];
2048 EXPECT_EQ(gfx::Size(16, 16), result.pixel_size);
2049 EXPECT_EQ(chrome::FAVICON, result.icon_type);
2050 }
2051
1925 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in. 2052 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in.
1926 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) { 2053 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
1927 GURL page_url1("http://www.google.com"); 2054 GURL page_url1("http://www.google.com");
1928 GURL page_url2("http://news.google.com"); 2055 GURL page_url2("http://news.google.com");
1929 GURL page_url3("http://mail.google.com"); 2056 GURL page_url3("http://mail.google.com");
1930 GURL icon_urla("http://www.google.com/favicon1.ico"); 2057 GURL icon_urla("http://www.google.com/favicon1.ico");
1931 GURL icon_urlb("http://www.google.com/favicon2.ico"); 2058 GURL icon_urlb("http://www.google.com/favicon2.ico");
1932 GURL icon_urlc("http://www.google.com/favicon3.ico"); 2059 GURL icon_urlc("http://www.google.com/favicon3.ico");
1933 2060
1934 // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON. 2061 // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON.
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
2769 // Delete all DTS index databases. 2896 // Delete all DTS index databases.
2770 backend_->DeleteFTSIndexDatabases(); 2897 backend_->DeleteFTSIndexDatabases();
2771 EXPECT_FALSE(base::PathExists(db1)); 2898 EXPECT_FALSE(base::PathExists(db1));
2772 EXPECT_FALSE(base::PathExists(db1_wal)); 2899 EXPECT_FALSE(base::PathExists(db1_wal));
2773 EXPECT_FALSE(base::PathExists(db1_journal)); 2900 EXPECT_FALSE(base::PathExists(db1_journal));
2774 EXPECT_FALSE(base::PathExists(db2_symlink)); 2901 EXPECT_FALSE(base::PathExists(db2_symlink));
2775 EXPECT_TRUE(base::PathExists(db2_actual)); // Symlinks shouldn't be followed. 2902 EXPECT_TRUE(base::PathExists(db2_actual)); // Symlinks shouldn't be followed.
2776 } 2903 }
2777 2904
2778 } // namespace history 2905 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698