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
3 // found in the LICENSE file.
5 #include "ash/root_window_controller.h"
7 #include "ash/test/ash_test_base.h"
8 #include "ash/wm/overview/window_selector_controller.h"
9 #include "ui/aura/test/event_generator.h"
10 #include "ui/aura/test/test_window_delegate.h"
11 #include "ui/aura/test/test_windows.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h"
17 class OverviewGestureHandlerTest : public test::AshTestBase {
19 OverviewGestureHandlerTest() {}
20 virtual ~OverviewGestureHandlerTest() {}
22 aura::Window* CreateWindow(const gfx::Rect& bounds) {
23 return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds);
27 return ash::Shell::GetInstance()->window_selector_controller()->
32 aura::test::TestWindowDelegate delegate_;
34 DISALLOW_COPY_AND_ASSIGN(OverviewGestureHandlerTest);
37 // Tests a swipe up with three fingers to enter and a swipe down to exit
39 TEST_F(OverviewGestureHandlerTest, VerticalSwipes) {
40 gfx::Rect bounds(0, 0, 400, 400);
41 aura::Window* root_window = Shell::GetPrimaryRootWindow();
42 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
43 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
44 aura::test::EventGenerator generator(root_window, root_window);
45 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
47 EXPECT_TRUE(IsSelecting());
49 // Swiping up again does nothing.
50 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
52 EXPECT_TRUE(IsSelecting());
54 // Swiping down exits.
55 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
57 EXPECT_FALSE(IsSelecting());
59 // Swiping down again does nothing.
60 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
62 EXPECT_FALSE(IsSelecting());
65 // Tests that a mostly horizontal swipe does not trigger overview.
66 TEST_F(OverviewGestureHandlerTest, HorizontalSwipes) {
67 gfx::Rect bounds(0, 0, 400, 400);
68 aura::Window* root_window = Shell::GetPrimaryRootWindow();
69 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
70 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
71 aura::test::EventGenerator generator(root_window, root_window);
72 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
74 EXPECT_FALSE(IsSelecting());
76 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
78 EXPECT_FALSE(IsSelecting());
81 // Tests a swipe up with three fingers without releasing followed by a swipe
82 // down by a lesser amount which should still be enough to exit.
83 TEST_F(OverviewGestureHandlerTest, SwipeUpDownWithoutReleasing) {
84 gfx::Rect bounds(0, 0, 400, 400);
85 aura::Window* root_window = Shell::GetPrimaryRootWindow();
86 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
87 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
88 aura::test::EventGenerator generator(root_window, root_window);
89 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue(
90 base::TimeTicks::Now().ToInternalValue());
93 base::TimeDelta step_delay(base::TimeDelta::FromMilliseconds(5));
94 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL,
101 generator.Dispatch(&fling_cancel);
103 // Scroll up by 1000px.
104 for (int i = 0; i < 100; ++i) {
105 timestamp += step_delay;
106 ui::ScrollEvent move(ui::ET_SCROLL,
113 generator.Dispatch(&move);
116 EXPECT_TRUE(IsSelecting());
118 // Without releasing scroll back down by 600px.
119 for (int i = 0; i < 60; ++i) {
120 timestamp += step_delay;
121 ui::ScrollEvent move(ui::ET_SCROLL,
128 generator.Dispatch(&move);
131 EXPECT_FALSE(IsSelecting());
132 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START,
139 generator.Dispatch(&fling_start);
142 // Tests a swipe down from the top of the screen to enter and exit overview.
143 TEST_F(OverviewGestureHandlerTest, GestureSwipe) {
144 gfx::Rect bounds(0, 0, 400, 400);
145 aura::Window* root_window = Shell::GetPrimaryRootWindow();
146 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
147 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
148 aura::test::EventGenerator generator(root_window, root_window);
149 gfx::Point start_points[3];
150 start_points[0] = start_points[1] = start_points[2] = gfx::Point();
151 generator.GestureMultiFingerScroll(3, start_points, 5, 10, 0, 100);
152 EXPECT_TRUE(IsSelecting());
154 generator.GestureMultiFingerScroll(3, start_points, 5, 10, 0, 100);
155 EXPECT_FALSE(IsSelecting());
158 // Tests that a swipe down from the top of a window doesn't enter overview.
159 // http://crbug.com/313859
160 TEST_F(OverviewGestureHandlerTest, GestureSwipeTopOfWindow) {
161 gfx::Rect bounds(100, 100, 400, 400);
162 aura::Window* root_window = Shell::GetPrimaryRootWindow();
163 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
164 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
165 aura::test::EventGenerator generator(root_window, window2.get());
166 gfx::Point start_points[3];
167 start_points[0] = start_points[1] = start_points[2] = gfx::Point(105, 105);
168 generator.GestureMultiFingerScroll(3, start_points, 5, 10, 0, 100);
169 EXPECT_FALSE(IsSelecting());