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

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 (comments) 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
28 bool IsSelecting() { 31 bool IsSelecting() {
29 return WmShell::Get()->window_selector_controller()->IsSelecting(); 32 return WmShell::Get()->window_selector_controller()->IsSelecting();
30 } 33 }
31 34
35 float vertical_threshold_pixels() const {
36 return OverviewGestureHandler::vertical_threshold_pixels_;
37 }
38
39 float horizontal_threshold_pixels() const {
40 return OverviewGestureHandler::horizontal_threshold_pixels_;
41 }
42
32 private: 43 private:
33 aura::test::TestWindowDelegate delegate_; 44 aura::test::TestWindowDelegate delegate_;
34 45
35 DISALLOW_COPY_AND_ASSIGN(OverviewGestureHandlerTest); 46 DISALLOW_COPY_AND_ASSIGN(OverviewGestureHandlerTest);
36 }; 47 };
37 48
38 // Tests a swipe up with three fingers to enter and a swipe down to exit 49 // Tests a swipe up with three fingers to enter and a swipe down to exit
39 // overview. 50 // overview.
40 TEST_F(OverviewGestureHandlerTest, VerticalSwipes) { 51 TEST_F(OverviewGestureHandlerTest, VerticalSwipes) {
41 gfx::Rect bounds(0, 0, 400, 400); 52 gfx::Rect bounds(0, 0, 400, 400);
42 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 53 aura::Window* root_window = Shell::GetPrimaryRootWindow();
43 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); 54 std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
44 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); 55 std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
45 ui::test::EventGenerator generator(root_window, root_window); 56 ui::test::EventGenerator generator(root_window, root_window);
57 const float long_swipe = 2 * vertical_threshold_pixels();
46 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), 58 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
47 0, -500, 100, 3); 59 0, -long_swipe, 100, 3);
48 EXPECT_TRUE(IsSelecting()); 60 EXPECT_TRUE(IsSelecting());
49 61
50 // Swiping up again does nothing. 62 // Swiping up again does nothing.
51 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), 63 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
52 0, -500, 100, 3); 64 0, -long_swipe, 100, 3);
53 EXPECT_TRUE(IsSelecting()); 65 EXPECT_TRUE(IsSelecting());
54 66
55 // Swiping down exits. 67 // Swiping down exits.
56 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), 68 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
57 0, 500, 100, 3); 69 0, long_swipe, 100, 3);
58 EXPECT_FALSE(IsSelecting()); 70 EXPECT_FALSE(IsSelecting());
59 71
60 // Swiping down again does nothing. 72 // Swiping down again does nothing.
61 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), 73 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
62 0, 500, 100, 3); 74 0, long_swipe, 100, 3);
63 EXPECT_FALSE(IsSelecting()); 75 EXPECT_FALSE(IsSelecting());
64 } 76 }
65 77
78 // Tests a swipe up with three fingers to enter overview and a swipe right or
tdanderson 2017/02/08 23:14:19 The OverviewGestureHandlerTest.VerticalSwipes test
varkha 2017/02/09 21:54:42 Done.
79 // left to move selection.
80 TEST_F(OverviewGestureHandlerTest, VerticalThenHorizontalSwipe) {
81 gfx::Rect bounds(0, 0, 400, 400);
82 aura::Window* root_window = Shell::GetPrimaryRootWindow();
83 std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
84 std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
85 std::unique_ptr<aura::Window> window3(CreateWindow(bounds));
86 std::unique_ptr<aura::Window> window4(CreateWindow(bounds));
87 std::unique_ptr<aura::Window> window5(CreateWindow(bounds));
88 ui::test::EventGenerator generator(root_window, root_window);
89 const float vertical_swipe = 2 * vertical_threshold_pixels();
90 const float horizontal_swipe = horizontal_threshold_pixels();
91 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
92 0, -vertical_swipe, 100, 3);
93 EXPECT_TRUE(IsSelecting());
94
95 // Long swipe right moves selection to the fourth window.
96 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
97 horizontal_swipe * 4, 0, 100, 3);
98 EXPECT_TRUE(IsSelecting());
99
100 // Short swipe left (3 fingers) moves selection to the third window.
101 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
102 -horizontal_swipe, 0, 100, 3);
103 EXPECT_TRUE(IsSelecting());
104
105 // Short swipe left (2 fingers) moves selection to the second window.
106 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
107 -horizontal_swipe, 0, 100, 2);
108 EXPECT_TRUE(IsSelecting());
109
110 // Swiping down exits and selects the currently-highlighted window.
111 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
112 0, vertical_swipe, 100, 3);
113 EXPECT_FALSE(IsSelecting());
114
115 // Second MRU window is selected (i.e. |window4|).
116 EXPECT_EQ(window4.get(), wm::GetActiveWindow());
117 }
118
66 // Tests that a mostly horizontal swipe does not trigger overview. 119 // Tests that a mostly horizontal swipe does not trigger overview.
tdanderson 2017/02/08 23:14:19 nit: while you're here it would be good to reword
varkha 2017/02/09 21:54:42 Done.
67 TEST_F(OverviewGestureHandlerTest, HorizontalSwipes) { 120 TEST_F(OverviewGestureHandlerTest, HorizontalSwipes) {
68 gfx::Rect bounds(0, 0, 400, 400); 121 gfx::Rect bounds(0, 0, 400, 400);
69 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 122 aura::Window* root_window = Shell::GetPrimaryRootWindow();
70 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); 123 std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
71 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); 124 std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
72 ui::test::EventGenerator generator(root_window, root_window); 125 ui::test::EventGenerator generator(root_window, root_window);
126 const float long_swipe = 2 * vertical_threshold_pixels();
73 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), 127 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
74 600, -500, 100, 3); 128 long_swipe + 100, -long_swipe, 100, 3);
75 EXPECT_FALSE(IsSelecting()); 129 EXPECT_FALSE(IsSelecting());
76 130
77 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), 131 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
78 -600, -500, 100, 3); 132 -long_swipe - 100, -long_swipe, 100, 3);
79 EXPECT_FALSE(IsSelecting()); 133 EXPECT_FALSE(IsSelecting());
80 } 134 }
81 135
82 // Tests a swipe up with three fingers without releasing followed by a swipe 136 // Tests a swipe up with three fingers without releasing followed by a swipe
83 // down by a lesser amount which should still be enough to exit. 137 // down by a lesser amount which should still be enough to exit.
84 TEST_F(OverviewGestureHandlerTest, SwipeUpDownWithoutReleasing) { 138 TEST_F(OverviewGestureHandlerTest, SwipeUpDownWithoutReleasing) {
85 gfx::Rect bounds(0, 0, 400, 400); 139 gfx::Rect bounds(0, 0, 400, 400);
86 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 140 aura::Window* root_window = Shell::GetPrimaryRootWindow();
87 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); 141 std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
88 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); 142 std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
(...skipping 24 matching lines...) Expand all
113 generator.Dispatch(&move); 167 generator.Dispatch(&move);
114 } 168 }
115 169
116 EXPECT_FALSE(IsSelecting()); 170 EXPECT_FALSE(IsSelecting());
117 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, start, timestamp, 0, 0, 171 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, start, timestamp, 0, 0,
118 10, 0, 10, num_fingers); 172 10, 0, 10, num_fingers);
119 generator.Dispatch(&fling_start); 173 generator.Dispatch(&fling_start);
120 } 174 }
121 175
122 } // namespace ash 176 } // namespace ash
OLDNEW
« ash/wm/gestures/overview_gesture_handler.cc ('K') | « ash/wm/gestures/overview_gesture_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698