Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / events / gestures / gesture_provider_aura_unittest.cc
blob79e06a8dc95fb9d9238550310622b54e11a79eb0
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"
11 namespace ui {
13 class GestureProviderAuraTest : public testing::Test,
14 public GestureProviderAuraClient {
15 public:
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(); }
28 private:
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 // TODO(tdresser): this redundant press with same id should be
41 // ignored; however, there is at least one case where we need to
42 // allow a touch press from a currently used touch id. See
43 // crbug.com/373125 for details.
44 EXPECT_TRUE(provider()->OnTouchEvent(&press2));
47 TEST_F(GestureProviderAuraTest, IgnoresExtraMoveOrReleaseEvents) {
48 base::TimeDelta time = ui::EventTimeForNow();
49 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
50 EXPECT_TRUE(provider()->OnTouchEvent(&press1));
52 time += base::TimeDelta::FromMilliseconds(10);
53 TouchEvent release1(ET_TOUCH_RELEASED, gfx::PointF(30, 40), 0, time);
54 EXPECT_TRUE(provider()->OnTouchEvent(&release1));
56 time += base::TimeDelta::FromMilliseconds(10);
57 TouchEvent release2(ET_TOUCH_RELEASED, gfx::PointF(30, 45), 0, time);
58 EXPECT_FALSE(provider()->OnTouchEvent(&release1));
60 time += base::TimeDelta::FromMilliseconds(10);
61 TouchEvent move1(ET_TOUCH_MOVED, gfx::PointF(70, 75), 0, time);
62 EXPECT_FALSE(provider()->OnTouchEvent(&move1));
65 TEST_F(GestureProviderAuraTest, IgnoresIdenticalMoveEvents) {
66 const float kRadiusX = 20.f;
67 const float kRadiusY = 30.f;
68 const float kAngle = 0.321f;
69 const float kForce = 40.f;
70 const int kTouchId0 = 5;
71 const int kTouchId1 = 3;
73 base::TimeDelta time = ui::EventTimeForNow();
74 TouchEvent press0_1(ET_TOUCH_PRESSED, gfx::PointF(9, 10), kTouchId0, time);
75 EXPECT_TRUE(provider()->OnTouchEvent(&press0_1));
77 TouchEvent press1_1(ET_TOUCH_PRESSED, gfx::PointF(40, 40), kTouchId1, time);
78 EXPECT_TRUE(provider()->OnTouchEvent(&press1_1));
80 time += base::TimeDelta::FromMilliseconds(10);
81 TouchEvent move0_1(ET_TOUCH_MOVED,
82 gfx::PointF(10, 10),
84 kTouchId0,
85 time,
86 kRadiusX,
87 kRadiusY,
88 kAngle,
89 kForce);
90 EXPECT_TRUE(provider()->OnTouchEvent(&move0_1));
92 TouchEvent move1_1(ET_TOUCH_MOVED,
93 gfx::PointF(100, 200),
95 kTouchId1,
96 time,
97 kRadiusX,
98 kRadiusY,
99 kAngle,
100 kForce);
101 EXPECT_TRUE(provider()->OnTouchEvent(&move1_1));
103 time += base::TimeDelta::FromMilliseconds(10);
104 TouchEvent move0_2(ET_TOUCH_MOVED,
105 gfx::PointF(10, 10),
107 kTouchId0,
108 time,
109 kRadiusX,
110 kRadiusY,
111 kAngle,
112 kForce);
113 // Nothing has changed, so ignore the move.
114 EXPECT_FALSE(provider()->OnTouchEvent(&move0_2));
116 TouchEvent move1_2(ET_TOUCH_MOVED,
117 gfx::PointF(100, 200),
119 kTouchId1,
120 time,
121 kRadiusX,
122 kRadiusY,
123 kAngle,
124 kForce);
125 // Nothing has changed, so ignore the move.
126 EXPECT_FALSE(provider()->OnTouchEvent(&move1_2));
128 time += base::TimeDelta::FromMilliseconds(10);
129 TouchEvent move0_3(ET_TOUCH_MOVED,
130 gfx::PointF(70, 75.1f),
132 kTouchId0,
133 time,
134 kRadiusX,
135 kRadiusY,
136 kAngle,
137 kForce);
138 // Position has changed, so don't ignore the move.
139 EXPECT_TRUE(provider()->OnTouchEvent(&move0_3));
141 time += base::TimeDelta::FromMilliseconds(10);
142 TouchEvent move0_4(ET_TOUCH_MOVED,
143 gfx::PointF(70, 75.1f),
145 kTouchId0,
146 time,
147 kRadiusX,
148 kRadiusY + 1,
149 kAngle,
150 kForce);
153 // TODO(jdduke): Test whether event marked as scroll trigger.
155 } // namespace ui