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

Side by Side Diff: chrome/browser/ui/views/bubble/border_contents_unittest.cc

Issue 8754003: Move border_contents_unittest.cc to ui/views/bubble/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and merge. Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/ui/views/bubble/border_contents.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 typedef testing::Test BorderContentsTest;
9
10 class TestBorderContents : public BorderContents {
11 public:
12 TestBorderContents() {}
13
14 void set_monitor_bounds(const gfx::Rect& bounds) {
15 monitor_bounds_ = bounds;
16 }
17
18 views::BubbleBorder* bubble_border() const {
19 return BorderContents::bubble_border();
20 }
21
22 protected:
23 virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) {
24 return monitor_bounds_;
25 }
26
27 private:
28 gfx::Rect monitor_bounds_;
29
30 DISALLOW_COPY_AND_ASSIGN(TestBorderContents);
31 };
32
33 // Tests that the arrow is moved appropriately when the info-bubble does not fit
34 // the screen.
35 TEST_F(BorderContentsTest, BorderContentsSizeAndGetBounds) {
36 TestBorderContents border_contents;
37 border_contents.Init();
38
39 gfx::Insets insets;
40 border_contents.bubble_border()->GetInsets(&insets);
41 int xposition = 95 - insets.width();
42
43 // Test that the info bubble displays normally when it fits.
44 gfx::Rect contents_bounds;
45 gfx::Rect window_bounds;
46 border_contents.set_monitor_bounds(gfx::Rect(0, 0, 1000, 1000));
47 border_contents.SizeAndGetBounds(
48 gfx::Rect(100, 100, 50, 50), // |position_relative_to|
49 views::BubbleBorder::TOP_LEFT,
50 false, // |allow_bubble_offscreen|
51 gfx::Size(500, 500), // |contents_size|
52 &contents_bounds, &window_bounds);
53 // The arrow shouldn't have changed from TOP_LEFT.
54 views::BubbleBorder::ArrowLocation arrow_location =
55 border_contents.bubble_border()->arrow_location();
56 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
57 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location));
58 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location));
59 EXPECT_GT(window_bounds.x(), xposition);
60 EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for
61 // arrow overlap.
62
63 // Test bubble not fitting on left.
64 border_contents.SizeAndGetBounds(
65 gfx::Rect(100, 100, 50, 50), // |position_relative_to|
66 views::BubbleBorder::TOP_RIGHT,
67 false, // |allow_bubble_offscreen|
68 gfx::Size(500, 500), // |contents_size|
69 &contents_bounds, &window_bounds);
70 arrow_location = border_contents.bubble_border()->arrow_location();
71 // The arrow should have changed to TOP_LEFT.
72 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
73 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location));
74 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location));
75 EXPECT_GT(window_bounds.x(), xposition);
76 EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for
77 // arrow overlap.
78
79 // Test bubble not fitting on left or top.
80 border_contents.SizeAndGetBounds(
81 gfx::Rect(100, 100, 50, 50), // |position_relative_to|
82 views::BubbleBorder::BOTTOM_RIGHT,
83 false, // |allow_bubble_offscreen|
84 gfx::Size(500, 500), // |contents_size|
85 &contents_bounds, &window_bounds);
86 arrow_location = border_contents.bubble_border()->arrow_location();
87 // The arrow should have changed to TOP_LEFT.
88 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
89 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location));
90 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location));
91 EXPECT_GT(window_bounds.x(), xposition);
92 EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for
93 // arrow overlap.
94
95 // Test bubble not fitting on top.
96 border_contents.SizeAndGetBounds(
97 gfx::Rect(100, 100, 50, 50), // |position_relative_to|
98 views::BubbleBorder::BOTTOM_LEFT,
99 false, // |allow_bubble_offscreen|
100 gfx::Size(500, 500), // |contents_size|
101 &contents_bounds, &window_bounds);
102 arrow_location = border_contents.bubble_border()->arrow_location();
103 // The arrow should have changed to TOP_LEFT.
104 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
105 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location));
106 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location));
107 EXPECT_GT(window_bounds.x(), xposition);
108 EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for
109 // arrow overlap.
110
111 // Test bubble not fitting on top and right.
112 border_contents.SizeAndGetBounds(
113 gfx::Rect(900, 100, 50, 50), // |position_relative_to|
114 views::BubbleBorder::BOTTOM_LEFT,
115 false, // |allow_bubble_offscreen|
116 gfx::Size(500, 500), // |contents_size|
117 &contents_bounds, &window_bounds);
118 arrow_location = border_contents.bubble_border()->arrow_location();
119 // The arrow should have changed to TOP_RIGHT.
120 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
121 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location));
122 EXPECT_FALSE(views::BubbleBorder::is_arrow_on_left(arrow_location));
123 EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
124 EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for
125 // arrow overlap.
126
127 // Test bubble not fitting on right.
128 border_contents.SizeAndGetBounds(
129 gfx::Rect(900, 100, 50, 50), // |position_relative_to|
130 views::BubbleBorder::TOP_LEFT,
131 false, // |allow_bubble_offscreen|
132 gfx::Size(500, 500), // |contents_size|
133 &contents_bounds, &window_bounds);
134 arrow_location = border_contents.bubble_border()->arrow_location();
135 // The arrow should have changed to TOP_RIGHT.
136 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
137 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location));
138 EXPECT_FALSE(views::BubbleBorder::is_arrow_on_left(arrow_location));
139 EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
140 EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for
141 // arrow overlap.
142
143 // Test bubble not fitting on bottom and right.
144 border_contents.SizeAndGetBounds(
145 gfx::Rect(900, 900, 50, 50), // |position_relative_to|
146 views::BubbleBorder::TOP_LEFT,
147 false, // |allow_bubble_offscreen|
148 gfx::Size(500, 500), // |contents_size|
149 &contents_bounds, &window_bounds);
150 arrow_location = border_contents.bubble_border()->arrow_location();
151 // The arrow should have changed to BOTTOM_RIGHT.
152 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
153 EXPECT_FALSE(views::BubbleBorder::is_arrow_on_top(arrow_location));
154 EXPECT_FALSE(views::BubbleBorder::is_arrow_on_left(arrow_location));
155 EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
156 EXPECT_LT(window_bounds.y(), 900 - 500 - 15); // -15 to roughly compensate
157 // for arrow height.
158
159 // Test bubble not fitting at the bottom.
160 border_contents.SizeAndGetBounds(
161 gfx::Rect(100, 900, 50, 50), // |position_relative_to|
162 views::BubbleBorder::TOP_LEFT,
163 false, // |allow_bubble_offscreen|
164 gfx::Size(500, 500), // |contents_size|
165 &contents_bounds, &window_bounds);
166 arrow_location = border_contents.bubble_border()->arrow_location();
167 // The arrow should have changed to BOTTOM_LEFT.
168 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
169 EXPECT_FALSE(views::BubbleBorder::is_arrow_on_top(arrow_location));
170 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location));
171 // The window should be right aligned with the position_relative_to.
172 EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
173 EXPECT_LT(window_bounds.y(), 900 - 500 - 15); // -15 to roughly compensate
174 // for arrow height.
175
176 // Test bubble not fitting at the bottom and left.
177 border_contents.SizeAndGetBounds(
178 gfx::Rect(100, 900, 50, 50), // |position_relative_to|
179 views::BubbleBorder::TOP_RIGHT,
180 false, // |allow_bubble_offscreen|
181 gfx::Size(500, 500), // |contents_size|
182 &contents_bounds, &window_bounds);
183 arrow_location = border_contents.bubble_border()->arrow_location();
184 // The arrow should have changed to BOTTOM_LEFT.
185 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
186 EXPECT_FALSE(views::BubbleBorder::is_arrow_on_top(arrow_location));
187 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location));
188 // The window should be right aligned with the position_relative_to.
189 EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
190 EXPECT_LT(window_bounds.y(), 900 - 500 - 15); // -15 to roughly compensate
191 // for arrow height.
192 }
193
194 // Tests that the arrow is not moved when the info-bubble does not fit the
195 // screen but moving it would make matter worse.
196 TEST_F(BorderContentsTest, BorderContentsSizeAndGetBoundsDontMoveArrow) {
197 TestBorderContents border_contents;
198 border_contents.Init();
199 gfx::Rect contents_bounds;
200 gfx::Rect window_bounds;
201 border_contents.set_monitor_bounds(gfx::Rect(0, 0, 1000, 1000));
202 border_contents.SizeAndGetBounds(
203 gfx::Rect(400, 100, 50, 50), // |position_relative_to|
204 views::BubbleBorder::TOP_LEFT,
205 false, // |allow_bubble_offscreen|
206 gfx::Size(500, 700), // |contents_size|
207 &contents_bounds, &window_bounds);
208
209 // The arrow should not have changed, as it would make it the bubble even more
210 // offscreen.
211 views::BubbleBorder::ArrowLocation arrow_location =
212 border_contents.bubble_border()->arrow_location();
213 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
214 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location));
215 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location));
216 }
217
218 // Test that the 'allow offscreen' prevents the bubble from moving.
219 TEST_F(BorderContentsTest, BorderContentsSizeAndGetBoundsAllowOffscreen) {
220 TestBorderContents border_contents;
221 border_contents.Init();
222 gfx::Rect contents_bounds;
223 gfx::Rect window_bounds;
224 border_contents.set_monitor_bounds(gfx::Rect(0, 0, 1000, 1000));
225 border_contents.SizeAndGetBounds(
226 gfx::Rect(100, 900, 50, 50), // |position_relative_to|
227 views::BubbleBorder::TOP_RIGHT,
228 true, // |allow_bubble_offscreen|
229 gfx::Size(500, 500), // |contents_size|
230 &contents_bounds, &window_bounds);
231
232 // The arrow should not have changed (eventhough the bubble does not fit).
233 views::BubbleBorder::ArrowLocation arrow_location =
234 border_contents.bubble_border()->arrow_location();
235 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location));
236 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location));
237 EXPECT_FALSE(views::BubbleBorder::is_arrow_on_left(arrow_location));
238 // The coordinates should be pointing to 'positive relative to' from
239 // TOP_RIGHT.
240 EXPECT_LT(window_bounds.x(), 100 + 50 - 500);
241 EXPECT_GT(window_bounds.y(), 900 + 50 - 10); // -10 to roughly compensate for
242 // arrow overlap.
243 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698