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 c8dc570c4f0103ed481221f980abfc7c284330cf..203fdc703d9e3175d8c1a89d48f35c25ac47894f 100644 |
| --- a/ash/system/tray/system_tray_unittest.cc |
| +++ b/ash/system/tray/system_tray_unittest.cc |
| @@ -56,7 +56,107 @@ class ModalWidgetDelegate : public views::WidgetDelegateView { |
| } // namespace |
| -typedef AshTestBase SystemTrayTest; |
| +class SystemTrayTest : public AshTestBase { |
| + public: |
| + SystemTrayTest() {} |
| + ~SystemTrayTest() override {} |
| + |
| + void SetUp() override { |
| + AshTestBase::SetUp(); |
| + shelf_ = GetPrimaryShelf(); |
| + system_tray_ = GetPrimarySystemTray(); |
| + } |
| + |
| + void set_in_maximize_mode(bool in_maximize_mode) { |
| + system_tray_->in_maximize_mode_ = in_maximize_mode; |
| + } |
| + |
| + void SendGestureEvent(gfx::Point& start, float delta) { |
| + base::TimeTicks timestamp = base::TimeTicks::Now(); |
| + ui::GestureEventDetails begin_details(ui::ET_GESTURE_SCROLL_BEGIN); |
| + ui::GestureEvent begin_event = ui::GestureEvent( |
| + start.x(), start.y(), ui::EF_NONE, timestamp, begin_details); |
| + 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(), ui::EF_NONE, timestamp, update_details); |
| + system_tray_->OnGestureEvent(&update_event); |
| + |
| + ui::GestureEventDetails end_details(ui::ET_GESTURE_SCROLL_END); |
| + ui::GestureEvent end_event = ui::GestureEvent( |
| + start.x(), start.y() + delta, ui::EF_NONE, timestamp, end_details); |
| + system_tray_->OnGestureEvent(&end_event); |
| + } |
| + |
| + float height() { |
|
xiyuan
2017/06/16 17:33:43
nit: height -> GetSystemBubbleHeight
minch1
2017/06/16 22:11:51
Done.
|
| + gfx::Rect bounds = gfx::Rect(); |
| + if (system_tray_->HasSystemBubble()) { |
| + bounds = system_tray_->GetSystemBubble() |
| + ->bubble_view() |
| + ->GetWidget() |
| + ->GetWindowBoundsInScreen(); |
| + } |
| + return bounds.height(); |
| + } |
| + |
| + Shelf* shelf() { return shelf_; } |
| + SystemTray* system_tray() { return system_tray_; } |
| + |
| + private: |
| + Shelf* shelf_ = nullptr; |
| + SystemTray* system_tray_ = nullptr; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SystemTrayTest); |
| +}; |
| + |
| +TEST_F(SystemTrayTest, SwipingOnSystemTray) { |
| + gfx::Point start = system_tray()->GetBoundsInScreen().CenterPoint(); |
| + shelf()->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| + system_tray()->ShowDefaultView(BUBBLE_CREATE_NEW); |
| + float delta = -height(); |
| + system_tray()->CloseSystemBubble(); |
| + |
| + // Swiping up on the system tray has no effect if it is not in maximize mode. |
| + set_in_maximize_mode(false); |
| + ASSERT_FALSE(system_tray()->HasSystemBubble()); |
| + SendGestureEvent(start, delta); |
| + ASSERT_FALSE(system_tray()->HasSystemBubble()); |
| + |
| + // Swiping up on the system tray should show the system tray bubble if it is |
| + // in masimize mode. |
|
xiyuan
2017/06/16 17:33:43
nit: masimize -> maximize
minch1
2017/06/16 22:11:51
Done.
|
| + set_in_maximize_mode(true); |
| + SendGestureEvent(start, delta); |
| + ASSERT_TRUE(system_tray()->HasSystemBubble()); |
|
xiyuan
2017/06/16 17:33:43
nit: ASSERT_TRUE -> EXPECT_TRUE
Use ASSERT_xxx wh
minch1
2017/06/16 22:11:51
Done.
|
| + |
|
xiyuan
2017/06/16 17:33:43
nit: move this empty line after CloseSystemBubble(
minch1
2017/06/16 22:11:51
Done.
|
| + system_tray()->CloseSystemBubble(); |
| + // Swiping up less than one third of the bubble's height should not show the |
| + // bubble. |
| + delta /= 4; |
| + SendGestureEvent(start, delta); |
| + ASSERT_FALSE(system_tray()->HasSystemBubble()); |
| + |
| + // Swiping up on system tray should not show the system tray bubble if the |
| + // shelf is left alignment. |
| + delta = height(); |
| + shelf()->SetAlignment(SHELF_ALIGNMENT_LEFT); |
| + SendGestureEvent(start, delta); |
| + ASSERT_FALSE(system_tray()->HasSystemBubble()); |
| + |
| + // Swiping up on system tray should not show the system tray bubble if the |
| + // shelf is right alignment. |
| + shelf()->SetAlignment(SHELF_ALIGNMENT_RIGHT); |
| + SendGestureEvent(start, delta); |
| + ASSERT_FALSE(system_tray()->HasSystemBubble()); |
| + |
| + // Swiping down on the shelf should not show the system tray bubble. |
| + shelf()->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| + delta = -delta; |
| + SendGestureEvent(start, delta); |
| + ASSERT_FALSE(system_tray()->HasSystemBubble()); |
| +} |
| // Verifies only the visible default views are recorded in the |
| // "Ash.SystemMenu.DefaultView.VisibleItems" histogram. |