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

Side by Side Diff: third_party/WebKit/Source/core/events/PointerEventFactoryTest.cpp

Issue 1426643008: Cleaning up PointerIdManager and add id re-mapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix EXPECT_EQ compilation error on Android Created 5 years 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
(Empty)
1 // Copyright 2015 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.
4
5 #include "config.h"
6 #include "core/events/PointerEventFactory.h"
7
8 #include "core/frame/FrameView.h"
9 #include "core/page/Page.h"
10 #include "public/platform/WebPointerProperties.h"
11 #include <climits>
12 #include <gtest/gtest.h>
13
14 namespace blink {
15
16 class PointerEventFactoryTest : public ::testing::Test {
17 protected:
18 void SetUp() override;
19 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckTouchCancel(
20 WebPointerProperties::PointerType, int rawId,
21 int uniqueId, bool isPrimary);
22 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckTouchEvent(
23 WebPointerProperties::PointerType, int rawId,
24 int uniqueId, bool isPrimary);
25 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckMouseEvent(
26 WebPointerProperties::PointerType, int rawId,
27 int uniqueId, bool isPrimary);
28
29 PointerEventFactory m_pointerEventFactory;
30 unsigned m_expectedMouseId;
31 unsigned m_mappedIdStart;
32
33 class PlatformTouchPointBuilder : public PlatformTouchPoint {
34 public:
35 PlatformTouchPointBuilder(WebPointerProperties::PointerType, int);
36 };
37
38 class PlatformMouseEventBuilder : public PlatformMouseEvent {
39 public:
40 PlatformMouseEventBuilder(WebPointerProperties::PointerType, int);
41 };
42 };
43
44 void PointerEventFactoryTest::SetUp()
45 {
46 m_expectedMouseId = 1;
47 m_mappedIdStart = 2;
48
49 }
50
51 PointerEventFactoryTest::PlatformTouchPointBuilder::PlatformTouchPointBuilder(
52 WebPointerProperties::PointerType pointerType, int id)
53 {
54 m_pointerProperties.id = id;
55 m_pointerProperties.pointerType = pointerType;
56 }
57
58 PointerEventFactoryTest::PlatformMouseEventBuilder::PlatformMouseEventBuilder(
59 WebPointerProperties::PointerType pointerType, int id)
60 {
61 m_pointerProperties.pointerType = pointerType;
62 m_pointerProperties.id = id;
63 }
64
65 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckTouc hCancel(
66 WebPointerProperties::PointerType pointerType, int rawId,
67 int uniqueId, bool isPrimary)
68 {
69 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create PointerCancel(
70 PointerEventFactoryTest::PlatformTouchPointBuilder(pointerType, rawId));
71 EXPECT_EQ(uniqueId, pointerEvent->pointerId());
72 EXPECT_EQ(isPrimary, pointerEvent->isPrimary());
73 return pointerEvent;
74 }
75
76 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckTouc hEvent(
77 WebPointerProperties::PointerType pointerType, int rawId,
78 int uniqueId, bool isPrimary)
79 {
80 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create (
81 EventTypeNames::pointerdown, PointerEventFactoryTest::PlatformTouchPoint Builder(pointerType, rawId), PlatformEvent::NoModifiers, 0, 0, 0, 0);
82 EXPECT_EQ(uniqueId, pointerEvent->pointerId());
83 EXPECT_EQ(isPrimary, pointerEvent->isPrimary());
84 return pointerEvent;
85 }
86
87 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckMous eEvent(
88 WebPointerProperties::PointerType pointerType, int rawId, int uniqueId, bool isPrimary)
89 {
90 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create (
91 EventTypeNames::pointerenter, PlatformMouseEventBuilder(pointerType, raw Id), nullptr, nullptr);
92 EXPECT_EQ(uniqueId, pointerEvent->pointerId());
93 EXPECT_EQ(isPrimary, pointerEvent->isPrimary());
94 return pointerEvent;
95 }
96
97 TEST_F(PointerEventFactoryTest, MousePointer)
98 {
99 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(We bPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true);
100 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckMouseEvent(We bPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true);
101
102 m_pointerEventFactory.remove(pointerEvent1);
103
104 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 0, m_expe ctedMouseId, true);
105
106 m_pointerEventFactory.remove(pointerEvent1);
107 m_pointerEventFactory.remove(pointerEvent2);
108
109 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 1, m_expe ctedMouseId, true);
110 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 20, m_exp ectedMouseId, true);
111 }
112
113 TEST_F(PointerEventFactoryTest, TouchPointerPrimaryRemovedWhileAnotherIsThere)
114 {
115 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
116 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 1, m_mapp edIdStart+1, false);
117
118 m_pointerEventFactory.remove(pointerEvent1);
119
120 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 2, m_mapp edIdStart+2, false);
121 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 1, m_mapp edIdStart+1, false);
122 }
123
124 TEST_F(PointerEventFactoryTest, TouchPointerReleasedAndPressedAgain)
125 {
126 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
127 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+1, false);
128
129 m_pointerEventFactory.remove(pointerEvent1);
130 m_pointerEventFactory.remove(pointerEvent2);
131
132 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 1, m_mapp edIdStart+2, true);
133 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mapp edIdStart+3, false);
134
135 m_pointerEventFactory.clear();
136
137 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 10, m_map pedIdStart, true);
138 }
139
140 TEST_F(PointerEventFactoryTest, TouchAndDrag)
141 {
142 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
143 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
144 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mapp edIdStart, true);
145
146 m_pointerEventFactory.remove(pointerEvent1);
147 m_pointerEventFactory.remove(pointerEvent2);
148
149 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mapp edIdStart+1, true);
150 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mapp edIdStart+1, true);
151
152 // Remove an obsolete (i.e. already removed) pointer event which should have no effect
153 m_pointerEventFactory.remove(pointerEvent1);
154
155 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mapp edIdStart+1, true);
156 createAndCheckTouchCancel(WebPointerProperties::PointerType::Touch, 0, m_map pedIdStart+1, true);
157 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mapp edIdStart+1, true);
158 }
159
160 TEST_F(PointerEventFactoryTest, MouseAndTouchAndPen)
161 {
162 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 0, m_expe ctedMouseId, true);
163 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
164 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+1, true);
165
166 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+2, false);
167 RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 2, m_mappedIdStart+3, false);
168 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+1, true);
169 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 47213, m_ma ppedIdStart+4, false);
170
171 m_pointerEventFactory.remove(pointerEvent1);
172 m_pointerEventFactory.remove(pointerEvent2);
173 m_pointerEventFactory.remove(pointerEvent3);
174
175 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 100, m_ma ppedIdStart+5, true);
176
177 m_pointerEventFactory.clear();
178
179 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 0, m_expe ctedMouseId, true);
180 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mapp edIdStart, true);
181 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+1, true);
182 }
183
184 TEST_F(PointerEventFactoryTest, PenAsTouchAndMouseEvent)
185 {
186 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(We bPointerProperties::PointerType::Pen, 0, m_mappedIdStart, true);
187 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 1, m_mapped IdStart+1, false);
188 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 2, m_mapped IdStart+2, false);
189 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart, true);
190 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 1, m_mapped IdStart+1, false);
191 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart, true);
192 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 1, m_mapped IdStart+1, false);
193
194 m_pointerEventFactory.remove(pointerEvent1);
195
196 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+3, false);
197 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+3, false);
198 createAndCheckTouchCancel(WebPointerProperties::PointerType::Pen, 0, m_mappe dIdStart+3, false);
199
200 m_pointerEventFactory.clear();
201
202 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 1, m_mapped IdStart, true);
203 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+1, false);
204 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 1, m_mapped IdStart, true);
205 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+1, false);
206 createAndCheckTouchCancel(WebPointerProperties::PointerType::Pen, 1, m_mappe dIdStart, true);
207 createAndCheckTouchCancel(WebPointerProperties::PointerType::Pen, 0, m_mappe dIdStart+1, false);
208 }
209
210
211 TEST_F(PointerEventFactoryTest, OutOfRange)
212 {
213 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(We bPointerProperties::PointerType::Unknown, 0, m_mappedIdStart, true);
214 createAndCheckMouseEvent(WebPointerProperties::PointerType::Unknown, 1, m_ma ppedIdStart+1, false);
215 createAndCheckMouseEvent(WebPointerProperties::PointerType::Unknown, 2, m_ma ppedIdStart+2, false);
216 createAndCheckTouchEvent(WebPointerProperties::PointerType::Unknown, 0, m_ma ppedIdStart, true);
217 createAndCheckTouchEvent(WebPointerProperties::PointerType::Unknown, 3, m_ma ppedIdStart+3, false);
218 createAndCheckMouseEvent(WebPointerProperties::PointerType::Unknown, 2, m_ma ppedIdStart+2, false);
219 createAndCheckTouchCancel(WebPointerProperties::PointerType::Unknown, 3, m_m appedIdStart+3, false);
220
221 m_pointerEventFactory.remove(pointerEvent1);
222
223 createAndCheckTouchEvent(WebPointerProperties::PointerType::Unknown, 0, m_ma ppedIdStart+4, false);
224 createAndCheckTouchEvent(WebPointerProperties::PointerType::Unknown, INT_MAX , m_mappedIdStart+5, false);
225
226 m_pointerEventFactory.clear();
227
228 for (int i = 0; i < 100; ++i) {
229 createAndCheckMouseEvent(WebPointerProperties::PointerType::Touch, i, m_ mappedIdStart+i, i == 0);
230 }
231
232 for (int i = 0; i < 100; ++i) {
233 createAndCheckTouchEvent(WebPointerProperties::PointerType::Mouse, i, m_ expectedMouseId, true);
234 }
235 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0, m_exp ectedMouseId, true);
236 }
237
238 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698