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 "ash/system/tray/system_tray.h" | 5 #include "ash/system/tray/system_tray.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/accelerators/accelerator_controller.h" | 10 #include "ash/accelerators/accelerator_controller.h" |
11 #include "ash/accessibility_delegate.h" | 11 #include "ash/accessibility_delegate.h" |
12 #include "ash/public/cpp/shell_window_ids.h" | 12 #include "ash/public/cpp/shell_window_ids.h" |
13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
14 #include "ash/shelf/shelf.h" | 14 #include "ash/shelf/shelf.h" |
15 #include "ash/shelf/shelf_widget.h" | |
15 #include "ash/shell.h" | 16 #include "ash/shell.h" |
16 #include "ash/system/status_area_widget.h" | 17 #include "ash/system/status_area_widget.h" |
17 #include "ash/system/tray/system_tray_bubble.h" | 18 #include "ash/system/tray/system_tray_bubble.h" |
18 #include "ash/system/tray/system_tray_item.h" | 19 #include "ash/system/tray/system_tray_item.h" |
19 #include "ash/system/tray/tray_constants.h" | 20 #include "ash/system/tray/tray_constants.h" |
20 #include "ash/system/web_notification/web_notification_tray.h" | 21 #include "ash/system/web_notification/web_notification_tray.h" |
21 #include "ash/test/ash_test_base.h" | 22 #include "ash/test/ash_test_base.h" |
22 #include "ash/test/status_area_widget_test_helper.h" | 23 #include "ash/test/status_area_widget_test_helper.h" |
23 #include "ash/test/test_system_tray_item.h" | 24 #include "ash/test/test_system_tray_item.h" |
25 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
24 #include "ash/wm/window_util.h" | 26 #include "ash/wm/window_util.h" |
25 #include "base/memory/ptr_util.h" | 27 #include "base/memory/ptr_util.h" |
26 #include "base/run_loop.h" | 28 #include "base/run_loop.h" |
27 #include "base/test/histogram_tester.h" | 29 #include "base/test/histogram_tester.h" |
28 #include "ui/base/ui_base_types.h" | 30 #include "ui/base/ui_base_types.h" |
29 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 31 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
30 #include "ui/events/test/event_generator.h" | 32 #include "ui/events/test/event_generator.h" |
31 #include "ui/gfx/geometry/point.h" | 33 #include "ui/gfx/geometry/point.h" |
32 #include "ui/gfx/geometry/rect.h" | 34 #include "ui/gfx/geometry/rect.h" |
33 #include "ui/views/controls/separator.h" | 35 #include "ui/views/controls/separator.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
49 ~ModalWidgetDelegate() override {} | 51 ~ModalWidgetDelegate() override {} |
50 | 52 |
51 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; } | 53 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; } |
52 | 54 |
53 private: | 55 private: |
54 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); | 56 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); |
55 }; | 57 }; |
56 | 58 |
57 } // namespace | 59 } // namespace |
58 | 60 |
59 typedef AshTestBase SystemTrayTest; | 61 class SystemTrayTest : public AshTestBase { |
62 public: | |
63 SystemTrayTest() {} | |
64 ~SystemTrayTest() override {} | |
65 | |
66 // Swiping on the system tray and ends with finger released. | |
67 void SendGestureEvent(gfx::Point& start, | |
68 float delta, | |
69 bool is_fling, | |
70 float velocity_y) { | |
71 SystemTray* system_tray = GetPrimarySystemTray(); | |
72 base::TimeTicks timestamp = base::TimeTicks::Now(); | |
73 SendScrollStartAndUpdate(start, delta, timestamp); | |
74 | |
75 ui::GestureEventDetails details = | |
76 is_fling | |
77 ? ui::GestureEventDetails(ui::ET_SCROLL_FLING_START, 0, velocity_y) | |
78 : ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END); | |
79 ui::GestureEvent event = ui::GestureEvent(start.x(), start.y() + delta, | |
80 ui::EF_NONE, timestamp, details); | |
81 system_tray->OnGestureEvent(&event); | |
82 } | |
83 | |
84 // Swiping on the system tray without releasing the finger. | |
85 void SendScrollStartAndUpdate(gfx::Point& start, | |
86 float delta, | |
87 base::TimeTicks& timestamp) { | |
88 SystemTray* system_tray = GetPrimarySystemTray(); | |
89 ui::GestureEventDetails begin_details(ui::ET_GESTURE_SCROLL_BEGIN); | |
90 ui::GestureEvent begin_event = ui::GestureEvent( | |
91 start.x(), start.y(), ui::EF_NONE, timestamp, begin_details); | |
92 system_tray->OnGestureEvent(&begin_event); | |
93 | |
94 ui::GestureEventDetails update_details(ui::ET_GESTURE_SCROLL_UPDATE, 0, | |
95 delta); | |
96 timestamp += base::TimeDelta::FromMilliseconds(100); | |
97 ui::GestureEvent update_event = ui::GestureEvent( | |
98 start.x(), start.y() + delta, ui::EF_NONE, timestamp, update_details); | |
99 system_tray->OnGestureEvent(&update_event); | |
100 } | |
101 | |
102 // Open the default system tray bubble to get the height of the bubble and | |
103 // then close it. | |
104 float GetSystemBubbleHeight() { | |
105 SystemTray* system_tray = GetPrimarySystemTray(); | |
106 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
107 gfx::Rect bounds = GetSystemBubbleBoundsInScreen(); | |
108 system_tray->CloseSystemBubble(); | |
109 return bounds.height(); | |
110 } | |
111 | |
112 gfx::Rect GetSystemBubbleBoundsInScreen() { | |
113 return GetPrimarySystemTray() | |
114 ->GetSystemBubble() | |
115 ->bubble_view() | |
116 ->GetWidget() | |
117 ->GetWindowBoundsInScreen(); | |
118 } | |
119 | |
120 private: | |
121 DISALLOW_COPY_AND_ASSIGN(SystemTrayTest); | |
122 }; | |
123 | |
124 // Swiping on the overlap area of shelf and system tray bubble during the | |
125 // animation should close the bubble. | |
126 TEST_F(SystemTrayTest, SwipingOnShelfDuringAnimation) { | |
tdanderson
2017/06/26 18:13:02
Awesome, thanks for adding this
| |
127 Shelf* shelf = GetPrimaryShelf(); | |
128 SystemTray* system_tray = GetPrimarySystemTray(); | |
129 gfx::Point start = system_tray->GetLocalBounds().CenterPoint(); | |
130 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
131 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
132 true); | |
133 | |
134 gfx::Rect shelf_bounds_in_screen = | |
135 shelf->shelf_widget()->GetWindowBoundsInScreen(); | |
136 | |
137 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
138 gfx::Rect original_bounds = GetSystemBubbleBoundsInScreen(); | |
139 system_tray->CloseSystemBubble(); | |
140 | |
141 // Enable animations so that we can make sure that they occur. | |
142 ui::ScopedAnimationDurationScaleMode regular_animations( | |
143 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | |
144 | |
145 ui::test::EventGenerator& generator = GetEventGenerator(); | |
146 gfx::Point point_on_shelf_start = | |
147 gfx::Point(original_bounds.x() + 5, shelf_bounds_in_screen.y() + 5); | |
148 gfx::Point point_on_shelf_end(point_on_shelf_start.x(), | |
149 shelf_bounds_in_screen.bottom()); | |
150 | |
151 // Swiping up exceed one third of the height of the bubble should show the | |
152 // bubble. | |
153 float delta = -original_bounds.height() / 2; | |
154 SendGestureEvent(start, delta, false, 0); | |
155 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
156 gfx::Rect current_bounds = GetSystemBubbleBoundsInScreen(); | |
tdanderson
2017/06/26 18:13:02
nit: newlines after lines 156, 164, 168 (before co
minch1
2017/06/26 23:26:48
Done.
| |
157 // Dragging the shelf during up animation should close the bubble. | |
158 if (current_bounds.y() != original_bounds.y()) { | |
159 generator.GestureScrollSequence(point_on_shelf_start, point_on_shelf_end, | |
160 base::TimeDelta::FromMilliseconds(100), 5); | |
161 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
162 } | |
163 | |
164 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
165 // Fling down on the shelf with a velocity that exceeds |kFlingVelocity|. | |
166 SendGestureEvent(start, delta, true, SystemTray::kFlingVelocity + 1); | |
167 current_bounds = GetSystemBubbleBoundsInScreen(); | |
168 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
169 // Dragging the shelf during down animation should close the bubble. | |
170 if (current_bounds.y() != original_bounds.y()) { | |
171 generator.GestureScrollSequence(point_on_shelf_start, point_on_shelf_end, | |
172 base::TimeDelta::FromMilliseconds(100), 5); | |
173 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
174 } | |
175 } | |
176 | |
177 // Swiping on the system tray ends with fling event. | |
178 TEST_F(SystemTrayTest, FlingOnSystemTray) { | |
179 Shelf* shelf = GetPrimaryShelf(); | |
180 SystemTray* system_tray = GetPrimarySystemTray(); | |
181 gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint(); | |
182 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
183 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
184 true); | |
185 | |
186 // Fling up on the system tray should show the bubble if the |velocity_y| is | |
187 // larger than |kFlingVelocity| and the dragging amount is larger than one | |
188 // third of the height of the bubble. | |
189 float delta = -GetSystemBubbleHeight(); | |
190 SendGestureEvent(start, delta, true, -(SystemTray::kFlingVelocity + 1)); | |
191 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
192 system_tray->CloseSystemBubble(); | |
193 | |
194 // Fling up on the system tray should show the bubble if the |velocity_y| is | |
195 // larger than |kFlingVelocity| even the dragging amount is less than one | |
196 // third of the height of the bubble. | |
197 delta /= 4; | |
198 SendGestureEvent(start, delta, true, -(SystemTray::kFlingVelocity + 1)); | |
199 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
200 system_tray->CloseSystemBubble(); | |
201 | |
202 // Fling up on the system tray should show the bubble if the |velocity_y| is | |
203 // less than |kFlingVelocity| but the dragging amount if larger than one third | |
204 // of the height of the bubble. | |
205 delta = -GetSystemBubbleHeight(); | |
206 SendGestureEvent(start, delta, true, -(SystemTray::kFlingVelocity - 1)); | |
207 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
208 system_tray->CloseSystemBubble(); | |
209 | |
210 // Fling up on the system tray should close the bubble if the |velocity_y| | |
211 // is less than |kFlingVelocity| and the dragging amount is less than one | |
212 // third of the height of the bubble. | |
213 delta /= 4; | |
214 SendGestureEvent(start, delta, true, -(SystemTray::kFlingVelocity - 1)); | |
215 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
216 | |
217 // Fling down on the system tray should close the bubble if the |velocity_y| | |
218 // is larger than kFLingVelocity. | |
219 SendGestureEvent(start, delta, true, SystemTray::kFlingVelocity + 1); | |
220 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
221 | |
222 // Fling down on the system tray should close the bubble if the |velocity_y| | |
223 // is larger than |kFlingVelocity| even the dragging amount is larger than one | |
224 // third of the height of the bubble. | |
225 delta = -GetSystemBubbleHeight(); | |
226 SendGestureEvent(start, delta, true, SystemTray::kFlingVelocity + 1); | |
227 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
228 | |
229 // Fling down on the system tray should open the bubble if the |velocity_y| is | |
230 // less than |kFlingVelocity| but the dragging amount exceed one third of the | |
231 // height of the bubble. | |
232 SendGestureEvent(start, delta, true, SystemTray::kFlingVelocity - 1); | |
233 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
234 system_tray->CloseSystemBubble(); | |
235 | |
236 // Fling down on the system tray should close the bubble if the |velocity_y| | |
237 // is less than |kFlingVelocity| and the dragging amount is less than one | |
238 // third of the height of the bubble. | |
239 delta /= 4; | |
240 SendGestureEvent(start, delta, true, SystemTray::kFlingVelocity - 1); | |
241 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
242 } | |
243 | |
244 // Touch outside the system tray bubble during swiping should close the bubble. | |
245 TEST_F(SystemTrayTest, TapOutsideCloseBubble) { | |
246 Shelf* shelf = GetPrimaryShelf(); | |
247 SystemTray* system_tray = GetPrimarySystemTray(); | |
248 gfx::Point start = system_tray->GetLocalBounds().CenterPoint(); | |
249 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
250 | |
251 float delta = -GetSystemBubbleHeight(); | |
252 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
253 true); | |
254 base::TimeTicks timestamp = base::TimeTicks::Now(); | |
255 SendScrollStartAndUpdate(start, delta, timestamp); | |
256 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
257 | |
258 ui::test::EventGenerator& generator = GetEventGenerator(); | |
259 gfx::Rect bounds = GetSystemBubbleBoundsInScreen(); | |
260 gfx::Point point_outside = gfx::Point(bounds.x() - 5, bounds.y() - 5); | |
261 generator.GestureTapAt(point_outside); | |
262 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
263 } | |
264 | |
265 // Swiping on the system tray ends with scroll event. | |
266 TEST_F(SystemTrayTest, SwipingOnSystemTray) { | |
267 Shelf* shelf = GetPrimaryShelf(); | |
268 SystemTray* system_tray = GetPrimarySystemTray(); | |
269 gfx::Point start = system_tray->GetLocalBounds().CenterPoint(); | |
270 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
271 | |
272 // Swiping up on the system tray has no effect if it is not in maximize mode. | |
273 float delta = -GetSystemBubbleHeight(); | |
274 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
275 false); | |
276 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
277 SendGestureEvent(start, delta, false, 0); | |
278 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
279 | |
280 // Swiping up on the system tray should show the system tray bubble if it is | |
281 // in maximize mode. | |
282 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
283 true); | |
284 SendGestureEvent(start, delta, false, 0); | |
285 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
286 system_tray->CloseSystemBubble(); | |
287 | |
288 // Swiping up less than one third of the bubble's height should not show the | |
289 // bubble. | |
290 delta /= 4; | |
291 SendGestureEvent(start, delta, false, 0); | |
292 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
293 | |
294 // Swiping up more than one third of the bubble's height should show the | |
295 // bubble. | |
296 delta = -GetSystemBubbleHeight() / 2; | |
297 SendGestureEvent(start, delta, false, 0); | |
298 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
299 system_tray->CloseSystemBubble(); | |
300 | |
301 // Swiping up on system tray should not show the system tray bubble if the | |
302 // shelf is left alignment. | |
303 delta = -GetSystemBubbleHeight(); | |
304 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | |
305 SendGestureEvent(start, delta, false, 0); | |
306 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
307 | |
308 // Swiping up on system tray should not show the system tray bubble if the | |
309 // shelf is right alignment. | |
310 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); | |
311 SendGestureEvent(start, delta, false, 0); | |
312 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
313 | |
314 // Swiping down on the shelf should not show the system tray bubble. | |
315 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
316 delta = -delta; | |
317 SendGestureEvent(start, delta, false, 0); | |
318 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
319 } | |
60 | 320 |
61 // Verifies only the visible default views are recorded in the | 321 // Verifies only the visible default views are recorded in the |
62 // "Ash.SystemMenu.DefaultView.VisibleItems" histogram. | 322 // "Ash.SystemMenu.DefaultView.VisibleItems" histogram. |
63 TEST_F(SystemTrayTest, OnlyVisibleItemsRecorded) { | 323 TEST_F(SystemTrayTest, OnlyVisibleItemsRecorded) { |
64 SystemTray* tray = GetPrimarySystemTray(); | 324 SystemTray* tray = GetPrimarySystemTray(); |
65 ASSERT_TRUE(tray->GetWidget()); | 325 ASSERT_TRUE(tray->GetWidget()); |
66 | 326 |
67 TestSystemTrayItem* test_item = new TestSystemTrayItem(); | 327 TestSystemTrayItem* test_item = new TestSystemTrayItem(); |
68 tray->AddTrayItem(base::WrapUnique(test_item)); | 328 tray->AddTrayItem(base::WrapUnique(test_item)); |
69 | 329 |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 | 846 |
587 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); | 847 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); |
588 } | 848 } |
589 | 849 |
590 TEST_F(SystemTrayTest, SeparatorThickness) { | 850 TEST_F(SystemTrayTest, SeparatorThickness) { |
591 EXPECT_EQ(kSeparatorWidth, views::Separator::kThickness); | 851 EXPECT_EQ(kSeparatorWidth, views::Separator::kThickness); |
592 } | 852 } |
593 | 853 |
594 } // namespace test | 854 } // namespace test |
595 } // namespace ash | 855 } // namespace ash |
OLD | NEW |