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

Side by Side Diff: ui/gfx/geometry/size_unittest.cc

Issue 2749513011: Stabilize empty rect handling in EnclosingRect. (Closed)
Patch Set: Rebase to ToT and fix comment typo. Created 3 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
« ui/gfx/geometry/size_f.h ('K') | « ui/gfx/geometry/size_f.h ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/geometry/size.h" 6 #include "ui/gfx/geometry/size.h"
7 #include "ui/gfx/geometry/size_conversions.h" 7 #include "ui/gfx/geometry/size_conversions.h"
8 #include "ui/gfx/geometry/size_f.h" 8 #include "ui/gfx/geometry/size_f.h"
9 9
10 namespace gfx { 10 namespace gfx {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 test = Size(10, 20); 147 test = Size(10, 20);
148 test.Enlarge(int_max, int_max); 148 test.Enlarge(int_max, int_max);
149 EXPECT_EQ(test, max_size); 149 EXPECT_EQ(test, max_size);
150 150
151 test = Size(-10, -20); 151 test = Size(-10, -20);
152 test.Enlarge(int_min, int_min); 152 test.Enlarge(int_min, int_min);
153 EXPECT_EQ(test, min_size); 153 EXPECT_EQ(test, min_size);
154 } 154 }
155 155
156 // This checks that we set IsEmpty appropriately.
157 TEST(SizeTest, TrivialDimensionTests) {
158 // First, using the constructor.
159 EXPECT_TRUE(SizeF(kTrivial / 2.f, 1.f).IsEmpty());
160 EXPECT_TRUE(SizeF(.01f, kTrivial / 2.f).IsEmpty());
161 EXPECT_TRUE(SizeF(0.f, 0.f).IsEmpty());
162 EXPECT_FALSE(SizeF(.01f, .01f).IsEmpty());
163
164 // Then use the setter.
165 SizeF test(2.f, 1.f);
166 EXPECT_FALSE(test.IsEmpty());
167
168 test.SetSize(kTrivial / 2.f, 1.f);
169 EXPECT_TRUE(test.IsEmpty());
170
171 test.SetSize(.01f, kTrivial / 2.f);
172 EXPECT_TRUE(test.IsEmpty());
173
174 test.SetSize(0.f, 0.f);
175 EXPECT_TRUE(test.IsEmpty());
176
177 test.SetSize(.01f, .01f);
178 EXPECT_FALSE(test.IsEmpty());
179
180 // Now just one dimension at a time.
181 test.set_width(kTrivial / 2.f);
182 EXPECT_TRUE(test.IsEmpty());
183
184 test.set_width(4e13f);
185 test.set_height(kTrivial / 2.f);
186 EXPECT_TRUE(test.IsEmpty());
187
188 test.set_width(kTrivial / 2.f);
189 test.set_height(4e13f);
190 EXPECT_TRUE(test.IsEmpty());
191
192 test.set_width(2.f);
193 EXPECT_FALSE(test.IsEmpty());
194 }
195
196 // These are the ramifications of the decision to keep the recorded size
197 // at zero for trivial sizes.
198 TEST(SizeTest, ClampsToZero) {
199 SizeF test(kTrivial / 2.f, 1.f);
200
201 EXPECT_EQ(test.width(), 0.f);
202 EXPECT_EQ(test.height(), 1.f);
203
204 test.SetSize(.01f, kTrivial / 2.f);
205
206 EXPECT_EQ(test.width(), .01f);
207 EXPECT_EQ(test.height(), 0.f);
208
209 test.SetSize(kTrivial, kTrivial);
210 test.Scale(0.5f);
211
212 EXPECT_EQ(test.width(), 0.f);
213 EXPECT_EQ(test.height(), 0.f);
214
215 test.SetSize(0.f, 0.f);
216 test.Enlarge(kTrivial / 2.f, kTrivial / 2.f);
217 test.Enlarge(kTrivial / 2.f, kTrivial / 2.f);
218 test.Enlarge(kTrivial / 2.f, kTrivial / 2.f);
219
220 EXPECT_EQ(test, SizeF(0.f, 0.f));
221 }
222
223 // These make sure the constructor and setter have the same effect on the
224 // boundary case. This claims to know the boundary, but not which way it goes.
225 TEST(SizeTest, ConsistentClamping) {
226 SizeF left(kTrivial, 0.f);
227 SizeF top(0.f, kTrivial);
228 SizeF right, bottom;
danakj 2017/03/23 20:12:06 Not sure that |right| and |bottom| express these,
Peter Mayo 2017/03/23 23:58:41 I have a better way I'll propose with the next edi
229 right.SetSize(kTrivial, 0.f);
230 bottom.SetSize(0.f, kTrivial);
231
232 EXPECT_EQ(left, right);
233 EXPECT_EQ(top, bottom);
234 }
235
156 } // namespace gfx 236 } // namespace gfx
OLDNEW
« ui/gfx/geometry/size_f.h ('K') | « ui/gfx/geometry/size_f.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698