Chromium Code Reviews| Index: ash/system/tray/system_tray_unittest.cc |
| diff --git a/ash/system/tray/system_tray_unittest.cc b/ash/system/tray/system_tray_unittest.cc |
| index 771e4deaa296aad7245c4aac0f73f4c99d32c060..a67a59374b69130a8ae6c4418558d7bcc1fff955 100644 |
| --- a/ash/system/tray/system_tray_unittest.cc |
| +++ b/ash/system/tray/system_tray_unittest.cc |
| @@ -18,6 +18,7 @@ |
| #include "ash/system/tray/system_tray_bubble.h" |
| #include "ash/system/tray/system_tray_item.h" |
| #include "ash/system/tray/tray_constants.h" |
| +#include "ash/system/tray_drag_controller.h" |
| #include "ash/system/web_notification/web_notification_tray.h" |
| #include "ash/test/ash_test_base.h" |
| #include "ash/test/status_area_widget_test_helper.h" |
| @@ -63,7 +64,8 @@ class SystemTrayTest : public AshTestBase { |
| SystemTrayTest() {} |
| ~SystemTrayTest() override {} |
| - // Swiping on the system tray and ends with finger released. |
| + // Swiping on the system tray and ends with finger released. Note, |start| is |
| + // based on the system tray or system tray bubble's coordinate space. |
| void SendGestureEvent(gfx::Point& start, |
| float delta, |
| bool is_fling, |
| @@ -78,7 +80,14 @@ class SystemTrayTest : public AshTestBase { |
| : ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END); |
| ui::GestureEvent event = ui::GestureEvent(start.x(), start.y() + delta, |
| ui::EF_NONE, timestamp, details); |
| - system_tray->OnGestureEvent(&event); |
| + ui::Event::DispatcherApi dispatch_helper(&event); |
|
msw
2017/07/14 02:00:46
Can you extract a helper function for the three si
minch1
2017/07/14 19:45:17
Done.
|
| + if (is_on_bubble_) { |
| + dispatch_helper.set_target(system_tray->GetSystemBubble()->bubble_view()); |
| + system_tray->GetSystemBubble()->bubble_view()->OnGestureEvent(&event); |
| + } else { |
| + dispatch_helper.set_target(system_tray); |
| + system_tray->OnGestureEvent(&event); |
| + } |
| } |
| // Swiping on the system tray without releasing the finger. |
| @@ -86,17 +95,38 @@ class SystemTrayTest : public AshTestBase { |
| float delta, |
| base::TimeTicks& timestamp) { |
| SystemTray* system_tray = GetPrimarySystemTray(); |
| - ui::GestureEventDetails begin_details(ui::ET_GESTURE_SCROLL_BEGIN); |
| + ui::GestureEventDetails begin_details(ui::ET_GESTURE_SCROLL_BEGIN, 0, |
| + scroll_y_hint_); |
| ui::GestureEvent begin_event = ui::GestureEvent( |
| start.x(), start.y(), ui::EF_NONE, timestamp, begin_details); |
| - system_tray->OnGestureEvent(&begin_event); |
| + |
| + ui::Event::DispatcherApi begin_dispatch_helper(&begin_event); |
| + if (is_on_bubble_) { |
| + begin_dispatch_helper.set_target( |
| + system_tray->GetSystemBubble()->bubble_view()); |
| + system_tray->GetSystemBubble()->bubble_view()->OnGestureEvent( |
| + &begin_event); |
| + } else { |
| + begin_dispatch_helper.set_target(system_tray); |
| + system_tray->OnGestureEvent(&begin_event); |
| + } |
| ui::GestureEventDetails update_details(ui::ET_GESTURE_SCROLL_UPDATE, 0, |
| delta); |
| timestamp += base::TimeDelta::FromMilliseconds(100); |
| ui::GestureEvent update_event = ui::GestureEvent( |
| start.x(), start.y() + delta, ui::EF_NONE, timestamp, update_details); |
| - system_tray->OnGestureEvent(&update_event); |
| + |
| + ui::Event::DispatcherApi update_dispatch_helper(&update_event); |
| + if (is_on_bubble_) { |
| + update_dispatch_helper.set_target( |
| + system_tray->GetSystemBubble()->bubble_view()); |
| + system_tray->GetSystemBubble()->bubble_view()->OnGestureEvent( |
| + &update_event); |
| + } else { |
| + update_dispatch_helper.set_target(system_tray); |
| + system_tray->OnGestureEvent(&update_event); |
| + } |
| } |
| // Open the default system tray bubble to get the height of the bubble and |
| @@ -117,7 +147,21 @@ class SystemTrayTest : public AshTestBase { |
| ->GetWindowBoundsInScreen(); |
| } |
| + void set_scroll_y_hint(float scroll_y_hint) { |
| + scroll_y_hint_ = scroll_y_hint; |
| + } |
| + |
| + void set_is_on_bubble(bool is_on_bubble) { is_on_bubble_ = is_on_bubble; } |
| + |
| private: |
| + // Distance that caused the scroll to start, which can be used to indicate the |
| + // scroll direction. |
| + float scroll_y_hint_ = -1.f; |
|
msw
2017/07/14 02:00:45
I think these two members might be better off as a
minch1
2017/07/14 19:45:17
Personally, I prefer to make them as the arguments
|
| + |
| + // True if the dragging is triggered on the system tray bubble, otherwise |
| + // false. |
|
msw
2017/07/14 02:00:45
nit: s/false/the dragging is triggered on the tray
minch1
2017/07/14 19:45:17
Done.
|
| + bool is_on_bubble_ = false; |
|
msw
2017/07/14 02:00:45
nit: maybe rename this to something like |target_b
minch1
2017/07/14 19:45:17
Done.
|
| + |
| DISALLOW_COPY_AND_ASSIGN(SystemTrayTest); |
| }; |
| @@ -164,7 +208,7 @@ TEST_F(SystemTrayTest, SwipingOnShelfDuringAnimation) { |
| // Fling down on the shelf with a velocity that exceeds |kFlingVelocity|. |
| EXPECT_FALSE(system_tray->HasSystemBubble()); |
| - SendGestureEvent(start, delta, true, SystemTray::kFlingVelocity + 1); |
| + SendGestureEvent(start, delta, true, TrayDragController::kFlingVelocity + 1); |
| current_bounds = GetSystemBubbleBoundsInScreen(); |
| EXPECT_TRUE(system_tray->HasSystemBubble()); |
| @@ -180,7 +224,7 @@ TEST_F(SystemTrayTest, SwipingOnShelfDuringAnimation) { |
| TEST_F(SystemTrayTest, FlingOnSystemTray) { |
| Shelf* shelf = GetPrimaryShelf(); |
| SystemTray* system_tray = GetPrimarySystemTray(); |
| - gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint(); |
| + gfx::Point start = system_tray->GetLocalBounds().CenterPoint(); |
| shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| true); |
| @@ -189,7 +233,8 @@ TEST_F(SystemTrayTest, FlingOnSystemTray) { |
| // larger than |kFlingVelocity| and the dragging amount is larger than one |
| // third of the height of the bubble. |
| float delta = -GetSystemBubbleHeight(); |
| - SendGestureEvent(start, delta, true, -(SystemTray::kFlingVelocity + 1)); |
| + SendGestureEvent(start, delta, true, |
| + -(TrayDragController::kFlingVelocity + 1)); |
| EXPECT_TRUE(system_tray->HasSystemBubble()); |
| system_tray->CloseSystemBubble(); |
| @@ -197,7 +242,8 @@ TEST_F(SystemTrayTest, FlingOnSystemTray) { |
| // larger than |kFlingVelocity| even the dragging amount is less than one |
| // third of the height of the bubble. |
| delta /= 4; |
| - SendGestureEvent(start, delta, true, -(SystemTray::kFlingVelocity + 1)); |
| + SendGestureEvent(start, delta, true, |
| + -(TrayDragController::kFlingVelocity + 1)); |
| EXPECT_TRUE(system_tray->HasSystemBubble()); |
| system_tray->CloseSystemBubble(); |
| @@ -205,7 +251,8 @@ TEST_F(SystemTrayTest, FlingOnSystemTray) { |
| // less than |kFlingVelocity| but the dragging amount if larger than one third |
| // of the height of the bubble. |
| delta = -GetSystemBubbleHeight(); |
| - SendGestureEvent(start, delta, true, -(SystemTray::kFlingVelocity - 1)); |
| + SendGestureEvent(start, delta, true, |
| + -(TrayDragController::kFlingVelocity - 1)); |
| EXPECT_TRUE(system_tray->HasSystemBubble()); |
| system_tray->CloseSystemBubble(); |
| @@ -213,25 +260,26 @@ TEST_F(SystemTrayTest, FlingOnSystemTray) { |
| // is less than |kFlingVelocity| and the dragging amount is less than one |
| // third of the height of the bubble. |
| delta /= 4; |
| - SendGestureEvent(start, delta, true, -(SystemTray::kFlingVelocity - 1)); |
| + SendGestureEvent(start, delta, true, |
| + -(TrayDragController::kFlingVelocity - 1)); |
| EXPECT_FALSE(system_tray->HasSystemBubble()); |
| // Fling down on the system tray should close the bubble if the |velocity_y| |
| // is larger than kFLingVelocity. |
| - SendGestureEvent(start, delta, true, SystemTray::kFlingVelocity + 1); |
| + SendGestureEvent(start, delta, true, TrayDragController::kFlingVelocity + 1); |
| EXPECT_FALSE(system_tray->HasSystemBubble()); |
| // Fling down on the system tray should close the bubble if the |velocity_y| |
| // is larger than |kFlingVelocity| even the dragging amount is larger than one |
| // third of the height of the bubble. |
| delta = -GetSystemBubbleHeight(); |
| - SendGestureEvent(start, delta, true, SystemTray::kFlingVelocity + 1); |
| + SendGestureEvent(start, delta, true, TrayDragController::kFlingVelocity + 1); |
| EXPECT_FALSE(system_tray->HasSystemBubble()); |
| // Fling down on the system tray should open the bubble if the |velocity_y| is |
| // less than |kFlingVelocity| but the dragging amount exceed one third of the |
| // height of the bubble. |
| - SendGestureEvent(start, delta, true, SystemTray::kFlingVelocity - 1); |
| + SendGestureEvent(start, delta, true, TrayDragController::kFlingVelocity - 1); |
| EXPECT_TRUE(system_tray->HasSystemBubble()); |
| system_tray->CloseSystemBubble(); |
| @@ -239,7 +287,7 @@ TEST_F(SystemTrayTest, FlingOnSystemTray) { |
| // is less than |kFlingVelocity| and the dragging amount is less than one |
| // third of the height of the bubble. |
| delta /= 4; |
| - SendGestureEvent(start, delta, true, SystemTray::kFlingVelocity - 1); |
| + SendGestureEvent(start, delta, true, TrayDragController::kFlingVelocity - 1); |
| EXPECT_FALSE(system_tray->HasSystemBubble()); |
| } |
| @@ -313,11 +361,48 @@ TEST_F(SystemTrayTest, SwipingOnSystemTray) { |
| SendGestureEvent(start, delta, false, 0); |
| EXPECT_FALSE(system_tray->HasSystemBubble()); |
| - // Swiping down on the shelf should not show the system tray bubble. |
| + // Beginning to scroll downward on the shelf should not show the system tray |
| + // bubble. |
|
msw
2017/07/14 02:00:46
nit: "bubble, even if the drag then moves upwards.
minch1
2017/07/14 19:45:17
Done.
|
| + shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| + set_scroll_y_hint(1.0); |
| + SendGestureEvent(start, delta, false, 0); |
| + EXPECT_FALSE(system_tray->HasSystemBubble()); |
| +} |
| + |
| +// Swiping on opened system tray bubble. |
| +TEST_F(SystemTrayTest, SwipingOnSystemTrayBubble) { |
| + Shelf* shelf = GetPrimaryShelf(); |
| + SystemTray* system_tray = GetPrimarySystemTray(); |
| shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| - delta = -delta; |
| + set_is_on_bubble(true); |
| + |
| + // Beginning to scroll downward and then swiping down more than one third of |
| + // the bubble's height should close the bubble. |
|
msw
2017/07/14 02:00:45
Thanks for adding the comment about maximize mode
minch1
2017/07/14 19:45:17
Done.
|
| + Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| + true); |
| + system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| + gfx::Rect bounds = |
| + system_tray->GetSystemBubble()->bubble_view()->GetLocalBounds(); |
| + float delta = bounds.height() / 2; |
| + gfx::Point start(bounds.x() + 5, bounds.y() + 5); |
| + set_scroll_y_hint(1.0); |
| SendGestureEvent(start, delta, false, 0); |
| EXPECT_FALSE(system_tray->HasSystemBubble()); |
| + |
| + // Beginning to scroll upward and then swiping down more than one third of the |
| + // bubble's height should also close the bubble. |
| + system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| + set_scroll_y_hint(-1.0); |
| + SendGestureEvent(start, delta, false, 0); |
| + EXPECT_FALSE(system_tray->HasSystemBubble()); |
| + |
| + // Swiping on the bubble has no effect if it is not in maximize mode. |
| + Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| + false); |
| + system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| + set_scroll_y_hint(-1.0); |
| + SendGestureEvent(start, delta, false, 0); |
| + EXPECT_TRUE(system_tray->HasSystemBubble()); |
| } |
| // Verifies only the visible default views are recorded in the |