| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/wm/gestures/overview_gesture_handler.h" |
| 6 |
| 5 #include "ash/common/wm/overview/window_selector_controller.h" | 7 #include "ash/common/wm/overview/window_selector_controller.h" |
| 6 #include "ash/common/wm_shell.h" | 8 #include "ash/common/wm_shell.h" |
| 7 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 8 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/wm/window_util.h" |
| 10 #include "ui/aura/test/test_window_delegate.h" | 13 #include "ui/aura/test/test_window_delegate.h" |
| 11 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
| 12 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_event_dispatcher.h" | 16 #include "ui/aura/window_event_dispatcher.h" |
| 14 #include "ui/events/test/event_generator.h" | 17 #include "ui/events/test/event_generator.h" |
| 15 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 16 | 19 |
| 17 namespace ash { | 20 namespace ash { |
| 18 | 21 |
| 19 class OverviewGestureHandlerTest : public test::AshTestBase { | 22 class OverviewGestureHandlerTest : public test::AshTestBase { |
| 20 public: | 23 public: |
| 21 OverviewGestureHandlerTest() {} | 24 OverviewGestureHandlerTest() {} |
| 22 ~OverviewGestureHandlerTest() override {} | 25 ~OverviewGestureHandlerTest() override {} |
| 23 | 26 |
| 24 aura::Window* CreateWindow(const gfx::Rect& bounds) { | 27 aura::Window* CreateWindow(const gfx::Rect& bounds) { |
| 25 return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds); | 28 return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds); |
| 26 } | 29 } |
| 27 | 30 |
| 31 void ToggleOverview() { |
| 32 WmShell::Get()->window_selector_controller()->ToggleOverview(); |
| 33 } |
| 34 |
| 28 bool IsSelecting() { | 35 bool IsSelecting() { |
| 29 return WmShell::Get()->window_selector_controller()->IsSelecting(); | 36 return WmShell::Get()->window_selector_controller()->IsSelecting(); |
| 30 } | 37 } |
| 31 | 38 |
| 39 float vertical_threshold_pixels() const { |
| 40 return OverviewGestureHandler::vertical_threshold_pixels_; |
| 41 } |
| 42 |
| 43 float horizontal_threshold_pixels() const { |
| 44 return OverviewGestureHandler::horizontal_threshold_pixels_; |
| 45 } |
| 46 |
| 32 private: | 47 private: |
| 33 aura::test::TestWindowDelegate delegate_; | 48 aura::test::TestWindowDelegate delegate_; |
| 34 | 49 |
| 35 DISALLOW_COPY_AND_ASSIGN(OverviewGestureHandlerTest); | 50 DISALLOW_COPY_AND_ASSIGN(OverviewGestureHandlerTest); |
| 36 }; | 51 }; |
| 37 | 52 |
| 38 // Tests a swipe up with three fingers to enter and a swipe down to exit | 53 // Tests a three fingers upwards scroll gesture to enter and a scroll down to |
| 39 // overview. | 54 // exit overview. |
| 40 TEST_F(OverviewGestureHandlerTest, VerticalSwipes) { | 55 TEST_F(OverviewGestureHandlerTest, VerticalScrolls) { |
| 41 gfx::Rect bounds(0, 0, 400, 400); | 56 gfx::Rect bounds(0, 0, 400, 400); |
| 42 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 57 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 43 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); | 58 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 44 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); | 59 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 45 ui::test::EventGenerator generator(root_window, root_window); | 60 ui::test::EventGenerator generator(root_window, root_window); |
| 61 const float long_scroll = 2 * vertical_threshold_pixels(); |
| 46 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 62 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 47 0, -500, 100, 3); | 63 0, -long_scroll, 100, 3); |
| 48 EXPECT_TRUE(IsSelecting()); | 64 EXPECT_TRUE(IsSelecting()); |
| 49 | 65 |
| 50 // Swiping up again does nothing. | 66 // Swiping up again does nothing. |
| 51 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 67 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 52 0, -500, 100, 3); | 68 0, -long_scroll, 100, 3); |
| 53 EXPECT_TRUE(IsSelecting()); | 69 EXPECT_TRUE(IsSelecting()); |
| 54 | 70 |
| 55 // Swiping down exits. | 71 // Swiping down exits. |
| 56 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 72 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 57 0, 500, 100, 3); | 73 0, long_scroll, 100, 3); |
| 58 EXPECT_FALSE(IsSelecting()); | 74 EXPECT_FALSE(IsSelecting()); |
| 59 | 75 |
| 60 // Swiping down again does nothing. | 76 // Swiping down again does nothing. |
| 61 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 77 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 62 0, 500, 100, 3); | 78 0, long_scroll, 100, 3); |
| 63 EXPECT_FALSE(IsSelecting()); | 79 EXPECT_FALSE(IsSelecting()); |
| 64 } | 80 } |
| 65 | 81 |
| 66 // Tests that a mostly horizontal swipe does not trigger overview. | 82 // Tests three finger horizontal scroll gesture to move selection left or right. |
| 67 TEST_F(OverviewGestureHandlerTest, HorizontalSwipes) { | 83 TEST_F(OverviewGestureHandlerTest, HorizontalScrollInOverview) { |
| 84 gfx::Rect bounds(0, 0, 400, 400); |
| 85 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 86 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 87 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 88 std::unique_ptr<aura::Window> window3(CreateWindow(bounds)); |
| 89 std::unique_ptr<aura::Window> window4(CreateWindow(bounds)); |
| 90 std::unique_ptr<aura::Window> window5(CreateWindow(bounds)); |
| 91 ui::test::EventGenerator generator(root_window, root_window); |
| 92 const float vertical_scroll = 2 * vertical_threshold_pixels(); |
| 93 const float horizontal_scroll = horizontal_threshold_pixels(); |
| 94 // Enter overview mode as if using an accelerator. |
| 95 // Entering overview mode with an upwards three-finger scroll gesture would |
| 96 // have the same result (allow selection using horizontal scroll). |
| 97 ToggleOverview(); |
| 98 EXPECT_TRUE(IsSelecting()); |
| 99 |
| 100 // Long scroll right moves selection to the fourth window. |
| 101 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 102 horizontal_scroll * 4, 0, 100, 3); |
| 103 EXPECT_TRUE(IsSelecting()); |
| 104 |
| 105 // Short scroll left (3 fingers) moves selection to the third window. |
| 106 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 107 -horizontal_scroll, 0, 100, 3); |
| 108 EXPECT_TRUE(IsSelecting()); |
| 109 |
| 110 // Short scroll left (3 fingers) moves selection to the second window. |
| 111 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 112 -horizontal_scroll, 0, 100, 3); |
| 113 EXPECT_TRUE(IsSelecting()); |
| 114 |
| 115 // Swiping down exits and selects the currently-highlighted window. |
| 116 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 117 0, vertical_scroll, 100, 3); |
| 118 EXPECT_FALSE(IsSelecting()); |
| 119 |
| 120 // Second MRU window is selected (i.e. |window4|). |
| 121 EXPECT_EQ(window4.get(), wm::GetActiveWindow()); |
| 122 } |
| 123 |
| 124 // Tests that a mostly horizontal three-finger scroll does not trigger overview. |
| 125 TEST_F(OverviewGestureHandlerTest, HorizontalScrolls) { |
| 68 gfx::Rect bounds(0, 0, 400, 400); | 126 gfx::Rect bounds(0, 0, 400, 400); |
| 69 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 127 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 70 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); | 128 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 71 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); | 129 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 72 ui::test::EventGenerator generator(root_window, root_window); | 130 ui::test::EventGenerator generator(root_window, root_window); |
| 131 const float long_scroll = 2 * vertical_threshold_pixels(); |
| 73 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 132 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 74 600, -500, 100, 3); | 133 long_scroll + 100, -long_scroll, 100, 3); |
| 75 EXPECT_FALSE(IsSelecting()); | 134 EXPECT_FALSE(IsSelecting()); |
| 76 | 135 |
| 77 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 136 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 78 -600, -500, 100, 3); | 137 -long_scroll - 100, -long_scroll, 100, 3); |
| 79 EXPECT_FALSE(IsSelecting()); | 138 EXPECT_FALSE(IsSelecting()); |
| 80 } | 139 } |
| 81 | 140 |
| 82 // Tests a swipe up with three fingers without releasing followed by a swipe | 141 // Tests a scroll up with three fingers without releasing followed by a scroll |
| 83 // down by a lesser amount which should still be enough to exit. | 142 // down by a lesser amount which should still be enough to exit. |
| 84 TEST_F(OverviewGestureHandlerTest, SwipeUpDownWithoutReleasing) { | 143 TEST_F(OverviewGestureHandlerTest, ScrollUpDownWithoutReleasing) { |
| 85 gfx::Rect bounds(0, 0, 400, 400); | 144 gfx::Rect bounds(0, 0, 400, 400); |
| 86 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 145 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 87 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); | 146 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 88 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); | 147 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 89 ui::test::EventGenerator generator(root_window, root_window); | 148 ui::test::EventGenerator generator(root_window, root_window); |
| 90 base::TimeTicks timestamp = base::TimeTicks::Now(); | 149 base::TimeTicks timestamp = base::TimeTicks::Now(); |
| 91 gfx::Point start; | 150 gfx::Point start; |
| 92 int num_fingers = 3; | 151 int num_fingers = 3; |
| 93 base::TimeDelta step_delay(base::TimeDelta::FromMilliseconds(5)); | 152 base::TimeDelta step_delay(base::TimeDelta::FromMilliseconds(5)); |
| 94 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, start, timestamp, 0, | 153 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, start, timestamp, 0, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 113 generator.Dispatch(&move); | 172 generator.Dispatch(&move); |
| 114 } | 173 } |
| 115 | 174 |
| 116 EXPECT_FALSE(IsSelecting()); | 175 EXPECT_FALSE(IsSelecting()); |
| 117 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, start, timestamp, 0, 0, | 176 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, start, timestamp, 0, 0, |
| 118 10, 0, 10, num_fingers); | 177 10, 0, 10, num_fingers); |
| 119 generator.Dispatch(&fling_start); | 178 generator.Dispatch(&fling_start); |
| 120 } | 179 } |
| 121 | 180 |
| 122 } // namespace ash | 181 } // namespace ash |
| OLD | NEW |