// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/favicon/core/favicon_backend.h" #include <memory> #include <vector> #include "base/containers/lru_cache.h" #include "base/files/scoped_temp_dir.h" #include "base/test/task_environment.h" #include "components/favicon/core/favicon_backend_delegate.h" #include "components/favicon/core/favicon_database.h" #include "components/favicon/core/favicon_types.h" #include "components/favicon_base/favicon_types.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/image/image_unittest_util.h" #include "url/gurl.h" namespace favicon { namespace { FaviconBitmap; FaviconBitmapType; IconMapping; IconType; IconTypeSet; ElementsAre; UnorderedElementsAre; RedirectCache; const int kTinyEdgeSize = …; const int kSmallEdgeSize = …; const int kLargeEdgeSize = …; const gfx::Size kTinySize = …; const gfx::Size kSmallSize = …; const gfx::Size kLargeSize = …; } // namespace class FaviconBackendTest : public testing::Test, public FaviconBackendDelegate { … }; // Test that SetFaviconMappingsForPageAndRedirects correctly updates icon // mappings based on redirects, icon URLs and icon types. TEST_F(FaviconBackendTest, SetFaviconMappingsForPageAndRedirects) { … } TEST_F(FaviconBackendTest, SetFaviconMappingsForPageAndRedirectsWithFragmentWithoutStripping) { … } // Test that there is no churn in icon mappings from calling // SetFavicons() twice with the same `bitmaps` parameter. TEST_F(FaviconBackendTest, SetFaviconMappingsForPageDuplicates) { … } // Test that calling SetFavicons() with FaviconBitmapData of different pixel // sizes than the initially passed in FaviconBitmapData deletes the no longer // used favicon bitmaps. TEST_F(FaviconBackendTest, SetFaviconsDeleteBitmaps) { … } // Test updating a single favicon bitmap's data via SetFavicons. TEST_F(FaviconBackendTest, SetFaviconsReplaceBitmapData) { … } // Test that if two pages share the same FaviconID, changing the favicon for // one page does not affect the other. TEST_F(FaviconBackendTest, SetFaviconsSameFaviconURLForTwoPages) { … } // Test that if two pages share the same favicon, reported via a single call to // SetFavicons(), it gets associated to both page URLs. TEST_F(FaviconBackendTest, SetFaviconsWithTwoPageURLs) { … } // Test that favicon mappings can be deleted using DeleteFaviconMappings(). TEST_F(FaviconBackendTest, DeleteFaviconMappings) { … } // Tests calling SetOnDemandFavicons(). Neither `page_url` nor `icon_url` are // known to the database. TEST_F(FaviconBackendTest, SetOnDemandFaviconsForEmptyDB) { … } // Tests calling SetOnDemandFavicons(). `page_url` is known to the database // but `icon_url` is not (the second should be irrelevant though). TEST_F(FaviconBackendTest, SetOnDemandFaviconsForPageInDB) { … } // Tests calling SetOnDemandFavicons(). `page_url` is not known to the // database but `icon_url` is. TEST_F(FaviconBackendTest, SetOnDemandFaviconsForIconInDB) { … } // Test repeatedly calling MergeFavicon(). `page_url` is initially not known // to the database. TEST_F(FaviconBackendTest, MergeFaviconPageURLNotInDB) { … } // Test calling MergeFavicon() when `page_url` is known to the database. TEST_F(FaviconBackendTest, MergeFaviconPageURLInDB) { … } // Test calling MergeFavicon() when `icon_url` is known to the database but not // mapped to `page_url`. TEST_F(FaviconBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) { … } // Test that MergeFavicon() does not add more than // `kMaxFaviconBitmapsPerIconURL` to a favicon. TEST_F(FaviconBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) { … } // Tests that the favicon set by MergeFavicon() shows up in the result of // GetFaviconsForURL(). TEST_F(FaviconBackendTest, MergeFaviconShowsUpInGetFaviconsForURLResult) { … } // Tests that calling MergeFavicon() with identical favicon data does not affect // the favicon bitmap's "last updated" time. This is important because sync // calls MergeFavicon() for all of the favicons that it manages at startup. TEST_F(FaviconBackendTest, MergeIdenticalFaviconDoesNotChangeLastUpdatedTime) { … } // Tests GetFaviconsForURL with icon_types priority, TEST_F(FaviconBackendTest, TestGetFaviconsForURLWithIconTypesPriority) { … } // Test the the first types of icon is returned if its size equal to the // second types icon. TEST_F(FaviconBackendTest, TestGetFaviconsForURLReturnFavicon) { … } // Test the favicon is returned if its size is smaller than minimal size, // because it is only one available. TEST_F(FaviconBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) { … } // Test the results of GetFaviconsForUrl() when there are no found favicons. TEST_F(FaviconBackendTest, GetFaviconsForUrlEmpty) { … } // Test the results of GetFaviconsForUrl() when there are matching favicons // but there are no associated favicon bitmaps. TEST_F(FaviconBackendTest, GetFaviconsForUrlNoFaviconBitmaps) { … } // Test that GetFaviconsForUrl() returns results for the bitmaps which most // closely match the passed in the desired pixel sizes. TEST_F(FaviconBackendTest, GetFaviconsForUrlSelectClosestMatch) { … } // Test the results of GetFaviconsForUrl() when called with different // `icon_types`. TEST_F(FaviconBackendTest, GetFaviconsForUrlIconType) { … } // Test that GetFaviconsForUrl() behaves correctly for different values of // `fallback_to_host`. TEST_F(FaviconBackendTest, GetFaviconsForUrlFallbackToHost) { … } // Test that when GetFaviconsForUrl() is called with multiple icon types that // the best favicon bitmap is selected from among all of the icon types. TEST_F(FaviconBackendTest, GetFaviconsForUrlMultipleIconTypes) { … } // Test that GetFaviconsForUrl() correctly sets the expired flag for bitmap // reults. TEST_F(FaviconBackendTest, GetFaviconsForUrlExpired) { … } // Test that a favicon isn't loaded cross-origin. TEST_F(FaviconBackendTest, FaviconCacheWillNotLoadCrossOrigin) { … } } // namespace favicon