Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/favicon/core/favicon_handler.h" | 5 #include "components/favicon/core/favicon_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 FaviconURL(GURL("http://www.google.com/b"), FAVICON, | 894 FaviconURL(GURL("http://www.google.com/b"), FAVICON, |
| 895 {gfx::Size(1024, 1024), gfx::Size(512, 512)}), | 895 {gfx::Size(1024, 1024), gfx::Size(512, 512)}), |
| 896 FaviconURL(GURL("http://www.google.com/c"), FAVICON, | 896 FaviconURL(GURL("http://www.google.com/c"), FAVICON, |
| 897 {gfx::Size(16, 16), gfx::Size(14, 14)}), | 897 {gfx::Size(16, 16), gfx::Size(14, 14)}), |
| 898 FaviconURL(GURL("http://www.google.com/d"), FAVICON, kEmptySizes), | 898 FaviconURL(GURL("http://www.google.com/d"), FAVICON, kEmptySizes), |
| 899 FaviconURL(GURL("http://www.google.com/e"), FAVICON, kEmptySizes)}; | 899 FaviconURL(GURL("http://www.google.com/e"), FAVICON, kEmptySizes)}; |
| 900 | 900 |
| 901 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 901 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
| 902 FaviconDriverObserver::NON_TOUCH_LARGEST, kSourceIconURLs); | 902 FaviconDriverObserver::NON_TOUCH_LARGEST, kSourceIconURLs); |
| 903 | 903 |
| 904 struct ExpectedResult { | 904 EXPECT_THAT( |
| 905 // The favicon's index in kSourceIconURLs. | 905 handler->GetIconURLs(), |
| 906 size_t favicon_index; | 906 ElementsAre( |
| 907 // Width of largest bitmap. | 907 // First is icon2, though its size larger than maximal. |
| 908 int width; | 908 GURL("http://www.google.com/b"), |
| 909 } results[] = { | 909 // Second is icon1. |
| 910 // First is icon2, though its size larger than maximal. | 910 GURL("http://www.google.com/a"), |
| 911 {1, 1024}, | 911 // Third is icon3. |
| 912 // Second is icon1 | 912 GURL("http://www.google.com/c"), |
| 913 // The 17x17 is largest. | 913 // The rest of bitmaps come in order, there is no "sizes" attribute. |
| 914 {0, 17}, | 914 GURL("http://www.google.com/d"), GURL("http://www.google.com/e"))); |
|
pkotwicz
2017/03/27 00:49:06
Can't you just swap FaviconHandler::image_urls() f
mastiz
2017/03/27 10:09:36
No, because we don't have size information. And I
pkotwicz
2017/03/27 19:12:44
Ok I see now.
Can you name each of the FaviconURL
mastiz
2017/03/28 09:09:30
This was done, but I had failed to export the chan
| |
| 915 // Third is icon3. | |
| 916 // The 16x16 is largest. | |
| 917 {2, 16}, | |
| 918 // The rest of bitmaps come in order, there is no "sizes" attribute. | |
| 919 {3, -1}, | |
| 920 {4, -1}, | |
| 921 }; | |
| 922 const std::vector<FaviconURL>& icons = handler->image_urls(); | |
| 923 ASSERT_EQ(5u, icons.size()); | |
| 924 for (size_t i = 0; i < icons.size(); ++i) { | |
| 925 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, | |
| 926 icons[i].icon_url); | |
| 927 if (results[i].width != -1) | |
| 928 EXPECT_EQ(results[i].width, icons[i].icon_sizes[0].width()); | |
| 929 } | |
| 930 } | 915 } |
| 931 | 916 |
| 932 TEST_F(FaviconHandlerTest, TestDownloadLargestFavicon) { | 917 TEST_F(FaviconHandlerTest, TestDownloadLargestFavicon) { |
| 933 // Names represent the bitmap sizes per icon. | 918 // Names represent the bitmap sizes per icon. |
| 934 const GURL kIconURL1024_512("http://www.google.com/a"); | 919 const GURL kIconURL1024_512("http://www.google.com/a"); |
| 935 const GURL kIconURL15_14("http://www.google.com/b"); | 920 const GURL kIconURL15_14("http://www.google.com/b"); |
| 936 const GURL kIconURL16_512("http://www.google.com/c"); | 921 const GURL kIconURL16_512("http://www.google.com/c"); |
| 937 const GURL kIconURLWithoutSize1("http://www.google.com/d"); | 922 const GURL kIconURLWithoutSize1("http://www.google.com/d"); |
| 938 const GURL kIconURLWithoutSize2("http://www.google.com/e"); | 923 const GURL kIconURLWithoutSize2("http://www.google.com/e"); |
| 939 | 924 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 972 | 957 |
| 973 RunHandlerWithCandidates( | 958 RunHandlerWithCandidates( |
| 974 FaviconDriverObserver::NON_TOUCH_LARGEST, | 959 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 975 {FaviconURL(kIconURL1, FAVICON, {gfx::Size(15, 15)}), | 960 {FaviconURL(kIconURL1, FAVICON, {gfx::Size(15, 15)}), |
| 976 FaviconURL(kIconURL2, FAVICON, {gfx::Size(14, 14), gfx::Size(16, 16)})}); | 961 FaviconURL(kIconURL2, FAVICON, {gfx::Size(14, 14), gfx::Size(16, 16)})}); |
| 977 | 962 |
| 978 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); | 963 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); |
| 979 } | 964 } |
| 980 | 965 |
| 981 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 966 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
| 982 const int kMaximalSize = FaviconHandler::GetMaximalIconSize(FAVICON); | 967 const int kMaximalSize = FaviconHandler::GetMaximalIconSize( |
| 968 FaviconDriverObserver::NON_TOUCH_LARGEST); | |
| 983 | 969 |
| 984 const GURL kIconURL1("http://www.google.com/b"); | 970 const GURL kIconURL1("http://www.google.com/b"); |
| 985 const GURL kIconURL2("http://www.google.com/c"); | 971 const GURL kIconURL2("http://www.google.com/c"); |
| 986 | 972 |
| 987 const int kOriginalSize1 = kMaximalSize + 1; | 973 const int kOriginalSize1 = kMaximalSize + 1; |
| 988 const int kOriginalSize2 = kMaximalSize + 2; | 974 const int kOriginalSize2 = kMaximalSize + 2; |
| 989 | 975 |
| 990 delegate_.fake_downloader().AddWithOriginalSizes( | 976 delegate_.fake_downloader().AddWithOriginalSizes( |
| 991 kIconURL1, IntVector{kMaximalSize}, IntVector{kOriginalSize1}); | 977 kIconURL1, IntVector{kMaximalSize}, IntVector{kOriginalSize1}); |
| 992 delegate_.fake_downloader().AddWithOriginalSizes( | 978 delegate_.fake_downloader().AddWithOriginalSizes( |
| 993 kIconURL2, IntVector{kMaximalSize}, IntVector{kOriginalSize2}); | 979 kIconURL2, IntVector{kMaximalSize}, IntVector{kOriginalSize2}); |
| 994 | 980 |
| 995 // Verify the largest bitmap was selected although it was scaled down to | 981 // Verify the best bitmap was selected (although smaller than |kIconURL2|) |
| 996 // maximal size and smaller than |kIconURL1| now. | 982 // and that it was scaled down to |kMaximalSize|. |
| 997 EXPECT_CALL(delegate_, | 983 EXPECT_CALL(delegate_, |
| 998 OnFaviconUpdated(_, _, kIconURL2, _, | 984 OnFaviconUpdated(_, _, kIconURL1, _, |
| 999 ImageSizeIs(kMaximalSize, kMaximalSize))); | 985 ImageSizeIs(kMaximalSize, kMaximalSize))); |
| 1000 | 986 |
| 1001 RunHandlerWithCandidates( | 987 RunHandlerWithCandidates( |
| 1002 FaviconDriverObserver::NON_TOUCH_LARGEST, | 988 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 1003 {FaviconURL(kIconURL1, FAVICON, | 989 {FaviconURL(kIconURL1, FAVICON, |
| 1004 SizeVector{gfx::Size(kOriginalSize1, kOriginalSize1)}), | 990 SizeVector{gfx::Size(kOriginalSize1, kOriginalSize1)}), |
| 1005 FaviconURL(kIconURL2, FAVICON, | 991 FaviconURL(kIconURL2, FAVICON, |
| 1006 SizeVector{gfx::Size(kOriginalSize2, kOriginalSize2)})}); | 992 SizeVector{gfx::Size(kOriginalSize2, kOriginalSize2)})}); |
| 1007 | 993 |
| 1008 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); | 994 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL1)); |
| 1009 } | 995 } |
| 1010 | 996 |
| 1011 // Test that if several icons are downloaded because the icons are smaller than | 997 // Test that if several icons are downloaded because the icons are smaller than |
| 1012 // expected that OnFaviconUpdated() is called with the largest downloaded | 998 // expected that OnFaviconUpdated() is called with the largest downloaded |
| 1013 // bitmap. | 999 // bitmap. |
| 1014 TEST_F(FaviconHandlerTest, TestKeepDownloadedLargestFavicon) { | 1000 TEST_F(FaviconHandlerTest, TestKeepDownloadedLargestFavicon) { |
| 1015 EXPECT_CALL(delegate_, | 1001 EXPECT_CALL(delegate_, |
| 1016 OnFaviconUpdated(_, _, kIconURL12x12, _, ImageSizeIs(12, 12))); | 1002 OnFaviconUpdated(_, _, kIconURL12x12, _, ImageSizeIs(12, 12))); |
| 1017 | 1003 |
| 1018 RunHandlerWithCandidates( | 1004 RunHandlerWithCandidates( |
| 1019 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1005 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 1020 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}), | 1006 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}), |
| 1021 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}), | 1007 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}), |
| 1022 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); | 1008 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); |
| 1023 } | 1009 } |
| 1024 | 1010 |
| 1025 } // namespace | 1011 } // namespace |
| 1026 } // namespace favicon | 1012 } // namespace favicon |
| OLD | NEW |