Chromium Code Reviews

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

Issue 1426643008: Cleaning up PointerIdManager and add id re-mapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing a link error in the shared_library case Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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/PointerIdManager.h"
7
8 #include "public/platform/WebPointerProperties.h"
9 #include <climits>
10 #include <gtest/gtest.h>
11
12 namespace blink {
13
14 class PointerIdManagerTest : public ::testing::Test {
15 protected:
16 void SetUp() override;
17
18 PointerIdManager m_pointerIdManager;
19 unsigned m_expectedMouseId;
20 unsigned m_mappedIdStart;
21 };
22
23 void PointerIdManagerTest::SetUp()
24 {
25 m_expectedMouseId = 1;
26 m_mappedIdStart = 2;
27
28 }
29 TEST_F(PointerIdManagerTest, MousePointer)
30 {
31 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
32 EXPECT_EQ(m_pointerIdManager.getType(m_expectedMouseId), WebPointerPropertie s::PointerType::Mouse);
33 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_expectedMouseId));
34
35 m_pointerIdManager.remove(m_expectedMouseId);
36 m_pointerIdManager.remove(PointerIdManager::GeneratedPointer(WebPointerPrope rties::PointerType::Mouse, 0));
37
38 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
39 EXPECT_EQ(m_pointerIdManager.getType(m_expectedMouseId), WebPointerPropertie s::PointerType::Mouse);
40 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_expectedMouseId));
41
42 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Mouse, 0)), m_expectedMouseId);
43 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Mouse, 0)), m_expectedMouseId);
44
45 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
46 EXPECT_EQ(m_pointerIdManager.getType(m_expectedMouseId), WebPointerPropertie s::PointerType::Mouse);
47 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_expectedMouseId));
48 }
49
50 TEST_F(PointerIdManagerTest, TouchPointerPrimaryRemovedWhileAnotherIsThere)
51 {
52 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
53
54 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart);
55
56 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart);
57 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart), WebPointerProperties: :PointerType::Touch);
58 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart));
59
60 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 1)), m_mappedIdStart+1);
61
62 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart);
63 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+1), WebPointerPropertie s::PointerType::Touch);
64 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+1));
65
66 m_pointerIdManager.remove(m_mappedIdStart);
67
68 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
69 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+1), WebPointerPropertie s::PointerType::Touch);
70 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+1));
71 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart), WebPointerProperties: :PointerType::Unknown);
72 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart));
73
74 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 5)), m_mappedIdStart+2);
75
76 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
77 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+2), WebPointerPropertie s::PointerType::Touch);
78 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+2));
79
80 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart+3);
81
82 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
83 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+3), WebPointerPropertie s::PointerType::Touch);
84 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+3));
85 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+2), WebPointerPropertie s::PointerType::Touch);
86 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+2));
87 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+1), WebPointerPropertie s::PointerType::Touch);
88 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+1));
89 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart), WebPointerProperties: :PointerType::Unknown);
90 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart));
91
92 }
93
94 TEST_F(PointerIdManagerTest, TouchPointerReleasedAndPressedAgain)
95 {
96 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
97
98 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart);
99 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 1)), m_mappedIdStart+1);
100
101 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart);
102 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart), WebPointerProperties: :PointerType::Touch);
103 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart));
104 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+1), WebPointerPropertie s::PointerType::Touch);
105 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+1));
106
107
108 m_pointerIdManager.remove(PointerIdManager::GeneratedPointer(WebPointerPrope rties::PointerType::Touch, 0));
109 m_pointerIdManager.remove(PointerIdManager::GeneratedPointer(WebPointerPrope rties::PointerType::Touch, 1));
110
111 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
112 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart), WebPointerProperties: :PointerType::Unknown);
113 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart));
114 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+1), WebPointerPropertie s::PointerType::Unknown);
115 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+1));
116
117
118 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 1)), m_mappedIdStart+2);
119 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart+3);
120
121 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart+2);
122 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+2), WebPointerPropertie s::PointerType::Touch);
123 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart+2));
124 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+3), WebPointerPropertie s::PointerType::Touch);
125 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+3));
126
127
128 m_pointerIdManager.clear();
129
130 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart+4);
131
132 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart+4);
133 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+4), WebPointerPropertie s::PointerType::Touch);
134 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart+4));
135
136 }
137
138 TEST_F(PointerIdManagerTest, TouchAndDrag)
139 {
140 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
141
142 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart);
143
144 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart);
145 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart), WebPointerProperties: :PointerType::Touch);
146 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart));
147
148 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart);
149 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart);
150
151 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart);
152 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart), WebPointerProperties: :PointerType::Touch);
153 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart));
154
155 m_pointerIdManager.remove(PointerIdManager::GeneratedPointer(WebPointerPrope rties::PointerType::Touch, 0));
156
157 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
158 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart), WebPointerProperties: :PointerType::Unknown);
159 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart));
160
161 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart+1);
162 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart+1);
163 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart+1);
164
165 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart+1);
166 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+1), WebPointerPropertie s::PointerType::Touch);
167 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart+1));
168
169 }
170
171 TEST_F(PointerIdManagerTest, MouseAndTouchAndPen)
172 {
173 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
174 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
175 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Pen), PointerIdManager::s_invalidId);
176
177 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Mouse, 0)), m_expectedMouseId);
178 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 0)), m_mappedIdStart);
179 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Pen, 0)), m_mappedIdStart+1);
180
181 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
182 EXPECT_EQ(m_pointerIdManager.getType(m_expectedMouseId), WebPointerPropertie s::PointerType::Mouse);
183 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_expectedMouseId));
184 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart);
185 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart), WebPointerProperties: :PointerType::Touch);
186 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart));
187 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Pen), m_mappedIdStart+1);
188 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+1), WebPointerPropertie s::PointerType::Pen);
189 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart+1));
190
191 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 1)), m_mappedIdStart+2);
192 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, 2)), m_mappedIdStart+3);
193 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Pen, 0)), m_mappedIdStart+1);
194 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Pen, 3)), m_mappedIdStart+4);
195
196 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
197 EXPECT_EQ(m_pointerIdManager.getType(m_expectedMouseId), WebPointerPropertie s::PointerType::Mouse);
198 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_expectedMouseId));
199 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart);
200 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart), WebPointerProperties: :PointerType::Touch);
201 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart));
202 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Pen), m_mappedIdStart+1);
203 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+1), WebPointerPropertie s::PointerType::Pen);
204 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart+1));
205
206 m_pointerIdManager.remove(PointerIdManager::GeneratedPointer(WebPointerPrope rties::PointerType::Touch, 1));
207 m_pointerIdManager.remove(PointerIdManager::GeneratedPointer(WebPointerPrope rties::PointerType::Touch, 2));
208 m_pointerIdManager.remove(m_mappedIdStart);
209
210 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
211 EXPECT_EQ(m_pointerIdManager.getType(m_expectedMouseId), WebPointerPropertie s::PointerType::Mouse);
212 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_expectedMouseId));
213 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
214 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Pen), m_mappedIdStart+1);
215 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+1), WebPointerPropertie s::PointerType::Pen);
216 EXPECT_TRUE(m_pointerIdManager.isPrimary(m_mappedIdStart+1));
217 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+4), WebPointerPropertie s::PointerType::Pen);
218 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+4));
219
220 m_pointerIdManager.remove(PointerIdManager::GeneratedPointer(WebPointerPrope rties::PointerType::Pen, 0));
221 m_pointerIdManager.remove(m_mappedIdStart+4);
222
223 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
224 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
225 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Pen), PointerIdManager::s_invalidId);
226
227 }
228
229 TEST_F(PointerIdManagerTest, OutOfRange)
230 {
231 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Unknown), PointerIdManager::s_invalidId);
232 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
233 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
234 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Pen), PointerIdManager::s_invalidId);
235
236
237 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Mouse, 0)), m_expectedMouseId);
238 m_pointerIdManager.remove(PointerIdManager::GeneratedPointer(WebPointerPrope rties::PointerType::Mouse, 10));
239 m_pointerIdManager.remove(PointerIdManager::GeneratedPointer(WebPointerPrope rties::PointerType::Pen, 20));
240 m_pointerIdManager.remove(m_mappedIdStart+100);
241
242 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Unknown), PointerIdManager::s_invalidId);
243 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
244 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
245 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Pen), PointerIdManager::s_invalidId);
246 EXPECT_EQ(m_pointerIdManager.getType(m_mappedIdStart+200), WebPointerPropert ies::PointerType::Unknown);
247 EXPECT_FALSE(m_pointerIdManager.isPrimary(m_mappedIdStart+200));
248 EXPECT_EQ(m_pointerIdManager.getType(PointerIdManager::s_invalidId), WebPoin terProperties::PointerType::Unknown);
249 EXPECT_FALSE(m_pointerIdManager.isPrimary(PointerIdManager::s_invalidId));
250 EXPECT_EQ(m_pointerIdManager.getType(UINT_MAX-1), WebPointerProperties::Poin terType::Unknown);
251 EXPECT_FALSE(m_pointerIdManager.isPrimary(UINT_MAX-1));
252
253 EXPECT_EQ(m_pointerIdManager.add(PointerIdManager::GeneratedPointer(WebPoint erProperties::PointerType::Touch, UINT_MAX-2)), m_mappedIdStart);
254
255 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Unknown), PointerIdManager::s_invalidId);
256 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
257 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), m_mappedIdStart);
258 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Pen), PointerIdManager::s_invalidId);
259
260 m_pointerIdManager.remove(PointerIdManager::GeneratedPointer(WebPointerPrope rties::PointerType::Touch, UINT_MAX-2));
261
262 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Unknown), PointerIdManager::s_invalidId);
263 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Mouse), m_expectedMouseId);
264 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Touch), PointerIdManager::s_invalidId);
265 EXPECT_EQ(m_pointerIdManager.getPrimaryId(WebPointerProperties::PointerType: :Pen), PointerIdManager::s_invalidId);
266
267 }
268
269 } // namespace blink
OLDNEW

Powered by Google App Engine