Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Side by Side Diff: ash/wm/gestures/overview_gesture_handler_unittest.cc

Issue 2667293002: [ash-md] Adds support for gesture to move selection in overview mode (Closed)
Patch Set: [ash-md] Adds support for gesture to move selection in overview mode (tuning) Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 3-finger scroll gesture would have
96 // 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 fourth MRU window.
106 // The first MRU window is skipped when selector is moved for the first time.
107 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
108 -horizontal_scroll, 0, 100, 3);
109 EXPECT_TRUE(IsSelecting());
110
111 // Short scroll left (3 fingers) moves selection to the second window.
112 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
113 -horizontal_scroll, 0, 100, 3);
114 EXPECT_TRUE(IsSelecting());
115
116 // Swiping down exits and selects the currently-highlighted window.
117 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
118 0, vertical_scroll, 100, 3);
119 EXPECT_FALSE(IsSelecting());
120
121 // Third MRU window is selected (i.e. |window3|).
122 EXPECT_EQ(window3.get(), wm::GetActiveWindow());
123 }
124
125 // Tests that a mostly horizontal scroll does not trigger overview.
tdanderson 2017/02/10 16:05:19 nit: three-finger scroll
varkha 2017/02/10 17:34:31 Done.
126 TEST_F(OverviewGestureHandlerTest, HorizontalScrolls) {
68 gfx::Rect bounds(0, 0, 400, 400); 127 gfx::Rect bounds(0, 0, 400, 400);
69 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 128 aura::Window* root_window = Shell::GetPrimaryRootWindow();
70 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); 129 std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
71 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); 130 std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
72 ui::test::EventGenerator generator(root_window, root_window); 131 ui::test::EventGenerator generator(root_window, root_window);
132 const float long_scroll = 2 * vertical_threshold_pixels();
73 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), 133 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
74 600, -500, 100, 3); 134 long_scroll + 100, -long_scroll, 100, 3);
75 EXPECT_FALSE(IsSelecting()); 135 EXPECT_FALSE(IsSelecting());
76 136
77 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), 137 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
78 -600, -500, 100, 3); 138 -long_scroll - 100, -long_scroll, 100, 3);
79 EXPECT_FALSE(IsSelecting()); 139 EXPECT_FALSE(IsSelecting());
80 } 140 }
81 141
82 // Tests a swipe up with three fingers without releasing followed by a swipe 142 // 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. 143 // down by a lesser amount which should still be enough to exit.
84 TEST_F(OverviewGestureHandlerTest, SwipeUpDownWithoutReleasing) { 144 TEST_F(OverviewGestureHandlerTest, ScrollUpDownWithoutReleasing) {
85 gfx::Rect bounds(0, 0, 400, 400); 145 gfx::Rect bounds(0, 0, 400, 400);
86 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 146 aura::Window* root_window = Shell::GetPrimaryRootWindow();
87 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); 147 std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
88 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); 148 std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
89 ui::test::EventGenerator generator(root_window, root_window); 149 ui::test::EventGenerator generator(root_window, root_window);
90 base::TimeTicks timestamp = base::TimeTicks::Now(); 150 base::TimeTicks timestamp = base::TimeTicks::Now();
91 gfx::Point start; 151 gfx::Point start;
92 int num_fingers = 3; 152 int num_fingers = 3;
93 base::TimeDelta step_delay(base::TimeDelta::FromMilliseconds(5)); 153 base::TimeDelta step_delay(base::TimeDelta::FromMilliseconds(5));
94 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, start, timestamp, 0, 154 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, start, timestamp, 0,
(...skipping 18 matching lines...) Expand all
113 generator.Dispatch(&move); 173 generator.Dispatch(&move);
114 } 174 }
115 175
116 EXPECT_FALSE(IsSelecting()); 176 EXPECT_FALSE(IsSelecting());
117 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, start, timestamp, 0, 0, 177 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, start, timestamp, 0, 0,
118 10, 0, 10, num_fingers); 178 10, 0, 10, num_fingers);
119 generator.Dispatch(&fling_start); 179 generator.Dispatch(&fling_start);
120 } 180 }
121 181
122 } // namespace ash 182 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698