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
3 // found in the LICENSE file.
5 #include "ui/views/bubble/bubble_border.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/stringprintf.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/views/test/views_test_base.h"
15 typedef views::ViewsTestBase BubbleBorderTest
;
17 TEST_F(BubbleBorderTest
, GetMirroredArrow
) {
18 // Horizontal mirroring.
19 EXPECT_EQ(BubbleBorder::TOP_RIGHT
,
20 BubbleBorder::horizontal_mirror(BubbleBorder::TOP_LEFT
));
21 EXPECT_EQ(BubbleBorder::TOP_LEFT
,
22 BubbleBorder::horizontal_mirror(BubbleBorder::TOP_RIGHT
));
24 EXPECT_EQ(BubbleBorder::BOTTOM_RIGHT
,
25 BubbleBorder::horizontal_mirror(BubbleBorder::BOTTOM_LEFT
));
26 EXPECT_EQ(BubbleBorder::BOTTOM_LEFT
,
27 BubbleBorder::horizontal_mirror(BubbleBorder::BOTTOM_RIGHT
));
29 EXPECT_EQ(BubbleBorder::RIGHT_TOP
,
30 BubbleBorder::horizontal_mirror(BubbleBorder::LEFT_TOP
));
31 EXPECT_EQ(BubbleBorder::LEFT_TOP
,
32 BubbleBorder::horizontal_mirror(BubbleBorder::RIGHT_TOP
));
34 EXPECT_EQ(BubbleBorder::RIGHT_BOTTOM
,
35 BubbleBorder::horizontal_mirror(BubbleBorder::LEFT_BOTTOM
));
36 EXPECT_EQ(BubbleBorder::LEFT_BOTTOM
,
37 BubbleBorder::horizontal_mirror(BubbleBorder::RIGHT_BOTTOM
));
39 EXPECT_EQ(BubbleBorder::TOP_CENTER
,
40 BubbleBorder::horizontal_mirror(BubbleBorder::TOP_CENTER
));
41 EXPECT_EQ(BubbleBorder::BOTTOM_CENTER
,
42 BubbleBorder::horizontal_mirror(BubbleBorder::BOTTOM_CENTER
));
44 EXPECT_EQ(BubbleBorder::RIGHT_CENTER
,
45 BubbleBorder::horizontal_mirror(BubbleBorder::LEFT_CENTER
));
46 EXPECT_EQ(BubbleBorder::LEFT_CENTER
,
47 BubbleBorder::horizontal_mirror(BubbleBorder::RIGHT_CENTER
));
49 EXPECT_EQ(BubbleBorder::NONE
,
50 BubbleBorder::horizontal_mirror(BubbleBorder::NONE
));
51 EXPECT_EQ(BubbleBorder::FLOAT
,
52 BubbleBorder::horizontal_mirror(BubbleBorder::FLOAT
));
54 // Vertical mirroring.
55 EXPECT_EQ(BubbleBorder::BOTTOM_LEFT
,
56 BubbleBorder::vertical_mirror(BubbleBorder::TOP_LEFT
));
57 EXPECT_EQ(BubbleBorder::BOTTOM_RIGHT
,
58 BubbleBorder::vertical_mirror(BubbleBorder::TOP_RIGHT
));
60 EXPECT_EQ(BubbleBorder::TOP_LEFT
,
61 BubbleBorder::vertical_mirror(BubbleBorder::BOTTOM_LEFT
));
62 EXPECT_EQ(BubbleBorder::TOP_RIGHT
,
63 BubbleBorder::vertical_mirror(BubbleBorder::BOTTOM_RIGHT
));
65 EXPECT_EQ(BubbleBorder::LEFT_BOTTOM
,
66 BubbleBorder::vertical_mirror(BubbleBorder::LEFT_TOP
));
67 EXPECT_EQ(BubbleBorder::RIGHT_BOTTOM
,
68 BubbleBorder::vertical_mirror(BubbleBorder::RIGHT_TOP
));
70 EXPECT_EQ(BubbleBorder::LEFT_TOP
,
71 BubbleBorder::vertical_mirror(BubbleBorder::LEFT_BOTTOM
));
72 EXPECT_EQ(BubbleBorder::RIGHT_TOP
,
73 BubbleBorder::vertical_mirror(BubbleBorder::RIGHT_BOTTOM
));
75 EXPECT_EQ(BubbleBorder::BOTTOM_CENTER
,
76 BubbleBorder::vertical_mirror(BubbleBorder::TOP_CENTER
));
77 EXPECT_EQ(BubbleBorder::TOP_CENTER
,
78 BubbleBorder::vertical_mirror(BubbleBorder::BOTTOM_CENTER
));
80 EXPECT_EQ(BubbleBorder::LEFT_CENTER
,
81 BubbleBorder::vertical_mirror(BubbleBorder::LEFT_CENTER
));
82 EXPECT_EQ(BubbleBorder::RIGHT_CENTER
,
83 BubbleBorder::vertical_mirror(BubbleBorder::RIGHT_CENTER
));
85 EXPECT_EQ(BubbleBorder::NONE
,
86 BubbleBorder::vertical_mirror(BubbleBorder::NONE
));
87 EXPECT_EQ(BubbleBorder::FLOAT
,
88 BubbleBorder::vertical_mirror(BubbleBorder::FLOAT
));
91 TEST_F(BubbleBorderTest
, HasArrow
) {
92 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::TOP_LEFT
));
93 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::TOP_RIGHT
));
95 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::BOTTOM_LEFT
));
96 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::BOTTOM_RIGHT
));
98 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::LEFT_TOP
));
99 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::RIGHT_TOP
));
101 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::LEFT_BOTTOM
));
102 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::RIGHT_BOTTOM
));
104 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::TOP_CENTER
));
105 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::BOTTOM_CENTER
));
107 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::LEFT_CENTER
));
108 EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::RIGHT_CENTER
));
110 EXPECT_FALSE(BubbleBorder::has_arrow(BubbleBorder::NONE
));
111 EXPECT_FALSE(BubbleBorder::has_arrow(BubbleBorder::FLOAT
));
114 TEST_F(BubbleBorderTest
, IsArrowOnLeft
) {
115 EXPECT_TRUE(BubbleBorder::is_arrow_on_left(BubbleBorder::TOP_LEFT
));
116 EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::TOP_RIGHT
));
118 EXPECT_TRUE(BubbleBorder::is_arrow_on_left(BubbleBorder::BOTTOM_LEFT
));
119 EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::BOTTOM_RIGHT
));
121 EXPECT_TRUE(BubbleBorder::is_arrow_on_left(BubbleBorder::LEFT_TOP
));
122 EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::RIGHT_TOP
));
124 EXPECT_TRUE(BubbleBorder::is_arrow_on_left(BubbleBorder::LEFT_BOTTOM
));
125 EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::RIGHT_BOTTOM
));
127 EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::TOP_CENTER
));
128 EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::BOTTOM_CENTER
));
130 EXPECT_TRUE(BubbleBorder::is_arrow_on_left(BubbleBorder::LEFT_CENTER
));
131 EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::RIGHT_CENTER
));
133 EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::NONE
));
134 EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::FLOAT
));
137 TEST_F(BubbleBorderTest
, IsArrowOnTop
) {
138 EXPECT_TRUE(BubbleBorder::is_arrow_on_top(BubbleBorder::TOP_LEFT
));
139 EXPECT_TRUE(BubbleBorder::is_arrow_on_top(BubbleBorder::TOP_RIGHT
));
141 EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::BOTTOM_LEFT
));
142 EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::BOTTOM_RIGHT
));
144 EXPECT_TRUE(BubbleBorder::is_arrow_on_top(BubbleBorder::LEFT_TOP
));
145 EXPECT_TRUE(BubbleBorder::is_arrow_on_top(BubbleBorder::RIGHT_TOP
));
147 EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::LEFT_BOTTOM
));
148 EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::RIGHT_BOTTOM
));
150 EXPECT_TRUE(BubbleBorder::is_arrow_on_top(BubbleBorder::TOP_CENTER
));
151 EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::BOTTOM_CENTER
));
153 EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::LEFT_CENTER
));
154 EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::RIGHT_CENTER
));
156 EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::NONE
));
157 EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::FLOAT
));
160 TEST_F(BubbleBorderTest
, IsArrowOnHorizontal
) {
161 EXPECT_TRUE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::TOP_LEFT
));
162 EXPECT_TRUE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::TOP_RIGHT
));
164 EXPECT_TRUE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::BOTTOM_LEFT
));
165 EXPECT_TRUE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::BOTTOM_RIGHT
));
167 EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::LEFT_TOP
));
168 EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::RIGHT_TOP
));
170 EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::LEFT_BOTTOM
));
172 BubbleBorder::is_arrow_on_horizontal(BubbleBorder::RIGHT_BOTTOM
));
174 EXPECT_TRUE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::TOP_CENTER
));
176 BubbleBorder::is_arrow_on_horizontal(BubbleBorder::BOTTOM_CENTER
));
178 EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::LEFT_CENTER
));
180 BubbleBorder::is_arrow_on_horizontal(BubbleBorder::RIGHT_CENTER
));
182 EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::NONE
));
183 EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::FLOAT
));
186 TEST_F(BubbleBorderTest
, IsArrowAtCenter
) {
187 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::TOP_LEFT
));
188 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::TOP_RIGHT
));
190 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::BOTTOM_LEFT
));
191 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::BOTTOM_RIGHT
));
193 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::LEFT_TOP
));
194 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::RIGHT_TOP
));
196 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::LEFT_BOTTOM
));
197 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::RIGHT_BOTTOM
));
199 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::TOP_CENTER
));
200 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::BOTTOM_CENTER
));
202 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::LEFT_CENTER
));
203 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::RIGHT_CENTER
));
205 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::NONE
));
206 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::FLOAT
));
209 TEST_F(BubbleBorderTest
, GetSizeForContentsSizeTest
) {
210 views::BubbleBorder
border(BubbleBorder::NONE
,
211 BubbleBorder::NO_SHADOW
,
214 const views::internal::BorderImages
* kImages
= border
.GetImagesForTest();
216 // kSmallSize is smaller than the minimum allowable size and does not
217 // contribute to the resulting size.
218 const gfx::Size kSmallSize
= gfx::Size(1, 2);
219 // kMediumSize is larger than the minimum allowable size and contributes to
220 // the resulting size.
221 const gfx::Size kMediumSize
= gfx::Size(50, 60);
223 const gfx::Size
kSmallHorizArrow(
224 2 * kImages
->border_thickness
+ kImages
->top_arrow
.width(),
225 kImages
->border_thickness
+ kImages
->arrow_thickness
+
226 kImages
->border_interior_thickness
);
228 const gfx::Size
kSmallVertArrow(kSmallHorizArrow
.height(),
229 kSmallHorizArrow
.width());
231 const gfx::Size
kSmallNoArrow(2 * kImages
->border_thickness
,
232 2 * kImages
->border_thickness
);
234 const gfx::Size
kMediumHorizArrow(
235 kMediumSize
.width() + 2 * border
.GetBorderThickness(),
236 kMediumSize
.height() + border
.GetBorderThickness() +
237 kImages
->arrow_thickness
);
239 const gfx::Size
kMediumVertArrow(
240 kMediumSize
.width() + border
.GetBorderThickness() +
241 kImages
->arrow_thickness
,
242 kMediumSize
.height() + 2 * border
.GetBorderThickness());
244 const gfx::Size
kMediumNoArrow(
245 kMediumSize
.width() + 2 * border
.GetBorderThickness(),
246 kMediumSize
.height() + 2 * border
.GetBorderThickness());
249 BubbleBorder::Arrow arrow
;
251 gfx::Size expected_with_arrow
;
252 gfx::Size expected_without_arrow
;
256 // Content size: kSmallSize
257 { BubbleBorder::TOP_LEFT
, kSmallSize
, kSmallHorizArrow
, kSmallNoArrow
},
258 { BubbleBorder::TOP_CENTER
, kSmallSize
, kSmallHorizArrow
, kSmallNoArrow
},
259 { BubbleBorder::TOP_RIGHT
, kSmallSize
, kSmallHorizArrow
, kSmallNoArrow
},
260 { BubbleBorder::BOTTOM_LEFT
, kSmallSize
, kSmallHorizArrow
, kSmallNoArrow
},
261 { BubbleBorder::BOTTOM_CENTER
, kSmallSize
, kSmallHorizArrow
,
263 { BubbleBorder::BOTTOM_RIGHT
, kSmallSize
, kSmallHorizArrow
, kSmallNoArrow
},
264 { BubbleBorder::LEFT_TOP
, kSmallSize
, kSmallVertArrow
, kSmallNoArrow
},
265 { BubbleBorder::LEFT_CENTER
, kSmallSize
, kSmallVertArrow
, kSmallNoArrow
},
266 { BubbleBorder::LEFT_BOTTOM
, kSmallSize
, kSmallVertArrow
, kSmallNoArrow
},
267 { BubbleBorder::RIGHT_TOP
, kSmallSize
, kSmallVertArrow
, kSmallNoArrow
},
268 { BubbleBorder::RIGHT_CENTER
, kSmallSize
, kSmallVertArrow
, kSmallNoArrow
},
269 { BubbleBorder::RIGHT_BOTTOM
, kSmallSize
, kSmallVertArrow
, kSmallNoArrow
},
270 { BubbleBorder::NONE
, kSmallSize
, kSmallNoArrow
, kSmallNoArrow
},
271 { BubbleBorder::FLOAT
, kSmallSize
, kSmallNoArrow
, kSmallNoArrow
},
273 // Content size: kMediumSize
274 { BubbleBorder::TOP_LEFT
, kMediumSize
, kMediumHorizArrow
, kMediumNoArrow
},
275 { BubbleBorder::TOP_CENTER
, kMediumSize
, kMediumHorizArrow
,
277 { BubbleBorder::TOP_RIGHT
, kMediumSize
, kMediumHorizArrow
, kMediumNoArrow
},
278 { BubbleBorder::BOTTOM_LEFT
, kMediumSize
, kMediumHorizArrow
,
280 { BubbleBorder::BOTTOM_CENTER
, kMediumSize
, kMediumHorizArrow
,
282 { BubbleBorder::BOTTOM_RIGHT
, kMediumSize
, kMediumHorizArrow
,
284 { BubbleBorder::LEFT_TOP
, kMediumSize
, kMediumVertArrow
, kMediumNoArrow
},
285 { BubbleBorder::LEFT_CENTER
, kMediumSize
, kMediumVertArrow
,
287 { BubbleBorder::LEFT_BOTTOM
, kMediumSize
, kMediumVertArrow
,
289 { BubbleBorder::RIGHT_TOP
, kMediumSize
, kMediumVertArrow
, kMediumNoArrow
},
290 { BubbleBorder::RIGHT_CENTER
, kMediumSize
, kMediumVertArrow
,
292 { BubbleBorder::RIGHT_BOTTOM
, kMediumSize
, kMediumVertArrow
,
294 { BubbleBorder::NONE
, kMediumSize
, kMediumNoArrow
, kMediumNoArrow
},
295 { BubbleBorder::FLOAT
, kMediumSize
, kMediumNoArrow
, kMediumNoArrow
}
298 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
299 SCOPED_TRACE(base::StringPrintf("i=%d arrow=%d",
300 static_cast<int>(i
), cases
[i
].arrow
));
302 border
.set_arrow(cases
[i
].arrow
);
304 border
.set_paint_arrow(BubbleBorder::PAINT_NORMAL
);
305 EXPECT_EQ(cases
[i
].expected_with_arrow
,
306 border
.GetSizeForContentsSize(cases
[i
].content
));
308 border
.set_paint_arrow(BubbleBorder::PAINT_TRANSPARENT
);
309 EXPECT_EQ(cases
[i
].expected_with_arrow
,
310 border
.GetSizeForContentsSize(cases
[i
].content
));
312 border
.set_paint_arrow(BubbleBorder::PAINT_NONE
);
313 EXPECT_EQ(cases
[i
].expected_without_arrow
,
314 border
.GetSizeForContentsSize(cases
[i
].content
));
318 TEST_F(BubbleBorderTest
, GetBoundsOriginTest
) {
319 views::BubbleBorder
border(BubbleBorder::TOP_LEFT
,
320 BubbleBorder::NO_SHADOW
,
323 const gfx::Rect
kAnchor(100, 100, 20, 30);
324 const gfx::Size
kContentSize(50, 60);
326 const views::internal::BorderImages
* kImages
= border
.GetImagesForTest();
328 border
.set_arrow(BubbleBorder::TOP_LEFT
);
329 const gfx::Size kTotalSizeWithHorizArrow
=
330 border
.GetSizeForContentsSize(kContentSize
);
332 border
.set_arrow(BubbleBorder::RIGHT_BOTTOM
);
333 const gfx::Size kTotalSizeWithVertArrow
=
334 border
.GetSizeForContentsSize(kContentSize
);
336 border
.set_arrow(BubbleBorder::NONE
);
337 const gfx::Size kTotalSizeWithNoArrow
=
338 border
.GetSizeForContentsSize(kContentSize
);
340 const int kBorderThickness
= border
.GetBorderThickness();
342 const int kArrowOffsetForHorizCenter
= kTotalSizeWithHorizArrow
.width() / 2;
343 const int kArrowOffsetForVertCenter
= kTotalSizeWithVertArrow
.height() / 2;
344 const int kArrowOffsetForNotCenter
=
345 kImages
->border_thickness
+ (kImages
->top_arrow
.width() / 2);
347 const int kArrowSize
=
348 kImages
->arrow_interior_thickness
+ BubbleBorder::kStroke
-
349 kImages
->arrow_thickness
;
351 const int kTopHorizArrowY
= kAnchor
.y() + kAnchor
.height() + kArrowSize
;
352 const int kBottomHorizArrowY
=
353 kAnchor
.y() - kArrowSize
- kTotalSizeWithHorizArrow
.height();
355 const int kLeftVertArrowX
= kAnchor
.x() + kAnchor
.width() + kArrowSize
;
356 const int kRightVertArrowX
=
357 kAnchor
.x() - kArrowSize
- kTotalSizeWithVertArrow
.width();
360 BubbleBorder::Arrow arrow
;
361 BubbleBorder::BubbleAlignment alignment
;
367 // Horizontal arrow tests.
368 { BubbleBorder::TOP_LEFT
, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR
,
369 kAnchor
.CenterPoint().x() - kArrowOffsetForNotCenter
, kTopHorizArrowY
},
370 { BubbleBorder::TOP_LEFT
, BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE
,
371 kAnchor
.x() + BubbleBorder::kStroke
- kBorderThickness
, kTopHorizArrowY
},
372 { BubbleBorder::TOP_CENTER
, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR
,
373 kAnchor
.CenterPoint().x() - kArrowOffsetForHorizCenter
, kTopHorizArrowY
},
374 { BubbleBorder::BOTTOM_RIGHT
, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR
,
375 kAnchor
.CenterPoint().x() + kArrowOffsetForNotCenter
-
376 kTotalSizeWithHorizArrow
.width(), kBottomHorizArrowY
},
377 { BubbleBorder::BOTTOM_RIGHT
, BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE
,
378 kAnchor
.x() + kAnchor
.width() - kTotalSizeWithHorizArrow
.width() +
379 kBorderThickness
- BubbleBorder::kStroke
, kBottomHorizArrowY
},
381 // Vertical arrow tests.
382 { BubbleBorder::LEFT_TOP
, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR
,
383 kLeftVertArrowX
, kAnchor
.CenterPoint().y() - kArrowOffsetForNotCenter
},
384 { BubbleBorder::LEFT_TOP
, BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE
,
385 kLeftVertArrowX
, kAnchor
.y() + BubbleBorder::kStroke
- kBorderThickness
},
386 { BubbleBorder::LEFT_CENTER
, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR
,
387 kLeftVertArrowX
, kAnchor
.CenterPoint().y() - kArrowOffsetForVertCenter
},
388 { BubbleBorder::RIGHT_BOTTOM
, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR
,
389 kRightVertArrowX
, kAnchor
.CenterPoint().y() + kArrowOffsetForNotCenter
-
390 kTotalSizeWithVertArrow
.height() },
391 { BubbleBorder::RIGHT_BOTTOM
, BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE
,
392 kRightVertArrowX
, kAnchor
.y() + kAnchor
.height() -
393 kTotalSizeWithVertArrow
.height() + kBorderThickness
-
394 BubbleBorder::kStroke
},
397 { BubbleBorder::NONE
, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR
,
398 kAnchor
.x() + (kAnchor
.width() - kTotalSizeWithNoArrow
.width()) / 2,
399 kAnchor
.y() + kAnchor
.height() },
400 { BubbleBorder::FLOAT
, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR
,
401 kAnchor
.x() + (kAnchor
.width() - kTotalSizeWithNoArrow
.width()) / 2,
402 kAnchor
.y() + (kAnchor
.height() - kTotalSizeWithNoArrow
.height()) / 2 },
405 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
406 SCOPED_TRACE(base::StringPrintf("i=%d arrow=%d alignment=%d",
407 static_cast<int>(i
), cases
[i
].arrow
, cases
[i
].alignment
));
408 border
.set_arrow(cases
[i
].arrow
);
409 border
.set_alignment(cases
[i
].alignment
);
411 gfx::Point origin
= border
.GetBounds(kAnchor
, kContentSize
).origin();
412 EXPECT_EQ(cases
[i
].expected_x
, origin
.x());
413 EXPECT_EQ(cases
[i
].expected_y
, origin
.y());
417 // Ensure all the shadow types pass some size validation and paint sanely.
418 TEST_F(BubbleBorderTest
, ShadowTypes
) {
419 const gfx::Rect
rect(0, 0, 320, 200);
421 paint_view
.SetBoundsRect(rect
);
423 for (int i
= 0; i
< BubbleBorder::SHADOW_COUNT
; ++i
) {
424 BubbleBorder::Shadow shadow
= static_cast<BubbleBorder::Shadow
>(i
);
425 SCOPED_TRACE(testing::Message() << "BubbleBorder::Shadow: " << shadow
);
426 gfx::Canvas
canvas(gfx::Size(640, 480), 1.0f
, false);
427 BubbleBorder
border(BubbleBorder::TOP_LEFT
, shadow
, SK_ColorWHITE
);
428 internal::BorderImages
* border_images
= border
.GetImagesForTest();
430 // Arrow assets should always be at least as big as the drawn arrow.
431 EXPECT_GE(border_images
->arrow_thickness
,
432 border_images
->arrow_interior_thickness
);
433 EXPECT_GE(border_images
->arrow_width
,
434 2 * border_images
->arrow_interior_thickness
);
436 // Border assets should always be at least as thick as the hittable border.
437 EXPECT_GE(border_images
->border_thickness
,
438 border_images
->border_interior_thickness
);
440 // For a TOP_LEFT arrow, the x-offset always matches the border thickness.
441 EXPECT_EQ(border
.GetArrowRect(rect
).x(), border_images
->border_thickness
);
442 border
.Paint(paint_view
, &canvas
);