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

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

Issue 1287103004: Sync ui/events to chromium @ https://codereview.chromium.org/1210203002 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 4 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
« no previous file with comments | « ui/events/gestures/gesture_provider_impl.cc ('k') | ui/events/gestures/gesture_recognizer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_impl.h" 9 #include "ui/events/gestures/gesture_provider_impl.h"
10 10
11 namespace ui { 11 namespace ui {
12 12
13 class GestureProviderImplTest : public testing::Test, 13 class GestureProviderImplTest : public testing::Test,
14 public GestureProviderImplClient { 14 public GestureProviderImplClient {
15 public: 15 public:
16 GestureProviderImplTest() {} 16 GestureProviderImplTest() {}
17 17
18 ~GestureProviderImplTest() override {} 18 ~GestureProviderImplTest() override {}
19 19
20 void OnGestureEvent(GestureEvent* event) override {} 20 void OnGestureEvent(GestureEvent* event) override {}
21 21
22 void SetUp() override { 22 void SetUp() override { provider_.reset(new GestureProviderImpl(this)); }
23 provider_.reset(new GestureProviderImpl(this));
24 }
25 23
26 void TearDown() override { provider_.reset(); } 24 void TearDown() override { provider_.reset(); }
27 25
28 GestureProviderImpl* provider() { return provider_.get(); } 26 GestureProviderImpl* provider() { return provider_.get(); }
29 27
30 private: 28 private:
31 scoped_ptr<GestureProviderImpl> provider_; 29 scoped_ptr<GestureProviderImpl> provider_;
32 base::MessageLoopForUI message_loop_; 30 base::MessageLoopForUI message_loop_;
33 }; 31 };
34 32
35 TEST_F(GestureProviderImplTest, IgnoresExtraPressEvents) { 33 TEST_F(GestureProviderImplTest, IgnoresExtraPressEvents) {
36 base::TimeDelta time = ui::EventTimeForNow(); 34 base::TimeDelta time = ui::EventTimeForNow();
37 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time); 35 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
38 EXPECT_TRUE(provider()->OnTouchEvent(press1)); 36 EXPECT_TRUE(provider()->OnTouchEvent(&press1));
39 37
40 time += base::TimeDelta::FromMilliseconds(10); 38 time += base::TimeDelta::FromMilliseconds(10);
41 TouchEvent press2(ET_TOUCH_PRESSED, gfx::PointF(30, 40), 0, time); 39 TouchEvent press2(ET_TOUCH_PRESSED, gfx::PointF(30, 40), 0, time);
42 // Redundant press with same id is ignored. 40 // TODO(tdresser): this redundant press with same id should be
43 EXPECT_FALSE(provider()->OnTouchEvent(press2)); 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));
44 } 45 }
45 46
46 TEST_F(GestureProviderImplTest, IgnoresExtraMoveOrReleaseEvents) { 47 TEST_F(GestureProviderImplTest, IgnoresExtraMoveOrReleaseEvents) {
47 base::TimeDelta time = ui::EventTimeForNow(); 48 base::TimeDelta time = ui::EventTimeForNow();
48 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time); 49 TouchEvent press1(ET_TOUCH_PRESSED, gfx::PointF(10, 10), 0, time);
49 EXPECT_TRUE(provider()->OnTouchEvent(press1)); 50 EXPECT_TRUE(provider()->OnTouchEvent(&press1));
50 51
51 time += base::TimeDelta::FromMilliseconds(10); 52 time += base::TimeDelta::FromMilliseconds(10);
52 TouchEvent release1(ET_TOUCH_RELEASED, gfx::PointF(30, 40), 0, time); 53 TouchEvent release1(ET_TOUCH_RELEASED, gfx::PointF(30, 40), 0, time);
53 EXPECT_TRUE(provider()->OnTouchEvent(release1)); 54 EXPECT_TRUE(provider()->OnTouchEvent(&release1));
54 55
55 time += base::TimeDelta::FromMilliseconds(10); 56 time += base::TimeDelta::FromMilliseconds(10);
56 TouchEvent release2(ET_TOUCH_RELEASED, gfx::PointF(30, 45), 0, time); 57 TouchEvent release2(ET_TOUCH_RELEASED, gfx::PointF(30, 45), 0, time);
57 EXPECT_FALSE(provider()->OnTouchEvent(release1)); 58 EXPECT_FALSE(provider()->OnTouchEvent(&release1));
58 59
59 time += base::TimeDelta::FromMilliseconds(10); 60 time += base::TimeDelta::FromMilliseconds(10);
60 TouchEvent move1(ET_TOUCH_MOVED, gfx::PointF(70, 75), 0, time); 61 TouchEvent move1(ET_TOUCH_MOVED, gfx::PointF(70, 75), 0, time);
61 EXPECT_FALSE(provider()->OnTouchEvent(move1)); 62 EXPECT_FALSE(provider()->OnTouchEvent(&move1));
62 } 63 }
63 64
64 TEST_F(GestureProviderImplTest, IgnoresIdenticalMoveEvents) { 65 TEST_F(GestureProviderImplTest, IgnoresIdenticalMoveEvents) {
65 const float kRadiusX = 20.f; 66 const float kRadiusX = 20.f;
66 const float kRadiusY = 30.f; 67 const float kRadiusY = 30.f;
67 const float kAngle = 0.321f; 68 const float kAngle = 0.321f;
68 const float kForce = 40.f; 69 const float kForce = 40.f;
69 const int kTouchId0 = 5; 70 const int kTouchId0 = 5;
70 const int kTouchId1 = 3; 71 const int kTouchId1 = 3;
71 72
72 base::TimeDelta time = ui::EventTimeForNow(); 73 base::TimeDelta time = ui::EventTimeForNow();
73 TouchEvent press0_1(ET_TOUCH_PRESSED, gfx::PointF(9, 10), kTouchId0, time); 74 TouchEvent press0_1(ET_TOUCH_PRESSED, gfx::PointF(9, 10), kTouchId0, time);
74 EXPECT_TRUE(provider()->OnTouchEvent(press0_1)); 75 EXPECT_TRUE(provider()->OnTouchEvent(&press0_1));
75 76
76 TouchEvent press1_1(ET_TOUCH_PRESSED, gfx::PointF(40, 40), kTouchId1, time); 77 TouchEvent press1_1(ET_TOUCH_PRESSED, gfx::PointF(40, 40), kTouchId1, time);
77 EXPECT_TRUE(provider()->OnTouchEvent(press1_1)); 78 EXPECT_TRUE(provider()->OnTouchEvent(&press1_1));
78 79
79 time += base::TimeDelta::FromMilliseconds(10); 80 time += base::TimeDelta::FromMilliseconds(10);
80 TouchEvent move0_1(ET_TOUCH_MOVED, gfx::PointF(10, 10), 0, kTouchId0, time, 81 TouchEvent move0_1(ET_TOUCH_MOVED,
81 kRadiusX, kRadiusY, kAngle, kForce); 82 gfx::PointF(10, 10),
82 EXPECT_TRUE(provider()->OnTouchEvent(move0_1)); 83 0,
84 kTouchId0,
85 time,
86 kRadiusX,
87 kRadiusY,
88 kAngle,
89 kForce);
90 EXPECT_TRUE(provider()->OnTouchEvent(&move0_1));
83 91
84 TouchEvent move1_1(ET_TOUCH_MOVED, gfx::PointF(100, 200), 0, kTouchId1, time, 92 TouchEvent move1_1(ET_TOUCH_MOVED,
85 kRadiusX, kRadiusY, kAngle, kForce); 93 gfx::PointF(100, 200),
86 EXPECT_TRUE(provider()->OnTouchEvent(move1_1)); 94 0,
95 kTouchId1,
96 time,
97 kRadiusX,
98 kRadiusY,
99 kAngle,
100 kForce);
101 EXPECT_TRUE(provider()->OnTouchEvent(&move1_1));
87 102
88 time += base::TimeDelta::FromMilliseconds(10); 103 time += base::TimeDelta::FromMilliseconds(10);
89 TouchEvent move0_2(ET_TOUCH_MOVED, gfx::PointF(10, 10), 0, kTouchId0, time, 104 TouchEvent move0_2(ET_TOUCH_MOVED,
90 kRadiusX, kRadiusY, kAngle, kForce); 105 gfx::PointF(10, 10),
106 0,
107 kTouchId0,
108 time,
109 kRadiusX,
110 kRadiusY,
111 kAngle,
112 kForce);
91 // Nothing has changed, so ignore the move. 113 // Nothing has changed, so ignore the move.
92 EXPECT_FALSE(provider()->OnTouchEvent(move0_2)); 114 EXPECT_FALSE(provider()->OnTouchEvent(&move0_2));
93 115
94 TouchEvent move1_2(ET_TOUCH_MOVED, gfx::PointF(100, 200), 0, kTouchId1, time, 116 TouchEvent move1_2(ET_TOUCH_MOVED,
95 kRadiusX, kRadiusY, kAngle, kForce); 117 gfx::PointF(100, 200),
118 0,
119 kTouchId1,
120 time,
121 kRadiusX,
122 kRadiusY,
123 kAngle,
124 kForce);
96 // Nothing has changed, so ignore the move. 125 // Nothing has changed, so ignore the move.
97 EXPECT_FALSE(provider()->OnTouchEvent(move1_2)); 126 EXPECT_FALSE(provider()->OnTouchEvent(&move1_2));
98 127
99 time += base::TimeDelta::FromMilliseconds(10); 128 time += base::TimeDelta::FromMilliseconds(10);
100 TouchEvent move0_3(ET_TOUCH_MOVED, gfx::PointF(70, 75.1f), 0, kTouchId0, time, 129 TouchEvent move0_3(ET_TOUCH_MOVED,
101 kRadiusX, kRadiusY, kAngle, kForce); 130 gfx::PointF(70, 75.1f),
131 0,
132 kTouchId0,
133 time,
134 kRadiusX,
135 kRadiusY,
136 kAngle,
137 kForce);
102 // Position has changed, so don't ignore the move. 138 // Position has changed, so don't ignore the move.
103 EXPECT_TRUE(provider()->OnTouchEvent(move0_3)); 139 EXPECT_TRUE(provider()->OnTouchEvent(&move0_3));
104 140
105 time += base::TimeDelta::FromMilliseconds(10); 141 time += base::TimeDelta::FromMilliseconds(10);
106 TouchEvent move0_4(ET_TOUCH_MOVED, gfx::PointF(70, 75.1f), 0, kTouchId0, time, 142 TouchEvent move0_4(ET_TOUCH_MOVED,
107 kRadiusX, kRadiusY + 1, kAngle, kForce); 143 gfx::PointF(70, 75.1f),
144 0,
145 kTouchId0,
146 time,
147 kRadiusX,
148 kRadiusY + 1,
149 kAngle,
150 kForce);
108 } 151 }
109 152
153 // TODO(jdduke): Test whether event marked as scroll trigger.
154
110 } // namespace ui 155 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gestures/gesture_provider_impl.cc ('k') | ui/events/gestures/gesture_recognizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698