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.
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"
13 class GestureProviderAuraTest
: public testing::Test
,
14 public GestureProviderAuraClient
{
16 GestureProviderAuraTest() {}
18 virtual ~GestureProviderAuraTest() {}
20 virtual void OnGestureEvent(GestureEvent
* event
) OVERRIDE
{}
22 virtual void SetUp() OVERRIDE
{
23 provider_
.reset(new GestureProviderAura(this));
26 virtual void TearDown() OVERRIDE
{ provider_
.reset(); }
28 GestureProviderAura
* provider() { return provider_
.get(); }
31 scoped_ptr
<GestureProviderAura
> provider_
;
32 base::MessageLoopForUI message_loop_
;
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
));
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
));
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
));
51 time
+= base::TimeDelta::FromMilliseconds(10);
52 TouchEvent
release1(ET_TOUCH_RELEASED
, gfx::PointF(30, 40), 0, time
);
53 EXPECT_TRUE(provider()->OnTouchEvent(release1
));
55 time
+= base::TimeDelta::FromMilliseconds(10);
56 TouchEvent
release2(ET_TOUCH_RELEASED
, gfx::PointF(30, 45), 0, time
);
57 EXPECT_FALSE(provider()->OnTouchEvent(release1
));
59 time
+= base::TimeDelta::FromMilliseconds(10);
60 TouchEvent
move1(ET_TOUCH_MOVED
, gfx::PointF(70, 75), 0, time
);
61 EXPECT_FALSE(provider()->OnTouchEvent(move1
));
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;
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
));
76 TouchEvent
press1_1(ET_TOUCH_PRESSED
, gfx::PointF(40, 40), kTouchId1
, time
);
77 EXPECT_TRUE(provider()->OnTouchEvent(press1_1
));
79 time
+= base::TimeDelta::FromMilliseconds(10);
80 TouchEvent
move0_1(ET_TOUCH_MOVED
,
89 EXPECT_TRUE(provider()->OnTouchEvent(move0_1
));
91 TouchEvent
move1_1(ET_TOUCH_MOVED
,
92 gfx::PointF(100, 200),
100 EXPECT_TRUE(provider()->OnTouchEvent(move1_1
));
102 time
+= base::TimeDelta::FromMilliseconds(10);
103 TouchEvent
move0_2(ET_TOUCH_MOVED
,
112 // Nothing has changed, so ignore the move.
113 EXPECT_FALSE(provider()->OnTouchEvent(move0_2
));
115 TouchEvent
move1_2(ET_TOUCH_MOVED
,
116 gfx::PointF(100, 200),
124 // Nothing has changed, so ignore the move.
125 EXPECT_FALSE(provider()->OnTouchEvent(move1_2
));
127 time
+= base::TimeDelta::FromMilliseconds(10);
128 TouchEvent
move0_3(ET_TOUCH_MOVED
,
129 gfx::PointF(70, 75.1f
),
137 // Position has changed, so don't ignore the move.
138 EXPECT_TRUE(provider()->OnTouchEvent(move0_3
));
140 time
+= base::TimeDelta::FromMilliseconds(10);
141 TouchEvent
move0_4(ET_TOUCH_MOVED
,
142 gfx::PointF(70, 75.1f
),