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

Side by Side Diff: chrome/browser/manifest/manifest_icon_selector_unittest.cc

Issue 1308533006: webapps: allow callers of icon downloader/selector to specify a minimum size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webapps-splashscreen-icon
Patch Set: Fix non-compiling test Created 5 years, 3 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 10 matching lines...) Expand all
21 21
22 class ManifestIconSelectorTest : public testing::Test { 22 class ManifestIconSelectorTest : public testing::Test {
23 protected: 23 protected:
24 ManifestIconSelectorTest() { 24 ManifestIconSelectorTest() {
25 test_screen_.display()->set_id(0x1337); 25 test_screen_.display()->set_id(0x1337);
26 test_screen_.display()->set_bounds(gfx::Rect(0, 0, 2560, 1440)); 26 test_screen_.display()->set_bounds(gfx::Rect(0, 0, 2560, 1440));
27 } 27 }
28 28
29 ~ManifestIconSelectorTest() override {} 29 ~ManifestIconSelectorTest() override {}
30 30
31 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons,
32 int minimum_icon_size_in_dp) {
33 return ManifestIconSelector::FindBestMatchingIcon(
34 icons, GetPreferredIconSizeInDp(),
35 minimum_icon_size_in_dp, &test_screen_);
36 }
37
31 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) { 38 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons) {
32 return ManifestIconSelector::FindBestMatchingIcon( 39 return FindBestMatchingIcon(icons, 0);
33 icons, GetPreferredIconSizeInDp(), &test_screen_);
34 } 40 }
35 41
36 void SetDisplayDeviceScaleFactor(float device_scale_factor) { 42 void SetDisplayDeviceScaleFactor(float device_scale_factor) {
37 test_screen_.display()->set_device_scale_factor(device_scale_factor); 43 test_screen_.display()->set_device_scale_factor(device_scale_factor);
38 } 44 }
39 45
40 static int GetPreferredIconSizeInDp() { 46 static int GetPreferredIconSizeInDp() {
41 return kPreferredIconSize; 47 return kPreferredIconSize;
42 } 48 }
43 49
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 std::vector<gfx::Size> sizes_3; 242 std::vector<gfx::Size> sizes_3;
237 243
238 sizes_1_2.push_back(gfx::Size(47, 47)); 244 sizes_1_2.push_back(gfx::Size(47, 47));
239 sizes_3.push_back(gfx::Size(95, 95)); 245 sizes_3.push_back(gfx::Size(95, 95));
240 246
241 std::vector<content::Manifest::Icon> icons; 247 std::vector<content::Manifest::Icon> icons;
242 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes_1_2)); 248 icons.push_back(CreateIcon("http://foo.com/icon_x1.png", "", 1.0, sizes_1_2));
243 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes_1_2)); 249 icons.push_back(CreateIcon("http://foo.com/icon_x2.png", "", 2.0, sizes_1_2));
244 icons.push_back(CreateIcon("http://foo.com/icon_x3.png", "", 3.0, sizes_3)); 250 icons.push_back(CreateIcon("http://foo.com/icon_x3.png", "", 3.0, sizes_3));
245 251
246 // Nothing matches here because there is a density scale factor lower bound of 252 // Nothing matches here because the minimum is 48.
247 // of 1.0 which since there is no density bucket smaller than the one
248 // associated with this scale factor.
249 SetDisplayDeviceScaleFactor(1.0f); 253 SetDisplayDeviceScaleFactor(1.0f);
250 GURL url = FindBestMatchingIcon(icons); 254 GURL url = FindBestMatchingIcon(icons, 48);
251 EXPECT_TRUE(url.is_empty()); 255 EXPECT_TRUE(url.is_empty());
252 256
253 // Nothing matches here as the icon is just smaller than the icon size 257 // Nothing matches here because the minimum is 48 again.
254 // one density bucket below (i.e. 96 is expected and 48 is the minimum).
255 SetDisplayDeviceScaleFactor(2.0f); 258 SetDisplayDeviceScaleFactor(2.0f);
256 url = FindBestMatchingIcon(icons); 259 url = FindBestMatchingIcon(icons, 48);
257 EXPECT_TRUE(url.is_empty()); 260 EXPECT_TRUE(url.is_empty());
258 261
259 // Nothing matches here as the icon is just smaller than the icon size 262 // Nothing matches here as the minimum is 96.
260 // one density bucket below (i.e. 144 is expected and 96 is the minimum).
261 SetDisplayDeviceScaleFactor(3.0f); 263 SetDisplayDeviceScaleFactor(3.0f);
262 url = FindBestMatchingIcon(icons); 264 url = FindBestMatchingIcon(icons, 96);
263 EXPECT_TRUE(url.is_empty()); 265 EXPECT_TRUE(url.is_empty());
264 } 266 }
265 267
266 TEST_F(ManifestIconSelectorTest, DoNotUseOtherDensities) { 268 TEST_F(ManifestIconSelectorTest, DoNotUseOtherDensities) {
267 // If there are only icons of densities that are not the current display 269 // If there are only icons of densities that are not the current display
268 // density or the default density, they are ignored. 270 // density or the default density, they are ignored.
269 std::vector<gfx::Size> sizes; 271 std::vector<gfx::Size> sizes;
270 sizes.push_back(gfx::Size(1024, 1024)); 272 sizes.push_back(gfx::Size(1024, 1024));
271 273
272 std::vector<content::Manifest::Icon> icons; 274 std::vector<content::Manifest::Icon> icons;
(...skipping 20 matching lines...) Expand all
293 // different icon sizes and checking which one is picked. 295 // different icon sizes and checking which one is picked.
294 // The Device Scale Factor is 1.0 and the preferred icon size is returned by 296 // The Device Scale Factor is 1.0 and the preferred icon size is returned by
295 // GetPreferredIconSizeInDp(). 297 // GetPreferredIconSizeInDp().
296 int very_small = GetPreferredIconSizeInDp() / 4; 298 int very_small = GetPreferredIconSizeInDp() / 4;
297 int small_size = GetPreferredIconSizeInDp() / 2; 299 int small_size = GetPreferredIconSizeInDp() / 2;
298 int bit_small = GetPreferredIconSizeInDp() - 1; 300 int bit_small = GetPreferredIconSizeInDp() - 1;
299 int bit_big = GetPreferredIconSizeInDp() + 1; 301 int bit_big = GetPreferredIconSizeInDp() + 1;
300 int big = GetPreferredIconSizeInDp() * 2; 302 int big = GetPreferredIconSizeInDp() * 2;
301 int very_big = GetPreferredIconSizeInDp() * 4; 303 int very_big = GetPreferredIconSizeInDp() * 4;
302 304
303 // (very_small, bit_small) => empty (since both are too small) 305 // (very_small, bit_small) => bit_small
304 { 306 {
305 std::vector<gfx::Size> sizes_1; 307 std::vector<gfx::Size> sizes_1;
306 sizes_1.push_back(gfx::Size(very_small, very_small)); 308 sizes_1.push_back(gfx::Size(very_small, very_small));
307 309
308 std::vector<gfx::Size> sizes_2; 310 std::vector<gfx::Size> sizes_2;
309 sizes_2.push_back(gfx::Size(bit_small, bit_small)); 311 sizes_2.push_back(gfx::Size(bit_small, bit_small));
310 312
311 std::vector<content::Manifest::Icon> icons; 313 std::vector<content::Manifest::Icon> icons;
312 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1)); 314 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1));
313 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2)); 315 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2));
314 316
315 GURL url = FindBestMatchingIcon(icons); 317 GURL url = FindBestMatchingIcon(icons);
316 EXPECT_EQ("", url.spec()); 318 EXPECT_EQ("http://foo.com/icon.png", url.spec());
317 } 319 }
318 320
319 // (very_small, bit_small, smaller) => empty (since both are too small) 321 // (very_small, bit_small, smaller) => bit_small
320 { 322 {
321 std::vector<gfx::Size> sizes_1; 323 std::vector<gfx::Size> sizes_1;
322 sizes_1.push_back(gfx::Size(very_small, very_small)); 324 sizes_1.push_back(gfx::Size(very_small, very_small));
323 325
324 std::vector<gfx::Size> sizes_2; 326 std::vector<gfx::Size> sizes_2;
325 sizes_2.push_back(gfx::Size(bit_small, bit_small)); 327 sizes_2.push_back(gfx::Size(bit_small, bit_small));
326 328
327 std::vector<gfx::Size> sizes_3; 329 std::vector<gfx::Size> sizes_3;
328 sizes_3.push_back(gfx::Size(small_size, small_size)); 330 sizes_3.push_back(gfx::Size(small_size, small_size));
329 331
330 std::vector<content::Manifest::Icon> icons; 332 std::vector<content::Manifest::Icon> icons;
331 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1)); 333 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_1));
332 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2)); 334 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 1.0, sizes_2));
333 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_3)); 335 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes_3));
334 336
335 GURL url = FindBestMatchingIcon(icons); 337 GURL url = FindBestMatchingIcon(icons);
336 EXPECT_EQ("", url.spec()); 338 EXPECT_EQ("http://foo.com/icon.png", url.spec());
337 } 339 }
338 340
339 // (very_big, big) => big 341 // (very_big, big) => big
340 { 342 {
341 std::vector<gfx::Size> sizes_1; 343 std::vector<gfx::Size> sizes_1;
342 sizes_1.push_back(gfx::Size(very_big, very_big)); 344 sizes_1.push_back(gfx::Size(very_big, very_big));
343 345
344 std::vector<gfx::Size> sizes_2; 346 std::vector<gfx::Size> sizes_2;
345 sizes_2.push_back(gfx::Size(big, big)); 347 sizes_2.push_back(gfx::Size(big, big));
346 348
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 451
450 std::vector<content::Manifest::Icon> icons; 452 std::vector<content::Manifest::Icon> icons;
451 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes)); 453 icons.push_back(CreateIcon("http://foo.com/icon_no.png", "", 1.0, sizes));
452 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 3.0, sizes)); 454 icons.push_back(CreateIcon("http://foo.com/icon.png", "", 3.0, sizes));
453 455
454 SetDisplayDeviceScaleFactor(3.0f); 456 SetDisplayDeviceScaleFactor(3.0f);
455 GURL url = FindBestMatchingIcon(icons); 457 GURL url = FindBestMatchingIcon(icons);
456 EXPECT_EQ("http://foo.com/icon.png", url.spec()); 458 EXPECT_EQ("http://foo.com/icon.png", url.spec());
457 } 459 }
458 } 460 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698