OLD | NEW |
---|---|
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 "ui/views/bubble/bubble_border.h" | 5 #include "ui/views/bubble/bubble_border.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | |
7 #include "ui/views/test/views_test_base.h" | 8 #include "ui/views/test/views_test_base.h" |
8 | 9 |
9 namespace views { | 10 namespace views { |
10 | 11 |
11 typedef ViewsTestBase BubbleBorderTest; | 12 class BubbleBorderTest : public views::ViewsTestBase { |
13 public: | |
14 const int kStroke = views::BubbleBorder::kStroke; | |
15 | |
16 const gfx::Size kSmallSize = gfx::Size(1, 1); | |
17 const gfx::Size kMediumSize = gfx::Size(50, 50); | |
18 | |
19 const gfx::Rect kGetOriginAnchor = gfx::Rect(100, 100, 20, 20); | |
msw
2014/08/19 21:35:40
nit: rename this kAnchor.
bruthig
2014/08/22 19:45:04
Done.
| |
20 const gfx::Size kGetOriginContentsSize = gfx::Size(50, 50); | |
msw
2014/08/19 21:35:40
nit: remove this and just use kMediumSize.
bruthig
2014/08/22 19:45:04
Done.
| |
21 | |
22 BubbleBorderTest() {} | |
23 virtual ~BubbleBorderTest() {} | |
24 | |
25 protected: | |
26 // Sets the bubble alignment. | |
27 void SetAlignment(BubbleBorder::BubbleAlignment alignment) { | |
28 bubble_border_->set_alignment(alignment); | |
29 } | |
30 | |
31 // Sets the arrow paint type. | |
32 void SetPaintArrow(BubbleBorder::ArrowPaintType value) { | |
33 bubble_border_->set_paint_arrow(value); | |
34 } | |
35 | |
36 // Gets the arrow thickness. | |
37 int GetArrowThickness() const { | |
38 return bubble_border_->GetArrowThickness(); | |
39 } | |
40 | |
41 // Gets the top arrow width. | |
42 int GetTopArrowWidth() const { | |
43 return bubble_border_->GetTopArrowWidth(); | |
44 } | |
45 | |
46 // Gets the image border thickness. | |
47 int GetBorderThickness() const { | |
48 return bubble_border_->GetBorderThickness(); | |
49 } | |
50 | |
51 // Gets the border thickness. | |
52 int GetBorderExteriorThickness() const { | |
53 return bubble_border_->GetBorderExteriorThickness(); | |
54 } | |
55 | |
56 // Gets the border interior thickness. | |
57 int GetBorderInteriorThickness() const { | |
58 return bubble_border_->GetBorderInteriorThickness(); | |
59 } | |
60 | |
61 // Get the arrow size. | |
62 int GetArrowSize() const { | |
63 return bubble_border_->GetArrowSize(); | |
64 } | |
65 | |
66 // Returns true iff the bubble_border_ has an arrow. | |
67 bool HasArrow() { | |
68 return BubbleBorder::has_arrow(bubble_border_->arrow()); | |
69 } | |
70 | |
71 // Get the size for the given |contents_size|. | |
72 gfx::Size GetSizeForContentsSize( | |
73 const gfx::Size& contents_size) const { | |
74 return bubble_border_->GetSizeForContentsSize(contents_size); | |
75 } | |
76 | |
77 // Gets an origin point for the fixed kGetOriginAnchor and | |
msw
2014/08/19 21:35:40
This helper can be re-written as a static for indi
| |
78 // kGetOriginContentsSize. | |
79 gfx::Point GetOrigin() { | |
80 return bubble_border_->GetBounds(kGetOriginAnchor, | |
81 kGetOriginContentsSize).origin(); | |
82 } | |
83 | |
84 // Creates a new BubbleBorder instance with the given |arrow|. | |
85 void CreateBubbleBorder(BubbleBorder::Arrow arrow) { | |
86 bubble_border_.reset(new BubbleBorder(arrow, | |
87 BubbleBorder::NO_SHADOW, | |
88 SK_ColorWHITE)); | |
89 } | |
90 | |
91 // Creates a new BubbleBorder instance with the given |arrow|. | |
92 void CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::Arrow arrow, | |
93 int& arrow_offset, | |
94 gfx::Size& size_for_contents_size) { | |
95 bubble_border_.reset(new BubbleBorder(arrow, | |
msw
2014/08/19 21:35:40
Have individual tests just do this as needed:
co
| |
96 BubbleBorder::NO_SHADOW, | |
97 SK_ColorWHITE)); | |
98 size_for_contents_size = GetSizeForContentsSize(kGetOriginContentsSize); | |
99 arrow_offset = bubble_border_->GetArrowOffset(size_for_contents_size); | |
100 } | |
101 | |
102 private: | |
103 scoped_ptr<BubbleBorder> bubble_border_; | |
msw
2014/08/19 21:35:39
Remove this and wrappers; let each test construct
| |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(BubbleBorderTest); | |
106 }; | |
107 | |
108 typedef BubbleBorderTest BubbleBorderGetSizeForContentsSizeTest; | |
109 typedef BubbleBorderTest BubbleBorderGetBoundsOriginTest; | |
12 | 110 |
13 TEST_F(BubbleBorderTest, GetMirroredArrow) { | 111 TEST_F(BubbleBorderTest, GetMirroredArrow) { |
14 // Horizontal mirroring. | 112 // Horizontal mirroring. |
15 EXPECT_EQ(BubbleBorder::TOP_RIGHT, | 113 EXPECT_EQ(BubbleBorder::TOP_RIGHT, |
16 BubbleBorder::horizontal_mirror(BubbleBorder::TOP_LEFT)); | 114 BubbleBorder::horizontal_mirror(BubbleBorder::TOP_LEFT)); |
17 EXPECT_EQ(BubbleBorder::TOP_LEFT, | 115 EXPECT_EQ(BubbleBorder::TOP_LEFT, |
18 BubbleBorder::horizontal_mirror(BubbleBorder::TOP_RIGHT)); | 116 BubbleBorder::horizontal_mirror(BubbleBorder::TOP_RIGHT)); |
19 | 117 |
20 EXPECT_EQ(BubbleBorder::BOTTOM_RIGHT, | 118 EXPECT_EQ(BubbleBorder::BOTTOM_RIGHT, |
21 BubbleBorder::horizontal_mirror(BubbleBorder::BOTTOM_LEFT)); | 119 BubbleBorder::horizontal_mirror(BubbleBorder::BOTTOM_LEFT)); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::TOP_CENTER)); | 293 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::TOP_CENTER)); |
196 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::BOTTOM_CENTER)); | 294 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::BOTTOM_CENTER)); |
197 | 295 |
198 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::LEFT_CENTER)); | 296 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::LEFT_CENTER)); |
199 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::RIGHT_CENTER)); | 297 EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::RIGHT_CENTER)); |
200 | 298 |
201 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::NONE)); | 299 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::NONE)); |
202 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::FLOAT)); | 300 EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::FLOAT)); |
203 } | 301 } |
204 | 302 |
205 TEST_F(BubbleBorderTest, TestMinimalSize) { | 303 TEST_F(BubbleBorderGetSizeForContentsSizeTest, WithHorizontalTopArrow) { |
206 gfx::Rect anchor = gfx::Rect(100, 100, 20, 20); | 304 CreateBubbleBorder(BubbleBorder::TOP_CENTER); |
207 gfx::Size contents = gfx::Size(10, 10); | 305 |
208 BubbleBorder b1(BubbleBorder::RIGHT_TOP, BubbleBorder::NO_SHADOW, 0); | 306 gfx::Size size; |
209 | 307 |
210 // The height should be much bigger then the requested size + border and | 308 ASSERT_TRUE(HasArrow()); |
msw
2014/08/19 21:35:39
Nit move asserts like this directly after the Bord
| |
211 // padding since it needs to be able to include the tip bitmap. | 309 |
212 gfx::Rect visible_tip_1 = b1.GetBounds(anchor, contents); | 310 SetPaintArrow(BubbleBorder::PAINT_NORMAL); |
213 EXPECT_GE(visible_tip_1.height(), 30); | 311 size = GetSizeForContentsSize(kSmallSize); |
214 EXPECT_LE(visible_tip_1.width(), 30); | 312 EXPECT_EQ(2 * GetBorderThickness() + GetTopArrowWidth(), size.width()); |
215 | 313 EXPECT_EQ(GetBorderThickness() |
216 // With the tip being invisible the height should now be much smaller. | 314 + GetArrowThickness() |
217 b1.set_paint_arrow(BubbleBorder::PAINT_TRANSPARENT); | 315 + GetBorderInteriorThickness(), |
218 gfx::Rect invisible_tip_1 = b1.GetBounds(anchor, contents); | 316 size.height()); |
219 EXPECT_LE(invisible_tip_1.height(), 30); | 317 |
220 EXPECT_LE(invisible_tip_1.width(), 30); | 318 size = GetSizeForContentsSize(kMediumSize); |
221 | 319 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), |
222 // When the orientation of the tip changes, the above mentioned tests need to | 320 size.width()); |
223 // be reverse for width and height. | 321 EXPECT_EQ(kMediumSize.height() |
224 BubbleBorder b2(BubbleBorder::TOP_RIGHT, BubbleBorder::NO_SHADOW, 0); | 322 + GetBorderExteriorThickness() |
225 | 323 + GetArrowThickness(), |
226 // The width should be much bigger then the requested size + border and | 324 size.height()); |
227 // padding since it needs to be able to include the tip bitmap. | 325 |
228 gfx::Rect visible_tip_2 = b2.GetBounds(anchor, contents); | 326 SetPaintArrow(BubbleBorder::PAINT_TRANSPARENT); |
229 EXPECT_GE(visible_tip_2.width(), 30); | 327 size = GetSizeForContentsSize(kSmallSize); |
230 EXPECT_LE(visible_tip_2.height(), 30); | 328 EXPECT_EQ(2 * GetBorderThickness() + GetTopArrowWidth(), size.width()); |
231 | 329 EXPECT_EQ(GetBorderThickness() |
232 // With the tip being invisible the width should now be much smaller. | 330 + GetArrowThickness() |
233 b2.set_paint_arrow(BubbleBorder::PAINT_TRANSPARENT); | 331 + GetBorderInteriorThickness(), |
234 gfx::Rect invisible_tip_2 = b2.GetBounds(anchor, contents); | 332 size.height()); |
235 EXPECT_LE(invisible_tip_2.width(), 30); | 333 |
236 EXPECT_LE(invisible_tip_2.height(), 30); | 334 size = GetSizeForContentsSize(kMediumSize); |
237 } | 335 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), |
238 | 336 size.width()); |
337 EXPECT_EQ(kMediumSize.height() | |
338 + GetBorderExteriorThickness() | |
339 + GetArrowThickness(), | |
340 size.height()); | |
341 | |
342 SetPaintArrow(BubbleBorder::PAINT_NONE); | |
343 size = GetSizeForContentsSize(kSmallSize); | |
344 EXPECT_EQ(2 * GetBorderThickness(), size.width()); | |
345 EXPECT_EQ(2 * GetBorderThickness(), size.height()); | |
346 | |
347 size = GetSizeForContentsSize(kMediumSize); | |
348 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
349 size.width()); | |
350 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
351 size.height()); | |
352 } | |
353 | |
354 TEST_F(BubbleBorderGetSizeForContentsSizeTest, WithHorizontalBottomArrow) { | |
msw
2014/08/19 21:35:40
All the expected values should be the same for a t
bruthig
2014/08/20 15:01:28
Interesting, I stayed away from this approach beca
msw
2014/08/20 20:41:02
Yeah, SCOPED_TRACE and looping over similar test c
bruthig
2014/08/22 19:45:04
Done.
| |
355 CreateBubbleBorder(BubbleBorder::BOTTOM_CENTER); | |
356 | |
357 gfx::Size size; | |
358 | |
359 ASSERT_TRUE(HasArrow()); | |
360 | |
361 SetPaintArrow(BubbleBorder::PAINT_NORMAL); | |
362 size = GetSizeForContentsSize(kSmallSize); | |
363 EXPECT_EQ(2 * GetBorderThickness() + GetTopArrowWidth(), size.width()); | |
364 EXPECT_EQ(GetBorderThickness() | |
365 + GetArrowThickness() | |
366 + GetBorderInteriorThickness(), | |
367 size.height()); | |
368 | |
369 size = GetSizeForContentsSize(kMediumSize); | |
370 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
371 size.width()); | |
372 EXPECT_EQ(kMediumSize.height() | |
373 + GetBorderExteriorThickness() | |
374 + GetArrowThickness(), | |
375 size.height()); | |
376 | |
377 SetPaintArrow(BubbleBorder::PAINT_TRANSPARENT); | |
378 size = GetSizeForContentsSize(kSmallSize); | |
379 EXPECT_EQ(2 * GetBorderThickness() + GetTopArrowWidth(), size.width()); | |
380 EXPECT_EQ(GetBorderThickness() | |
381 + GetArrowThickness() | |
382 + GetBorderInteriorThickness(), | |
383 size.height()); | |
384 | |
385 size = GetSizeForContentsSize(kMediumSize); | |
386 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
387 size.width()); | |
388 EXPECT_EQ(kMediumSize.height() | |
389 + GetBorderExteriorThickness() | |
390 + GetArrowThickness(), | |
391 size.height()); | |
392 | |
393 SetPaintArrow(BubbleBorder::PAINT_NONE); | |
394 size = GetSizeForContentsSize(kSmallSize); | |
395 EXPECT_EQ(2 * GetBorderThickness(), size.width()); | |
396 EXPECT_EQ(2 * GetBorderThickness(), size.height()); | |
397 | |
398 size = GetSizeForContentsSize(kMediumSize); | |
399 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
400 size.width()); | |
401 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
402 size.height()); | |
403 } | |
404 | |
405 TEST_F(BubbleBorderGetSizeForContentsSizeTest, WithVerticalLeftArrow) { | |
406 CreateBubbleBorder(BubbleBorder::LEFT_CENTER); | |
407 | |
408 gfx::Size size; | |
409 | |
410 ASSERT_TRUE(HasArrow()); | |
411 | |
412 SetPaintArrow(BubbleBorder::PAINT_NORMAL); | |
413 size = GetSizeForContentsSize(kSmallSize); | |
414 EXPECT_EQ(GetBorderThickness() | |
415 + GetArrowThickness() | |
416 + GetBorderInteriorThickness(), | |
417 size.width()); | |
418 EXPECT_EQ(2 * GetBorderThickness() + GetTopArrowWidth(), size.height()); | |
419 | |
420 size = GetSizeForContentsSize(kMediumSize); | |
421 EXPECT_EQ(kMediumSize.height() | |
422 + GetBorderExteriorThickness() | |
423 + GetArrowThickness(), | |
424 size.width()); | |
425 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
426 size.height()); | |
427 | |
428 SetPaintArrow(BubbleBorder::PAINT_TRANSPARENT); | |
429 size = GetSizeForContentsSize(kSmallSize); | |
430 EXPECT_EQ(GetBorderThickness() | |
431 + GetArrowThickness() | |
432 + GetBorderInteriorThickness(), | |
433 size.width()); | |
434 EXPECT_EQ(2 * GetBorderThickness() + GetTopArrowWidth(), size.height()); | |
435 | |
436 size = GetSizeForContentsSize(kMediumSize); | |
437 EXPECT_EQ(kMediumSize.height() | |
438 + GetBorderExteriorThickness() | |
439 + GetArrowThickness(), | |
440 size.width()); | |
441 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
442 size.height()); | |
443 | |
444 SetPaintArrow(BubbleBorder::PAINT_NONE); | |
445 size = GetSizeForContentsSize(kSmallSize); | |
446 EXPECT_EQ(2 * GetBorderThickness(), size.width()); | |
447 EXPECT_EQ(2 * GetBorderThickness(), size.height()); | |
448 | |
449 size = GetSizeForContentsSize(kMediumSize); | |
450 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
451 size.width()); | |
452 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
453 size.height()); | |
454 } | |
455 | |
456 TEST_F(BubbleBorderGetSizeForContentsSizeTest, WithVerticalRightArrow) { | |
457 CreateBubbleBorder(BubbleBorder::RIGHT_CENTER); | |
458 | |
459 gfx::Size size; | |
460 | |
461 ASSERT_TRUE(HasArrow()); | |
462 | |
463 SetPaintArrow(BubbleBorder::PAINT_NORMAL); | |
464 size = GetSizeForContentsSize(kSmallSize); | |
465 EXPECT_EQ(GetBorderThickness() | |
466 + GetArrowThickness() | |
467 + GetBorderInteriorThickness(), | |
468 size.width()); | |
469 EXPECT_EQ(2 * GetBorderThickness() + GetTopArrowWidth(), size.height()); | |
470 | |
471 size = GetSizeForContentsSize(kMediumSize); | |
472 EXPECT_EQ(kMediumSize.height() | |
473 + GetBorderExteriorThickness() | |
474 + GetArrowThickness(), | |
475 size.width()); | |
476 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
477 size.height()); | |
478 | |
479 SetPaintArrow(BubbleBorder::PAINT_TRANSPARENT); | |
480 size = GetSizeForContentsSize(kSmallSize); | |
481 EXPECT_EQ(GetBorderThickness() | |
482 + GetArrowThickness() | |
483 + GetBorderInteriorThickness(), | |
484 size.width()); | |
485 EXPECT_EQ(2 * GetBorderThickness() + GetTopArrowWidth(), size.height()); | |
486 | |
487 size = GetSizeForContentsSize(kMediumSize); | |
488 EXPECT_EQ(kMediumSize.height() | |
489 + GetBorderExteriorThickness() | |
490 + GetArrowThickness(), | |
491 size.width()); | |
492 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
493 size.height()); | |
494 | |
495 SetPaintArrow(BubbleBorder::PAINT_NONE); | |
496 size = GetSizeForContentsSize(kSmallSize); | |
497 EXPECT_EQ(2 * GetBorderThickness(), size.width()); | |
498 EXPECT_EQ(2 * GetBorderThickness(), size.height()); | |
499 | |
500 size = GetSizeForContentsSize(kMediumSize); | |
501 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
502 size.width()); | |
503 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
504 size.height()); | |
505 } | |
506 | |
507 TEST_F(BubbleBorderGetSizeForContentsSizeTest, WithoutArrow) { | |
508 CreateBubbleBorder(BubbleBorder::NONE); | |
509 | |
510 gfx::Size size; | |
511 | |
512 ASSERT_FALSE(HasArrow()); | |
513 | |
514 SetPaintArrow(BubbleBorder::PAINT_NORMAL); | |
515 size = GetSizeForContentsSize(kSmallSize); | |
516 EXPECT_EQ(2 * GetBorderThickness(), size.width()); | |
517 EXPECT_EQ(2 * GetBorderThickness(), size.height()); | |
518 | |
519 size = GetSizeForContentsSize(kMediumSize); | |
520 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
521 size.width()); | |
522 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
523 size.height()); | |
524 | |
525 SetPaintArrow(BubbleBorder::PAINT_TRANSPARENT); | |
526 size = GetSizeForContentsSize(kSmallSize); | |
527 EXPECT_EQ(2 * GetBorderThickness(), size.width()); | |
528 EXPECT_EQ(2 * GetBorderThickness(), size.height()); | |
529 | |
530 size = GetSizeForContentsSize(kMediumSize); | |
531 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
532 size.width()); | |
533 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
534 size.height()); | |
535 | |
536 SetPaintArrow(BubbleBorder::PAINT_NONE); | |
537 size = GetSizeForContentsSize(kSmallSize); | |
538 EXPECT_EQ(2 * GetBorderThickness(), size.width()); | |
539 EXPECT_EQ(2 * GetBorderThickness(), size.height()); | |
540 | |
541 size = GetSizeForContentsSize(kMediumSize); | |
542 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
543 size.width()); | |
544 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
545 size.height()); | |
546 } | |
547 | |
548 | |
549 TEST_F(BubbleBorderGetSizeForContentsSizeTest, WithFloatArrow) { | |
550 CreateBubbleBorder(BubbleBorder::FLOAT); | |
551 | |
552 gfx::Size size; | |
553 | |
554 ASSERT_FALSE(HasArrow()); | |
555 | |
556 SetPaintArrow(BubbleBorder::PAINT_NORMAL); | |
557 size = GetSizeForContentsSize(kSmallSize); | |
558 EXPECT_EQ(2 * GetBorderThickness(), size.width()); | |
559 EXPECT_EQ(2 * GetBorderThickness(), size.height()); | |
560 | |
561 size = GetSizeForContentsSize(kMediumSize); | |
562 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
563 size.width()); | |
564 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
565 size.height()); | |
566 | |
567 SetPaintArrow(BubbleBorder::PAINT_TRANSPARENT); | |
568 size = GetSizeForContentsSize(kSmallSize); | |
569 EXPECT_EQ(2 * GetBorderThickness(), size.width()); | |
570 EXPECT_EQ(2 * GetBorderThickness(), size.height()); | |
571 | |
572 size = GetSizeForContentsSize(kMediumSize); | |
573 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
574 size.width()); | |
575 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
576 size.height()); | |
577 | |
578 SetPaintArrow(BubbleBorder::PAINT_NONE); | |
579 size = GetSizeForContentsSize(kSmallSize); | |
580 EXPECT_EQ(2 * GetBorderThickness(), size.width()); | |
581 EXPECT_EQ(2 * GetBorderThickness(), size.height()); | |
582 | |
583 size = GetSizeForContentsSize(kMediumSize); | |
584 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
585 size.width()); | |
586 EXPECT_EQ(kMediumSize.width() + 2 * GetBorderExteriorThickness(), | |
587 size.height()); | |
588 } | |
589 | |
590 TEST_F(BubbleBorderGetBoundsOriginTest, ArrowIsHorizontalLeft) { | |
msw
2014/08/19 21:35:40
Ditto request to remove similar test cases or cons
bruthig
2014/08/22 19:45:04
Done.
| |
591 int arrow_offset; | |
592 gfx::Size size_for_contents_size; | |
593 CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::TOP_LEFT, | |
594 arrow_offset, | |
595 size_for_contents_size); | |
596 | |
597 gfx::Point origin; | |
598 | |
599 SetAlignment(BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR); | |
600 origin = GetOrigin(); | |
601 EXPECT_EQ(kGetOriginAnchor.x() + kGetOriginAnchor.width() / 2 - arrow_offset, | |
602 origin.x()); | |
603 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height() + GetArrowSize(), | |
604 origin.y()); | |
605 | |
606 SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
607 origin = GetOrigin(); | |
608 EXPECT_EQ(kGetOriginAnchor.x() + kStroke - GetBorderExteriorThickness(), | |
609 origin.x()); | |
610 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height() + GetArrowSize(), | |
611 origin.y()); | |
612 } | |
613 | |
614 TEST_F(BubbleBorderGetBoundsOriginTest, ArrowIsHorizontalCenter) { | |
615 int arrow_offset; | |
616 gfx::Size size_for_contents_size; | |
617 CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::TOP_CENTER, | |
618 arrow_offset, | |
619 size_for_contents_size); | |
620 | |
621 gfx::Point origin; | |
622 | |
623 SetAlignment(BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR); | |
624 origin = GetOrigin(); | |
625 EXPECT_EQ(kGetOriginAnchor.x() + kGetOriginAnchor.width() / 2 - arrow_offset, | |
626 origin.x()); | |
627 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height() + GetArrowSize(), | |
628 origin.y()); | |
629 | |
630 SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
631 origin = GetOrigin(); | |
632 EXPECT_EQ(kGetOriginAnchor.x() + kGetOriginAnchor.width() / 2 - arrow_offset, | |
633 origin.x()); | |
634 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height() + GetArrowSize(), | |
635 origin.y()); | |
636 } | |
637 | |
638 TEST_F(BubbleBorderGetBoundsOriginTest, ArrowIsHorizontalRight) { | |
639 int arrow_offset; | |
640 gfx::Size size_for_contents_size; | |
641 CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::TOP_RIGHT, | |
642 arrow_offset, | |
643 size_for_contents_size); | |
644 | |
645 gfx::Point origin; | |
646 | |
647 SetAlignment(BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR); | |
648 origin = GetOrigin(); | |
649 EXPECT_EQ(kGetOriginAnchor.x() | |
650 + kGetOriginAnchor.width() / 2 | |
651 + arrow_offset | |
652 - size_for_contents_size.width(), | |
653 origin.x()); | |
654 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height() + GetArrowSize(), | |
655 origin.y()); | |
656 | |
657 SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
658 origin = GetOrigin(); | |
659 EXPECT_EQ(kGetOriginAnchor.x() | |
660 + kGetOriginAnchor.width() | |
661 - size_for_contents_size.width() | |
662 + GetBorderExteriorThickness() | |
663 - kStroke, | |
664 origin.x()); | |
665 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height() + GetArrowSize(), | |
666 origin.y()); | |
667 } | |
668 | |
669 TEST_F(BubbleBorderGetBoundsOriginTest, ArrowIsHorizontalBottom) { | |
670 int arrow_offset; | |
671 gfx::Size size_for_contents_size; | |
672 CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::BOTTOM_LEFT, | |
673 arrow_offset, | |
674 size_for_contents_size); | |
675 | |
676 gfx::Point origin; | |
677 | |
678 SetAlignment(BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR); | |
679 origin = GetOrigin(); | |
680 EXPECT_EQ(kGetOriginAnchor.y() | |
681 - GetArrowSize() | |
682 - size_for_contents_size.height(), | |
683 origin.y()); | |
684 | |
685 SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
686 origin = GetOrigin(); | |
687 EXPECT_EQ(kGetOriginAnchor.y() | |
688 - GetArrowSize() | |
689 - size_for_contents_size.height(), | |
690 origin.y()); | |
691 } | |
692 | |
693 TEST_F(BubbleBorderGetBoundsOriginTest, ArrowIsVerticalTop) { | |
694 int arrow_offset; | |
695 gfx::Size size_for_contents_size; | |
696 CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::LEFT_TOP, | |
697 arrow_offset, | |
698 size_for_contents_size); | |
699 | |
700 gfx::Point origin; | |
701 | |
702 SetAlignment(BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR); | |
703 origin = GetOrigin(); | |
704 EXPECT_EQ(kGetOriginAnchor.x() | |
705 + kGetOriginAnchor.width() | |
706 + GetArrowSize(), | |
707 origin.x()); | |
708 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height() / 2 - arrow_offset, | |
709 origin.y()); | |
710 | |
711 SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
712 origin = GetOrigin(); | |
713 EXPECT_EQ(kGetOriginAnchor.x() + kGetOriginAnchor.width() + GetArrowSize(), | |
714 origin.x()); | |
715 EXPECT_EQ(kGetOriginAnchor.y() + kStroke - GetBorderExteriorThickness(), | |
716 origin.y()); | |
717 } | |
718 | |
719 TEST_F(BubbleBorderGetBoundsOriginTest, ArrowIsVerticalCenter) { | |
720 int arrow_offset; | |
721 gfx::Size size_for_contents_size; | |
722 CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::LEFT_CENTER, | |
723 arrow_offset, | |
724 size_for_contents_size); | |
725 | |
726 gfx::Point origin; | |
727 | |
728 SetAlignment(BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR); | |
729 origin = GetOrigin(); | |
730 EXPECT_EQ(kGetOriginAnchor.x() + kGetOriginAnchor.width() + GetArrowSize(), | |
731 origin.x()); | |
732 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height() / 2 - arrow_offset, | |
733 origin.y()); | |
734 | |
735 SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
736 origin = GetOrigin(); | |
737 EXPECT_EQ(kGetOriginAnchor.x() + kGetOriginAnchor.width() + GetArrowSize(), | |
738 origin.x()); | |
739 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height() / 2 - arrow_offset, | |
740 origin.y()); | |
741 } | |
742 | |
743 TEST_F(BubbleBorderGetBoundsOriginTest, ArrowIsVerticalBottom) { | |
744 int arrow_offset; | |
745 gfx::Size size_for_contents_size; | |
746 CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::LEFT_BOTTOM, | |
747 arrow_offset, | |
748 size_for_contents_size); | |
749 | |
750 gfx::Point origin; | |
751 | |
752 SetAlignment(BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR); | |
753 origin = GetOrigin(); | |
754 EXPECT_EQ(kGetOriginAnchor.x() | |
755 + kGetOriginAnchor.width() | |
756 + GetArrowSize(), | |
757 origin.x()); | |
758 EXPECT_EQ(kGetOriginAnchor.y() | |
759 + kGetOriginAnchor.height() / 2 | |
760 + arrow_offset | |
761 - size_for_contents_size.height(), | |
762 origin.y()); | |
763 | |
764 SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
765 origin = GetOrigin(); | |
766 EXPECT_EQ(kGetOriginAnchor.x() + kGetOriginAnchor.width() + GetArrowSize(), | |
767 origin.x()); | |
768 EXPECT_EQ(kGetOriginAnchor.y() | |
769 + kGetOriginAnchor.height() | |
770 - size_for_contents_size.height() | |
771 + GetBorderExteriorThickness() | |
772 - kStroke, | |
773 origin.y()); | |
774 } | |
775 | |
776 TEST_F(BubbleBorderGetBoundsOriginTest, ArrowIsVerticalRight) { | |
777 int arrow_offset; | |
778 gfx::Size size_for_contents_size; | |
779 CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::RIGHT_CENTER, | |
780 arrow_offset, | |
781 size_for_contents_size); | |
782 | |
783 gfx::Point origin; | |
784 | |
785 SetAlignment(BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR); | |
786 origin = GetOrigin(); | |
787 EXPECT_EQ(kGetOriginAnchor.x() | |
788 - GetArrowSize() | |
789 - size_for_contents_size.width(), | |
790 origin.x()); | |
791 | |
792 SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
793 origin = GetOrigin(); | |
794 EXPECT_EQ(kGetOriginAnchor.x() | |
795 - GetArrowSize() | |
796 - size_for_contents_size.width(), | |
797 origin.x()); | |
798 } | |
799 | |
800 TEST_F(BubbleBorderGetBoundsOriginTest, ArrowIsNone) { | |
801 int arrow_offset; | |
802 gfx::Size size_for_contents_size; | |
803 CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::NONE, | |
804 arrow_offset, | |
805 size_for_contents_size); | |
806 | |
807 gfx::Point origin; | |
808 | |
809 SetAlignment(BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR); | |
810 origin = GetOrigin(); | |
811 EXPECT_EQ(kGetOriginAnchor.x() | |
812 + (kGetOriginAnchor.width() - size_for_contents_size.width()) / 2, | |
813 origin.x()); | |
814 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height(), origin.y()); | |
815 | |
816 SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
817 origin = GetOrigin(); | |
818 EXPECT_EQ(kGetOriginAnchor.x() | |
819 + (kGetOriginAnchor.width() - size_for_contents_size.width()) / 2, | |
820 origin.x()); | |
821 EXPECT_EQ(kGetOriginAnchor.y() + kGetOriginAnchor.height(), origin.y()); | |
822 } | |
823 | |
824 TEST_F(BubbleBorderGetBoundsOriginTest, ArrowIsFloat) { | |
825 int arrow_offset; | |
826 gfx::Size size_for_contents_size; | |
827 CreateBubbleBorderForGetBoundsOrginTest(BubbleBorder::FLOAT, | |
828 arrow_offset, | |
829 size_for_contents_size); | |
830 | |
831 gfx::Point origin; | |
832 | |
833 SetAlignment(BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR); | |
834 origin = GetOrigin(); | |
835 EXPECT_EQ(kGetOriginAnchor.x() | |
836 + (kGetOriginAnchor.width() | |
837 - size_for_contents_size.width()) / 2, | |
838 origin.x()); | |
839 EXPECT_EQ(kGetOriginAnchor.y() | |
840 + (kGetOriginAnchor.height() | |
841 - size_for_contents_size.height()) / 2, | |
842 origin.y()); | |
843 | |
844 SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
845 origin = GetOrigin(); | |
846 EXPECT_EQ(kGetOriginAnchor.x() | |
847 + (kGetOriginAnchor.width() - size_for_contents_size.width()) / 2, | |
848 origin.x()); | |
849 EXPECT_EQ(kGetOriginAnchor.y() | |
850 + (kGetOriginAnchor.height() | |
851 - size_for_contents_size.height()) / 2, | |
852 origin.y()); | |
853 } | |
239 | 854 |
240 } // namespace views | 855 } // namespace views |
OLD | NEW |