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

Side by Side 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 test failures 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 unified diff | Download patch
OLDNEW
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 "chrome/browser/manifest/manifest_icon_selector.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 CreateIcon("http://foo.com/icon.png", "", 1.0, std::vector<gfx::Size>())); 76 CreateIcon("http://foo.com/icon.png", "", 1.0, std::vector<gfx::Size>()));
77 77
78 GURL url = FindBestMatchingIcon(icons); 78 GURL url = FindBestMatchingIcon(icons);
79 EXPECT_TRUE(url.is_empty()); 79 EXPECT_TRUE(url.is_empty());
80 } 80 }
81 81
82 TEST_F(ManifestIconSelectorTest, MIMETypeFiltering) { 82 TEST_F(ManifestIconSelectorTest, MIMETypeFiltering) {
83 // Icons with type specified to a MIME type that isn't a valid image MIME type 83 // Icons with type specified to a MIME type that isn't a valid image MIME type
84 // are ignored. 84 // are ignored.
85 std::vector<gfx::Size> sizes; 85 std::vector<gfx::Size> sizes;
86 sizes.push_back(gfx::Size(10, 10)); 86 sizes.push_back(gfx::Size(48, 48));
87 87
88 std::vector<content::Manifest::Icon> icons; 88 std::vector<content::Manifest::Icon> icons;
89 icons.push_back( 89 icons.push_back(
90 CreateIcon("http://foo.com/icon.png", "image/foo_bar", 1.0, sizes)); 90 CreateIcon("http://foo.com/icon.png", "image/foo_bar", 1.0, sizes));
91 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/", 1.0, sizes)); 91 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/", 1.0, sizes));
92 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/", 1.0, sizes)); 92 icons.push_back(CreateIcon("http://foo.com/icon.png", "image/", 1.0, sizes));
93 icons.push_back( 93 icons.push_back(
94 CreateIcon("http://foo.com/icon.png", "video/mp4", 1.0, sizes)); 94 CreateIcon("http://foo.com/icon.png", "video/mp4", 1.0, sizes));
95 95
96 GURL url = FindBestMatchingIcon(icons); 96 GURL url = FindBestMatchingIcon(icons);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 url = FindBestMatchingIcon(icons); 185 url = FindBestMatchingIcon(icons);
186 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); 186 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec());
187 } 187 }
188 188
189 TEST_F(ManifestIconSelectorTest, DeviceDensityFirst) { 189 TEST_F(ManifestIconSelectorTest, DeviceDensityFirst) {
190 // If there is no perfect icon but an icon of the current device density is 190 // If there is no perfect icon but an icon of the current device density is
191 // present, it will be picked. 191 // present, it will be picked.
192 // This test has three icons each are marked with sizes set to the preferred 192 // This test has three icons each are marked with sizes set to the preferred
193 // icon size for the associated density. 193 // icon size for the associated density.
194 std::vector<gfx::Size> sizes; 194 std::vector<gfx::Size> sizes;
195 sizes.push_back(gfx::Size(2, 2)); 195 sizes.push_back(gfx::Size(97, 97));
mlamouri (slow - plz ping) 2015/08/19 15:02:54 Put a very high value so it's clear we don't filte
Lalit Maganti 2015/08/20 14:53:50 Done.
196 196
197 std::vector<content::Manifest::Icon> icons; 197 std::vector<content::Manifest::Icon> icons;
198 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes)); 198 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes));
199 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes)); 199 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes));
200 icons.push_back(CreateIcon("http://foo.com/icon_x3.png", "", 3.0, sizes)); 200 icons.push_back(CreateIcon("http://foo.com/icon_x3.png", "", 3.0, sizes));
201 201
202 SetDisplayDeviceScaleFactor(1.0f); 202 SetDisplayDeviceScaleFactor(1.0f);
203 GURL url = FindBestMatchingIcon(icons); 203 GURL url = FindBestMatchingIcon(icons);
204 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); 204 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec());
205 205
206 SetDisplayDeviceScaleFactor(2.0f); 206 SetDisplayDeviceScaleFactor(2.0f);
207 url = FindBestMatchingIcon(icons); 207 url = FindBestMatchingIcon(icons);
208 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec()); 208 EXPECT_EQ("http://foo.com/icon_x2.png", url.spec());
209 209
210 SetDisplayDeviceScaleFactor(3.0f); 210 SetDisplayDeviceScaleFactor(3.0f);
211 url = FindBestMatchingIcon(icons); 211 url = FindBestMatchingIcon(icons);
212 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec()); 212 EXPECT_EQ("http://foo.com/icon_x3.png", url.spec());
213 } 213 }
214 214
215 TEST_F(ManifestIconSelectorTest, DeviceDensityFallback) { 215 TEST_F(ManifestIconSelectorTest, DeviceDensityFallback) {
216 // If there is no perfect icon but and no icon of the current display density, 216 // If there is no perfect icon but and no icon of the current display density,
217 // an icon of density 1.0 will be used. 217 // an icon of density 1.0 will be used.
218 std::vector<gfx::Size> sizes; 218 std::vector<gfx::Size> sizes;
219 sizes.push_back(gfx::Size(2, 2)); 219 sizes.push_back(gfx::Size(97, 97));
mlamouri (slow - plz ping) 2015/08/19 15:02:54 ditto
Lalit Maganti 2015/08/20 14:53:49 Done.
220 220
221 std::vector<content::Manifest::Icon> icons; 221 std::vector<content::Manifest::Icon> icons;
222 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes)); 222 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes));
223 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes)); 223 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes));
224 224
225 SetDisplayDeviceScaleFactor(3.0f); 225 SetDisplayDeviceScaleFactor(3.0f);
226 GURL url = FindBestMatchingIcon(icons); 226 GURL url = FindBestMatchingIcon(icons);
227 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec()); 227 EXPECT_EQ("http://foo.com/icon_x1.png", url.spec());
228 } 228 }
229 229
230 TEST_F(ManifestIconSelectorTest, DeviceDensityFirstRejectsSmall) {
231 // We check that size is no smaller than one density bucket smaller if we have
232 // to resort to densities to find an icon.
233 std::vector<gfx::Size> sizes;
234 sizes.push_back(gfx::Size(47, 47));
235
236 std::vector<content::Manifest::Icon> icons;
237 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes));
238 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes));
239 icons.push_back(CreateIcon("http://foo.com/icon_x3.png", "", 3.0, sizes));
240
241 SetDisplayDeviceScaleFactor(1.0f);
mlamouri (slow - plz ping) 2015/08/19 15:02:54 nit: add comment explaining what happens.
gone 2015/08/19 22:31:56 Yeah, I can't even tell what the test is supposed
Lalit Maganti 2015/08/20 14:53:50 Made the comment much clearer.
242 GURL url = FindBestMatchingIcon(icons);
243 EXPECT_EQ("", url.spec());
244
245 SetDisplayDeviceScaleFactor(2.0f);
246 url = FindBestMatchingIcon(icons);
247 EXPECT_EQ("", url.spec());
248
249 SetDisplayDeviceScaleFactor(3.0f);
250 url = FindBestMatchingIcon(icons);
251 EXPECT_EQ("", url.spec());
252 }
253
254 TEST_F(ManifestIconSelectorTest, DeviceDensityFallbackRejectsSmall) {
mlamouri (slow - plz ping) 2015/08/19 15:02:54 I don't think that test is needed.
Lalit Maganti 2015/08/20 14:53:49 Done.
255 // We check that size is no smaller than one density bucket smaller if we have
256 // to resort to densities to find an icon.
257 std::vector<gfx::Size> sizes;
258 sizes.push_back(gfx::Size(47, 47));
259
260 std::vector<content::Manifest::Icon> icons;
261 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes));
262 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes));
263
264 SetDisplayDeviceScaleFactor(3.0f);
265 GURL url = FindBestMatchingIcon(icons);
266 EXPECT_EQ("", url.spec());
267 }
268
230 TEST_F(ManifestIconSelectorTest, DoNotUseOtherDensities) { 269 TEST_F(ManifestIconSelectorTest, DoNotUseOtherDensities) {
231 // If there are only icons of densities that are not the current display 270 // If there are only icons of densities that are not the current display
232 // density or the default density, they are ignored. 271 // density or the default density, they are ignored.
233 std::vector<gfx::Size> sizes; 272 std::vector<gfx::Size> sizes;
234 sizes.push_back(gfx::Size(2, 2)); 273 sizes.push_back(gfx::Size(2, 2));
235 274
236 std::vector<content::Manifest::Icon> icons; 275 std::vector<content::Manifest::Icon> icons;
237 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes)); 276 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes));
238 277
239 SetDisplayDeviceScaleFactor(3.0f); 278 SetDisplayDeviceScaleFactor(3.0f);
(...skipping 17 matching lines...) Expand all
257 // different icon sizes and checking which one is picked. 296 // different icon sizes and checking which one is picked.
258 // The Device Scale Factor is 1.0 and the preferred icon size is returned by 297 // The Device Scale Factor is 1.0 and the preferred icon size is returned by
259 // GetPreferredIconSizeInDp(). 298 // GetPreferredIconSizeInDp().
260 int very_small = GetPreferredIconSizeInDp() / 4; 299 int very_small = GetPreferredIconSizeInDp() / 4;
261 int small_size = GetPreferredIconSizeInDp() / 2; 300 int small_size = GetPreferredIconSizeInDp() / 2;
262 int bit_small = GetPreferredIconSizeInDp() - 1; 301 int bit_small = GetPreferredIconSizeInDp() - 1;
263 int bit_big = GetPreferredIconSizeInDp() + 1; 302 int bit_big = GetPreferredIconSizeInDp() + 1;
264 int big = GetPreferredIconSizeInDp() * 2; 303 int big = GetPreferredIconSizeInDp() * 2;
265 int very_big = GetPreferredIconSizeInDp() * 4; 304 int very_big = GetPreferredIconSizeInDp() * 4;
266 305
267 // (very_small, bit_small) => bit_small 306 // (very_small, bit_small) => empty (since both are too small)
268 { 307 {
269 std::vector<gfx::Size> sizes_1; 308 std::vector<gfx::Size> sizes_1;
270 sizes_1.push_back(gfx::Size(very_small, very_small)); 309 sizes_1.push_back(gfx::Size(very_small, very_small));
271 310
272 std::vector<gfx::Size> sizes_2; 311 std::vector<gfx::Size> sizes_2;
273 sizes_2.push_back(gfx::Size(bit_small, bit_small)); 312 sizes_2.push_back(gfx::Size(bit_small, bit_small));
274 313
275 std::vector<content::Manifest::Icon> icons; 314 std::vector<content::Manifest::Icon> icons;
276 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1)); 315 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1));
277 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2)); 316 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2));
278 317
279 GURL url = FindBestMatchingIcon(icons); 318 GURL url = FindBestMatchingIcon(icons);
280 EXPECT_EQ("http://foo.com/icon.png", url.spec()); 319 EXPECT_EQ("", url.spec());
281 } 320 }
282 321
283 // (very_small, bit_small, smaller) => bit_small 322 // (very_small, bit_small, smaller) => empty (since both are too small)
284 { 323 {
285 std::vector<gfx::Size> sizes_1; 324 std::vector<gfx::Size> sizes_1;
286 sizes_1.push_back(gfx::Size(very_small, very_small)); 325 sizes_1.push_back(gfx::Size(very_small, very_small));
287 326
288 std::vector<gfx::Size> sizes_2; 327 std::vector<gfx::Size> sizes_2;
289 sizes_2.push_back(gfx::Size(bit_small, bit_small)); 328 sizes_2.push_back(gfx::Size(bit_small, bit_small));
290 329
291 std::vector<gfx::Size> sizes_3; 330 std::vector<gfx::Size> sizes_3;
292 sizes_3.push_back(gfx::Size(small_size, small_size)); 331 sizes_3.push_back(gfx::Size(small_size, small_size));
293 332
294 std::vector<content::Manifest::Icon> icons; 333 std::vector<content::Manifest::Icon> icons;
295 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1)); 334 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1));
296 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2)); 335 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2));
297 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_3)); 336 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_3));
298 337
299 GURL url = FindBestMatchingIcon(icons); 338 GURL url = FindBestMatchingIcon(icons);
300 EXPECT_EQ("http://foo.com/icon.png", url.spec()); 339 EXPECT_EQ("", url.spec());
301 } 340 }
302 341
303 // (very_big, big) => big 342 // (very_big, big) => big
304 { 343 {
305 std::vector<gfx::Size> sizes_1; 344 std::vector<gfx::Size> sizes_1;
306 sizes_1.push_back(gfx::Size(very_big, very_big)); 345 sizes_1.push_back(gfx::Size(very_big, very_big));
307 346
308 std::vector<gfx::Size> sizes_2; 347 std::vector<gfx::Size> sizes_2;
309 sizes_2.push_back(gfx::Size(big, big)); 348 sizes_2.push_back(gfx::Size(big, big));
310 349
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 452
414 std::vector<content::Manifest::Icon> icons; 453 std::vector<content::Manifest::Icon> icons;
415 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes)); 454 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes));
416 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 3.0, sizes)); 455 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 3.0, sizes));
417 456
418 SetDisplayDeviceScaleFactor(3.0f); 457 SetDisplayDeviceScaleFactor(3.0f);
419 GURL url = FindBestMatchingIcon(icons); 458 GURL url = FindBestMatchingIcon(icons);
420 EXPECT_EQ("http://foo.com/icon.png", url.spec()); 459 EXPECT_EQ("http://foo.com/icon.png", url.spec());
421 } 460 }
422 } 461 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698