Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: ui/events/gestures/gesture_provider_impl_unittest.cc

Issue 789363004: WindowManagerApp should recognize gestures (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rename Aura to Impl and add FIXME Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/event_utils.h" 8 #include "ui/events/event_utils.h"
9 #include "ui/events/gestures/gesture_provider_aura.h" 9 #include "ui/events/gestures/gesture_provider_impl.h"
10 10
11 namespace ui { 11 namespace ui {
12 12
13 class GestureProviderAuraTest : public testing::Test, 13 class GestureProviderImplTest : public testing::Test,
14 public GestureProviderAuraClient { 14 public GestureProviderImplClient {
15 public: 15 public:
16 GestureProviderAuraTest() {} 16 GestureProviderImplTest() {}
17 17
18 virtual ~GestureProviderAuraTest() {} 18 virtual ~GestureProviderImplTest() {}
19 19
20 virtual void OnGestureEvent(GestureEvent* event) override {} 20 virtual void OnGestureEvent(GestureEvent* event) override {}
21 21
22 virtual void SetUp() override { 22 virtual void SetUp() override {
23 provider_.reset(new GestureProviderAura(this)); 23 provider_.reset(new GestureProviderImpl(this));
24 } 24 }
25 25
26 virtual void TearDown() override { provider_.reset(); } 26 virtual void TearDown() override { provider_.reset(); }
27 27
28 GestureProviderAura* provider() { return provider_.get(); } 28 GestureProviderImpl* provider() { return provider_.get(); }
29 29
30 private: 30 private:
31 scoped_ptr<GestureProviderAura> provider_; 31 scoped_ptr<GestureProviderImpl> provider_;
32 base::MessageLoopForUI message_loop_; 32 base::MessageLoopForUI message_loop_;
33 }; 33 };
34 34
35 TEST_F(GestureProviderAuraTest, IgnoresExtraPressEvents) { 35 TEST_F(GestureProviderImplTest, IgnoresExtraPressEvents) {
36 base::TimeDelta time = ui::EventTimeForNow(); 36 base::TimeDelta time = ui::EventTimeForNow();
37 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time); 37 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
38 EXPECT_TRUE(provider()->OnTouchEvent(press1)); 38 EXPECT_TRUE(provider()->OnTouchEvent(press1));
39 39
40 time += base::TimeDelta::FromMilliseconds(10); 40 time += base::TimeDelta::FromMilliseconds(10);
41 TouchEvent press2(ET_TOUCH_PRESSED, gfx::PointF(30, 40), 0, time); 41 TouchEvent press2(ET_TOUCH_PRESSED, gfx::PointF(30, 40), 0, time);
42 // Redundant press with same id is ignored. 42 // Redundant press with same id is ignored.
43 EXPECT_FALSE(provider()->OnTouchEvent(press2)); 43 EXPECT_FALSE(provider()->OnTouchEvent(press2));
44 } 44 }
45 45
46 TEST_F(GestureProviderAuraTest, IgnoresExtraMoveOrReleaseEvents) { 46 TEST_F(GestureProviderImplTest, IgnoresExtraMoveOrReleaseEvents) {
47 base::TimeDelta time = ui::EventTimeForNow(); 47 base::TimeDelta time = ui::EventTimeForNow();
48 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time); 48 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
49 EXPECT_TRUE(provider()->OnTouchEvent(press1)); 49 EXPECT_TRUE(provider()->OnTouchEvent(press1));
50 50
51 time += base::TimeDelta::FromMilliseconds(10); 51 time += base::TimeDelta::FromMilliseconds(10);
52 TouchEvent release1(ET_TOUCH_RELEASED, gfx::PointF(30, 40), 0, time); 52 TouchEvent release1(ET_TOUCH_RELEASED, gfx::PointF(30, 40), 0, time);
53 EXPECT_TRUE(provider()->OnTouchEvent(release1)); 53 EXPECT_TRUE(provider()->OnTouchEvent(release1));
54 54
55 time += base::TimeDelta::FromMilliseconds(10); 55 time += base::TimeDelta::FromMilliseconds(10);
56 TouchEvent release2(ET_TOUCH_RELEASED, gfx::PointF(30, 45), 0, time); 56 TouchEvent release2(ET_TOUCH_RELEASED, gfx::PointF(30, 45), 0, time);
57 EXPECT_FALSE(provider()->OnTouchEvent(release1)); 57 EXPECT_FALSE(provider()->OnTouchEvent(release1));
58 58
59 time += base::TimeDelta::FromMilliseconds(10); 59 time += base::TimeDelta::FromMilliseconds(10);
60 TouchEvent move1(ET_TOUCH_MOVED, gfx::PointF(70, 75), 0, time); 60 TouchEvent move1(ET_TOUCH_MOVED, gfx::PointF(70, 75), 0, time);
61 EXPECT_FALSE(provider()->OnTouchEvent(move1)); 61 EXPECT_FALSE(provider()->OnTouchEvent(move1));
62 } 62 }
63 63
64 TEST_F(GestureProviderAuraTest, IgnoresIdenticalMoveEvents) { 64 TEST_F(GestureProviderImplTest, IgnoresIdenticalMoveEvents) {
65 const float kRadiusX = 20.f; 65 const float kRadiusX = 20.f;
66 const float kRadiusY = 30.f; 66 const float kRadiusY = 30.f;
67 const float kAngle = 0.321f; 67 const float kAngle = 0.321f;
68 const float kForce = 40.f; 68 const float kForce = 40.f;
69 const int kTouchId0 = 5; 69 const int kTouchId0 = 5;
70 const int kTouchId1 = 3; 70 const int kTouchId1 = 3;
71 71
72 base::TimeDelta time = ui::EventTimeForNow(); 72 base::TimeDelta time = ui::EventTimeForNow();
73 TouchEvent press0_1(ET_TOUCH_PRESSED, gfx::PointF(9, 10), kTouchId0, time); 73 TouchEvent press0_1(ET_TOUCH_PRESSED, gfx::PointF(9, 10), kTouchId0, time);
74 EXPECT_TRUE(provider()->OnTouchEvent(press0_1)); 74 EXPECT_TRUE(provider()->OnTouchEvent(press0_1));
75 75
76 TouchEvent press1_1(ET_TOUCH_PRESSED, gfx::PointF(40, 40), kTouchId1, time); 76 TouchEvent press1_1(ET_TOUCH_PRESSED, gfx::PointF(40, 40), kTouchId1, time);
77 EXPECT_TRUE(provider()->OnTouchEvent(press1_1)); 77 EXPECT_TRUE(provider()->OnTouchEvent(press1_1));
78 78
79 time += base::TimeDelta::FromMilliseconds(10); 79 time += base::TimeDelta::FromMilliseconds(10);
80 TouchEvent move0_1(ET_TOUCH_MOVED, 80 TouchEvent move0_1(ET_TOUCH_MOVED, gfx::PointF(10, 10), 0, kTouchId0, time,
81 gfx::PointF(10, 10), 81 kRadiusX, kRadiusY, kAngle, kForce);
82 0,
83 kTouchId0,
84 time,
85 kRadiusX,
86 kRadiusY,
87 kAngle,
88 kForce);
89 EXPECT_TRUE(provider()->OnTouchEvent(move0_1)); 82 EXPECT_TRUE(provider()->OnTouchEvent(move0_1));
90 83
91 TouchEvent move1_1(ET_TOUCH_MOVED, 84 TouchEvent move1_1(ET_TOUCH_MOVED, gfx::PointF(100, 200), 0, kTouchId1, time,
92 gfx::PointF(100, 200), 85 kRadiusX, kRadiusY, kAngle, kForce);
93 0,
94 kTouchId1,
95 time,
96 kRadiusX,
97 kRadiusY,
98 kAngle,
99 kForce);
100 EXPECT_TRUE(provider()->OnTouchEvent(move1_1)); 86 EXPECT_TRUE(provider()->OnTouchEvent(move1_1));
101 87
102 time += base::TimeDelta::FromMilliseconds(10); 88 time += base::TimeDelta::FromMilliseconds(10);
103 TouchEvent move0_2(ET_TOUCH_MOVED, 89 TouchEvent move0_2(ET_TOUCH_MOVED, gfx::PointF(10, 10), 0, kTouchId0, time,
104 gfx::PointF(10, 10), 90 kRadiusX, kRadiusY, kAngle, kForce);
105 0,
106 kTouchId0,
107 time,
108 kRadiusX,
109 kRadiusY,
110 kAngle,
111 kForce);
112 // Nothing has changed, so ignore the move. 91 // Nothing has changed, so ignore the move.
113 EXPECT_FALSE(provider()->OnTouchEvent(move0_2)); 92 EXPECT_FALSE(provider()->OnTouchEvent(move0_2));
114 93
115 TouchEvent move1_2(ET_TOUCH_MOVED, 94 TouchEvent move1_2(ET_TOUCH_MOVED, gfx::PointF(100, 200), 0, kTouchId1, time,
116 gfx::PointF(100, 200), 95 kRadiusX, kRadiusY, kAngle, kForce);
117 0,
118 kTouchId1,
119 time,
120 kRadiusX,
121 kRadiusY,
122 kAngle,
123 kForce);
124 // Nothing has changed, so ignore the move. 96 // Nothing has changed, so ignore the move.
125 EXPECT_FALSE(provider()->OnTouchEvent(move1_2)); 97 EXPECT_FALSE(provider()->OnTouchEvent(move1_2));
126 98
127 time += base::TimeDelta::FromMilliseconds(10); 99 time += base::TimeDelta::FromMilliseconds(10);
128 TouchEvent move0_3(ET_TOUCH_MOVED, 100 TouchEvent move0_3(ET_TOUCH_MOVED, gfx::PointF(70, 75.1f), 0, kTouchId0, time,
129 gfx::PointF(70, 75.1f), 101 kRadiusX, kRadiusY, kAngle, kForce);
130 0,
131 kTouchId0,
132 time,
133 kRadiusX,
134 kRadiusY,
135 kAngle,
136 kForce);
137 // Position has changed, so don't ignore the move. 102 // Position has changed, so don't ignore the move.
138 EXPECT_TRUE(provider()->OnTouchEvent(move0_3)); 103 EXPECT_TRUE(provider()->OnTouchEvent(move0_3));
139 104
140 time += base::TimeDelta::FromMilliseconds(10); 105 time += base::TimeDelta::FromMilliseconds(10);
141 TouchEvent move0_4(ET_TOUCH_MOVED, 106 TouchEvent move0_4(ET_TOUCH_MOVED, gfx::PointF(70, 75.1f), 0, kTouchId0, time,
142 gfx::PointF(70, 75.1f), 107 kRadiusX, kRadiusY + 1, kAngle, kForce);
143 0,
144 kTouchId0,
145 time,
146 kRadiusX,
147 kRadiusY + 1,
148 kAngle,
149 kForce);
150 } 108 }
151 109
152 } // namespace ui 110 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gestures/gesture_provider_impl.cc ('k') | ui/events/gestures/gesture_recognizer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698