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/shell.h" | 15 #include "ash/shell.h" |
16 #include "ash/system/status_area_widget.h" | 16 #include "ash/system/status_area_widget.h" |
17 #include "ash/system/tray/system_tray_bubble.h" | 17 #include "ash/system/tray/system_tray_bubble.h" |
18 #include "ash/system/tray/system_tray_item.h" | 18 #include "ash/system/tray/system_tray_item.h" |
19 #include "ash/system/tray/system_tray_test_api.h" | |
minch1
2017/06/20 16:45:35
Will remove this in next PS.
tdanderson
2017/06/20 22:42:31
Acknowledged.
| |
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 void SendGestureEvent(gfx::Point& start, | |
tdanderson
2017/06/20 22:42:31
nit: can you please add brief documentation for ea
minch1
2017/06/22 17:42:11
Done.
| |
67 float delta, | |
68 bool is_fling, | |
69 float velocity_y) { | |
70 SystemTray* system_tray = GetPrimarySystemTray(); | |
71 base::TimeTicks timestamp = base::TimeTicks::Now(); | |
72 SendScrollStartAndUpdate(start, delta, timestamp); | |
73 | |
74 if (is_fling) { | |
tdanderson
2017/06/20 22:42:31
To simplify this, you could replace lines 74-85 wi
minch1
2017/06/22 17:42:11
Done.
| |
75 ui::GestureEventDetails fling_details(ui::ET_SCROLL_FLING_START, 0, | |
76 velocity_y); | |
77 ui::GestureEvent fling_event = ui::GestureEvent( | |
78 start.x(), start.y() + delta, ui::EF_NONE, timestamp, fling_details); | |
79 system_tray->OnGestureEvent(&fling_event); | |
80 } else { | |
81 ui::GestureEventDetails end_details(ui::ET_GESTURE_SCROLL_END); | |
82 ui::GestureEvent end_event = ui::GestureEvent( | |
83 start.x(), start.y() + delta, ui::EF_NONE, timestamp, end_details); | |
84 system_tray->OnGestureEvent(&end_event); | |
85 } | |
86 } | |
87 | |
88 float GetSystemBubbleHeight() { | |
tdanderson
2017/06/20 22:42:29
Does this function always return the same value? Y
minch1
2017/06/22 17:42:11
It is not always the same value when you open the
tdanderson
2017/06/22 20:21:42
Acknowledged.
| |
89 SystemTray* system_tray = GetPrimarySystemTray(); | |
90 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
91 gfx::Rect bounds = system_tray->GetSystemBubble() | |
92 ->bubble_view() | |
93 ->GetWidget() | |
94 ->GetWindowBoundsInScreen(); | |
95 system_tray->CloseSystemBubble(); | |
96 | |
97 return bounds.height(); | |
98 } | |
99 | |
100 void SendScrollStartAndUpdate(gfx::Point& start, | |
101 float delta, | |
102 base::TimeTicks& timestamp) { | |
103 SystemTray* system_tray = GetPrimarySystemTray(); | |
104 ui::GestureEventDetails begin_details(ui::ET_GESTURE_SCROLL_BEGIN); | |
105 ui::GestureEvent begin_event = ui::GestureEvent( | |
106 start.x(), start.y(), ui::EF_NONE, timestamp, begin_details); | |
107 system_tray->OnGestureEvent(&begin_event); | |
108 | |
109 ui::GestureEventDetails update_details(ui::ET_GESTURE_SCROLL_UPDATE, 0, | |
110 delta); | |
111 timestamp += base::TimeDelta::FromMilliseconds(100); | |
112 ui::GestureEvent update_event = ui::GestureEvent( | |
113 start.x(), start.y(), ui::EF_NONE, timestamp, update_details); | |
114 system_tray->OnGestureEvent(&update_event); | |
115 } | |
116 | |
117 private: | |
118 DISALLOW_COPY_AND_ASSIGN(SystemTrayTest); | |
119 }; | |
120 | |
121 TEST_F(SystemTrayTest, FlingOnSystemTray) { | |
tdanderson
2017/06/20 22:42:31
nit: can you please add brief documentation above
minch1
2017/06/22 17:42:11
Done.
| |
122 Shelf* shelf = GetPrimaryShelf(); | |
123 SystemTray* system_tray = GetPrimarySystemTray(); | |
124 gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint(); | |
125 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
126 float kFlingVelocity = 100.0f; | |
tdanderson
2017/06/20 22:42:30
I think it would be a good idea to define this con
minch1
2017/06/22 17:42:11
Done.
| |
127 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
128 true); | |
129 | |
130 // Fling up on the system tray should show the bubble if the |velocity_y| is | |
131 // larger than kFlingVelocity and the dragging amount is larger than one third | |
132 // of the height of the bubble. | |
133 float delta = -GetSystemBubbleHeight(); | |
134 SendGestureEvent(start, delta, true, -(kFlingVelocity + 1)); | |
135 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
136 system_tray->CloseSystemBubble(); | |
137 | |
138 // Fling up on the system tray should show the bubble if the |velocity_y| is | |
139 // larger than kFlingVelocity even the dragging amount is less than one third | |
140 // of the height of the bubble. | |
141 delta /= 4; | |
142 SendGestureEvent(start, delta, true, -(kFlingVelocity + 1)); | |
143 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
144 system_tray->CloseSystemBubble(); | |
145 | |
146 // Fling up on the system tray should show the bubble if the |velocity_y| is | |
147 // less than kFlingVelocity but the dragging amount if larger than one third | |
148 // of the height of the bubble. | |
149 delta = -GetSystemBubbleHeight(); | |
150 SendGestureEvent(start, delta, true, -(kFlingVelocity - 1)); | |
151 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
152 system_tray->CloseSystemBubble(); | |
153 | |
154 // Fling up on the system tray should close the bubble if the |velocity_y| | |
155 // is less than kFlingVelocity and the dragging amount is less than one third | |
156 // of the height of the bubble. | |
157 delta /= 4; | |
158 SendGestureEvent(start, delta, true, -(kFlingVelocity - 1)); | |
159 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
160 | |
161 // Fling down on the system tray should close the bubble if the |velocity_y| | |
162 // is larger than kFLingVelocity. | |
163 SendGestureEvent(start, delta, true, kFlingVelocity + 1); | |
164 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
165 | |
166 // Fling down on the system tray should close the bubble if the |velocity_y| | |
167 // is larger than kFlingVelocity even the dragging amount is larger than one | |
168 // third of the height of the bubble. | |
169 delta = -GetSystemBubbleHeight(); | |
170 SendGestureEvent(start, delta, true, kFlingVelocity + 1); | |
171 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
172 | |
173 // Fling down on the system tray should open the bubble if the |velocity_y| is | |
174 // less than kFlingVelocity but the dragging amount exceed one third of the | |
175 // height of the bubble. | |
176 SendGestureEvent(start, delta, true, kFlingVelocity - 1); | |
177 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
178 system_tray->CloseSystemBubble(); | |
179 | |
180 // Fling down on the system tray should close the bubble if the |velocity_y| | |
181 // is less than kFlingVelocity and the dragging amount is less than one third | |
182 // of the height of the bubble. | |
183 delta /= 4; | |
184 SendGestureEvent(start, delta, true, kFlingVelocity - 1); | |
185 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
186 } | |
187 | |
188 TEST_F(SystemTrayTest, TapOutsideCloseBubble) { | |
tdanderson
2017/06/20 22:42:31
Thanks for adding this test after fixing the crash
| |
189 Shelf* shelf = GetPrimaryShelf(); | |
190 SystemTray* system_tray = GetPrimarySystemTray(); | |
191 gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint(); | |
192 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
193 | |
194 float delta = -GetSystemBubbleHeight(); | |
195 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
196 true); | |
197 base::TimeTicks timestamp = base::TimeTicks::Now(); | |
198 SendScrollStartAndUpdate(start, delta, timestamp); | |
199 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
200 | |
201 ui::test::EventGenerator& generator = GetEventGenerator(); | |
202 gfx::Rect bounds = system_tray->GetSystemBubble() | |
203 ->bubble_view() | |
204 ->GetWidget() | |
205 ->GetWindowBoundsInScreen(); | |
206 gfx::Point point_outside = gfx::Point(bounds.x() - 5, bounds.y() - 5); | |
207 generator.GestureTapAt(point_outside); | |
208 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
209 } | |
210 | |
211 TEST_F(SystemTrayTest, SwipingOnSystemTray) { | |
212 Shelf* shelf = GetPrimaryShelf(); | |
213 SystemTray* system_tray = GetPrimarySystemTray(); | |
214 gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint(); | |
215 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
216 | |
217 // Swiping up on the system tray has no effect if it is not in maximize mode. | |
218 float delta = -GetSystemBubbleHeight(); | |
219 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
220 false); | |
221 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
222 SendGestureEvent(start, delta, false, 0); | |
223 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
224 | |
225 // Swiping up on the system tray should show the system tray bubble if it is | |
226 // in maximize mode. | |
227 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
228 true); | |
229 SendGestureEvent(start, delta, false, 0); | |
230 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
231 system_tray->CloseSystemBubble(); | |
232 | |
233 // Swiping up less than one third of the bubble's height should not show the | |
234 // bubble. | |
235 delta /= 4; | |
236 SendGestureEvent(start, delta, false, 0); | |
237 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
238 | |
239 // Swiping up more than one third of the bubble's height should show the | |
240 // bubble. | |
241 delta = -GetSystemBubbleHeight() / 2; | |
242 SendGestureEvent(start, delta, false, 0); | |
243 EXPECT_TRUE(system_tray->HasSystemBubble()); | |
244 system_tray->CloseSystemBubble(); | |
245 | |
246 // Swiping up on system tray should not show the system tray bubble if the | |
247 // shelf is left alignment. | |
248 delta = -GetSystemBubbleHeight(); | |
249 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | |
250 SendGestureEvent(start, delta, false, 0); | |
251 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
252 | |
253 // Swiping up on system tray should not show the system tray bubble if the | |
254 // shelf is right alignment. | |
255 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); | |
256 SendGestureEvent(start, delta, false, 0); | |
257 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
258 | |
259 // Swiping down on the shelf should not show the system tray bubble. | |
260 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
261 delta = -delta; | |
262 SendGestureEvent(start, delta, false, 0); | |
263 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
264 } | |
60 | 265 |
61 // Verifies only the visible default views are recorded in the | 266 // Verifies only the visible default views are recorded in the |
62 // "Ash.SystemMenu.DefaultView.VisibleItems" histogram. | 267 // "Ash.SystemMenu.DefaultView.VisibleItems" histogram. |
63 TEST_F(SystemTrayTest, OnlyVisibleItemsRecorded) { | 268 TEST_F(SystemTrayTest, OnlyVisibleItemsRecorded) { |
64 SystemTray* tray = GetPrimarySystemTray(); | 269 SystemTray* tray = GetPrimarySystemTray(); |
65 ASSERT_TRUE(tray->GetWidget()); | 270 ASSERT_TRUE(tray->GetWidget()); |
66 | 271 |
67 TestSystemTrayItem* test_item = new TestSystemTrayItem(); | 272 TestSystemTrayItem* test_item = new TestSystemTrayItem(); |
68 tray->AddTrayItem(base::WrapUnique(test_item)); | 273 tray->AddTrayItem(base::WrapUnique(test_item)); |
69 | 274 |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 | 791 |
587 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); | 792 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); |
588 } | 793 } |
589 | 794 |
590 TEST_F(SystemTrayTest, SeparatorThickness) { | 795 TEST_F(SystemTrayTest, SeparatorThickness) { |
591 EXPECT_EQ(kSeparatorWidth, views::Separator::kThickness); | 796 EXPECT_EQ(kSeparatorWidth, views::Separator::kThickness); |
592 } | 797 } |
593 | 798 |
594 } // namespace test | 799 } // namespace test |
595 } // namespace ash | 800 } // namespace ash |
OLD | NEW |