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 ~GestureProviderAuraTest() override {}
20 void OnGestureEvent(GestureEvent* event) override {}
22 void SetUp() override { provider_.reset(new GestureProviderAura(this)); }
24 void TearDown() override { provider_.reset(); }
26 GestureProviderAura* provider() { return provider_.get(); }
29 scoped_ptr<GestureProviderAura> provider_;
30 base::MessageLoopForUI message_loop_;
33 TEST_F(GestureProviderAuraTest, IgnoresExtraPressEvents) {
34 base::TimeDelta time = ui::EventTimeForNow();
35 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
36 EXPECT_TRUE(provider()->OnTouchEvent(press1));
38 time += base::TimeDelta::FromMilliseconds(10);
39 TouchEvent press2(ET_TOUCH_PRESSED, gfx::PointF(30, 40), 0, time);
40 // Redundant press with same id is ignored.
41 EXPECT_FALSE(provider()->OnTouchEvent(press2));
44 TEST_F(GestureProviderAuraTest, IgnoresExtraMoveOrReleaseEvents) {
45 base::TimeDelta time = ui::EventTimeForNow();
46 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
47 EXPECT_TRUE(provider()->OnTouchEvent(press1));
49 time += base::TimeDelta::FromMilliseconds(10);
50 TouchEvent release1(ET_TOUCH_RELEASED, gfx::PointF(30, 40), 0, time);
51 EXPECT_TRUE(provider()->OnTouchEvent(release1));
53 time += base::TimeDelta::FromMilliseconds(10);
54 TouchEvent release2(ET_TOUCH_RELEASED, gfx::PointF(30, 45), 0, time);
55 EXPECT_FALSE(provider()->OnTouchEvent(release1));
57 time += base::TimeDelta::FromMilliseconds(10);
58 TouchEvent move1(ET_TOUCH_MOVED, gfx::PointF(70, 75), 0, time);
59 EXPECT_FALSE(provider()->OnTouchEvent(move1));
62 TEST_F(GestureProviderAuraTest, IgnoresIdenticalMoveEvents) {
63 const float kRadiusX = 20.f;
64 const float kRadiusY = 30.f;
65 const float kAngle = 0.321f;
66 const float kForce = 40.f;
67 const int kTouchId0 = 5;
68 const int kTouchId1 = 3;
70 base::TimeDelta time = ui::EventTimeForNow();
71 TouchEvent press0_1(ET_TOUCH_PRESSED, gfx::PointF(9, 10), kTouchId0, time);
72 EXPECT_TRUE(provider()->OnTouchEvent(press0_1));
74 TouchEvent press1_1(ET_TOUCH_PRESSED, gfx::PointF(40, 40), kTouchId1, time);
75 EXPECT_TRUE(provider()->OnTouchEvent(press1_1));
77 time += base::TimeDelta::FromMilliseconds(10);
78 TouchEvent move0_1(ET_TOUCH_MOVED,
87 EXPECT_TRUE(provider()->OnTouchEvent(move0_1));
89 TouchEvent move1_1(ET_TOUCH_MOVED,
90 gfx::PointF(100, 200),
98 EXPECT_TRUE(provider()->OnTouchEvent(move1_1));
100 time += base::TimeDelta::FromMilliseconds(10);
101 TouchEvent move0_2(ET_TOUCH_MOVED,
110 // Nothing has changed, so ignore the move.
111 EXPECT_FALSE(provider()->OnTouchEvent(move0_2));
113 TouchEvent move1_2(ET_TOUCH_MOVED,
114 gfx::PointF(100, 200),
122 // Nothing has changed, so ignore the move.
123 EXPECT_FALSE(provider()->OnTouchEvent(move1_2));
125 time += base::TimeDelta::FromMilliseconds(10);
126 TouchEvent move0_3(ET_TOUCH_MOVED,
127 gfx::PointF(70, 75.1f),
135 // Position has changed, so don't ignore the move.
136 EXPECT_TRUE(provider()->OnTouchEvent(move0_3));
138 time += base::TimeDelta::FromMilliseconds(10);
139 TouchEvent move0_4(ET_TOUCH_MOVED,
140 gfx::PointF(70, 75.1f),