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/tray_constants.h" | 19 #include "ash/system/tray/tray_constants.h" |
20 #include "ash/system/web_notification/web_notification_tray.h" | 20 #include "ash/system/web_notification/web_notification_tray.h" |
21 #include "ash/test/ash_test_base.h" | 21 #include "ash/test/ash_test_base.h" |
22 #include "ash/test/status_area_widget_test_helper.h" | 22 #include "ash/test/status_area_widget_test_helper.h" |
23 #include "ash/test/test_system_tray_item.h" | 23 #include "ash/test/test_system_tray_item.h" |
| 24 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
24 #include "ash/wm/window_util.h" | 25 #include "ash/wm/window_util.h" |
25 #include "base/memory/ptr_util.h" | 26 #include "base/memory/ptr_util.h" |
26 #include "base/run_loop.h" | 27 #include "base/run_loop.h" |
27 #include "base/test/histogram_tester.h" | 28 #include "base/test/histogram_tester.h" |
28 #include "ui/base/ui_base_types.h" | 29 #include "ui/base/ui_base_types.h" |
29 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 30 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
30 #include "ui/events/test/event_generator.h" | 31 #include "ui/events/test/event_generator.h" |
31 #include "ui/gfx/geometry/point.h" | 32 #include "ui/gfx/geometry/point.h" |
32 #include "ui/gfx/geometry/rect.h" | 33 #include "ui/gfx/geometry/rect.h" |
33 #include "ui/views/controls/separator.h" | 34 #include "ui/views/controls/separator.h" |
(...skipping 15 matching lines...) Expand all Loading... |
49 ~ModalWidgetDelegate() override {} | 50 ~ModalWidgetDelegate() override {} |
50 | 51 |
51 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; } | 52 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; } |
52 | 53 |
53 private: | 54 private: |
54 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); | 55 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); |
55 }; | 56 }; |
56 | 57 |
57 } // namespace | 58 } // namespace |
58 | 59 |
59 typedef AshTestBase SystemTrayTest; | 60 class SystemTrayTest : public AshTestBase { |
| 61 public: |
| 62 SystemTrayTest() {} |
| 63 ~SystemTrayTest() override {} |
| 64 |
| 65 // Swiping on the system tray and end with finger released. |
| 66 void SendGestureEvent(gfx::Point& start, |
| 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 ui::GestureEventDetails details = |
| 75 is_fling |
| 76 ? ui::GestureEventDetails(ui::ET_SCROLL_FLING_START, 0, velocity_y) |
| 77 : ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END); |
| 78 ui::GestureEvent event = ui::GestureEvent(start.x(), start.y() + delta, |
| 79 ui::EF_NONE, timestamp, details); |
| 80 system_tray->OnGestureEvent(&event); |
| 81 } |
| 82 |
| 83 // Swiping on the system tray without releasing the finger. |
| 84 void SendScrollStartAndUpdate(gfx::Point& start, |
| 85 float delta, |
| 86 base::TimeTicks& timestamp) { |
| 87 SystemTray* system_tray = GetPrimarySystemTray(); |
| 88 ui::GestureEventDetails begin_details(ui::ET_GESTURE_SCROLL_BEGIN); |
| 89 ui::GestureEvent begin_event = ui::GestureEvent( |
| 90 start.x(), start.y(), ui::EF_NONE, timestamp, begin_details); |
| 91 system_tray->OnGestureEvent(&begin_event); |
| 92 |
| 93 ui::GestureEventDetails update_details(ui::ET_GESTURE_SCROLL_UPDATE, 0, |
| 94 delta); |
| 95 timestamp += base::TimeDelta::FromMilliseconds(100); |
| 96 ui::GestureEvent update_event = ui::GestureEvent( |
| 97 start.x(), start.y(), ui::EF_NONE, timestamp, update_details); |
| 98 system_tray->OnGestureEvent(&update_event); |
| 99 } |
| 100 |
| 101 // Open the default system tray bubble to get the height of the bubble and |
| 102 // then close it. |
| 103 float GetSystemBubbleHeight() { |
| 104 SystemTray* system_tray = GetPrimarySystemTray(); |
| 105 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 106 gfx::Rect bounds = system_tray->GetSystemBubble() |
| 107 ->bubble_view() |
| 108 ->GetWidget() |
| 109 ->GetWindowBoundsInScreen(); |
| 110 system_tray->CloseSystemBubble(); |
| 111 |
| 112 return bounds.height(); |
| 113 } |
| 114 |
| 115 private: |
| 116 DISALLOW_COPY_AND_ASSIGN(SystemTrayTest); |
| 117 }; |
| 118 |
| 119 // Swiping on the system tray ends with fling event. |
| 120 TEST_F(SystemTrayTest, FlingOnSystemTray) { |
| 121 Shelf* shelf = GetPrimaryShelf(); |
| 122 SystemTray* system_tray = GetPrimarySystemTray(); |
| 123 gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint(); |
| 124 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| 125 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 126 true); |
| 127 |
| 128 // Fling up on the system tray should show the bubble if the |velocity_y| is |
| 129 // larger than kFlingVelocity and the dragging amount is larger than one third |
| 130 // of the height of the bubble. |
| 131 float delta = -GetSystemBubbleHeight(); |
| 132 SendGestureEvent(start, delta, true, -(kFlingVelocity + 1)); |
| 133 EXPECT_TRUE(system_tray->HasSystemBubble()); |
| 134 system_tray->CloseSystemBubble(); |
| 135 |
| 136 // Fling up on the system tray should show the bubble if the |velocity_y| is |
| 137 // larger than kFlingVelocity even the dragging amount is less than one third |
| 138 // of the height of the bubble. |
| 139 delta /= 4; |
| 140 SendGestureEvent(start, delta, true, -(kFlingVelocity + 1)); |
| 141 EXPECT_TRUE(system_tray->HasSystemBubble()); |
| 142 system_tray->CloseSystemBubble(); |
| 143 |
| 144 // Fling up on the system tray should show the bubble if the |velocity_y| is |
| 145 // less than kFlingVelocity but the dragging amount if larger than one third |
| 146 // of the height of the bubble. |
| 147 delta = -GetSystemBubbleHeight(); |
| 148 SendGestureEvent(start, delta, true, -(kFlingVelocity - 1)); |
| 149 EXPECT_TRUE(system_tray->HasSystemBubble()); |
| 150 system_tray->CloseSystemBubble(); |
| 151 |
| 152 // Fling up on the system tray should close the bubble if the |velocity_y| |
| 153 // is less than kFlingVelocity and the dragging amount is less than one third |
| 154 // of the height of the bubble. |
| 155 delta /= 4; |
| 156 SendGestureEvent(start, delta, true, -(kFlingVelocity - 1)); |
| 157 EXPECT_FALSE(system_tray->HasSystemBubble()); |
| 158 |
| 159 // Fling down on the system tray should close the bubble if the |velocity_y| |
| 160 // is larger than kFLingVelocity. |
| 161 SendGestureEvent(start, delta, true, kFlingVelocity + 1); |
| 162 EXPECT_FALSE(system_tray->HasSystemBubble()); |
| 163 |
| 164 // Fling down on the system tray should close the bubble if the |velocity_y| |
| 165 // is larger than kFlingVelocity even the dragging amount is larger than one |
| 166 // third of the height of the bubble. |
| 167 delta = -GetSystemBubbleHeight(); |
| 168 SendGestureEvent(start, delta, true, kFlingVelocity + 1); |
| 169 EXPECT_FALSE(system_tray->HasSystemBubble()); |
| 170 |
| 171 // Fling down on the system tray should open the bubble if the |velocity_y| is |
| 172 // less than kFlingVelocity but the dragging amount exceed one third of the |
| 173 // height of the bubble. |
| 174 SendGestureEvent(start, delta, true, kFlingVelocity - 1); |
| 175 EXPECT_TRUE(system_tray->HasSystemBubble()); |
| 176 system_tray->CloseSystemBubble(); |
| 177 |
| 178 // Fling down on the system tray should close the bubble if the |velocity_y| |
| 179 // is less than kFlingVelocity and the dragging amount is less than one third |
| 180 // of the height of the bubble. |
| 181 delta /= 4; |
| 182 SendGestureEvent(start, delta, true, kFlingVelocity - 1); |
| 183 EXPECT_FALSE(system_tray->HasSystemBubble()); |
| 184 } |
| 185 |
| 186 // Touch outside the system tray bubble during swiping should close the bubble. |
| 187 TEST_F(SystemTrayTest, TapOutsideCloseBubble) { |
| 188 Shelf* shelf = GetPrimaryShelf(); |
| 189 SystemTray* system_tray = GetPrimarySystemTray(); |
| 190 gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint(); |
| 191 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| 192 |
| 193 float delta = -GetSystemBubbleHeight(); |
| 194 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 195 true); |
| 196 base::TimeTicks timestamp = base::TimeTicks::Now(); |
| 197 SendScrollStartAndUpdate(start, delta, timestamp); |
| 198 EXPECT_TRUE(system_tray->HasSystemBubble()); |
| 199 |
| 200 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 201 gfx::Rect bounds = system_tray->GetSystemBubble() |
| 202 ->bubble_view() |
| 203 ->GetWidget() |
| 204 ->GetWindowBoundsInScreen(); |
| 205 gfx::Point point_outside = gfx::Point(bounds.x() - 5, bounds.y() - 5); |
| 206 generator.GestureTapAt(point_outside); |
| 207 EXPECT_FALSE(system_tray->HasSystemBubble()); |
| 208 } |
| 209 |
| 210 // Swiping on the system tray ends with scroll event. |
| 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 |