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

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: add a new method 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 1904 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 GetScaleFactors1x2x(), &bitmap_results); 1915 GetScaleFactors1x2x(), &bitmap_results);
1916 1916
1917 EXPECT_EQ(2u, bitmap_results.size()); 1917 EXPECT_EQ(2u, bitmap_results.size());
1918 const chrome::FaviconBitmapResult& first_result = bitmap_results[0]; 1918 const chrome::FaviconBitmapResult& first_result = bitmap_results[0];
1919 const chrome::FaviconBitmapResult& result = 1919 const chrome::FaviconBitmapResult& result =
1920 (first_result.pixel_size == kSmallSize) ? first_result 1920 (first_result.pixel_size == kSmallSize) ? first_result
1921 : bitmap_results[1]; 1921 : bitmap_results[1];
1922 EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data)); 1922 EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data));
1923 } 1923 }
1924 1924
1925 // Tests GetFaviconsForURL with icon_types priority,
1926 TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) {
1927 GURL page_url("http://www.google.com");
1928 GURL icon_url("http://www.google.com/favicon.ico");
1929 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
1930
1931 std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
1932 std::vector<gfx::Size> favicon_size;
1933 favicon_size.push_back(gfx::Size(16, 16));
1934 favicon_size.push_back(gfx::Size(32, 32));
1935 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
1936 ASSERT_EQ(2u, favicon_bitmap_data.size());
1937
1938 std::vector<chrome::FaviconBitmapData> touch_icon_bitmap_data;
1939 std::vector<gfx::Size> touch_icon_size;
1940 touch_icon_size.push_back(gfx::Size(64, 64));
1941 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data);
1942 ASSERT_EQ(1u, touch_icon_bitmap_data.size());
1943
1944 // Set some preexisting favicons for |page_url|.
1945 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
1946 backend_->SetFavicons(page_url, chrome::TOUCH_ICON, touch_icon_bitmap_data);
1947
1948 std::vector<chrome::FaviconBitmapResult> bitmap_results;
1949 std::vector<int> icon_types;
1950 icon_types.push_back(chrome::FAVICON);
1951 icon_types.push_back(chrome::TOUCH_ICON);
1952
1953 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &bitmap_results);
1954
1955 // Verify the result icon is 32x32 favicon.
1956 EXPECT_EQ(1u, bitmap_results.size());
1957 chrome::FaviconBitmapResult& result = bitmap_results[0];
1958 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
1959 EXPECT_EQ(chrome::FAVICON, result.icon_type);
1960
1961 // Change Minimal size to 32x32 and verify the 64x64 touch icon returned.
1962 bitmap_results.clear();
1963 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &bitmap_results);
1964 EXPECT_EQ(1u, bitmap_results.size());
1965 result = bitmap_results[0];
1966 EXPECT_EQ(gfx::Size(64, 64), result.pixel_size);
1967 EXPECT_EQ(chrome::TOUCH_ICON, result.icon_type);
1968 }
1969
1970 // Test the the first types of icon is returned if its size equal to the
1971 // second types icon.
1972 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) {
1973 GURL page_url("http://www.google.com");
1974 GURL icon_url("http://www.google.com/favicon.ico");
1975 GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
1976
1977 std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
1978 std::vector<gfx::Size> favicon_size;
1979 favicon_size.push_back(gfx::Size(16, 16));
1980 favicon_size.push_back(gfx::Size(32, 32));
1981 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
1982 ASSERT_EQ(2u, favicon_bitmap_data.size());
1983
1984 std::vector<chrome::FaviconBitmapData> touch_icon_bitmap_data;
1985 std::vector<gfx::Size> touch_icon_size;
1986 touch_icon_size.push_back(gfx::Size(32, 32));
1987 GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data);
1988 ASSERT_EQ(1u, touch_icon_bitmap_data.size());
1989
1990 // Set some preexisting favicons for |page_url|.
1991 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
1992 backend_->SetFavicons(page_url, chrome::TOUCH_ICON, touch_icon_bitmap_data);
1993
1994 std::vector<chrome::FaviconBitmapResult> bitmap_results;
1995 std::vector<int> icon_types;
1996 icon_types.push_back(chrome::FAVICON);
1997 icon_types.push_back(chrome::TOUCH_ICON);
1998
1999 backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &bitmap_results);
2000
2001 // Verify the result icon is 32x32 favicon.
2002 EXPECT_EQ(1u, bitmap_results.size());
2003 chrome::FaviconBitmapResult& result = bitmap_results[0];
2004 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
2005 EXPECT_EQ(chrome::FAVICON, result.icon_type);
2006
2007 // Change minimal size to 32x32 and verify the 32x32 favicon returned.
2008 bitmap_results.clear();
2009 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &bitmap_results);
2010 EXPECT_EQ(1u, bitmap_results.size());
2011 result = bitmap_results[0];
2012 EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
2013 EXPECT_EQ(chrome::FAVICON, result.icon_type);
2014 }
2015
2016 // Test the favicon is returned if its size is smaller than minimal size,
2017 // because it is only one available.
2018 TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) {
2019 GURL page_url("http://www.google.com");
2020 GURL icon_url("http://www.google.com/favicon.ico");
2021
2022 std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
2023 std::vector<gfx::Size> favicon_size;
2024 favicon_size.push_back(gfx::Size(16, 16));
2025 GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
2026 ASSERT_EQ(1u, favicon_bitmap_data.size());
2027
2028 // Set preexisting favicons for |page_url|.
2029 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
2030
2031 std::vector<chrome::FaviconBitmapResult> bitmap_results;
2032 std::vector<int> icon_types;
2033 icon_types.push_back(chrome::FAVICON);
2034 icon_types.push_back(chrome::TOUCH_ICON);
2035
2036 backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &bitmap_results);
2037
2038 // Verify 16x16 icon is returned, even it small than minimal_size.
2039 EXPECT_EQ(1u, bitmap_results.size());
2040 chrome::FaviconBitmapResult& result = bitmap_results[0];
2041 EXPECT_EQ(gfx::Size(16, 16), result.pixel_size);
2042 EXPECT_EQ(chrome::FAVICON, result.icon_type);
2043 }
2044
1925 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in. 2045 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in.
1926 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) { 2046 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
1927 GURL page_url1("http://www.google.com"); 2047 GURL page_url1("http://www.google.com");
1928 GURL page_url2("http://news.google.com"); 2048 GURL page_url2("http://news.google.com");
1929 GURL page_url3("http://mail.google.com"); 2049 GURL page_url3("http://mail.google.com");
1930 GURL icon_urla("http://www.google.com/favicon1.ico"); 2050 GURL icon_urla("http://www.google.com/favicon1.ico");
1931 GURL icon_urlb("http://www.google.com/favicon2.ico"); 2051 GURL icon_urlb("http://www.google.com/favicon2.ico");
1932 GURL icon_urlc("http://www.google.com/favicon3.ico"); 2052 GURL icon_urlc("http://www.google.com/favicon3.ico");
1933 2053
1934 // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON. 2054 // |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. 2889 // Delete all DTS index databases.
2770 backend_->DeleteFTSIndexDatabases(); 2890 backend_->DeleteFTSIndexDatabases();
2771 EXPECT_FALSE(base::PathExists(db1)); 2891 EXPECT_FALSE(base::PathExists(db1));
2772 EXPECT_FALSE(base::PathExists(db1_wal)); 2892 EXPECT_FALSE(base::PathExists(db1_wal));
2773 EXPECT_FALSE(base::PathExists(db1_journal)); 2893 EXPECT_FALSE(base::PathExists(db1_journal));
2774 EXPECT_FALSE(base::PathExists(db2_symlink)); 2894 EXPECT_FALSE(base::PathExists(db2_symlink));
2775 EXPECT_TRUE(base::PathExists(db2_actual)); // Symlinks shouldn't be followed. 2895 EXPECT_TRUE(base::PathExists(db2_actual)); // Symlinks shouldn't be followed.
2776 } 2896 }
2777 2897
2778 } // namespace history 2898 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698