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

Unified Diff: chrome/browser/manifest/manifest_icon_selector_unittest.cc

Issue 1285063003: manifest: rework icon selector to include small icon cut-off (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix final comments Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/manifest/manifest_icon_selector.cc ('k') | chrome/test/data/banners/launcher-icon-4x.png » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/manifest/manifest_icon_selector_unittest.cc
diff --git a/chrome/browser/manifest/manifest_icon_selector_unittest.cc b/chrome/browser/manifest/manifest_icon_selector_unittest.cc
index cff4263a61b2b4c4bee34e54d036b466339bcdb2..36bd1d44812848de8d1b7ddefcca4a83eeb4d36b 100644
--- a/chrome/browser/manifest/manifest_icon_selector_unittest.cc
+++ b/chrome/browser/manifest/manifest_icon_selector_unittest.cc
@@ -83,7 +83,7 @@ TEST_F(ManifestIconSelectorTest, MIMETypeFiltering) {
// Icons with type specified to a MIME type that isn't a valid image MIME type
// are ignored.
std::vector<gfx::Size> sizes;
- sizes.push_back(gfx::Size(10, 10));
+ sizes.push_back(gfx::Size(1024, 1024));
std::vector<content::Manifest::Icon> icons;
icons.push_back(
@@ -151,7 +151,7 @@ TEST_F(ManifestIconSelectorTest, PreferredSizeOfCurrentDensityIsUsedFirst) {
TEST_F(ManifestIconSelectorTest, PreferredSizeOfDefaultDensityIsUsedSecond) {
// This test has three icons. The first one is of density zero and is marked
// with three sizes which are the preferred icon size for density 1, 2 and 3.
- // The icon for density 2 and 3 have a size set to 2x2 and 3x3.
+ // The icon for density 2 and 3 have a size set to 1024x1024.
// Regardless of the device scale factor, the icon of density 1 is going to be
// used because it matches the preferred size.
std::vector<gfx::Size> sizes_1;
@@ -163,10 +163,10 @@ TEST_F(ManifestIconSelectorTest, PreferredSizeOfDefaultDensityIsUsedSecond) {
GetPreferredIconSizeInDp() * 3));
std::vector<gfx::Size> sizes_2;
- sizes_2.push_back(gfx::Size(2, 2));
+ sizes_2.push_back(gfx::Size(1024, 1024));
std::vector<gfx::Size> sizes_3;
- sizes_3.push_back(gfx::Size(3, 3));
+ sizes_3.push_back(gfx::Size(1024, 1024));
std::vector<content::Manifest::Icon> icons;
icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes_1));
@@ -192,7 +192,7 @@ TEST_F(ManifestIconSelectorTest, DeviceDensityFirst) {
// This test has three icons each are marked with sizes set to the preferred
// icon size for the associated density.
std::vector<gfx::Size> sizes;
- sizes.push_back(gfx::Size(2, 2));
+ sizes.push_back(gfx::Size(1024, 1024));
std::vector<content::Manifest::Icon> icons;
icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes));
@@ -216,7 +216,7 @@ TEST_F(ManifestIconSelectorTest, DeviceDensityFallback) {
// If there is no perfect icon but and no icon of the current display density,
// an icon of density 1.0 will be used.
std::vector<gfx::Size> sizes;
- sizes.push_back(gfx::Size(2, 2));
+ sizes.push_back(gfx::Size(1024, 1024));
std::vector<content::Manifest::Icon> icons;
icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes));
@@ -227,11 +227,47 @@ TEST_F(ManifestIconSelectorTest, DeviceDensityFallback) {
EXPECT_EQ("http://foo.com/icon_x1.png", url.spec());
}
+TEST_F(ManifestIconSelectorTest, DeviceDensityMatchRejectsTooSmall) {
+ // If we have to resort to density matching to find icons, then an icon of
+ // the correct size has not been found. Make sure that an icon which is just
+ // slightly smaller than one density bucket below the device is not chosen
+ // even if the density matches.
+ std::vector<gfx::Size> sizes_1_2;
+ std::vector<gfx::Size> sizes_3;
+
+ sizes_1_2.push_back(gfx::Size(47, 47));
+ sizes_3.push_back(gfx::Size(95, 95));
+
+ std::vector<content::Manifest::Icon> icons;
+ icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes_1_2));
+ icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes_1_2));
+ icons.push_back(CreateIcon("http://foo.com/icon_x3.png", "", 3.0, sizes_3));
+
+ // Nothing matches here because there is a density scale factor lower bound of
+ // of 1.0 which since there is no density bucket smaller than the one
+ // associated with this scale factor.
+ SetDisplayDeviceScaleFactor(1.0f);
+ GURL url = FindBestMatchingIcon(icons);
+ EXPECT_TRUE(url.is_empty());
+
+ // Nothing matches here as the icon is just smaller than the icon size
+ // one density bucket below (i.e. 96 is expected and 48 is the minimum).
+ SetDisplayDeviceScaleFactor(2.0f);
+ url = FindBestMatchingIcon(icons);
+ EXPECT_TRUE(url.is_empty());
+
+ // Nothing matches here as the icon is just smaller than the icon size
+ // one density bucket below (i.e. 144 is expected and 96 is the minimum).
+ SetDisplayDeviceScaleFactor(3.0f);
+ url = FindBestMatchingIcon(icons);
+ EXPECT_TRUE(url.is_empty());
+}
+
TEST_F(ManifestIconSelectorTest, DoNotUseOtherDensities) {
// If there are only icons of densities that are not the current display
// density or the default density, they are ignored.
std::vector<gfx::Size> sizes;
- sizes.push_back(gfx::Size(2, 2));
+ sizes.push_back(gfx::Size(1024, 1024));
std::vector<content::Manifest::Icon> icons;
icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes));
@@ -243,7 +279,7 @@ TEST_F(ManifestIconSelectorTest, DoNotUseOtherDensities) {
TEST_F(ManifestIconSelectorTest, NotSquareIconsAreIgnored) {
std::vector<gfx::Size> sizes;
- sizes.push_back(gfx::Size(20, 2));
+ sizes.push_back(gfx::Size(1024, 1023));
std::vector<content::Manifest::Icon> icons;
icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes));
@@ -264,7 +300,7 @@ TEST_F(ManifestIconSelectorTest, ClosestIconToPreferred) {
int big = GetPreferredIconSizeInDp() * 2;
int very_big = GetPreferredIconSizeInDp() * 4;
- // (very_small, bit_small) => bit_small
+ // (very_small, bit_small) => empty (since both are too small)
{
std::vector<gfx::Size> sizes_1;
sizes_1.push_back(gfx::Size(very_small, very_small));
@@ -277,10 +313,10 @@ TEST_F(ManifestIconSelectorTest, ClosestIconToPreferred) {
icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2));
GURL url = FindBestMatchingIcon(icons);
- EXPECT_EQ("http://foo.com/icon.png", url.spec());
+ EXPECT_EQ("", url.spec());
}
- // (very_small, bit_small, smaller) => bit_small
+ // (very_small, bit_small, smaller) => empty (since both are too small)
{
std::vector<gfx::Size> sizes_1;
sizes_1.push_back(gfx::Size(very_small, very_small));
@@ -297,7 +333,7 @@ TEST_F(ManifestIconSelectorTest, ClosestIconToPreferred) {
icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_3));
GURL url = FindBestMatchingIcon(icons);
- EXPECT_EQ("http://foo.com/icon.png", url.spec());
+ EXPECT_EQ("", url.spec());
}
// (very_big, big) => big
« no previous file with comments | « chrome/browser/manifest/manifest_icon_selector.cc ('k') | chrome/test/data/banners/launcher-icon-4x.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698