Chromium Code Reviews| 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" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); | 56 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 class SystemTrayTest : public AshTestBase { | 61 class SystemTrayTest : public AshTestBase { |
| 62 public: | 62 public: |
| 63 SystemTrayTest() {} | 63 SystemTrayTest() {} |
| 64 ~SystemTrayTest() override {} | 64 ~SystemTrayTest() override {} |
| 65 | 65 |
| 66 // Swiping on the system tray and ends with finger released. | 66 // Swiping on the system tray and ends with finger released. Note, |start| is |
| 67 // based on the view's own cooidinates. | |
|
sammiequon
2017/06/30 17:46:02
nit: coordinates
minch1
2017/06/30 19:08:04
Done.
| |
| 67 void SendGestureEvent(gfx::Point& start, | 68 void SendGestureEvent(gfx::Point& start, |
| 68 float delta, | 69 float delta, |
| 69 bool is_fling, | 70 bool is_fling, |
| 70 float velocity_y) { | 71 float velocity_y) { |
| 71 SystemTray* system_tray = GetPrimarySystemTray(); | 72 SystemTray* system_tray = GetPrimarySystemTray(); |
| 72 base::TimeTicks timestamp = base::TimeTicks::Now(); | 73 base::TimeTicks timestamp = base::TimeTicks::Now(); |
| 73 SendScrollStartAndUpdate(start, delta, timestamp); | 74 SendScrollStartAndUpdate(start, delta, timestamp); |
| 74 | 75 |
| 75 ui::GestureEventDetails details = | 76 ui::GestureEventDetails details = |
| 76 is_fling | 77 is_fling |
| 77 ? ui::GestureEventDetails(ui::ET_SCROLL_FLING_START, 0, velocity_y) | 78 ? ui::GestureEventDetails(ui::ET_SCROLL_FLING_START, 0, velocity_y) |
| 78 : ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END); | 79 : ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END); |
| 79 ui::GestureEvent event = ui::GestureEvent(start.x(), start.y() + delta, | 80 ui::GestureEvent event = ui::GestureEvent(start.x(), start.y() + delta, |
| 80 ui::EF_NONE, timestamp, details); | 81 ui::EF_NONE, timestamp, details); |
| 81 system_tray->OnGestureEvent(&event); | 82 if (is_on_bubble_) |
| 83 system_tray->GetSystemBubble()->bubble_view()->OnGestureEvent(&event); | |
| 84 else | |
| 85 system_tray->OnGestureEvent(&event); | |
| 82 } | 86 } |
| 83 | 87 |
| 84 // Swiping on the system tray without releasing the finger. | 88 // Swiping on the system tray without releasing the finger. |
| 85 void SendScrollStartAndUpdate(gfx::Point& start, | 89 void SendScrollStartAndUpdate(gfx::Point& start, |
| 86 float delta, | 90 float delta, |
| 87 base::TimeTicks& timestamp) { | 91 base::TimeTicks& timestamp) { |
| 88 SystemTray* system_tray = GetPrimarySystemTray(); | 92 SystemTray* system_tray = GetPrimarySystemTray(); |
| 89 ui::GestureEventDetails begin_details(ui::ET_GESTURE_SCROLL_BEGIN); | 93 ui::GestureEventDetails begin_details(ui::ET_GESTURE_SCROLL_BEGIN, 0, |
| 94 scroll_y_hint_); | |
| 90 ui::GestureEvent begin_event = ui::GestureEvent( | 95 ui::GestureEvent begin_event = ui::GestureEvent( |
| 91 start.x(), start.y(), ui::EF_NONE, timestamp, begin_details); | 96 start.x(), start.y(), ui::EF_NONE, timestamp, begin_details); |
| 92 system_tray->OnGestureEvent(&begin_event); | 97 |
| 98 if (is_on_bubble_) { | |
| 99 system_tray->GetSystemBubble()->bubble_view()->OnGestureEvent( | |
| 100 &begin_event); | |
| 101 } else { | |
| 102 system_tray->OnGestureEvent(&begin_event); | |
| 103 } | |
| 93 | 104 |
| 94 ui::GestureEventDetails update_details(ui::ET_GESTURE_SCROLL_UPDATE, 0, | 105 ui::GestureEventDetails update_details(ui::ET_GESTURE_SCROLL_UPDATE, 0, |
| 95 delta); | 106 delta); |
| 96 timestamp += base::TimeDelta::FromMilliseconds(100); | 107 timestamp += base::TimeDelta::FromMilliseconds(100); |
| 97 ui::GestureEvent update_event = ui::GestureEvent( | 108 ui::GestureEvent update_event = ui::GestureEvent( |
| 98 start.x(), start.y() + delta, ui::EF_NONE, timestamp, update_details); | 109 start.x(), start.y() + delta, ui::EF_NONE, timestamp, update_details); |
| 99 system_tray->OnGestureEvent(&update_event); | 110 |
| 111 if (is_on_bubble_) { | |
| 112 system_tray->GetSystemBubble()->bubble_view()->OnGestureEvent( | |
| 113 &update_event); | |
| 114 } else { | |
| 115 system_tray->OnGestureEvent(&update_event); | |
| 116 } | |
| 100 } | 117 } |
| 101 | 118 |
| 102 // Open the default system tray bubble to get the height of the bubble and | 119 // Open the default system tray bubble to get the height of the bubble and |
| 103 // then close it. | 120 // then close it. |
| 104 float GetSystemBubbleHeight() { | 121 float GetSystemBubbleHeight() { |
| 105 SystemTray* system_tray = GetPrimarySystemTray(); | 122 SystemTray* system_tray = GetPrimarySystemTray(); |
| 106 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); | 123 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| 107 gfx::Rect bounds = GetSystemBubbleBoundsInScreen(); | 124 gfx::Rect bounds = GetSystemBubbleBoundsInScreen(); |
| 108 system_tray->CloseSystemBubble(); | 125 system_tray->CloseSystemBubble(); |
| 109 return bounds.height(); | 126 return bounds.height(); |
| 110 } | 127 } |
| 111 | 128 |
| 112 gfx::Rect GetSystemBubbleBoundsInScreen() { | 129 gfx::Rect GetSystemBubbleBoundsInScreen() { |
| 113 return GetPrimarySystemTray() | 130 return GetPrimarySystemTray() |
| 114 ->GetSystemBubble() | 131 ->GetSystemBubble() |
| 115 ->bubble_view() | 132 ->bubble_view() |
| 116 ->GetWidget() | 133 ->GetWidget() |
| 117 ->GetWindowBoundsInScreen(); | 134 ->GetWindowBoundsInScreen(); |
| 118 } | 135 } |
| 119 | 136 |
| 137 void set_scroll_y_hint(float scroll_y_hint) { | |
| 138 scroll_y_hint_ = scroll_y_hint; | |
| 139 } | |
| 140 | |
| 141 void set_is_on_bubble(bool is_on_bubble) { is_on_bubble_ = is_on_bubble; } | |
| 142 | |
| 120 private: | 143 private: |
| 144 float scroll_y_hint_ = -1.f; | |
| 145 bool is_on_bubble_ = false; | |
| 146 | |
| 121 DISALLOW_COPY_AND_ASSIGN(SystemTrayTest); | 147 DISALLOW_COPY_AND_ASSIGN(SystemTrayTest); |
| 122 }; | 148 }; |
| 123 | 149 |
| 124 // Swiping on the overlap area of shelf and system tray bubble during the | 150 // Swiping on the overlap area of shelf and system tray bubble during the |
| 125 // animation should close the bubble. | 151 // animation should close the bubble. |
| 126 TEST_F(SystemTrayTest, SwipingOnShelfDuringAnimation) { | 152 TEST_F(SystemTrayTest, SwipingOnShelfDuringAnimation) { |
| 127 Shelf* shelf = GetPrimaryShelf(); | 153 Shelf* shelf = GetPrimaryShelf(); |
| 128 SystemTray* system_tray = GetPrimarySystemTray(); | 154 SystemTray* system_tray = GetPrimarySystemTray(); |
| 129 gfx::Point start = system_tray->GetLocalBounds().CenterPoint(); | 155 gfx::Point start = system_tray->GetLocalBounds().CenterPoint(); |
| 130 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | 156 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 generator.GestureScrollSequence(point_on_shelf_start, point_on_shelf_end, | 199 generator.GestureScrollSequence(point_on_shelf_start, point_on_shelf_end, |
| 174 base::TimeDelta::FromMilliseconds(100), 5); | 200 base::TimeDelta::FromMilliseconds(100), 5); |
| 175 EXPECT_FALSE(system_tray->HasSystemBubble()); | 201 EXPECT_FALSE(system_tray->HasSystemBubble()); |
| 176 } | 202 } |
| 177 } | 203 } |
| 178 | 204 |
| 179 // Swiping on the system tray ends with fling event. | 205 // Swiping on the system tray ends with fling event. |
| 180 TEST_F(SystemTrayTest, FlingOnSystemTray) { | 206 TEST_F(SystemTrayTest, FlingOnSystemTray) { |
| 181 Shelf* shelf = GetPrimaryShelf(); | 207 Shelf* shelf = GetPrimaryShelf(); |
| 182 SystemTray* system_tray = GetPrimarySystemTray(); | 208 SystemTray* system_tray = GetPrimarySystemTray(); |
| 183 gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint(); | 209 gfx::Point start = system_tray->GetLocalBounds().CenterPoint(); |
| 184 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | 210 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| 185 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 211 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 186 true); | 212 true); |
| 187 | 213 |
| 188 // Fling up on the system tray should show the bubble if the |velocity_y| is | 214 // Fling up on the system tray should show the bubble if the |velocity_y| is |
| 189 // larger than |kFlingVelocity| and the dragging amount is larger than one | 215 // larger than |kFlingVelocity| and the dragging amount is larger than one |
| 190 // third of the height of the bubble. | 216 // third of the height of the bubble. |
| 191 float delta = -GetSystemBubbleHeight(); | 217 float delta = -GetSystemBubbleHeight(); |
| 192 SendGestureEvent(start, delta, true, -(SystemTray::kFlingVelocity + 1)); | 218 SendGestureEvent(start, delta, true, -(SystemTray::kFlingVelocity + 1)); |
| 193 EXPECT_TRUE(system_tray->HasSystemBubble()); | 219 EXPECT_TRUE(system_tray->HasSystemBubble()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | 332 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); |
| 307 SendGestureEvent(start, delta, false, 0); | 333 SendGestureEvent(start, delta, false, 0); |
| 308 EXPECT_FALSE(system_tray->HasSystemBubble()); | 334 EXPECT_FALSE(system_tray->HasSystemBubble()); |
| 309 | 335 |
| 310 // Swiping up on system tray should not show the system tray bubble if the | 336 // Swiping up on system tray should not show the system tray bubble if the |
| 311 // shelf is right alignment. | 337 // shelf is right alignment. |
| 312 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); | 338 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); |
| 313 SendGestureEvent(start, delta, false, 0); | 339 SendGestureEvent(start, delta, false, 0); |
| 314 EXPECT_FALSE(system_tray->HasSystemBubble()); | 340 EXPECT_FALSE(system_tray->HasSystemBubble()); |
| 315 | 341 |
| 316 // Swiping down on the shelf should not show the system tray bubble. | 342 // Begins to scroll downward on the shelf should not show the system tray |
| 343 // bubble. | |
| 317 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | 344 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| 318 delta = -delta; | 345 set_scroll_y_hint(1.0); |
| 319 SendGestureEvent(start, delta, false, 0); | 346 SendGestureEvent(start, delta, false, 0); |
| 320 EXPECT_FALSE(system_tray->HasSystemBubble()); | 347 EXPECT_FALSE(system_tray->HasSystemBubble()); |
| 321 } | 348 } |
| 349 | |
| 350 // Swiping on opened system tray bubble. | |
| 351 TEST_F(SystemTrayTest, SwipingOnSystemTrayBubble) { | |
| 352 Shelf* shelf = GetPrimaryShelf(); | |
| 353 SystemTray* system_tray = GetPrimarySystemTray(); | |
| 354 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
| 355 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 356 true); | |
| 357 set_is_on_bubble(true); | |
| 358 | |
| 359 // Begins to scroll downward and swiping down more than one third of the | |
| 360 // bubble's height should close the bubble. | |
| 361 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 362 gfx::Rect bounds = | |
| 363 system_tray->GetSystemBubble()->bubble_view()->GetLocalBounds(); | |
| 364 float delta = bounds.height() / 2; | |
| 365 gfx::Point start(bounds.x() + 5, bounds.y() + 5); | |
| 366 set_scroll_y_hint(1.0); | |
| 367 SendGestureEvent(start, delta, false, 0); | |
| 368 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
| 369 | |
| 370 // Begins to scroll upward and swiping down more than one third of the | |
| 371 // bubble's height should also close the bubble. | |
| 372 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); | |
| 373 set_scroll_y_hint(-1.0); | |
| 374 SendGestureEvent(start, delta, false, 0); | |
| 375 EXPECT_FALSE(system_tray->HasSystemBubble()); | |
| 376 } | |
| 322 | 377 |
| 323 // Verifies only the visible default views are recorded in the | 378 // Verifies only the visible default views are recorded in the |
| 324 // "Ash.SystemMenu.DefaultView.VisibleItems" histogram. | 379 // "Ash.SystemMenu.DefaultView.VisibleItems" histogram. |
| 325 TEST_F(SystemTrayTest, OnlyVisibleItemsRecorded) { | 380 TEST_F(SystemTrayTest, OnlyVisibleItemsRecorded) { |
| 326 SystemTray* tray = GetPrimarySystemTray(); | 381 SystemTray* tray = GetPrimarySystemTray(); |
| 327 ASSERT_TRUE(tray->GetWidget()); | 382 ASSERT_TRUE(tray->GetWidget()); |
| 328 | 383 |
| 329 TestSystemTrayItem* test_item = new TestSystemTrayItem(); | 384 TestSystemTrayItem* test_item = new TestSystemTrayItem(); |
| 330 tray->AddTrayItem(base::WrapUnique(test_item)); | 385 tray->AddTrayItem(base::WrapUnique(test_item)); |
| 331 | 386 |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 848 | 903 |
| 849 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); | 904 EXPECT_EQ(0, notification_tray->tray_bubble_height_for_test()); |
| 850 } | 905 } |
| 851 | 906 |
| 852 TEST_F(SystemTrayTest, SeparatorThickness) { | 907 TEST_F(SystemTrayTest, SeparatorThickness) { |
| 853 EXPECT_EQ(kSeparatorWidth, views::Separator::kThickness); | 908 EXPECT_EQ(kSeparatorWidth, views::Separator::kThickness); |
| 854 } | 909 } |
| 855 | 910 |
| 856 } // namespace test | 911 } // namespace test |
| 857 } // namespace ash | 912 } // namespace ash |
| OLD | NEW |