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

Side by Side Diff: ui/gfx/win/rect_util_unittest.cc

Issue 1426933002: Refactor Windows DPI Point, Rect, and Size for Multiple Monitor DPI Awareness (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Other Unit Tests - Moved Inner Classes Outside Created 4 years, 11 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 2016 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/geometry/rect.h"
7 #include "ui/gfx/win/rect_util.h"
8
9 namespace gfx {
10 namespace win {
11
12 TEST(RectUtilTest, RectTouchBottom) {
13 EXPECT_EQ(RectEdge::BOTTOM,
14 RectTouch(gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 2, 1, 1)));
15 }
16
17 TEST(RectUtilTest, RectTouchLeft) {
18 EXPECT_EQ(RectEdge::LEFT,
19 RectTouch(gfx::Rect(1, 1, 1, 1), gfx::Rect(0, 1, 1, 1)));
20 }
21
22 TEST(RectUtilTest, RectTouchTop) {
23 EXPECT_EQ(RectEdge::TOP,
24 RectTouch(gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 0, 1, 1)));
25 }
26
27 TEST(RectUtilTest, RectTouchRight) {
28 EXPECT_EQ(RectEdge::RIGHT,
29 RectTouch(gfx::Rect(1, 1, 1, 1), gfx::Rect(2, 1, 1, 1)));
30 }
31
32 TEST(RectUtilTest, RectTouchBottomRightCorner) {
33 EXPECT_EQ(RectEdge::BOTTOM,
34 RectTouch(gfx::Rect(1, 1, 1, 1), gfx::Rect(2, 2, 1, 1)));
35 }
36
37 TEST(RectUtilTest, RectTouchBottomLeftCorner) {
38 EXPECT_EQ(RectEdge::BOTTOM,
39 RectTouch(gfx::Rect(1, 1, 1, 1), gfx::Rect(0, 2, 1, 1)));
40 }
41
42 TEST(RectUtilTest, RectTouchUpperLeftCorner) {
43 EXPECT_EQ(RectEdge::LEFT,
44 RectTouch(gfx::Rect(1, 1, 1, 1), gfx::Rect(0, 0, 1, 1)));
45 }
46
47 TEST(RectUtilTest, RectTouchUpperRightCorner) {
48 EXPECT_EQ(RectEdge::TOP,
49 RectTouch(gfx::Rect(1, 1, 1, 1), gfx::Rect(2, 0, 1, 1)));
50 }
51
52 TEST(RectUtilTest, RectTouchNone) {
53 EXPECT_EQ(RectEdge::NONE,
54 RectTouch(gfx::Rect(1, 1, 1, 1), gfx::Rect(3, 1, 1, 1)));
55 }
56
57 TEST(RectUtilTest, ScaleAndPositionRectNoScaleRight) {
58 // Top edge aligned.
59 EXPECT_EQ(gfx::Rect(800, 0, 1024, 768),
60 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
61 gfx::Rect(0, 0, 800, 600),
62 gfx::Rect(800, 0, 1024, 768),
63 1.0f));
64 // Bottom edge aligned.
65 EXPECT_EQ(gfx::Rect(800, -168, 1024, 768),
66 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
67 gfx::Rect(0, 0, 800, 600),
68 gfx::Rect(800, -168, 1024, 768),
69 1.0f));
70 // Offset to the top.
71 EXPECT_EQ(gfx::Rect(800, -10, 1024, 768),
72 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
73 gfx::Rect(0, 0, 800, 600),
74 gfx::Rect(800, -10, 1024, 768),
75 1.0f));
76 // Offset to the bottom.
77 EXPECT_EQ(gfx::Rect(800, 10, 1024, 768),
78 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
79 gfx::Rect(0, 0, 800, 600),
80 gfx::Rect(800, 10, 1024, 768),
81 1.0f));
82
83 }
84
85 TEST(RectUtilTest, ScaleAndPositionRectNoScaleLeft) {
86 // Top edge aligned.
87 EXPECT_EQ(gfx::Rect(-1024, 0, 1024, 768),
88 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
89 gfx::Rect(0, 0, 800, 600),
90 gfx::Rect(-1024, 0, 1024, 768),
91 1.0f));
92 // Bottom edge aligned.
93 EXPECT_EQ(gfx::Rect(-1024, -168, 1024, 768),
94 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
95 gfx::Rect(0, 0, 800, 600),
96 gfx::Rect(-1024, -168, 1024, 768),
97 1.0f));
98 // Offset to the top.
99 EXPECT_EQ(gfx::Rect(-1024, -10, 1024, 768),
100 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
101 gfx::Rect(0, 0, 800, 600),
102 gfx::Rect(-1024, -10, 1024, 768),
103 1.0f));
104 // Offset to the bottom.
105 EXPECT_EQ(gfx::Rect(-1024, 10, 1024, 768),
106 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
107 gfx::Rect(0, 0, 800, 600),
108 gfx::Rect(-1024, 10, 1024, 768),
109 1.0f));
110 }
111
112 TEST(RectUtilTest, ScaleAndPositionRectNoScaleTop) {
113 // Left edge aligned.
114 EXPECT_EQ(gfx::Rect(0, -768, 1024, 768),
115 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
116 gfx::Rect(0, 0, 800, 600),
117 gfx::Rect(0, -768, 1024, 768),
118 1.0f));
119 // Right edge aligned.
120 EXPECT_EQ(gfx::Rect(-224, -768, 1024, 768),
121 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
122 gfx::Rect(0, 0, 800, 600),
123 gfx::Rect(-224, -768, 1024, 768),
124 1.0f));
125 // Offset to the right.
126 EXPECT_EQ(gfx::Rect(10, -768, 1024, 768),
127 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
128 gfx::Rect(0, 0, 800, 600),
129 gfx::Rect(10, -768, 1024, 768),
130 1.0f));
131 // Offset to the left.
132 EXPECT_EQ(gfx::Rect(-10, -768, 1024, 768),
133 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
134 gfx::Rect(0, 0, 800, 600),
135 gfx::Rect(-10, -768, 1024, 768),
136 1.0f));
137 }
138
139 TEST(RectUtilTest, ScaleAndPositionRectNoScaleBottom) {
140 // Left edge aligned.
141 EXPECT_EQ(gfx::Rect(0, 600, 1024, 768),
142 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
143 gfx::Rect(0, 0, 800, 600),
144 gfx::Rect(0, 600, 1024, 768),
145 1.0f));
146 // Right edge aligned.
147 EXPECT_EQ(gfx::Rect(-224, 600, 1024, 768),
148 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
149 gfx::Rect(0, 0, 800, 600),
150 gfx::Rect(-224, 600, 1024, 768),
151 1.0f));
152 // Offset to the right
153 EXPECT_EQ(gfx::Rect(10, 600, 1024, 768),
154 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
155 gfx::Rect(0, 0, 800, 600),
156 gfx::Rect(10, 600, 1024, 768),
157 1.0f));
158 // Offset to the left
159 EXPECT_EQ(gfx::Rect(-10, 600, 1024, 768),
160 ScaleAndPositionRect(gfx::Rect(0, 0, 800, 600),
161 gfx::Rect(0, 0, 800, 600),
162 gfx::Rect(-10, 600, 1024, 768),
163 1.0f));
164 }
165
166 TEST(RectUtilTest, ScaleAndPositionRectNoScaleOddDimensions) {
167 EXPECT_EQ(gfx::Rect(59, 77, 7, 9),
168 ScaleAndPositionRect(gfx::Rect(35, 72, 24, 24),
169 gfx::Rect(35, 72, 24, 24),
170 gfx::Rect(59, 77, 7, 9),
171 1.0f));
172 EXPECT_EQ(gfx::Rect(-701, 9, 702, 2),
173 ScaleAndPositionRect(gfx::Rect(1, 7, 30, 40),
174 gfx::Rect(1, 7, 30, 40),
175 gfx::Rect(-701, 9, 702, 2),
176 1.0f));
177 }
178
179 TEST(RectUtilTest, ScaleAndPositionRect2xScale) {
180 // Side by side to the right.
181 EXPECT_EQ(gfx::Rect(900, 50, 500, 350),
182 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
183 gfx::Rect(100, 50, 800, 600),
184 gfx::Rect(900, 50, 1000, 700),
185 2.0f));
186 // Side-by-side to the left.
187 EXPECT_EQ(gfx::Rect(-400, 50, 500, 350),
188 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
189 gfx::Rect(100, 50, 800, 600),
190 gfx::Rect(-900, 50, 1000, 700),
191 2.0f));
192
193 // Side-by-side to the top.
194 EXPECT_EQ(gfx::Rect(75, -300, 500, 350),
195 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
196 gfx::Rect(100, 50, 800, 600),
197 gfx::Rect(50, -650, 1000, 700),
198 2.0f));
199
200 // Side-by-side on the bottom.
201 EXPECT_EQ(gfx::Rect(75, 650, 500, 350),
202 ScaleAndPositionRect(gfx::Rect(100, 50, 800, 600),
203 gfx::Rect(100, 50, 800, 600),
204 gfx::Rect(50, 650, 1000, 700),
205 2.0f));
206
207 // Side by side to the right.
208 EXPECT_EQ(gfx::Rect(500, 50, 500, 350),
209 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
210 gfx::Rect(100, 50, 800, 600),
211 gfx::Rect(900, 50, 1000, 700),
212 2.0f));
213
214 // Side-by-side to the left.
215 EXPECT_EQ(gfx::Rect(-400, 50, 500, 350),
216 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
217 gfx::Rect(100, 50, 800, 600),
218 gfx::Rect(-900, 50, 1000, 700),
219 2.0f));
220
221 // Side-by-side to the top.
222 EXPECT_EQ(gfx::Rect(75, -300, 500, 350),
223 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
224 gfx::Rect(100, 50, 800, 600),
225 gfx::Rect(50, -650, 1000, 700),
226 2.0f));
227
228
229 // Side-by-side to the bottom.
230 EXPECT_EQ(gfx::Rect(75, 350, 500, 350),
231 ScaleAndPositionRect(gfx::Rect(100, 50, 400, 300),
232 gfx::Rect(100, 50, 800, 600),
233 gfx::Rect(50, 650, 1000, 700),
234 2.0f));
235 }
236
237 TEST(RectUtilTest, SquaredDistanceBetweenRectsFullyIntersecting) {
238 gfx::Rect rect1(0, 0, 100, 100);
239 gfx::Rect rect2(5, 5, 10, 10);
240 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect1, rect2));
241 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect2, rect1));
242 }
243
244 TEST(RectUtilTest, SquaredDistanceBetweenRectsPartiallyIntersecting) {
245 gfx::Rect rect1(0, 0, 10, 10);
246 gfx::Rect rect2(5, 5, 10, 10);
247 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect1, rect2));
248 EXPECT_EQ(0, SquaredDistanceBetweenRects(rect2, rect1));
249 }
250
251 TEST(RectUtilTest, SquaredDistanceBetweenRectsTouching) {
252 gfx::Rect ref(2, 2, 2, 2);
253
254 gfx::Rect top_left(0, 0, 2, 2);
255 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left));
256 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left, ref));
257 gfx::Rect top_left_partial_top(1, 0, 2, 2);
258 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left_partial_top));
259 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left_partial_top, ref));
260 gfx::Rect top(2, 0, 2, 2);
261 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top));
262 EXPECT_EQ(0, SquaredDistanceBetweenRects(top, ref));
263 gfx::Rect top_right_partial_top(3, 0, 2, 2);
264 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_right_partial_top));
265 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_right_partial_top, ref));
266 gfx::Rect top_right(4, 0, 2, 2);
267 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_right));
268 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_right, ref));
269
270 gfx::Rect top_left_partial_left(0, 1, 2, 2);
271 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, top_left_partial_left));
272 EXPECT_EQ(0, SquaredDistanceBetweenRects(top_left_partial_left, ref));
273 gfx::Rect left(0, 2, 2, 2);
274 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, left));
275 EXPECT_EQ(0, SquaredDistanceBetweenRects(left, ref));
276 gfx::Rect bottom_left_partial(0, 3, 2, 2);
277 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, bottom_left_partial));
278 EXPECT_EQ(0, SquaredDistanceBetweenRects(bottom_left_partial, ref));
279 gfx::Rect bottom_left(0, 4, 2, 2);
280 EXPECT_EQ(0, SquaredDistanceBetweenRects(ref, bottom_left));
281 EXPECT_EQ(0, SquaredDistanceBetweenRects(bottom_left, ref));
282 }
283
284 TEST(RectUtilTest, SquaredDistanceBetweenRectsOverlapping) {
285 gfx::Rect ref(5, 5, 2, 2);
286
287 gfx::Rect top_left_partial_top(4, 0, 2, 2);
288 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_left_partial_top));
289 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_left_partial_top, ref));
290 gfx::Rect top(5, 0, 2, 2);
291 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top));
292 EXPECT_EQ(9, SquaredDistanceBetweenRects(top, ref));
293 gfx::Rect top_right_partial(6, 0, 2, 2);
294 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_right_partial));
295 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_right_partial, ref));
296
297 gfx::Rect top_left_partial_left(0, 4, 2, 2);
298 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, top_left_partial_left));
299 EXPECT_EQ(9, SquaredDistanceBetweenRects(top_left_partial_left, ref));
300 gfx::Rect left(0, 5, 2, 2);
301 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, left));
302 EXPECT_EQ(9, SquaredDistanceBetweenRects(left, ref));
303 gfx::Rect bottom_left_partial(0, 6, 2, 2);
304 EXPECT_EQ(9, SquaredDistanceBetweenRects(ref, bottom_left_partial));
305 EXPECT_EQ(9, SquaredDistanceBetweenRects(bottom_left_partial, ref));
306 }
307
308 TEST(RectUtilTest, SquaredDistanceBetweenRectsDiagonals) {
309 gfx::Rect ref(5, 5, 2, 2);
310
311 gfx::Rect top_left(0, 0, 2, 2);
312 EXPECT_EQ(18, SquaredDistanceBetweenRects(ref, top_left));
313 EXPECT_EQ(18, SquaredDistanceBetweenRects(top_left, ref));
314
315 gfx::Rect top_right(10, 0, 2, 2);
316 EXPECT_EQ(18, SquaredDistanceBetweenRects(ref, top_right));
317 EXPECT_EQ(18, SquaredDistanceBetweenRects(top_right, ref));
318 }
319
320
321 } // namespace win
322 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698