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

Side by Side Diff: ui/gfx/image/image_family_unittest.cc

Issue 13713002: ImageFamily: Renamed Get method to GetBest. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 8 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
« no previous file with comments | « ui/gfx/image/image_family.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/gfx/image/image.h" 6 #include "ui/gfx/image/image.h"
7 #include "ui/gfx/image/image_family.h" 7 #include "ui/gfx/image/image_family.h"
8 #include "ui/gfx/image/image_skia.h" 8 #include "ui/gfx/image/image_skia.h"
9 #include "ui/gfx/image/image_unittest_util.h" 9 #include "ui/gfx/image/image_unittest_util.h"
10 10
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 EXPECT_EQ(gfx::Size(512, 128), it->Size()); 89 EXPECT_EQ(gfx::Size(512, 128), it->Size());
90 ++it; 90 ++it;
91 91
92 EXPECT_TRUE(it == end); 92 EXPECT_TRUE(it == end);
93 } 93 }
94 94
95 TEST_F(ImageFamilyTest, Get) { 95 TEST_F(ImageFamilyTest, Get) {
96 // Get on an empty family. 96 // Get on an empty family.
97 gfx::ImageFamily empty_family; 97 gfx::ImageFamily empty_family;
98 EXPECT_TRUE(empty_family.empty()); 98 EXPECT_TRUE(empty_family.empty());
99 EXPECT_FALSE(empty_family.Get(32, 32)); 99 EXPECT_FALSE(empty_family.GetBest(32, 32));
100 EXPECT_FALSE(empty_family.Get(0, 32)); 100 EXPECT_FALSE(empty_family.GetBest(0, 32));
101 EXPECT_FALSE(empty_family.Get(32, 0)); 101 EXPECT_FALSE(empty_family.GetBest(32, 0));
102 102
103 // Get various aspect ratios and sizes on the sample family. 103 // Get various aspect ratios and sizes on the sample family.
104 104
105 // 0x0 (expect the smallest square image). 105 // 0x0 (expect the smallest square image).
106 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(0, 0), 16, 16); 106 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 0), 16, 16);
107 // Get(0, N) or Get(N, 0) should be treated the same as Get(0, 0). 107 // GetBest(0, N) or GetBest(N, 0) should be treated the same as GetBest(0, 0).
108 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(0, 16), 16, 16); 108 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 16), 16, 16);
109 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(0, 64), 16, 16); 109 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 64), 16, 16);
110 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(16, 0), 16, 16); 110 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(16, 0), 16, 16);
111 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(64, 0), 16, 16); 111 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(64, 0), 16, 16);
112 112
113 // Thinner than thinnest image. 113 // Thinner than thinnest image.
114 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(2, 12), 3, 12); 114 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(2, 12), 3, 12);
115 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(2, 13), 12, 48); 115 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(2, 13), 12, 48);
116 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(10, 60), 12, 48); 116 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(10, 60), 12, 48);
117 117
118 // Between two images' aspect ratio. 118 // Between two images' aspect ratio.
119 // Note: Testing the boundary around 1:2 and 2:1, half way to 1:4 and 4:1. 119 // Note: Testing the boundary around 1:2 and 2:1, half way to 1:4 and 4:1.
120 // Ties are broken by favouring the thinner aspect ratio. 120 // Ties are broken by favouring the thinner aspect ratio.
121 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(63, 32), 64, 64); 121 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(63, 32), 64, 64);
122 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(64, 32), 64, 64); 122 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(64, 32), 64, 64);
123 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(65, 32), 256, 64); 123 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(65, 32), 256, 64);
124 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(32, 63), 64, 64); 124 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 63), 64, 64);
125 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(32, 64), 12, 48); 125 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 64), 12, 48);
126 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(32, 65), 12, 48); 126 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 65), 12, 48);
127 127
128 // Exact match aspect ratio. 128 // Exact match aspect ratio.
129 // Exact match size. 129 // Exact match size.
130 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(32, 32), 32, 32); 130 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 32), 32, 32);
131 // Slightly smaller. 131 // Slightly smaller.
132 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(31, 31), 32, 32); 132 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(31, 31), 32, 32);
133 // Much smaller. 133 // Much smaller.
134 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(17, 17), 32, 32); 134 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(17, 17), 32, 32);
135 // Exact match size. 135 // Exact match size.
136 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(16, 16), 16, 16); 136 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(16, 16), 16, 16);
137 // Smaller than any image. 137 // Smaller than any image.
138 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(3, 3), 16, 16); 138 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(3, 3), 16, 16);
139 // Larger than any image. 139 // Larger than any image.
140 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(512, 512), 64, 64); 140 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(512, 512), 64, 64);
141 // 1:4 aspect ratio. 141 // 1:4 aspect ratio.
142 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(16, 64), 12, 48); 142 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(16, 64), 12, 48);
143 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(2, 8), 3, 12); 143 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(2, 8), 3, 12);
144 // 4:1 aspect ratio. 144 // 4:1 aspect ratio.
145 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(64, 16), 256, 64); 145 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(64, 16), 256, 64);
146 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(260, 65), 512, 128); 146 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(260, 65), 512, 128);
147 147
148 // Wider than widest image. 148 // Wider than widest image.
149 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(255, 51), 256, 64); 149 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(255, 51), 256, 64);
150 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(260, 52), 512, 128); 150 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(260, 52), 512, 128);
151 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(654, 129), 512, 128); 151 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(654, 129), 512, 128);
152 } 152 }
153 153
154 // Test adding and looking up images with 0 width and height. 154 // Test adding and looking up images with 0 width and height.
155 TEST_F(ImageFamilyTest, ZeroWidthAndHeight) { 155 TEST_F(ImageFamilyTest, ZeroWidthAndHeight) {
156 // An empty Image. Should be considered to have 0 width and height. 156 // An empty Image. Should be considered to have 0 width and height.
157 image_family_.Add(gfx::Image()); 157 image_family_.Add(gfx::Image());
158 // Images with 0 width OR height should be treated the same as an image with 0 158 // Images with 0 width OR height should be treated the same as an image with 0
159 // width AND height (in fact, the ImageSkias should be indistinguishable). 159 // width AND height (in fact, the ImageSkias should be indistinguishable).
160 image_family_.Add(gt::CreateImageSkia(32, 0)); 160 image_family_.Add(gt::CreateImageSkia(32, 0));
161 image_family_.Add(gt::CreateImageSkia(0, 32)); 161 image_family_.Add(gt::CreateImageSkia(0, 32));
162 162
163 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(0, 0), 0, 0); 163 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 0), 0, 0);
164 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(1, 1), 16, 16); 164 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(1, 1), 16, 16);
165 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(32, 32), 32, 32); 165 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 32), 32, 32);
166 166
167 // Get(0, N) or Get(N, 0) should be treated the same as Get(0, 0). 167 // GetBest(0, N) or GetBest(N, 0) should be treated the same as GetBest(0, 0).
168 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(0, 1), 0, 0); 168 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 1), 0, 0);
169 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(0, 32), 0, 0); 169 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 32), 0, 0);
170 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(1, 0), 0, 0); 170 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(1, 0), 0, 0);
171 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(32, 0), 0, 0); 171 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 0), 0, 0);
172 172
173 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(1, 32), 12, 48); 173 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(1, 32), 12, 48);
174 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.Get(32, 1), 256, 64); 174 EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 1), 256, 64);
175 } 175 }
176 176
177 } // namespace 177 } // namespace
OLDNEW
« no previous file with comments | « ui/gfx/image/image_family.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698