Skip to content

Commit 013bd0b

Browse files
authored
fix: update touchscreen tests (#11960)
1 parent 70ad3b2 commit 013bd0b

File tree

4 files changed

+265
-149
lines changed

4 files changed

+265
-149
lines changed

Diff for: packages/puppeteer-core/src/cdp/Input.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import type {CDPSession} from '../api/CDPSession.js';
1010
import type {Point} from '../api/ElementHandle.js';
1111
import {
1212
Keyboard,
13-
type KeyDownOptions,
14-
type KeyPressOptions,
1513
Mouse,
1614
MouseButton,
15+
Touchscreen,
16+
type KeyDownOptions,
17+
type KeyPressOptions,
18+
type KeyboardTypeOptions,
1719
type MouseClickOptions,
1820
type MouseMoveOptions,
1921
type MouseOptions,
2022
type MouseWheelOptions,
21-
Touchscreen,
22-
type KeyboardTypeOptions,
2323
} from '../api/Input.js';
2424
import {
2525
_keyDefinitions,
@@ -573,6 +573,7 @@ export class CdpTouchscreen extends Touchscreen {
573573
y: Math.round(y),
574574
radiusX: 0.5,
575575
radiusY: 0.5,
576+
force: 0.5,
576577
},
577578
],
578579
modifiers: this.#keyboard._modifiers,
@@ -588,6 +589,7 @@ export class CdpTouchscreen extends Touchscreen {
588589
y: Math.round(y),
589590
radiusX: 0.5,
590591
radiusY: 0.5,
592+
force: 0.5,
591593
},
592594
],
593595
modifiers: this.#keyboard._modifiers,

Diff for: test/TestExpectations.json

-6
Original file line numberDiff line numberDiff line change
@@ -3287,12 +3287,6 @@
32873287
"parameters": ["chrome", "webDriverBiDi"],
32883288
"expectations": ["FAIL"]
32893289
},
3290-
{
3291-
"testIdPattern": "[touchscreen.spec] Touchscreen Touchscreen.prototype.touchMove should work",
3292-
"platforms": ["darwin", "linux", "win32"],
3293-
"parameters": ["cdp", "chrome"],
3294-
"expectations": ["FAIL"]
3295-
},
32963290
{
32973291
"testIdPattern": "[touchscreen.spec] Touchscreen Touchscreen.prototype.touchMove should work",
32983292
"platforms": ["darwin", "linux", "win32"],

Diff for: test/assets/input/touchscreen.html

+48-98
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Touch test</title>
55
</head>
66

7-
<body>
7+
<body style="touch-action: none">
88
<style>
99
button {
1010
box-sizing: border-box;
@@ -20,103 +20,53 @@
2020
<button>Click target</button>
2121
<script>
2222
var allEvents = [];
23-
globalThis.addEventListener(
24-
"touchstart",
25-
(event) => {
26-
allEvents.push({
27-
type: "touchstart",
28-
touches: [...event.changedTouches].map((touch) => [
29-
touch.clientX,
30-
touch.clientY,
31-
touch.radiusX,
32-
touch.radiusY,
33-
]),
34-
});
35-
},
36-
true,
37-
);
38-
globalThis.addEventListener(
39-
"touchmove",
40-
(event) => {
41-
allEvents.push({
42-
type: "touchmove",
43-
touches: [...event.changedTouches].map((touch) => [
44-
touch.clientX,
45-
touch.clientY,
46-
touch.radiusX,
47-
touch.radiusY,
48-
]),
49-
});
50-
},
51-
true,
52-
);
53-
globalThis.addEventListener(
54-
"touchend",
55-
(event) => {
56-
allEvents.push({
57-
type: "touchend",
58-
touches: [...event.changedTouches].map((touch) => [
59-
touch.clientX,
60-
touch.clientY,
61-
touch.radiusX,
62-
touch.radiusY,
63-
])
64-
});
65-
},
66-
true,
67-
);
68-
globalThis.addEventListener(
69-
"pointerdown",
70-
(event) => {
71-
allEvents.push({
72-
type: "pointerdown",
73-
x: event.x,
74-
y: event.y,
75-
width: event.width,
76-
height: event.height,
77-
});
78-
},
79-
true,
80-
);
81-
globalThis.addEventListener(
82-
"pointermove",
83-
(event) => {
84-
allEvents.push({
85-
type: "pointermove",
86-
x: event.x,
87-
y: event.y,
88-
width: event.width,
89-
height: event.height,
90-
});
91-
},
92-
true,
93-
);
94-
globalThis.addEventListener(
95-
"pointerup",
96-
(event) => {
97-
allEvents.push({
98-
type: "pointerup",
99-
x: event.x,
100-
y: event.y,
101-
width: event.width,
102-
height: event.height,
103-
});
104-
},
105-
true,
106-
);
107-
globalThis.addEventListener(
108-
"click",
109-
(event) => {
110-
allEvents.push({
111-
type: "click",
112-
x: event.x,
113-
y: event.y,
114-
width: event.width,
115-
height: event.height,
116-
});
117-
},
118-
true,
119-
);
23+
for (const name of ["touchstart", "touchmove", "touchend"]) {
24+
globalThis.addEventListener(
25+
name,
26+
(event) => {
27+
allEvents.push({
28+
type: name,
29+
changedTouches: [...event.changedTouches].map((touch) => ({
30+
clientX: touch.clientX,
31+
clientY: touch.clientY,
32+
radiusX: touch.radiusX,
33+
radiusY: touch.radiusY,
34+
force: touch.force,
35+
})),
36+
activeTouches: [...event.touches].map((touch) => ({
37+
clientX: touch.clientX,
38+
clientY: touch.clientY,
39+
radiusX: touch.radiusX,
40+
radiusY: touch.radiusY,
41+
force: touch.force,
42+
})),
43+
});
44+
},
45+
true,
46+
);
47+
}
48+
for (const name of ['pointerdown', 'pointermove', 'pointerup', 'click']) {
49+
globalThis.addEventListener(
50+
name,
51+
(event) => {
52+
allEvents.push({
53+
type: name,
54+
x: event.x,
55+
y: event.y,
56+
width: event.width,
57+
height: event.height,
58+
altitudeAngle: event.altitudeAngle,
59+
azimuthAngle: event.azimuthAngle,
60+
pressure: event.pressure,
61+
pointerType: event.pointerType,
62+
twist: event.twist,
63+
tiltX: event.tiltX,
64+
tiltY: event.tiltY,
65+
});
66+
},
67+
true,
68+
);
69+
}
12070
</script>
12171
</body>
12272
</html>

0 commit comments

Comments
 (0)