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

Side by Side Diff: ui/gfx/icon_family_unittest.cc

Issue 12881003: ShortcutInfo::favicon is now a gfx::ImageFamily instead of gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added test suite for icon_family. Created 7 years, 9 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/gfx/icon_family.h"
7 #include "ui/gfx/image/image_unittest_util.h"
8
9 namespace {
10
11 namespace gt = gfx::test;
12
13 // Tests that |image_skia| != NULL, and has the given width and height.
14 void ExpectImageSkiaNonNullAndSize(const gfx::ImageSkia* image_skia, int width,
15 int height) {
16 EXPECT_NE(static_cast<gfx::ImageSkia*>(NULL), image_skia);
17 EXPECT_EQ(width, image_skia->width());
18 EXPECT_EQ(height, image_skia->height());
19 }
20
21 class IconFamilyTest : public testing::Test {
22 public:
23 // Construct an IconFamily. Implicitly tests Add and Empty.
24 virtual void SetUp() {
25 EXPECT_TRUE(icon_family.empty());
26
27 // Aspect ratio 1:1.
28 icon_family.Add(gt::CreateImageSkia(32, 32));
29 EXPECT_FALSE(icon_family.empty());
30 icon_family.Add(gt::CreateImageSkia(16, 16));
31 icon_family.Add(gt::CreateImageSkia(64, 64));
32 // Aspect ratio 1:2.
33 icon_family.Add(gt::CreateImageSkia(3, 6));
34 icon_family.Add(gt::CreateImageSkia(12, 24));
35 // Aspect ratio 2:1.
36 icon_family.Add(gt::CreateImageSkia(256, 128));
37 icon_family.Add(gt::CreateImageSkia(128, 64));
38
39 EXPECT_FALSE(icon_family.empty());
40 }
41
42 gfx::IconFamily icon_family;
43 };
44
45 TEST_F(IconFamilyTest, Clear) {
46 icon_family.clear();
47 EXPECT_TRUE(icon_family.empty());
48 }
49
50 // Tests iteration over an IconFamily.
51 TEST_F(IconFamilyTest, Iteration) {
52 gfx::IconFamily::const_iterator it = icon_family.begin();
53 gfx::IconFamily::const_iterator end = icon_family.end();
54
55 // Expect iteration in order of aspect ratio (from thinnest to widest), then
56 // size.
57 EXPECT_TRUE(it != end);
58 EXPECT_EQ(gfx::Size(3, 6), it->size());
59 ++it;
60 EXPECT_TRUE(it != end);
61 EXPECT_EQ(gfx::Size(12, 24), it->size());
62 it++; // Test post-increment.
63 EXPECT_TRUE(it != end);
64 EXPECT_EQ(gfx::Size(16, 16), it->size());
65 ++it;
66 EXPECT_TRUE(it != end);
67 EXPECT_EQ(gfx::Size(32, 32), it->size());
68 --it; // Test decrement
69 EXPECT_TRUE(it != end);
70 EXPECT_EQ(gfx::Size(16, 16), it->size());
71 ++it;
72 ++it;
73 EXPECT_TRUE(it != end);
74 EXPECT_EQ(gfx::Size(64, 64), (*it).size()); // Test operator*.
75 ++it;
76 EXPECT_TRUE(it != end);
77 EXPECT_EQ(gfx::Size(128, 64), it->size());
78 ++it;
79 EXPECT_TRUE(it != end);
80 EXPECT_EQ(gfx::Size(256, 128), it->size());
81 ++it;
82
83 EXPECT_TRUE(it == end);
84 }
85
86 TEST_F(IconFamilyTest, Get) {
87 // Get on an empty family.
88 gfx::IconFamily empty_family;
89 EXPECT_TRUE(empty_family.empty());
90 EXPECT_EQ(static_cast<gfx::ImageSkia*>(NULL), empty_family.Get(32, 32));
91 EXPECT_EQ(static_cast<gfx::ImageSkia*>(NULL), empty_family.Get(0, 32));
92 EXPECT_EQ(static_cast<gfx::ImageSkia*>(NULL), empty_family.Get(32, 0));
93
94 // Get various aspect ratios and sizes on the sample family.
95 // Exact match.
96 ExpectImageSkiaNonNullAndSize(icon_family.Get(32, 32), 32, 32);
97 // Same aspect ratio, slightly smaller.
98 ExpectImageSkiaNonNullAndSize(icon_family.Get(31, 31), 32, 32);
99 // Same aspect ratio, much smaller.
100 ExpectImageSkiaNonNullAndSize(icon_family.Get(17, 17), 32, 32);
101 // Exact match.
102 ExpectImageSkiaNonNullAndSize(icon_family.Get(16, 16), 16, 16);
103 // Smaller than any image.
104 ExpectImageSkiaNonNullAndSize(icon_family.Get(3, 3), 16, 16);
105 // Larger than any image.
106 ExpectImageSkiaNonNullAndSize(icon_family.Get(512, 512), 64, 64);
107 // Wider aspect ratio.
108 ExpectImageSkiaNonNullAndSize(icon_family.Get(32, 16), 128, 64);
109 ExpectImageSkiaNonNullAndSize(icon_family.Get(130, 65), 256, 128);
110 // Thinner aspect ratio.
111 ExpectImageSkiaNonNullAndSize(icon_family.Get(16, 32), 12, 24);
112 // TODO(mgiuca): No idea why this fails.
113 //ExpectImageSkiaNonNullAndSize(icon_family.Get(2, 4), 3, 6);
114 // TODO(mgiuca): In between two aspect ratios. Test the border cases and
115 // possibly change the calculation to use a ratio instead of difference.
116 // TODO(mgiuca): An aspect ratio thinner than 1:2. (Smaller, equal, greater
117 // than all.)
118 // TODO(mgiuca): An aspect ratio wider than 2:1. (Smaller, equal, greater than
119 // all.)
120 // Get the smallest square image.
121 ExpectImageSkiaNonNullAndSize(icon_family.Get(0, 0), 16, 16);
122 // Get the image >=0x5 with the thinnest aspect ratio.
123 // TODO(mgiuca): Currently fails because the width is <5.
124 //ExpectImageSkiaNonNullAndSize(icon_family.Get(0, 5), 3, 6);
125 // Get the image >=0x7 with the thinnest aspect ratio.
126 ExpectImageSkiaNonNullAndSize(icon_family.Get(0, 7), 12, 24);
127 // Get the image >=127x0 with the widest aspect ratio.
128 // TODO(mgiuca): Currently fails because the height is <127.
129 //ExpectImageSkiaNonNullAndSize(icon_family.Get(127, 0), 128, 64);
130 // Get the image >=129x0 with the widest aspect ratio.
131 ExpectImageSkiaNonNullAndSize(icon_family.Get(129, 0), 256, 128);
132 }
133
134 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698