Skip to content

Commit 09345e9

Browse files
[Interop] Add a WPT for PE attributes for right-button events. (#37387)
Bug: 876994, 649521 Change-Id: I9d1ef3127fc660862b45809c4aaf22e9ada4a9a3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4087242 Reviewed-by: Kevin Ellis <[email protected]> Commit-Queue: Mustaq Ahmed <[email protected]> Cr-Commit-Position: refs/heads/main@{#1081465} Co-authored-by: Mustaq Ahmed <[email protected]>
1 parent 47ce936 commit 09345e9

File tree

2 files changed

+182
-6
lines changed

2 files changed

+182
-6
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Pointer Events properties tests</title>
5+
<meta name="viewport" content="width=device-width">
6+
<meta name="variant" content="?mouse">
7+
<meta name="variant" content="?pen">
8+
<link rel="stylesheet" type="text/css" href="pointerevent_styles.css">
9+
<script src="/resources/testharness.js"></script>
10+
<script src="/resources/testharnessreport.js"></script>
11+
<script src="/resources/testdriver.js"></script>
12+
<script src="/resources/testdriver-actions.js"></script>
13+
<script src="/resources/testdriver-vendor.js"></script>
14+
<!-- Additional helper script for common checks across event types -->
15+
<script type="text/javascript" src="pointerevent_support.js"></script>
16+
<script>
17+
var input_pointertype = location.search.substring(1);
18+
var detected_eventTypes = {};
19+
var eventList = [
20+
'pointerover', 'pointerenter', 'pointermove', 'pointerdown',
21+
'pointerup', 'pointerout', 'pointerleave'
22+
];
23+
var expectedPointerId = NaN;
24+
25+
function resetTestState() {
26+
detected_eventTypes = {};
27+
document.getElementById("square1").style.visibility = 'visible';
28+
document.getElementById('innerFrame').contentDocument
29+
.getElementById("square2").style.visibility = 'hidden';
30+
expectedPointerId = NaN;
31+
}
32+
function checkPointerEventAttributes(
33+
event, targetBoundingClientRect, testNamePrefix) {
34+
if (detected_eventTypes[event.type])
35+
return;
36+
var expectedEventType =
37+
eventList[Object.keys(detected_eventTypes).length];
38+
detected_eventTypes[event.type] = true;
39+
var pointerTestName = (testNamePrefix ? testNamePrefix + ' ' : '')
40+
+ expectedPointerType + ' ' + expectedEventType;
41+
42+
test(function() {
43+
assert_equals(event.type, expectedEventType);
44+
}, pointerTestName + "'s type should be " + expectedEventType);
45+
46+
// Test button and buttons
47+
if (event.type == 'pointerdown') {
48+
test(function() {
49+
assert_equals(event.button, 2);
50+
}, pointerTestName + "'s button attribute is 2 when right mouse "
51+
+ "button is pressed.");
52+
test(function() {
53+
assert_equals(event.buttons, 2);
54+
}, pointerTestName + "'s buttons attribute is 2 when right mouse "
55+
+ "button is pressed.");
56+
} else if (event.type == 'pointerup') {
57+
test(function() {
58+
assert_equals(event.button, 2);
59+
}, pointerTestName + "'s button attribute is 0 when right mouse "
60+
+ "button is just released.");
61+
test(function() {
62+
assert_equals(event.buttons, 0);
63+
}, pointerTestName + "'s buttons attribute is 0 when right mouse "
64+
+ "button is just released.");
65+
} else {
66+
test(function() {
67+
assert_equals(event.button, -1);
68+
}, pointerTestName + "'s button is -1 when mouse buttons are in "
69+
+ "released state.");
70+
test(function() {
71+
assert_equals(event.buttons, 0);
72+
}, pointerTestName + "'s buttons is 0 when mouse buttons are in "
73+
+ "released state.");
74+
}
75+
76+
// Test clientX and clientY
77+
if (event.type != 'pointerout' && event.type != 'pointerleave' ) {
78+
test(function () {
79+
assert_greater_than_equal(
80+
event.clientX, targetBoundingClientRect.left,
81+
"clientX should be greater or equal than left of the box");
82+
assert_greater_than_equal(
83+
event.clientY, targetBoundingClientRect.top,
84+
"clientY should be greater or equal than top of the box");
85+
assert_less_than_equal(
86+
event.clientX, targetBoundingClientRect.right,
87+
"clientX should be less or equal than right of the box");
88+
assert_less_than_equal(
89+
event.clientY, targetBoundingClientRect.bottom,
90+
"clientY should be less or equal than bottom of the box");
91+
}, pointerTestName + "'s ClientX and ClientY attributes are correct.");
92+
} else {
93+
test(function () {
94+
assert_true(
95+
event.clientX < targetBoundingClientRect.left
96+
|| event.clientX >= targetBoundingClientRect.right
97+
|| event.clientY < targetBoundingClientRect.top
98+
|| event.clientY >= targetBoundingClientRect.bottom,
99+
"ClientX/Y should be out of the boundaries of the box");
100+
}, pointerTestName + "'s ClientX and ClientY attributes are correct.");
101+
}
102+
103+
check_PointerEvent(event, testNamePrefix);
104+
105+
// Test isPrimary
106+
test(function () {
107+
assert_equals(event.isPrimary, true);
108+
}, pointerTestName + ".isPrimary attribute is correct.");
109+
110+
// Test pointerId value
111+
if (isNaN(expectedPointerId)) {
112+
expectedPointerId = event.pointerId;
113+
} else {
114+
test(function () {
115+
assert_equals(event.pointerId, expectedPointerId);
116+
}, pointerTestName + ".pointerId should be the same as previous "
117+
+ "pointer events for this active pointer.");
118+
}
119+
}
120+
121+
async function run() {
122+
var test_pointerEvent = setup_pointerevent_test(
123+
"pointerevent attributes", [input_pointertype]);
124+
var square1 = document.getElementById("square1");
125+
var rectSquare1 = square1.getBoundingClientRect();
126+
var innerFrame = document.getElementById('innerFrame');
127+
var square2 = innerFrame.contentDocument.getElementById('square2');
128+
var rectSquare2 = square2.getBoundingClientRect();
129+
var actions_promise;
130+
131+
eventList.forEach(function(eventName) {
132+
on_event(square1, eventName, function (event) {
133+
if (square1.style.visibility == 'hidden')
134+
return;
135+
checkPointerEventAttributes(event, rectSquare1, "");
136+
if (Object.keys(detected_eventTypes).length == eventList.length) {
137+
square1.style.visibility = 'hidden';
138+
detected_eventTypes = {};
139+
square2.style.visibility = 'visible';
140+
expectedPointerId = NaN;
141+
}
142+
});
143+
on_event(square2, eventName, function (event) {
144+
checkPointerEventAttributes(event, rectSquare2, "Inner frame");
145+
if (Object.keys(detected_eventTypes).length == eventList.length) {
146+
square2.style.visibility = 'hidden';
147+
test_pointerEvent.done();
148+
}
149+
});
150+
});
151+
152+
// Inject mouse or pen inputs.
153+
await rightClickInTarget(input_pointertype, square1);
154+
await moveToDocument(input_pointertype);
155+
await rightClickInTarget(input_pointertype, square2);
156+
await moveToDocument(input_pointertype);
157+
}
158+
</script>
159+
</head>
160+
<body onload="run()">
161+
<h1>Pointer Events hoverable pointer attributes test</h1>
162+
<h2 id="pointerTypeDescription"></h2>
163+
<div id="square1" class="square"></div>
164+
<iframe id="innerFrame"
165+
src="resources/pointerevent_attributes_hoverable_pointers-iframe.html">
166+
</iframe>
167+
</body>
168+
</html>

pointerevents/pointerevent_support.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ function check_PointerEvent(event, testNamePrefix) {
129129
assert_less_than_equal(event.pressure, 1, "pressure is less than or equal to 1");
130130

131131
if (event.buttons === 0) {
132-
assert_equals(event.pressure, 0, "pressure is 0 for mouse with no buttons pressed");
133-
}
134-
135-
// TA: 1.7, 1.8
136-
if (event.pointerType === "mouse") {
137-
if (event.buttons !== 0) {
132+
assert_equals(event.pressure, 0, "pressure is 0 with no buttons pressed");
133+
} else {
134+
assert_greater_than(event.pressure, 0, "pressure is greater than 0 with a button pressed");
135+
if (event.pointerType === "mouse") {
138136
assert_equals(event.pressure, 0.5, "pressure is 0.5 for mouse with a button pressed");
139137
}
140138
}
@@ -335,6 +333,16 @@ function clickInTarget(pointerType, target) {
335333
.send();
336334
}
337335

336+
function rightClickInTarget(pointerType, target) {
337+
let pointerId = pointerType + "Pointer1";
338+
let actions = new test_driver.Actions();
339+
return actions.addPointer(pointerId, pointerType)
340+
.pointerMove(0, 0, {origin: target})
341+
.pointerDown({button:actions.ButtonType.RIGHT})
342+
.pointerUp({button:actions.ButtonType.RIGHT})
343+
.send();
344+
}
345+
338346
function twoFingerDrag(target) {
339347
return new test_driver.Actions()
340348
.addPointer("touchPointer1", "touch")

0 commit comments

Comments
 (0)