Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / events / gestures / gesture_provider_aura_unittest.cc
blobb51ca616c65fb95b35ae0567a8eb2c691e0cb60e
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 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(); }
30 private:
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,
81 gfx::PointF(10, 10),
83 kTouchId0,
84 time,
85 kRadiusX,
86 kRadiusY,
87 kAngle,
88 kForce);
89 EXPECT_TRUE(provider()->OnTouchEvent(move0_1));
91 TouchEvent move1_1(ET_TOUCH_MOVED,
92 gfx::PointF(100, 200),
94 kTouchId1,
95 time,
96 kRadiusX,
97 kRadiusY,
98 kAngle,
99 kForce);
100 EXPECT_TRUE(provider()->OnTouchEvent(move1_1));
102 time += base::TimeDelta::FromMilliseconds(10);
103 TouchEvent move0_2(ET_TOUCH_MOVED,
104 gfx::PointF(10, 10),
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));
115 TouchEvent move1_2(ET_TOUCH_MOVED,
116 gfx::PointF(100, 200),
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));
127 time += base::TimeDelta::FromMilliseconds(10);
128 TouchEvent move0_3(ET_TOUCH_MOVED,
129 gfx::PointF(70, 75.1f),
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));
140 time += base::TimeDelta::FromMilliseconds(10);
141 TouchEvent move0_4(ET_TOUCH_MOVED,
142 gfx::PointF(70, 75.1f),
144 kTouchId0,
145 time,
146 kRadiusX,
147 kRadiusY + 1,
148 kAngle,
149 kForce);
152 } // namespace ui