summaryrefslogtreecommitdiffstats
path: root/ui/events/gestures/gesture_provider_aura_unittest.cc
blob: b51ca616c65fb95b35ae0567a8eb2c691e0cb60e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event_utils.h"
#include "ui/events/gestures/gesture_provider_aura.h"

namespace ui {

class GestureProviderAuraTest : public testing::Test,
                                public GestureProviderAuraClient {
 public:
  GestureProviderAuraTest() {}

  virtual ~GestureProviderAuraTest() {}

  virtual void OnGestureEvent(GestureEvent* event) OVERRIDE {}

  virtual void SetUp() OVERRIDE {
    provider_.reset(new GestureProviderAura(this));
  }

  virtual void TearDown() OVERRIDE { provider_.reset(); }

  GestureProviderAura* provider() { return provider_.get(); }

 private:
  scoped_ptr<GestureProviderAura> provider_;
  base::MessageLoopForUI message_loop_;
};

TEST_F(GestureProviderAuraTest, IgnoresExtraPressEvents) {
  base::TimeDelta time = ui::EventTimeForNow();
  TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
  EXPECT_TRUE(provider()->OnTouchEvent(press1));

  time += base::TimeDelta::FromMilliseconds(10);
  TouchEvent press2(ET_TOUCH_PRESSED, gfx::PointF(30, 40), 0, time);
  // Redundant press with same id is ignored.
  EXPECT_FALSE(provider()->OnTouchEvent(press2));
}

TEST_F(GestureProviderAuraTest, IgnoresExtraMoveOrReleaseEvents) {
  base::TimeDelta time = ui::EventTimeForNow();
  TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
  EXPECT_TRUE(provider()->OnTouchEvent(press1));

  time += base::TimeDelta::FromMilliseconds(10);
  TouchEvent release1(ET_TOUCH_RELEASED, gfx::PointF(30, 40), 0, time);
  EXPECT_TRUE(provider()->OnTouchEvent(release1));

  time += base::TimeDelta::FromMilliseconds(10);
  TouchEvent release2(ET_TOUCH_RELEASED, gfx::PointF(30, 45), 0, time);
  EXPECT_FALSE(provider()->OnTouchEvent(release1));

  time += base::TimeDelta::FromMilliseconds(10);
  TouchEvent move1(ET_TOUCH_MOVED, gfx::PointF(70, 75), 0, time);
  EXPECT_FALSE(provider()->OnTouchEvent(move1));
}

TEST_F(GestureProviderAuraTest, IgnoresIdenticalMoveEvents) {
  const float kRadiusX = 20;
  const float kRadiusY = 30;
  const float kAngle = 120;
  const float kForce = 40;
  const int kTouchId0 = 5;
  const int kTouchId1 = 3;

  base::TimeDelta time = ui::EventTimeForNow();
  TouchEvent press0_1(ET_TOUCH_PRESSED, gfx::PointF(9, 10), kTouchId0, time);
  EXPECT_TRUE(provider()->OnTouchEvent(press0_1));

  TouchEvent press1_1(ET_TOUCH_PRESSED, gfx::PointF(40, 40), kTouchId1, time);
  EXPECT_TRUE(provider()->OnTouchEvent(press1_1));

  time += base::TimeDelta::FromMilliseconds(10);
  TouchEvent move0_1(ET_TOUCH_MOVED,
                   gfx::PointF(10, 10),
                   0,
                   kTouchId0,
                   time,
                   kRadiusX,
                   kRadiusY,
                   kAngle,
                   kForce);
  EXPECT_TRUE(provider()->OnTouchEvent(move0_1));

  TouchEvent move1_1(ET_TOUCH_MOVED,
                   gfx::PointF(100, 200),
                   0,
                   kTouchId1,
                   time,
                   kRadiusX,
                   kRadiusY,
                   kAngle,
                   kForce);
  EXPECT_TRUE(provider()->OnTouchEvent(move1_1));

  time += base::TimeDelta::FromMilliseconds(10);
  TouchEvent move0_2(ET_TOUCH_MOVED,
                     gfx::PointF(10, 10),
                     0,
                     kTouchId0,
                     time,
                     kRadiusX,
                     kRadiusY,
                     kAngle,
                     kForce);
  // Nothing has changed, so ignore the move.
  EXPECT_FALSE(provider()->OnTouchEvent(move0_2));

  TouchEvent move1_2(ET_TOUCH_MOVED,
                     gfx::PointF(100, 200),
                     0,
                     kTouchId1,
                     time,
                     kRadiusX,
                     kRadiusY,
                     kAngle,
                     kForce);
  // Nothing has changed, so ignore the move.
  EXPECT_FALSE(provider()->OnTouchEvent(move1_2));

  time += base::TimeDelta::FromMilliseconds(10);
  TouchEvent move0_3(ET_TOUCH_MOVED,
                     gfx::PointF(70, 75.1f),
                     0,
                     kTouchId0,
                     time,
                     kRadiusX,
                     kRadiusY,
                     kAngle,
                     kForce);
  // Position has changed, so don't ignore the move.
  EXPECT_TRUE(provider()->OnTouchEvent(move0_3));

  time += base::TimeDelta::FromMilliseconds(10);
  TouchEvent move0_4(ET_TOUCH_MOVED,
                     gfx::PointF(70, 75.1f),
                     0,
                     kTouchId0,
                     time,
                     kRadiusX,
                     kRadiusY + 1,
                     kAngle,
                     kForce);
}

}  // namespace ui