• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "ui/views/bubble/bubble_border.h"
6 
7 #include "ui/views/test/views_test_base.h"
8 
9 namespace views {
10 
11 typedef ViewsTestBase BubbleBorderTest;
12 
TEST_F(BubbleBorderTest,GetMirroredArrow)13 TEST_F(BubbleBorderTest, GetMirroredArrow) {
14   // Horizontal mirroring.
15   EXPECT_EQ(BubbleBorder::TOP_RIGHT,
16             BubbleBorder::horizontal_mirror(BubbleBorder::TOP_LEFT));
17   EXPECT_EQ(BubbleBorder::TOP_LEFT,
18             BubbleBorder::horizontal_mirror(BubbleBorder::TOP_RIGHT));
19 
20   EXPECT_EQ(BubbleBorder::BOTTOM_RIGHT,
21             BubbleBorder::horizontal_mirror(BubbleBorder::BOTTOM_LEFT));
22   EXPECT_EQ(BubbleBorder::BOTTOM_LEFT,
23             BubbleBorder::horizontal_mirror(BubbleBorder::BOTTOM_RIGHT));
24 
25   EXPECT_EQ(BubbleBorder::RIGHT_TOP,
26             BubbleBorder::horizontal_mirror(BubbleBorder::LEFT_TOP));
27   EXPECT_EQ(BubbleBorder::LEFT_TOP,
28             BubbleBorder::horizontal_mirror(BubbleBorder::RIGHT_TOP));
29 
30   EXPECT_EQ(BubbleBorder::RIGHT_BOTTOM,
31             BubbleBorder::horizontal_mirror(BubbleBorder::LEFT_BOTTOM));
32   EXPECT_EQ(BubbleBorder::LEFT_BOTTOM,
33             BubbleBorder::horizontal_mirror(BubbleBorder::RIGHT_BOTTOM));
34 
35   EXPECT_EQ(BubbleBorder::TOP_CENTER,
36             BubbleBorder::horizontal_mirror(BubbleBorder::TOP_CENTER));
37   EXPECT_EQ(BubbleBorder::BOTTOM_CENTER,
38             BubbleBorder::horizontal_mirror(BubbleBorder::BOTTOM_CENTER));
39 
40   EXPECT_EQ(BubbleBorder::RIGHT_CENTER,
41             BubbleBorder::horizontal_mirror(BubbleBorder::LEFT_CENTER));
42   EXPECT_EQ(BubbleBorder::LEFT_CENTER,
43             BubbleBorder::horizontal_mirror(BubbleBorder::RIGHT_CENTER));
44 
45   EXPECT_EQ(BubbleBorder::NONE,
46             BubbleBorder::horizontal_mirror(BubbleBorder::NONE));
47   EXPECT_EQ(BubbleBorder::FLOAT,
48             BubbleBorder::horizontal_mirror(BubbleBorder::FLOAT));
49 
50   // Vertical mirroring.
51   EXPECT_EQ(BubbleBorder::BOTTOM_LEFT,
52             BubbleBorder::vertical_mirror(BubbleBorder::TOP_LEFT));
53   EXPECT_EQ(BubbleBorder::BOTTOM_RIGHT,
54             BubbleBorder::vertical_mirror(BubbleBorder::TOP_RIGHT));
55 
56   EXPECT_EQ(BubbleBorder::TOP_LEFT,
57             BubbleBorder::vertical_mirror(BubbleBorder::BOTTOM_LEFT));
58   EXPECT_EQ(BubbleBorder::TOP_RIGHT,
59             BubbleBorder::vertical_mirror(BubbleBorder::BOTTOM_RIGHT));
60 
61   EXPECT_EQ(BubbleBorder::LEFT_BOTTOM,
62             BubbleBorder::vertical_mirror(BubbleBorder::LEFT_TOP));
63   EXPECT_EQ(BubbleBorder::RIGHT_BOTTOM,
64             BubbleBorder::vertical_mirror(BubbleBorder::RIGHT_TOP));
65 
66   EXPECT_EQ(BubbleBorder::LEFT_TOP,
67             BubbleBorder::vertical_mirror(BubbleBorder::LEFT_BOTTOM));
68   EXPECT_EQ(BubbleBorder::RIGHT_TOP,
69             BubbleBorder::vertical_mirror(BubbleBorder::RIGHT_BOTTOM));
70 
71   EXPECT_EQ(BubbleBorder::BOTTOM_CENTER,
72             BubbleBorder::vertical_mirror(BubbleBorder::TOP_CENTER));
73   EXPECT_EQ(BubbleBorder::TOP_CENTER,
74             BubbleBorder::vertical_mirror(BubbleBorder::BOTTOM_CENTER));
75 
76   EXPECT_EQ(BubbleBorder::LEFT_CENTER,
77             BubbleBorder::vertical_mirror(BubbleBorder::LEFT_CENTER));
78   EXPECT_EQ(BubbleBorder::RIGHT_CENTER,
79             BubbleBorder::vertical_mirror(BubbleBorder::RIGHT_CENTER));
80 
81   EXPECT_EQ(BubbleBorder::NONE,
82             BubbleBorder::vertical_mirror(BubbleBorder::NONE));
83   EXPECT_EQ(BubbleBorder::FLOAT,
84             BubbleBorder::vertical_mirror(BubbleBorder::FLOAT));
85 }
86 
TEST_F(BubbleBorderTest,HasArrow)87 TEST_F(BubbleBorderTest, HasArrow) {
88   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::TOP_LEFT));
89   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::TOP_RIGHT));
90 
91   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::BOTTOM_LEFT));
92   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::BOTTOM_RIGHT));
93 
94   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::LEFT_TOP));
95   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::RIGHT_TOP));
96 
97   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::LEFT_BOTTOM));
98   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::RIGHT_BOTTOM));
99 
100   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::TOP_CENTER));
101   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::BOTTOM_CENTER));
102 
103   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::LEFT_CENTER));
104   EXPECT_TRUE(BubbleBorder::has_arrow(BubbleBorder::RIGHT_CENTER));
105 
106   EXPECT_FALSE(BubbleBorder::has_arrow(BubbleBorder::NONE));
107   EXPECT_FALSE(BubbleBorder::has_arrow(BubbleBorder::FLOAT));
108 }
109 
TEST_F(BubbleBorderTest,IsArrowOnLeft)110 TEST_F(BubbleBorderTest, IsArrowOnLeft) {
111   EXPECT_TRUE(BubbleBorder::is_arrow_on_left(BubbleBorder::TOP_LEFT));
112   EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::TOP_RIGHT));
113 
114   EXPECT_TRUE(BubbleBorder::is_arrow_on_left(BubbleBorder::BOTTOM_LEFT));
115   EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::BOTTOM_RIGHT));
116 
117   EXPECT_TRUE(BubbleBorder::is_arrow_on_left(BubbleBorder::LEFT_TOP));
118   EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::RIGHT_TOP));
119 
120   EXPECT_TRUE(BubbleBorder::is_arrow_on_left(BubbleBorder::LEFT_BOTTOM));
121   EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::RIGHT_BOTTOM));
122 
123   EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::TOP_CENTER));
124   EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::BOTTOM_CENTER));
125 
126   EXPECT_TRUE(BubbleBorder::is_arrow_on_left(BubbleBorder::LEFT_CENTER));
127   EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::RIGHT_CENTER));
128 
129   EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::NONE));
130   EXPECT_FALSE(BubbleBorder::is_arrow_on_left(BubbleBorder::FLOAT));
131 }
132 
TEST_F(BubbleBorderTest,IsArrowOnTop)133 TEST_F(BubbleBorderTest, IsArrowOnTop) {
134   EXPECT_TRUE(BubbleBorder::is_arrow_on_top(BubbleBorder::TOP_LEFT));
135   EXPECT_TRUE(BubbleBorder::is_arrow_on_top(BubbleBorder::TOP_RIGHT));
136 
137   EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::BOTTOM_LEFT));
138   EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::BOTTOM_RIGHT));
139 
140   EXPECT_TRUE(BubbleBorder::is_arrow_on_top(BubbleBorder::LEFT_TOP));
141   EXPECT_TRUE(BubbleBorder::is_arrow_on_top(BubbleBorder::RIGHT_TOP));
142 
143   EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::LEFT_BOTTOM));
144   EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::RIGHT_BOTTOM));
145 
146   EXPECT_TRUE(BubbleBorder::is_arrow_on_top(BubbleBorder::TOP_CENTER));
147   EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::BOTTOM_CENTER));
148 
149   EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::LEFT_CENTER));
150   EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::RIGHT_CENTER));
151 
152   EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::NONE));
153   EXPECT_FALSE(BubbleBorder::is_arrow_on_top(BubbleBorder::FLOAT));
154 }
155 
TEST_F(BubbleBorderTest,IsArrowOnHorizontal)156 TEST_F(BubbleBorderTest, IsArrowOnHorizontal) {
157   EXPECT_TRUE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::TOP_LEFT));
158   EXPECT_TRUE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::TOP_RIGHT));
159 
160   EXPECT_TRUE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::BOTTOM_LEFT));
161   EXPECT_TRUE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::BOTTOM_RIGHT));
162 
163   EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::LEFT_TOP));
164   EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::RIGHT_TOP));
165 
166   EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::LEFT_BOTTOM));
167   EXPECT_FALSE(
168       BubbleBorder::is_arrow_on_horizontal(BubbleBorder::RIGHT_BOTTOM));
169 
170   EXPECT_TRUE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::TOP_CENTER));
171   EXPECT_TRUE(
172       BubbleBorder::is_arrow_on_horizontal(BubbleBorder::BOTTOM_CENTER));
173 
174   EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::LEFT_CENTER));
175   EXPECT_FALSE(
176       BubbleBorder::is_arrow_on_horizontal(BubbleBorder::RIGHT_CENTER));
177 
178   EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::NONE));
179   EXPECT_FALSE(BubbleBorder::is_arrow_on_horizontal(BubbleBorder::FLOAT));
180 }
181 
TEST_F(BubbleBorderTest,IsArrowAtCenter)182 TEST_F(BubbleBorderTest, IsArrowAtCenter) {
183   EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::TOP_LEFT));
184   EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::TOP_RIGHT));
185 
186   EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::BOTTOM_LEFT));
187   EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::BOTTOM_RIGHT));
188 
189   EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::LEFT_TOP));
190   EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::RIGHT_TOP));
191 
192   EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::LEFT_BOTTOM));
193   EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::RIGHT_BOTTOM));
194 
195   EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::TOP_CENTER));
196   EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::BOTTOM_CENTER));
197 
198   EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::LEFT_CENTER));
199   EXPECT_TRUE(BubbleBorder::is_arrow_at_center(BubbleBorder::RIGHT_CENTER));
200 
201   EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::NONE));
202   EXPECT_FALSE(BubbleBorder::is_arrow_at_center(BubbleBorder::FLOAT));
203 }
204 
TEST_F(BubbleBorderTest,TestMinimalSize)205 TEST_F(BubbleBorderTest, TestMinimalSize) {
206   gfx::Rect anchor = gfx::Rect(100, 100, 20, 20);
207   gfx::Size contents = gfx::Size(10, 10);
208   BubbleBorder b1(BubbleBorder::RIGHT_TOP, BubbleBorder::NO_SHADOW, 0);
209 
210   // The height should be much bigger then the requested size + border and
211   // padding since it needs to be able to include the tip bitmap.
212   gfx::Rect visible_tip_1 = b1.GetBounds(anchor, contents);
213   EXPECT_GE(visible_tip_1.height(), 30);
214   EXPECT_LE(visible_tip_1.width(), 30);
215 
216   // With the tip being invisible the height should now be much smaller.
217   b1.set_paint_arrow(BubbleBorder::PAINT_TRANSPARENT);
218   gfx::Rect invisible_tip_1 = b1.GetBounds(anchor, contents);
219   EXPECT_LE(invisible_tip_1.height(), 30);
220   EXPECT_LE(invisible_tip_1.width(), 30);
221 
222   // When the orientation of the tip changes, the above mentioned tests need to
223   // be reverse for width and height.
224   BubbleBorder b2(BubbleBorder::TOP_RIGHT, BubbleBorder::NO_SHADOW, 0);
225 
226   // The width should be much bigger then the requested size + border and
227   // padding since it needs to be able to include the tip bitmap.
228   gfx::Rect visible_tip_2 = b2.GetBounds(anchor, contents);
229   EXPECT_GE(visible_tip_2.width(), 30);
230   EXPECT_LE(visible_tip_2.height(), 30);
231 
232   // With the tip being invisible the width should now be much smaller.
233   b2.set_paint_arrow(BubbleBorder::PAINT_TRANSPARENT);
234   gfx::Rect invisible_tip_2 = b2.GetBounds(anchor, contents);
235   EXPECT_LE(invisible_tip_2.width(), 30);
236   EXPECT_LE(invisible_tip_2.height(), 30);
237 }
238 
239 
240 }  // namespace views
241