| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/manifest/manifest_icon_selector.h" | 5 #include "content/public/browser/manifest_icon_selector.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using IconPurpose = content::Manifest::Icon::IconPurpose; | 14 namespace content { |
| 15 |
| 16 using IconPurpose = Manifest::Icon::IconPurpose; |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 const int kIdealIconSize = 144; | 20 const int kIdealIconSize = 144; |
| 19 const int kMinimumIconSize = 0; | 21 const int kMinimumIconSize = 0; |
| 20 | 22 |
| 21 static content::Manifest::Icon CreateIcon(const std::string& url, | 23 static Manifest::Icon CreateIcon(const std::string& url, |
| 22 const std::string& type, | 24 const std::string& type, |
| 23 const std::vector<gfx::Size> sizes, | 25 const std::vector<gfx::Size> sizes, |
| 24 IconPurpose purpose) { | 26 IconPurpose purpose) { |
| 25 content::Manifest::Icon icon; | 27 Manifest::Icon icon; |
| 26 icon.src = GURL(url); | 28 icon.src = GURL(url); |
| 27 icon.type = base::UTF8ToUTF16(type); | 29 icon.type = base::UTF8ToUTF16(type); |
| 28 icon.sizes = sizes; | 30 icon.sizes = sizes; |
| 29 icon.purpose.push_back(purpose); | 31 icon.purpose.push_back(purpose); |
| 30 | 32 |
| 31 return icon; | 33 return icon; |
| 32 } | 34 } |
| 33 | 35 |
| 34 } // anonymous namespace | 36 } // anonymous namespace |
| 35 | 37 |
| 36 TEST(ManifestIconSelector, NoIcons) { | 38 TEST(ManifestIconSelector, NoIcons) { |
| 37 // No icons should return the empty URL. | 39 // No icons should return the empty URL. |
| 38 std::vector<content::Manifest::Icon> icons; | 40 std::vector<Manifest::Icon> icons; |
| 39 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 41 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 40 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 42 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 41 EXPECT_TRUE(url.is_empty()); | 43 EXPECT_TRUE(url.is_empty()); |
| 42 } | 44 } |
| 43 | 45 |
| 44 TEST(ManifestIconSelector, NoSizes) { | 46 TEST(ManifestIconSelector, NoSizes) { |
| 45 // Icon with no sizes are ignored. | 47 // Icon with no sizes are ignored. |
| 46 std::vector<content::Manifest::Icon> icons; | 48 std::vector<Manifest::Icon> icons; |
| 47 icons.push_back(CreateIcon("http://foo.com/icon.png", "", | 49 icons.push_back(CreateIcon("http://foo.com/icon.png", "", |
| 48 std::vector<gfx::Size>(), IconPurpose::ANY)); | 50 std::vector<gfx::Size>(), IconPurpose::ANY)); |
| 49 | 51 |
| 50 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 52 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 51 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 53 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 52 EXPECT_TRUE(url.is_empty()); | 54 EXPECT_TRUE(url.is_empty()); |
| 53 } | 55 } |
| 54 | 56 |
| 55 TEST(ManifestIconSelector, MIMETypeFiltering) { | 57 TEST(ManifestIconSelector, MIMETypeFiltering) { |
| 56 // Icons with type specified to a MIME type that isn't a valid image MIME type | 58 // Icons with type specified to a MIME type that isn't a valid image MIME type |
| 57 // are ignored. | 59 // are ignored. |
| 58 std::vector<gfx::Size> sizes; | 60 std::vector<gfx::Size> sizes; |
| 59 sizes.push_back(gfx::Size(1024, 1024)); | 61 sizes.push_back(gfx::Size(1024, 1024)); |
| 60 | 62 |
| 61 std::vector<content::Manifest::Icon> icons; | 63 std::vector<Manifest::Icon> icons; |
| 62 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/foo_bar", sizes, | 64 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/foo_bar", sizes, |
| 63 IconPurpose::ANY)); | 65 IconPurpose::ANY)); |
| 64 icons.push_back( | 66 icons.push_back( |
| 65 CreateIcon("http://foo.com/icon.png", "image/", sizes, IconPurpose::ANY)); | 67 CreateIcon("http://foo.com/icon.png", "image/", sizes, IconPurpose::ANY)); |
| 66 icons.push_back( | 68 icons.push_back( |
| 67 CreateIcon("http://foo.com/icon.png", "image/", sizes, IconPurpose::ANY)); | 69 CreateIcon("http://foo.com/icon.png", "image/", sizes, IconPurpose::ANY)); |
| 68 icons.push_back(CreateIcon("http://foo.com/icon.png", "video/mp4", sizes, | 70 icons.push_back(CreateIcon("http://foo.com/icon.png", "video/mp4", sizes, |
| 69 IconPurpose::ANY)); | 71 IconPurpose::ANY)); |
| 70 | 72 |
| 71 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 73 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 98 // Icons with purpose specified to non-matching purpose are ignored. | 100 // Icons with purpose specified to non-matching purpose are ignored. |
| 99 std::vector<gfx::Size> sizes_48; | 101 std::vector<gfx::Size> sizes_48; |
| 100 sizes_48.push_back(gfx::Size(48, 48)); | 102 sizes_48.push_back(gfx::Size(48, 48)); |
| 101 | 103 |
| 102 std::vector<gfx::Size> sizes_96; | 104 std::vector<gfx::Size> sizes_96; |
| 103 sizes_96.push_back(gfx::Size(96, 96)); | 105 sizes_96.push_back(gfx::Size(96, 96)); |
| 104 | 106 |
| 105 std::vector<gfx::Size> sizes_144; | 107 std::vector<gfx::Size> sizes_144; |
| 106 sizes_144.push_back(gfx::Size(144, 144)); | 108 sizes_144.push_back(gfx::Size(144, 144)); |
| 107 | 109 |
| 108 std::vector<content::Manifest::Icon> icons; | 110 std::vector<Manifest::Icon> icons; |
| 109 icons.push_back( | 111 icons.push_back(CreateIcon("http://foo.com/icon_48.png", "", sizes_48, |
| 110 CreateIcon("http://foo.com/icon_48.png", "", sizes_48, IconPurpose::BADGE)
); | 112 IconPurpose::BADGE)); |
| 111 icons.push_back( | 113 icons.push_back( |
| 112 CreateIcon("http://foo.com/icon_96.png", "", sizes_96, IconPurpose::ANY)); | 114 CreateIcon("http://foo.com/icon_96.png", "", sizes_96, IconPurpose::ANY)); |
| 113 icons.push_back(CreateIcon("http://foo.com/icon_144.png", "", sizes_144, | 115 icons.push_back(CreateIcon("http://foo.com/icon_144.png", "", sizes_144, |
| 114 IconPurpose::ANY)); | 116 IconPurpose::ANY)); |
| 115 | 117 |
| 116 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 118 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 117 icons, 48, kMinimumIconSize, IconPurpose::BADGE); | 119 icons, 48, kMinimumIconSize, IconPurpose::BADGE); |
| 118 EXPECT_EQ("http://foo.com/icon_48.png", url.spec()); | 120 EXPECT_EQ("http://foo.com/icon_48.png", url.spec()); |
| 119 | 121 |
| 120 url = ManifestIconSelector::FindBestMatchingIcon( | 122 url = ManifestIconSelector::FindBestMatchingIcon(icons, 48, kMinimumIconSize, |
| 121 icons, 48, kMinimumIconSize, IconPurpose::ANY); | 123 IconPurpose::ANY); |
| 122 EXPECT_EQ("http://foo.com/icon_96.png", url.spec()); | 124 EXPECT_EQ("http://foo.com/icon_96.png", url.spec()); |
| 123 | 125 |
| 124 url = ManifestIconSelector::FindBestMatchingIcon(icons, 96, kMinimumIconSize, | 126 url = ManifestIconSelector::FindBestMatchingIcon(icons, 96, kMinimumIconSize, |
| 125 IconPurpose::BADGE); | 127 IconPurpose::BADGE); |
| 126 EXPECT_EQ("http://foo.com/icon_48.png", url.spec()); | 128 EXPECT_EQ("http://foo.com/icon_48.png", url.spec()); |
| 127 | 129 |
| 128 url = ManifestIconSelector::FindBestMatchingIcon(icons, 96, 96, | 130 url = ManifestIconSelector::FindBestMatchingIcon(icons, 96, 96, |
| 129 IconPurpose::BADGE); | 131 IconPurpose::BADGE); |
| 130 EXPECT_TRUE(url.is_empty()); | 132 EXPECT_TRUE(url.is_empty()); |
| 131 | 133 |
| 132 url = ManifestIconSelector::FindBestMatchingIcon(icons, 144, kMinimumIconSize, | 134 url = ManifestIconSelector::FindBestMatchingIcon(icons, 144, kMinimumIconSize, |
| 133 IconPurpose::ANY); | 135 IconPurpose::ANY); |
| 134 EXPECT_EQ("http://foo.com/icon_144.png", url.spec()); | 136 EXPECT_EQ("http://foo.com/icon_144.png", url.spec()); |
| 135 } | 137 } |
| 136 | 138 |
| 137 TEST(ManifestIconSelector, IdealSizeIsUsedFirst) { | 139 TEST(ManifestIconSelector, IdealSizeIsUsedFirst) { |
| 138 // Each icon is marked with sizes that match the ideal icon size. | 140 // Each icon is marked with sizes that match the ideal icon size. |
| 139 std::vector<gfx::Size> sizes_48; | 141 std::vector<gfx::Size> sizes_48; |
| 140 sizes_48.push_back(gfx::Size(48, 48)); | 142 sizes_48.push_back(gfx::Size(48, 48)); |
| 141 | 143 |
| 142 std::vector<gfx::Size> sizes_96; | 144 std::vector<gfx::Size> sizes_96; |
| 143 sizes_96.push_back(gfx::Size(96, 96)); | 145 sizes_96.push_back(gfx::Size(96, 96)); |
| 144 | 146 |
| 145 std::vector<gfx::Size> sizes_144; | 147 std::vector<gfx::Size> sizes_144; |
| 146 sizes_144.push_back(gfx::Size(144, 144)); | 148 sizes_144.push_back(gfx::Size(144, 144)); |
| 147 | 149 |
| 148 std::vector<content::Manifest::Icon> icons; | 150 std::vector<Manifest::Icon> icons; |
| 149 icons.push_back( | 151 icons.push_back( |
| 150 CreateIcon("http://foo.com/icon_48.png", "", sizes_48, IconPurpose::ANY)); | 152 CreateIcon("http://foo.com/icon_48.png", "", sizes_48, IconPurpose::ANY)); |
| 151 icons.push_back( | 153 icons.push_back( |
| 152 CreateIcon("http://foo.com/icon_96.png", "", sizes_96, IconPurpose::ANY)); | 154 CreateIcon("http://foo.com/icon_96.png", "", sizes_96, IconPurpose::ANY)); |
| 153 icons.push_back(CreateIcon("http://foo.com/icon_144.png", "", sizes_144, | 155 icons.push_back(CreateIcon("http://foo.com/icon_144.png", "", sizes_144, |
| 154 IconPurpose::ANY)); | 156 IconPurpose::ANY)); |
| 155 | 157 |
| 156 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 158 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 157 icons, 48, kMinimumIconSize, IconPurpose::ANY); | 159 icons, 48, kMinimumIconSize, IconPurpose::ANY); |
| 158 EXPECT_EQ("http://foo.com/icon_48.png", url.spec()); | 160 EXPECT_EQ("http://foo.com/icon_48.png", url.spec()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 173 sizes_1.push_back(gfx::Size(kIdealIconSize, kIdealIconSize)); | 175 sizes_1.push_back(gfx::Size(kIdealIconSize, kIdealIconSize)); |
| 174 sizes_1.push_back(gfx::Size(kIdealIconSize * 2, kIdealIconSize * 2)); | 176 sizes_1.push_back(gfx::Size(kIdealIconSize * 2, kIdealIconSize * 2)); |
| 175 sizes_1.push_back(gfx::Size(kIdealIconSize * 3, kIdealIconSize * 3)); | 177 sizes_1.push_back(gfx::Size(kIdealIconSize * 3, kIdealIconSize * 3)); |
| 176 | 178 |
| 177 std::vector<gfx::Size> sizes_2; | 179 std::vector<gfx::Size> sizes_2; |
| 178 sizes_2.push_back(gfx::Size(1024, 1024)); | 180 sizes_2.push_back(gfx::Size(1024, 1024)); |
| 179 | 181 |
| 180 std::vector<gfx::Size> sizes_3; | 182 std::vector<gfx::Size> sizes_3; |
| 181 sizes_3.push_back(gfx::Size(1024, 1024)); | 183 sizes_3.push_back(gfx::Size(1024, 1024)); |
| 182 | 184 |
| 183 std::vector<content::Manifest::Icon> icons; | 185 std::vector<Manifest::Icon> icons; |
| 184 icons.push_back( | 186 icons.push_back( |
| 185 CreateIcon("http://foo.com/icon_x1.png", "", sizes_1, IconPurpose::ANY)); | 187 CreateIcon("http://foo.com/icon_x1.png", "", sizes_1, IconPurpose::ANY)); |
| 186 icons.push_back( | 188 icons.push_back( |
| 187 CreateIcon("http://foo.com/icon_x2.png", "", sizes_2, IconPurpose::ANY)); | 189 CreateIcon("http://foo.com/icon_x2.png", "", sizes_2, IconPurpose::ANY)); |
| 188 icons.push_back( | 190 icons.push_back( |
| 189 CreateIcon("http://foo.com/icon_x3.png", "", sizes_3, IconPurpose::ANY)); | 191 CreateIcon("http://foo.com/icon_x3.png", "", sizes_3, IconPurpose::ANY)); |
| 190 | 192 |
| 191 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 193 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 192 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 194 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 193 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 195 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 205 // If there is no perfect icon, the smallest larger icon will be chosen. | 207 // If there is no perfect icon, the smallest larger icon will be chosen. |
| 206 std::vector<gfx::Size> sizes_1; | 208 std::vector<gfx::Size> sizes_1; |
| 207 sizes_1.push_back(gfx::Size(90, 90)); | 209 sizes_1.push_back(gfx::Size(90, 90)); |
| 208 | 210 |
| 209 std::vector<gfx::Size> sizes_2; | 211 std::vector<gfx::Size> sizes_2; |
| 210 sizes_2.push_back(gfx::Size(128, 128)); | 212 sizes_2.push_back(gfx::Size(128, 128)); |
| 211 | 213 |
| 212 std::vector<gfx::Size> sizes_3; | 214 std::vector<gfx::Size> sizes_3; |
| 213 sizes_3.push_back(gfx::Size(192, 192)); | 215 sizes_3.push_back(gfx::Size(192, 192)); |
| 214 | 216 |
| 215 std::vector<content::Manifest::Icon> icons; | 217 std::vector<Manifest::Icon> icons; |
| 216 icons.push_back( | 218 icons.push_back( |
| 217 CreateIcon("http://foo.com/icon_x1.png", "", sizes_1, IconPurpose::ANY)); | 219 CreateIcon("http://foo.com/icon_x1.png", "", sizes_1, IconPurpose::ANY)); |
| 218 icons.push_back( | 220 icons.push_back( |
| 219 CreateIcon("http://foo.com/icon_x2.png", "", sizes_2, IconPurpose::ANY)); | 221 CreateIcon("http://foo.com/icon_x2.png", "", sizes_2, IconPurpose::ANY)); |
| 220 icons.push_back( | 222 icons.push_back( |
| 221 CreateIcon("http://foo.com/icon_x3.png", "", sizes_3, IconPurpose::ANY)); | 223 CreateIcon("http://foo.com/icon_x3.png", "", sizes_3, IconPurpose::ANY)); |
| 222 | 224 |
| 223 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 225 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 224 icons, 48, kMinimumIconSize, IconPurpose::ANY); | 226 icons, 48, kMinimumIconSize, IconPurpose::ANY); |
| 225 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 227 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
| 226 | 228 |
| 227 url = ManifestIconSelector::FindBestMatchingIcon(icons, 96, kMinimumIconSize, | 229 url = ManifestIconSelector::FindBestMatchingIcon(icons, 96, kMinimumIconSize, |
| 228 IconPurpose::ANY); | 230 IconPurpose::ANY); |
| 229 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); | 231 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); |
| 230 | 232 |
| 231 url = ManifestIconSelector::FindBestMatchingIcon(icons, 144, kMinimumIconSize, | 233 url = ManifestIconSelector::FindBestMatchingIcon(icons, 144, kMinimumIconSize, |
| 232 IconPurpose::ANY); | 234 IconPurpose::ANY); |
| 233 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); | 235 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); |
| 234 } | 236 } |
| 235 | 237 |
| 236 TEST(ManifestIconSelector, FallbackToLargestIconLargerThanMinimum) { | 238 TEST(ManifestIconSelector, FallbackToLargestIconLargerThanMinimum) { |
| 237 // When an icon of the correct size has not been found, we fall back to the | 239 // When an icon of the correct size has not been found, we fall back to the |
| 238 // closest non-matching sizes. Make sure that the minimum passed is enforced. | 240 // closest non-matching sizes. Make sure that the minimum passed is enforced. |
| 239 std::vector<gfx::Size> sizes_1_2; | 241 std::vector<gfx::Size> sizes_1_2; |
| 240 std::vector<gfx::Size> sizes_3; | 242 std::vector<gfx::Size> sizes_3; |
| 241 | 243 |
| 242 sizes_1_2.push_back(gfx::Size(47, 47)); | 244 sizes_1_2.push_back(gfx::Size(47, 47)); |
| 243 sizes_3.push_back(gfx::Size(95, 95)); | 245 sizes_3.push_back(gfx::Size(95, 95)); |
| 244 | 246 |
| 245 std::vector<content::Manifest::Icon> icons; | 247 std::vector<Manifest::Icon> icons; |
| 246 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", sizes_1_2, | 248 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", sizes_1_2, |
| 247 IconPurpose::ANY)); | 249 IconPurpose::ANY)); |
| 248 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", sizes_1_2, | 250 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", sizes_1_2, |
| 249 IconPurpose::ANY)); | 251 IconPurpose::ANY)); |
| 250 icons.push_back( | 252 icons.push_back( |
| 251 CreateIcon("http://foo.com/icon_x3.png", "", sizes_3, IconPurpose::ANY)); | 253 CreateIcon("http://foo.com/icon_x3.png", "", sizes_3, IconPurpose::ANY)); |
| 252 | 254 |
| 253 // Icon 3 should match. | 255 // Icon 3 should match. |
| 254 GURL url = ManifestIconSelector::FindBestMatchingIcon(icons, 1024, 48, | 256 GURL url = ManifestIconSelector::FindBestMatchingIcon(icons, 1024, 48, |
| 255 IconPurpose::ANY); | 257 IconPurpose::ANY); |
| 256 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); | 258 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); |
| 257 | 259 |
| 258 // Nothing matches here as the minimum is 96. | 260 // Nothing matches here as the minimum is 96. |
| 259 url = ManifestIconSelector::FindBestMatchingIcon(icons, 1024, 96, | 261 url = ManifestIconSelector::FindBestMatchingIcon(icons, 1024, 96, |
| 260 IconPurpose::ANY); | 262 IconPurpose::ANY); |
| 261 EXPECT_TRUE(url.is_empty()); | 263 EXPECT_TRUE(url.is_empty()); |
| 262 } | 264 } |
| 263 | 265 |
| 264 TEST(ManifestIconSelector, IdealVeryCloseToMinimumMatches) { | 266 TEST(ManifestIconSelector, IdealVeryCloseToMinimumMatches) { |
| 265 std::vector<gfx::Size> sizes; | 267 std::vector<gfx::Size> sizes; |
| 266 sizes.push_back(gfx::Size(2, 2)); | 268 sizes.push_back(gfx::Size(2, 2)); |
| 267 | 269 |
| 268 std::vector<content::Manifest::Icon> icons; | 270 std::vector<Manifest::Icon> icons; |
| 269 icons.push_back( | 271 icons.push_back( |
| 270 CreateIcon("http://foo.com/icon_x1.png", "", sizes, IconPurpose::ANY)); | 272 CreateIcon("http://foo.com/icon_x1.png", "", sizes, IconPurpose::ANY)); |
| 271 | 273 |
| 272 GURL url = | 274 GURL url = |
| 273 ManifestIconSelector::FindBestMatchingIcon(icons, 2, 1, IconPurpose::ANY); | 275 ManifestIconSelector::FindBestMatchingIcon(icons, 2, 1, IconPurpose::ANY); |
| 274 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 276 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
| 275 } | 277 } |
| 276 | 278 |
| 277 TEST(ManifestIconSelector, SizeVeryCloseToMinimumMatches) { | 279 TEST(ManifestIconSelector, SizeVeryCloseToMinimumMatches) { |
| 278 std::vector<gfx::Size> sizes; | 280 std::vector<gfx::Size> sizes; |
| 279 sizes.push_back(gfx::Size(2, 2)); | 281 sizes.push_back(gfx::Size(2, 2)); |
| 280 | 282 |
| 281 std::vector<content::Manifest::Icon> icons; | 283 std::vector<Manifest::Icon> icons; |
| 282 icons.push_back( | 284 icons.push_back( |
| 283 CreateIcon("http://foo.com/icon_x1.png", "", sizes, IconPurpose::ANY)); | 285 CreateIcon("http://foo.com/icon_x1.png", "", sizes, IconPurpose::ANY)); |
| 284 | 286 |
| 285 GURL url = ManifestIconSelector::FindBestMatchingIcon(icons, 200, 1, | 287 GURL url = ManifestIconSelector::FindBestMatchingIcon(icons, 200, 1, |
| 286 IconPurpose::ANY); | 288 IconPurpose::ANY); |
| 287 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); | 289 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); |
| 288 } | 290 } |
| 289 | 291 |
| 290 TEST(ManifestIconSelector, NotSquareIconsAreIgnored) { | 292 TEST(ManifestIconSelector, NotSquareIconsAreIgnored) { |
| 291 std::vector<gfx::Size> sizes; | 293 std::vector<gfx::Size> sizes; |
| 292 sizes.push_back(gfx::Size(1024, 1023)); | 294 sizes.push_back(gfx::Size(1024, 1023)); |
| 293 | 295 |
| 294 std::vector<content::Manifest::Icon> icons; | 296 std::vector<Manifest::Icon> icons; |
| 295 icons.push_back( | 297 icons.push_back( |
| 296 CreateIcon("http://foo.com/icon.png", "", sizes, IconPurpose::ANY)); | 298 CreateIcon("http://foo.com/icon.png", "", sizes, IconPurpose::ANY)); |
| 297 | 299 |
| 298 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 300 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 299 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 301 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 300 EXPECT_TRUE(url.is_empty()); | 302 EXPECT_TRUE(url.is_empty()); |
| 301 } | 303 } |
| 302 | 304 |
| 303 TEST(ManifestIconSelector, ClosestIconToIdeal) { | 305 TEST(ManifestIconSelector, ClosestIconToIdeal) { |
| 304 // Ensure ManifestIconSelector::FindBestMatchingIcon selects the closest icon | 306 // Ensure ManifestIconSelector::FindBestMatchingIcon selects the closest icon |
| 305 // to the ideal size when presented with a number of options. | 307 // to the ideal size when presented with a number of options. |
| 306 int very_small = kIdealIconSize / 4; | 308 int very_small = kIdealIconSize / 4; |
| 307 int small_size = kIdealIconSize / 2; | 309 int small_size = kIdealIconSize / 2; |
| 308 int bit_small = kIdealIconSize - 1; | 310 int bit_small = kIdealIconSize - 1; |
| 309 int bit_big = kIdealIconSize + 1; | 311 int bit_big = kIdealIconSize + 1; |
| 310 int big = kIdealIconSize * 2; | 312 int big = kIdealIconSize * 2; |
| 311 int very_big = kIdealIconSize * 4; | 313 int very_big = kIdealIconSize * 4; |
| 312 | 314 |
| 313 // (very_small, bit_small) => bit_small | 315 // (very_small, bit_small) => bit_small |
| 314 { | 316 { |
| 315 std::vector<gfx::Size> sizes_1; | 317 std::vector<gfx::Size> sizes_1; |
| 316 sizes_1.push_back(gfx::Size(very_small, very_small)); | 318 sizes_1.push_back(gfx::Size(very_small, very_small)); |
| 317 | 319 |
| 318 std::vector<gfx::Size> sizes_2; | 320 std::vector<gfx::Size> sizes_2; |
| 319 sizes_2.push_back(gfx::Size(bit_small, bit_small)); | 321 sizes_2.push_back(gfx::Size(bit_small, bit_small)); |
| 320 | 322 |
| 321 std::vector<content::Manifest::Icon> icons; | 323 std::vector<Manifest::Icon> icons; |
| 322 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, | 324 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, |
| 323 IconPurpose::ANY)); | 325 IconPurpose::ANY)); |
| 324 icons.push_back( | 326 icons.push_back( |
| 325 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); | 327 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); |
| 326 | 328 |
| 327 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 329 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 328 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 330 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 329 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 331 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 330 } | 332 } |
| 331 | 333 |
| 332 // (very_small, bit_small, small_size) => bit_small | 334 // (very_small, bit_small, small_size) => bit_small |
| 333 { | 335 { |
| 334 std::vector<gfx::Size> sizes_1; | 336 std::vector<gfx::Size> sizes_1; |
| 335 sizes_1.push_back(gfx::Size(very_small, very_small)); | 337 sizes_1.push_back(gfx::Size(very_small, very_small)); |
| 336 | 338 |
| 337 std::vector<gfx::Size> sizes_2; | 339 std::vector<gfx::Size> sizes_2; |
| 338 sizes_2.push_back(gfx::Size(bit_small, bit_small)); | 340 sizes_2.push_back(gfx::Size(bit_small, bit_small)); |
| 339 | 341 |
| 340 std::vector<gfx::Size> sizes_3; | 342 std::vector<gfx::Size> sizes_3; |
| 341 sizes_3.push_back(gfx::Size(small_size, small_size)); | 343 sizes_3.push_back(gfx::Size(small_size, small_size)); |
| 342 | 344 |
| 343 std::vector<content::Manifest::Icon> icons; | 345 std::vector<Manifest::Icon> icons; |
| 344 icons.push_back(CreateIcon("http://foo.com/icon_no_1.png", "", sizes_1, | 346 icons.push_back(CreateIcon("http://foo.com/icon_no_1.png", "", sizes_1, |
| 345 IconPurpose::ANY)); | 347 IconPurpose::ANY)); |
| 346 icons.push_back( | 348 icons.push_back( |
| 347 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); | 349 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); |
| 348 icons.push_back(CreateIcon("http://foo.com/icon_no_2.png", "", sizes_3, | 350 icons.push_back(CreateIcon("http://foo.com/icon_no_2.png", "", sizes_3, |
| 349 IconPurpose::ANY)); | 351 IconPurpose::ANY)); |
| 350 | 352 |
| 351 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 353 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 352 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 354 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 353 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 355 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 354 } | 356 } |
| 355 | 357 |
| 356 // (very_big, big) => big | 358 // (very_big, big) => big |
| 357 { | 359 { |
| 358 std::vector<gfx::Size> sizes_1; | 360 std::vector<gfx::Size> sizes_1; |
| 359 sizes_1.push_back(gfx::Size(very_big, very_big)); | 361 sizes_1.push_back(gfx::Size(very_big, very_big)); |
| 360 | 362 |
| 361 std::vector<gfx::Size> sizes_2; | 363 std::vector<gfx::Size> sizes_2; |
| 362 sizes_2.push_back(gfx::Size(big, big)); | 364 sizes_2.push_back(gfx::Size(big, big)); |
| 363 | 365 |
| 364 std::vector<content::Manifest::Icon> icons; | 366 std::vector<Manifest::Icon> icons; |
| 365 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, | 367 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, |
| 366 IconPurpose::ANY)); | 368 IconPurpose::ANY)); |
| 367 icons.push_back( | 369 icons.push_back( |
| 368 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); | 370 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); |
| 369 | 371 |
| 370 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 372 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 371 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 373 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 372 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 374 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 373 } | 375 } |
| 374 | 376 |
| 375 // (very_big, big, bit_big) => bit_big | 377 // (very_big, big, bit_big) => bit_big |
| 376 { | 378 { |
| 377 std::vector<gfx::Size> sizes_1; | 379 std::vector<gfx::Size> sizes_1; |
| 378 sizes_1.push_back(gfx::Size(very_big, very_big)); | 380 sizes_1.push_back(gfx::Size(very_big, very_big)); |
| 379 | 381 |
| 380 std::vector<gfx::Size> sizes_2; | 382 std::vector<gfx::Size> sizes_2; |
| 381 sizes_2.push_back(gfx::Size(big, big)); | 383 sizes_2.push_back(gfx::Size(big, big)); |
| 382 | 384 |
| 383 std::vector<gfx::Size> sizes_3; | 385 std::vector<gfx::Size> sizes_3; |
| 384 sizes_3.push_back(gfx::Size(bit_big, bit_big)); | 386 sizes_3.push_back(gfx::Size(bit_big, bit_big)); |
| 385 | 387 |
| 386 std::vector<content::Manifest::Icon> icons; | 388 std::vector<Manifest::Icon> icons; |
| 387 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, | 389 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, |
| 388 IconPurpose::ANY)); | 390 IconPurpose::ANY)); |
| 389 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_2, | 391 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_2, |
| 390 IconPurpose::ANY)); | 392 IconPurpose::ANY)); |
| 391 icons.push_back( | 393 icons.push_back( |
| 392 CreateIcon("http://foo.com/icon.png", "", sizes_3, IconPurpose::ANY)); | 394 CreateIcon("http://foo.com/icon.png", "", sizes_3, IconPurpose::ANY)); |
| 393 | 395 |
| 394 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 396 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 395 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 397 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 396 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 398 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 397 } | 399 } |
| 398 | 400 |
| 399 // (bit_small, very_big) => very_big | 401 // (bit_small, very_big) => very_big |
| 400 { | 402 { |
| 401 std::vector<gfx::Size> sizes_1; | 403 std::vector<gfx::Size> sizes_1; |
| 402 sizes_1.push_back(gfx::Size(bit_small, bit_small)); | 404 sizes_1.push_back(gfx::Size(bit_small, bit_small)); |
| 403 | 405 |
| 404 std::vector<gfx::Size> sizes_2; | 406 std::vector<gfx::Size> sizes_2; |
| 405 sizes_2.push_back(gfx::Size(very_big, very_big)); | 407 sizes_2.push_back(gfx::Size(very_big, very_big)); |
| 406 | 408 |
| 407 std::vector<content::Manifest::Icon> icons; | 409 std::vector<Manifest::Icon> icons; |
| 408 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, | 410 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, |
| 409 IconPurpose::ANY)); | 411 IconPurpose::ANY)); |
| 410 icons.push_back( | 412 icons.push_back( |
| 411 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); | 413 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); |
| 412 | 414 |
| 413 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 415 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 414 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 416 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 415 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 417 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 416 } | 418 } |
| 417 | 419 |
| 418 // (bit_small, bit_big) => bit_big | 420 // (bit_small, bit_big) => bit_big |
| 419 { | 421 { |
| 420 std::vector<gfx::Size> sizes_1; | 422 std::vector<gfx::Size> sizes_1; |
| 421 sizes_1.push_back(gfx::Size(bit_small, bit_small)); | 423 sizes_1.push_back(gfx::Size(bit_small, bit_small)); |
| 422 | 424 |
| 423 std::vector<gfx::Size> sizes_2; | 425 std::vector<gfx::Size> sizes_2; |
| 424 sizes_2.push_back(gfx::Size(bit_big, bit_big)); | 426 sizes_2.push_back(gfx::Size(bit_big, bit_big)); |
| 425 | 427 |
| 426 std::vector<content::Manifest::Icon> icons; | 428 std::vector<Manifest::Icon> icons; |
| 427 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, | 429 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, |
| 428 IconPurpose::ANY)); | 430 IconPurpose::ANY)); |
| 429 icons.push_back( | 431 icons.push_back( |
| 430 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); | 432 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); |
| 431 | 433 |
| 432 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 434 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 433 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 435 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 434 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 436 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 435 } | 437 } |
| 436 } | 438 } |
| 437 | 439 |
| 438 TEST(ManifestIconSelector, UseAnyIfNoIdealSize) { | 440 TEST(ManifestIconSelector, UseAnyIfNoIdealSize) { |
| 439 // 'any' (ie. gfx::Size(0,0)) should be used if there is no icon of a | 441 // 'any' (ie. gfx::Size(0,0)) should be used if there is no icon of a |
| 440 // ideal size. | 442 // ideal size. |
| 441 | 443 |
| 442 // Icon with 'any' and icon with ideal size => ideal size is chosen. | 444 // Icon with 'any' and icon with ideal size => ideal size is chosen. |
| 443 { | 445 { |
| 444 std::vector<gfx::Size> sizes_1; | 446 std::vector<gfx::Size> sizes_1; |
| 445 sizes_1.push_back(gfx::Size(kIdealIconSize, kIdealIconSize)); | 447 sizes_1.push_back(gfx::Size(kIdealIconSize, kIdealIconSize)); |
| 446 std::vector<gfx::Size> sizes_2; | 448 std::vector<gfx::Size> sizes_2; |
| 447 sizes_2.push_back(gfx::Size(0, 0)); | 449 sizes_2.push_back(gfx::Size(0, 0)); |
| 448 | 450 |
| 449 std::vector<content::Manifest::Icon> icons; | 451 std::vector<Manifest::Icon> icons; |
| 450 icons.push_back( | 452 icons.push_back( |
| 451 CreateIcon("http://foo.com/icon.png", "", sizes_1, IconPurpose::ANY)); | 453 CreateIcon("http://foo.com/icon.png", "", sizes_1, IconPurpose::ANY)); |
| 452 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_2, | 454 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_2, |
| 453 IconPurpose::ANY)); | 455 IconPurpose::ANY)); |
| 454 | 456 |
| 455 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 457 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 456 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 458 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 457 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 459 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 458 } | 460 } |
| 459 | 461 |
| 460 // Icon with 'any' and icon larger than ideal size => any is chosen. | 462 // Icon with 'any' and icon larger than ideal size => any is chosen. |
| 461 { | 463 { |
| 462 std::vector<gfx::Size> sizes_1; | 464 std::vector<gfx::Size> sizes_1; |
| 463 sizes_1.push_back(gfx::Size(kIdealIconSize + 1, kIdealIconSize + 1)); | 465 sizes_1.push_back(gfx::Size(kIdealIconSize + 1, kIdealIconSize + 1)); |
| 464 std::vector<gfx::Size> sizes_2; | 466 std::vector<gfx::Size> sizes_2; |
| 465 sizes_2.push_back(gfx::Size(0, 0)); | 467 sizes_2.push_back(gfx::Size(0, 0)); |
| 466 | 468 |
| 467 std::vector<content::Manifest::Icon> icons; | 469 std::vector<Manifest::Icon> icons; |
| 468 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, | 470 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", sizes_1, |
| 469 IconPurpose::ANY)); | 471 IconPurpose::ANY)); |
| 470 icons.push_back( | 472 icons.push_back( |
| 471 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); | 473 CreateIcon("http://foo.com/icon.png", "", sizes_2, IconPurpose::ANY)); |
| 472 | 474 |
| 473 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 475 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 474 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); | 476 icons, kIdealIconSize, kMinimumIconSize, IconPurpose::ANY); |
| 475 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 477 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 476 } | 478 } |
| 477 | 479 |
| 478 // Multiple icons with 'any' => the last one is chosen. | 480 // Multiple icons with 'any' => the last one is chosen. |
| 479 { | 481 { |
| 480 std::vector<gfx::Size> sizes; | 482 std::vector<gfx::Size> sizes; |
| 481 sizes.push_back(gfx::Size(0, 0)); | 483 sizes.push_back(gfx::Size(0, 0)); |
| 482 | 484 |
| 483 std::vector<content::Manifest::Icon> icons; | 485 std::vector<Manifest::Icon> icons; |
| 484 icons.push_back( | 486 icons.push_back( |
| 485 CreateIcon("http://foo.com/icon_no1.png", "", sizes, IconPurpose::ANY)); | 487 CreateIcon("http://foo.com/icon_no1.png", "", sizes, IconPurpose::ANY)); |
| 486 icons.push_back( | 488 icons.push_back( |
| 487 CreateIcon("http://foo.com/icon_no2.png", "", sizes, IconPurpose::ANY)); | 489 CreateIcon("http://foo.com/icon_no2.png", "", sizes, IconPurpose::ANY)); |
| 488 icons.push_back( | 490 icons.push_back( |
| 489 CreateIcon("http://foo.com/icon.png", "", sizes, IconPurpose::ANY)); | 491 CreateIcon("http://foo.com/icon.png", "", sizes, IconPurpose::ANY)); |
| 490 | 492 |
| 491 GURL url = ManifestIconSelector::FindBestMatchingIcon( | 493 GURL url = ManifestIconSelector::FindBestMatchingIcon( |
| 492 icons, kIdealIconSize * 3, kMinimumIconSize, IconPurpose::ANY); | 494 icons, kIdealIconSize * 3, kMinimumIconSize, IconPurpose::ANY); |
| 493 EXPECT_EQ("http://foo.com/icon.png", url.spec()); | 495 EXPECT_EQ("http://foo.com/icon.png", url.spec()); |
| 494 } | 496 } |
| 495 } | 497 } |
| 498 |
| 499 } // namespace content |
| OLD | NEW |