Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ui / events / gestures / gesture_provider_aura_unittest.cc
1 // Copyright 2014 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 "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/event_utils.h"
9 #include "ui/events/gestures/gesture_provider_aura.h"
10
11 namespace ui {
12
13 class GestureProviderAuraTest : public testing::Test,
14                                 public GestureProviderAuraClient {
15  public:
16   GestureProviderAuraTest() {}
17
18   virtual ~GestureProviderAuraTest() {}
19
20   virtual void OnGestureEvent(GestureEvent* event) OVERRIDE {}
21
22   virtual void SetUp() OVERRIDE {
23     provider_.reset(new GestureProviderAura(this));
24   }
25
26   virtual void TearDown() OVERRIDE { provider_.reset(); }
27
28   GestureProviderAura* provider() { return provider_.get(); }
29
30  private:
31   scoped_ptr<GestureProviderAura> provider_;
32   base::MessageLoopForUI message_loop_;
33 };
34
35 TEST_F(GestureProviderAuraTest, IgnoresExtraPressEvents) {
36   base::TimeDelta time = ui::EventTimeForNow();
37   TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
38   EXPECT_TRUE(provider()->OnTouchEvent(press1));
39
40   time += base::TimeDelta::FromMilliseconds(10);
41   TouchEvent press2(ET_TOUCH_PRESSED, gfx::PointF(30, 40), 0, time);
42   // Redundant press with same id is ignored.
43   EXPECT_FALSE(provider()->OnTouchEvent(press2));
44 }
45
46 TEST_F(GestureProviderAuraTest, IgnoresExtraMoveOrReleaseEvents) {
47   base::TimeDelta time = ui::EventTimeForNow();
48   TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
49   EXPECT_TRUE(provider()->OnTouchEvent(press1));
50
51   time += base::TimeDelta::FromMilliseconds(10);
52   TouchEvent release1(ET_TOUCH_RELEASED, gfx::PointF(30, 40), 0, time);
53   EXPECT_TRUE(provider()->OnTouchEvent(release1));
54
55   time += base::TimeDelta::FromMilliseconds(10);
56   TouchEvent release2(ET_TOUCH_RELEASED, gfx::PointF(30, 45), 0, time);
57   EXPECT_FALSE(provider()->OnTouchEvent(release1));
58
59   time += base::TimeDelta::FromMilliseconds(10);
60   TouchEvent move1(ET_TOUCH_MOVED, gfx::PointF(70, 75), 0, time);
61   EXPECT_FALSE(provider()->OnTouchEvent(move1));
62 }
63
64 TEST_F(GestureProviderAuraTest, IgnoresIdenticalMoveEvents) {
65   const float kRadiusX = 20;
66   const float kRadiusY = 30;
67   const float kAngle = 120;
68   const float kForce = 40;
69   const int kTouchId0 = 5;
70   const int kTouchId1 = 3;
71
72   base::TimeDelta time = ui::EventTimeForNow();
73   TouchEvent press0_1(ET_TOUCH_PRESSED, gfx::PointF(9, 10), kTouchId0, time);
74   EXPECT_TRUE(provider()->OnTouchEvent(press0_1));
75
76   TouchEvent press1_1(ET_TOUCH_PRESSED, gfx::PointF(40, 40), kTouchId1, time);
77   EXPECT_TRUE(provider()->OnTouchEvent(press1_1));
78
79   time += base::TimeDelta::FromMilliseconds(10);
80   TouchEvent move0_1(ET_TOUCH_MOVED,
81                    gfx::PointF(10, 10),
82                    0,
83                    kTouchId0,
84                    time,
85                    kRadiusX,
86                    kRadiusY,
87                    kAngle,
88                    kForce);
89   EXPECT_TRUE(provider()->OnTouchEvent(move0_1));
90
91   TouchEvent move1_1(ET_TOUCH_MOVED,
92                    gfx::PointF(100, 200),
93                    0,
94                    kTouchId1,
95                    time,
96                    kRadiusX,
97                    kRadiusY,
98                    kAngle,
99                    kForce);
100   EXPECT_TRUE(provider()->OnTouchEvent(move1_1));
101
102   time += base::TimeDelta::FromMilliseconds(10);
103   TouchEvent move0_2(ET_TOUCH_MOVED,
104                      gfx::PointF(10, 10),
105                      0,
106                      kTouchId0,
107                      time,
108                      kRadiusX,
109                      kRadiusY,
110                      kAngle,
111                      kForce);
112   // Nothing has changed, so ignore the move.
113   EXPECT_FALSE(provider()->OnTouchEvent(move0_2));
114
115   TouchEvent move1_2(ET_TOUCH_MOVED,
116                      gfx::PointF(100, 200),
117                      0,
118                      kTouchId1,
119                      time,
120                      kRadiusX,
121                      kRadiusY,
122                      kAngle,
123                      kForce);
124   // Nothing has changed, so ignore the move.
125   EXPECT_FALSE(provider()->OnTouchEvent(move1_2));
126
127   time += base::TimeDelta::FromMilliseconds(10);
128   TouchEvent move0_3(ET_TOUCH_MOVED,
129                      gfx::PointF(70, 75.1f),
130                      0,
131                      kTouchId0,
132                      time,
133                      kRadiusX,
134                      kRadiusY,
135                      kAngle,
136                      kForce);
137   // Position has changed, so don't ignore the move.
138   EXPECT_TRUE(provider()->OnTouchEvent(move0_3));
139
140   time += base::TimeDelta::FromMilliseconds(10);
141   TouchEvent move0_4(ET_TOUCH_MOVED,
142                      gfx::PointF(70, 75.1f),
143                      0,
144                      kTouchId0,
145                      time,
146                      kRadiusX,
147                      kRadiusY + 1,
148                      kAngle,
149                      kForce);
150 }
151
152 }  // namespace ui