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/test_window_delegate.h"
10 #include "ui/aura/test/test_windows.h"
11 #include "ui/aura/window.h"
12 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/events/test/event_generator.h"
14 #include "ui/views/widget/widget.h"
18 class OverviewGestureHandlerTest
: public test::AshTestBase
{
20 OverviewGestureHandlerTest() {}
21 ~OverviewGestureHandlerTest() override
{}
23 aura::Window
* CreateWindow(const gfx::Rect
& bounds
) {
24 return CreateTestWindowInShellWithDelegate(&delegate_
, -1, bounds
);
28 return ash::Shell::GetInstance()->window_selector_controller()->
33 aura::test::TestWindowDelegate delegate_
;
35 DISALLOW_COPY_AND_ASSIGN(OverviewGestureHandlerTest
);
38 // Tests a swipe up with three fingers to enter and a swipe down to exit
40 TEST_F(OverviewGestureHandlerTest
, VerticalSwipes
) {
41 gfx::Rect
bounds(0, 0, 400, 400);
42 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
43 scoped_ptr
<aura::Window
> window1(CreateWindow(bounds
));
44 scoped_ptr
<aura::Window
> window2(CreateWindow(bounds
));
45 ui::test::EventGenerator
generator(root_window
, root_window
);
46 generator
.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
48 EXPECT_TRUE(IsSelecting());
50 // Swiping up again does nothing.
51 generator
.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
53 EXPECT_TRUE(IsSelecting());
55 // Swiping down exits.
56 generator
.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
58 EXPECT_FALSE(IsSelecting());
60 // Swiping down again does nothing.
61 generator
.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
63 EXPECT_FALSE(IsSelecting());
66 // Tests that a mostly horizontal swipe does not trigger overview.
67 TEST_F(OverviewGestureHandlerTest
, HorizontalSwipes
) {
68 gfx::Rect
bounds(0, 0, 400, 400);
69 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
70 scoped_ptr
<aura::Window
> window1(CreateWindow(bounds
));
71 scoped_ptr
<aura::Window
> window2(CreateWindow(bounds
));
72 ui::test::EventGenerator
generator(root_window
, root_window
);
73 generator
.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
75 EXPECT_FALSE(IsSelecting());
77 generator
.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
79 EXPECT_FALSE(IsSelecting());
82 // 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.
84 TEST_F(OverviewGestureHandlerTest
, SwipeUpDownWithoutReleasing
) {
85 gfx::Rect
bounds(0, 0, 400, 400);
86 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
87 scoped_ptr
<aura::Window
> window1(CreateWindow(bounds
));
88 scoped_ptr
<aura::Window
> window2(CreateWindow(bounds
));
89 ui::test::EventGenerator
generator(root_window
, root_window
);
90 base::TimeDelta timestamp
= base::TimeDelta::FromInternalValue(
91 base::TimeTicks::Now().ToInternalValue());
94 base::TimeDelta
step_delay(base::TimeDelta::FromMilliseconds(5));
95 ui::ScrollEvent
fling_cancel(ui::ET_SCROLL_FLING_CANCEL
,
102 generator
.Dispatch(&fling_cancel
);
104 // Scroll up by 1000px.
105 for (int i
= 0; i
< 100; ++i
) {
106 timestamp
+= step_delay
;
107 ui::ScrollEvent
move(ui::ET_SCROLL
,
114 generator
.Dispatch(&move
);
117 EXPECT_TRUE(IsSelecting());
119 // Without releasing scroll back down by 600px.
120 for (int i
= 0; i
< 60; ++i
) {
121 timestamp
+= step_delay
;
122 ui::ScrollEvent
move(ui::ET_SCROLL
,
129 generator
.Dispatch(&move
);
132 EXPECT_FALSE(IsSelecting());
133 ui::ScrollEvent
fling_start(ui::ET_SCROLL_FLING_START
,
140 generator
.Dispatch(&fling_start
);