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

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: Set mouse pointer type in the event sender 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> createAndCheckTouchEvent(
20 WebPointerProperties::PointerType, int rawId,
21 int uniqueId, bool isPrimary);
22 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckMouseEvent(
23 WebPointerProperties::PointerType, int rawId,
24 int uniqueId, bool isPrimary);
25
26 PointerEventFactory m_pointerEventFactory;
27 unsigned m_expectedMouseId;
28 unsigned m_mappedIdStart;
29
30 class PlatformTouchPointBuilder : public PlatformTouchPoint {
31 public:
32 PlatformTouchPointBuilder(WebPointerProperties::PointerType, int);
33 };
34
35 class PlatformMouseEventBuilder : public PlatformMouseEvent {
36 public:
37 PlatformMouseEventBuilder(WebPointerProperties::PointerType, int);
38 };
39 };
40
41 void PointerEventFactoryTest::SetUp()
42 {
43 m_expectedMouseId = 1;
44 m_mappedIdStart = 2;
45
46 }
47
48 PointerEventFactoryTest::PlatformTouchPointBuilder::PlatformTouchPointBuilder(
49 WebPointerProperties::PointerType pointerType, int id)
50 : PlatformTouchPoint()
mustaq 2015/12/02 15:53:46 This call could be implicit I guess?
Navid Zolghadr 2015/12/02 16:49:08 Done.
51 {
52 m_pointerProperties.id = id;
53 m_pointerProperties.pointerType = pointerType;
54 }
55
56 PointerEventFactoryTest::PlatformMouseEventBuilder::PlatformMouseEventBuilder(
57 WebPointerProperties::PointerType pointerType, int id)
58 : PlatformMouseEvent()
59 {
60 m_pointerProperties.pointerType = pointerType;
61 m_pointerProperties.id = id;
62 }
63
64 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckTouc hEvent(
65 WebPointerProperties::PointerType pointerType, int rawId,
66 int uniqueId, bool isPrimary)
67 {
68 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create (
69 EventTypeNames::pointerdown, PointerEventFactoryTest::PlatformTouchPoint Builder(pointerType, rawId), PlatformEvent::NoModifiers, 0, 0, 0, 0);
70 EXPECT_EQ(uniqueId, pointerEvent->pointerId());
71 EXPECT_EQ(isPrimary, pointerEvent->isPrimary());
72 return pointerEvent;
73 }
74
75 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckMous eEvent(
76 WebPointerProperties::PointerType pointerType, int rawId, int uniqueId, bool isPrimary)
77 {
78 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create (
79 EventTypeNames::pointerenter, PlatformMouseEventBuilder(pointerType, raw Id), nullptr, nullptr);
80 EXPECT_EQ(uniqueId, pointerEvent->pointerId());
81 EXPECT_EQ(isPrimary, pointerEvent->isPrimary());
82 return pointerEvent;
83 }
84
85 TEST_F(PointerEventFactoryTest, MousePointer)
86 {
87 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(We bPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true);
88 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckMouseEvent(We bPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true);
89
90 m_pointerEventFactory.remove(pointerEvent1);
91
92 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 0, m_expe ctedMouseId, true);
93
94 m_pointerEventFactory.remove(pointerEvent1);
95 m_pointerEventFactory.remove(pointerEvent2);
96
97 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 1, m_expe ctedMouseId, true);
98 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 20, m_exp ectedMouseId, true);
99 }
100
101 TEST_F(PointerEventFactoryTest, TouchPointerPrimaryRemovedWhileAnotherIsThere)
102 {
103 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
104 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+1, false);
105
106 m_pointerEventFactory.remove(pointerEvent1);
107
108 RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 2, m_mappedIdStart+2, false);
109 RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+1, false);
110 }
111
112 TEST_F(PointerEventFactoryTest, TouchPointerReleasedAndPressedAgain)
113 {
114 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
115 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+1, false);
116
117 m_pointerEventFactory.remove(pointerEvent1);
118 m_pointerEventFactory.remove(pointerEvent2);
119
120 RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+2, true);
121 RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart+3, false);
122
123 m_pointerEventFactory.clear();
124
125 RefPtrWillBeRawPtr<PointerEvent> pointerEvent5 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 10, m_mappedIdStart+4, true);
126 }
127
128 TEST_F(PointerEventFactoryTest, TouchAndDrag)
129 {
130 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
131 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
132 RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
133
134 m_pointerEventFactory.remove(pointerEvent1);
135 m_pointerEventFactory.remove(pointerEvent2);
136
137 RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart+1, true);
138 RefPtrWillBeRawPtr<PointerEvent> pointerEvent5 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart+1, true);
139
140 // Remove an obsolete (i.e. already removed) pointer event which should have no effect
141 m_pointerEventFactory.remove(pointerEvent1);
142
143 RefPtrWillBeRawPtr<PointerEvent> pointerEvent6 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart+1, true);
144 }
145
146 TEST_F(PointerEventFactoryTest, MouseAndTouchAndPen)
147 {
148 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(We bPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true);
149 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true);
150 RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Pen, 0, m_mappedIdStart+1, true);
151
152 RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+2, false);
153 RefPtrWillBeRawPtr<PointerEvent> pointerEvent5 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 2, m_mappedIdStart+3, false);
154 RefPtrWillBeRawPtr<PointerEvent> pointerEvent6 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Pen, 0, m_mappedIdStart+1, true);
155 RefPtrWillBeRawPtr<PointerEvent> pointerEvent7 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Pen, 47213, m_mappedIdStart+4, false);
156
157 m_pointerEventFactory.remove(pointerEvent2);
158 m_pointerEventFactory.remove(pointerEvent4);
159 m_pointerEventFactory.remove(pointerEvent5);
160
161 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 100, m_ma ppedIdStart+5, true);
162
163 m_pointerEventFactory.clear();
164
165 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 0, m_expe ctedMouseId, true);
166 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mapp edIdStart+6, true);
167 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+7, true);
168 }
169
170 TEST_F(PointerEventFactoryTest, PenAsTouchAndMouseEvent)
171 {
172 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(We bPointerProperties::PointerType::Pen, 0, m_mappedIdStart, true);
173 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 1, m_mapped IdStart+1, false);
174 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 2, m_mapped IdStart+2, false);
175 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart, true);
176 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 1, m_mapped IdStart+1, false);
177 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart, true);
178 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 1, m_mapped IdStart+1, false);
179
180 m_pointerEventFactory.remove(pointerEvent1);
181
182 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+3, false);
183 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+3, false);
184
185 m_pointerEventFactory.clear();
186
187 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 1, m_mapped IdStart+4, true);
188 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+5, false);
189 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 1, m_mapped IdStart+4, true);
190 createAndCheckMouseEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+5, false);
191 }
192
193
194 TEST_F(PointerEventFactoryTest, OutOfRange)
195 {
196 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(We bPointerProperties::PointerType::Unknown, 0, m_mappedIdStart, true);
197 createAndCheckMouseEvent(WebPointerProperties::PointerType::Unknown, 1, m_ma ppedIdStart+1, false);
198 createAndCheckMouseEvent(WebPointerProperties::PointerType::Unknown, 2, m_ma ppedIdStart+2, false);
199 createAndCheckTouchEvent(WebPointerProperties::PointerType::Unknown, 0, m_ma ppedIdStart, true);
200 createAndCheckTouchEvent(WebPointerProperties::PointerType::Unknown, 3, m_ma ppedIdStart+3, false);
201 createAndCheckMouseEvent(WebPointerProperties::PointerType::Unknown, 2, m_ma ppedIdStart+2, false);
202
203 m_pointerEventFactory.remove(pointerEvent1);
204
205 createAndCheckTouchEvent(WebPointerProperties::PointerType::Unknown, 0, m_ma ppedIdStart+4, false);
206 createAndCheckTouchEvent(WebPointerProperties::PointerType::Unknown, INT_MAX , m_mappedIdStart+5, false);
207
208 m_pointerEventFactory.clear();
209
210 for (int i = 0; i < 100; ++i) {
211 createAndCheckMouseEvent(WebPointerProperties::PointerType::Touch, i, m_ mappedIdStart+6+i, i == 0);
212 }
213
214 for (int i = 0; i < 100; ++i) {
215 createAndCheckTouchEvent(WebPointerProperties::PointerType::Mouse, i, m_ expectedMouseId, true);
216 }
217 }
218
219 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698