Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ash / wm / gestures / overview_gesture_handler_unittest.cc
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.
4
5 #include "ash/root_window_controller.h"
6 #include "ash/shell.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"
14
15 namespace ash {
16
17 class OverviewGestureHandlerTest : public test::AshTestBase {
18  public:
19   OverviewGestureHandlerTest() {}
20   virtual ~OverviewGestureHandlerTest() {}
21
22   aura::Window* CreateWindow(const gfx::Rect& bounds) {
23     return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds);
24   }
25
26   bool IsSelecting() {
27     return ash::Shell::GetInstance()->window_selector_controller()->
28         IsSelecting();
29   }
30
31  private:
32   aura::test::TestWindowDelegate delegate_;
33
34   DISALLOW_COPY_AND_ASSIGN(OverviewGestureHandlerTest);
35 };
36
37 // Tests a swipe up with three fingers to enter and a swipe down to exit
38 // overview.
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),
46       0, -500, 100, 3);
47   EXPECT_TRUE(IsSelecting());
48
49   // Swiping up again does nothing.
50   generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
51       0, -500, 100, 3);
52   EXPECT_TRUE(IsSelecting());
53
54   // Swiping down exits.
55   generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
56       0, 500, 100, 3);
57   EXPECT_FALSE(IsSelecting());
58
59   // Swiping down again does nothing.
60   generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
61       0, 500, 100, 3);
62   EXPECT_FALSE(IsSelecting());
63 }
64
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),
73       600, -500, 100, 3);
74   EXPECT_FALSE(IsSelecting());
75
76   generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5),
77       -600, -500, 100, 3);
78   EXPECT_FALSE(IsSelecting());
79 }
80
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());
91   gfx::Point start;
92   int num_fingers = 3;
93   base::TimeDelta step_delay(base::TimeDelta::FromMilliseconds(5));
94   ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL,
95                                start,
96                                timestamp,
97                                0,
98                                0, 0,
99                                0, 0,
100                                num_fingers);
101   generator.Dispatch(&fling_cancel);
102
103   // Scroll up by 1000px.
104   for (int i = 0; i < 100; ++i) {
105     timestamp += step_delay;
106     ui::ScrollEvent move(ui::ET_SCROLL,
107                          start,
108                          timestamp,
109                          0,
110                          0, -10,
111                          0, -10,
112                          num_fingers);
113     generator.Dispatch(&move);
114   }
115
116   EXPECT_TRUE(IsSelecting());
117
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,
122                          start,
123                          timestamp,
124                          0,
125                          0, 10,
126                          0, 10,
127                          num_fingers);
128     generator.Dispatch(&move);
129   }
130
131   EXPECT_FALSE(IsSelecting());
132   ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START,
133                               start,
134                               timestamp,
135                               0,
136                               0, 10,
137                               0, 10,
138                               num_fingers);
139   generator.Dispatch(&fling_start);
140 }
141
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());
153
154   generator.GestureMultiFingerScroll(3, start_points, 5, 10, 0, 100);
155   EXPECT_FALSE(IsSelecting());
156 }
157
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());
170 }
171
172 }  // namespace ash