Truly independent web browser
LibWeb: Cover legacy mouse and pointer event targets
Andreas Kling34e26ef83752
diff --git a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]new file mode 100644index 00000000000..7e66cbdba1e--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]@@ -0,0 +1,23 @@+Harness status: OK++Found 16 tests++1 Pass+1 Fail+14 Optional Feature Unsupported+Pass Main-frame attribute test.+Fail Inner-frame attribute test.+Optional Feature Unsupported Main-frame mouse pointerover.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerover.toElement value is null+Optional Feature Unsupported Main-frame mouse pointerenter.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerenter.toElement value is null+Optional Feature Unsupported Main-frame mouse pointermove.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointermove.toElement value is null+Optional Feature Unsupported Main-frame mouse pointerdown.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerdown.toElement value is null+Optional Feature Unsupported Main-frame mouse pointerup.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerup.toElement value is null+Optional Feature Unsupported Main-frame mouse pointerout.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerout.toElement value is null+Optional Feature Unsupported Main-frame mouse pointerleave.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerleave.toElement value is null\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]new file mode 100644index 00000000000..7e66cbdba1e--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]@@ -0,0 +1,23 @@+Harness status: OK++Found 16 tests++1 Pass+1 Fail+14 Optional Feature Unsupported+Pass Main-frame attribute test.+Fail Inner-frame attribute test.+Optional Feature Unsupported Main-frame mouse pointerover.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerover.toElement value is null+Optional Feature Unsupported Main-frame mouse pointerenter.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerenter.toElement value is null+Optional Feature Unsupported Main-frame mouse pointermove.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointermove.toElement value is null+Optional Feature Unsupported Main-frame mouse pointerdown.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerdown.toElement value is null+Optional Feature Unsupported Main-frame mouse pointerup.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerup.toElement value is null+Optional Feature Unsupported Main-frame mouse pointerout.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerout.toElement value is null+Optional Feature Unsupported Main-frame mouse pointerleave.fromElement value is null+Optional Feature Unsupported Main-frame mouse pointerleave.toElement value is null\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]new file mode 100644index 00000000000..371324ed478--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]@@ -0,0 +1,23 @@+Harness status: OK++Found 16 tests++1 Pass+1 Fail+14 Optional Feature Unsupported+Pass Main-frame attribute test.+Fail Inner-frame attribute test.+Optional Feature Unsupported Main-frame pen pointerover.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerover.toElement value is null+Optional Feature Unsupported Main-frame pen pointerenter.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerenter.toElement value is null+Optional Feature Unsupported Main-frame pen pointermove.fromElement value is null+Optional Feature Unsupported Main-frame pen pointermove.toElement value is null+Optional Feature Unsupported Main-frame pen pointerdown.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerdown.toElement value is null+Optional Feature Unsupported Main-frame pen pointerup.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerup.toElement value is null+Optional Feature Unsupported Main-frame pen pointerout.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerout.toElement value is null+Optional Feature Unsupported Main-frame pen pointerleave.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerleave.toElement value is null\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]new file mode 100644index 00000000000..371324ed478--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]@@ -0,0 +1,23 @@+Harness status: OK++Found 16 tests++1 Pass+1 Fail+14 Optional Feature Unsupported+Pass Main-frame attribute test.+Fail Inner-frame attribute test.+Optional Feature Unsupported Main-frame pen pointerover.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerover.toElement value is null+Optional Feature Unsupported Main-frame pen pointerenter.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerenter.toElement value is null+Optional Feature Unsupported Main-frame pen pointermove.fromElement value is null+Optional Feature Unsupported Main-frame pen pointermove.toElement value is null+Optional Feature Unsupported Main-frame pen pointerdown.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerdown.toElement value is null+Optional Feature Unsupported Main-frame pen pointerup.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerup.toElement value is null+Optional Feature Unsupported Main-frame pen pointerout.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerout.toElement value is null+Optional Feature Unsupported Main-frame pen pointerleave.fromElement value is null+Optional Feature Unsupported Main-frame pen pointerleave.toElement value is null\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]new file mode 100644index 00000000000..88104e90741--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]@@ -0,0 +1,23 @@+Harness status: OK++Found 16 tests++1 Pass+1 Fail+14 Optional Feature Unsupported+Pass Main-frame attribute test.+Fail Inner-frame attribute test.+Optional Feature Unsupported Main-frame touch pointerover.fromElement value is null+Optional Feature Unsupported Main-frame touch pointerover.toElement value is null+Optional Feature Unsupported Main-frame touch pointerenter.fromElement value is null+Optional Feature Unsupported Main-frame touch pointerenter.toElement value is null+Optional Feature Unsupported Main-frame touch pointerdown.fromElement value is null+Optional Feature Unsupported Main-frame touch pointerdown.toElement value is null+Optional Feature Unsupported Main-frame touch pointermove.fromElement value is null+Optional Feature Unsupported Main-frame touch pointermove.toElement value is null+Optional Feature Unsupported Main-frame touch pointerup.fromElement value is null+Optional Feature Unsupported Main-frame touch pointerup.toElement value is null+Optional Feature Unsupported Main-frame touch pointerout.fromElement value is null+Optional Feature Unsupported Main-frame touch pointerout.toElement value is null+Optional Feature Unsupported Main-frame touch pointerleave.fromElement value is null+Optional Feature Unsupported Main-frame touch pointerleave.toElement value is null\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/pointerevents/pointerevent_attributes.optional.html b/Tests/LibWeb/Text/input/wpt-import/pointerevents/pointerevent_attributes.optional.htmlnew file mode 100644index 00000000000..74eaf310a75--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/pointerevents/pointerevent_attributes.optional.html@@ -0,0 +1,134 @@+<!doctype html>+<title>Pointer Events optional attributes</title>+<meta name="viewport" content="width=device-width">+<meta name="variant" content="?mouse">+<meta name="variant" content="?pen">+<meta name="variant" content="?mouse-right">+<meta name="variant" content="?pen-right">+<meta name="variant" content="?touch">+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="../resources/testdriver.js"></script>+<script src="../resources/testdriver-actions.js"></script>+<script src="../resources/testdriver-vendor.js"></script>+<script type="text/javascript" src="pointerevent_support.js"></script>+<script>+ "use strict";+ const queryStringFragments = location.search.substring(1).split('-');+ const pointerType = queryStringFragments[0];+ const button = queryStringFragments[1] === "right" ? "right" : undefined;++ assert_true(['mouse', 'pen', 'touch'].indexOf(pointerType) >= 0,+ `Unexpected pointer type (${pointerType})`);++ let frameLoaded = undefined;+ const frameLoadedPromise = new Promise(resolve => {+ frameLoaded = resolve;+ });++ const eventsTested = [+ 'pointerover',+ 'pointerenter',+ 'pointerdown',+ 'pointerup',+ 'pointerout',+ 'pointerleave',+ 'pointermove'+ ];++ async function runTests() {+ await frameLoadedPromise;++ // Prevent opening a contextmenu on right-click.+ addEventListener("contextmenu", e => e.preventDefault());+ frames[0].addEventListener("contextmenu", e => e.preventDefault());++ function addPromiseTest(testNamePrefix, target) {+ const testName = `${testNamePrefix} attribute test.`;++ promise_test(async test => {+ let eventsLogged = [];++ function eventChecker(e) {+ e.preventDefault();+ eventsLogged.push(e.type);+ check_PointerEvent(e, testNamePrefix, true);+ };++ eventsTested.forEach(type => {+ target.addEventListener(type, eventChecker, { once: true });+ test.add_cleanup(() => {+ target.removeEventListener(type, eventChecker, { once: true });+ });+ });++ // Start with a click in the same frame but outside the target, then+ // scrub the target, then move outside again to make sure the boundary+ // events are fired for hoverable pointers. Non-hoverable pointers fire+ // those events on pointerdown/up.+ {+ const actions = new test_driver.Actions();+ let buttonArguments = (button == 'right')+ ? { button: actions.ButtonType.RIGHT }+ : undefined;+ await actions+ .addPointer('pointer1', pointerType)+ .pointerMove(100, 0, { origin: target })+ .pointerDown()+ .pointerUp()+ .pointerMove(-20, 0, { origin: target })+ .pointerDown(buttonArguments)+ .pointerMove(20, 0, { origin: target })+ .pointerUp(buttonArguments)+ .pointerMove(0, 0)+ .send();+ }++ // Processing a click or tap on the done button is used to signal that+ // all other events should have been handled.+ {+ const doneButton = document.getElementById('done');+ const clickOnDone = getEvent('pointerup', doneButton);+ await new test_driver.Actions()+ .addPointer('pointer1', pointerType)+ .pointerMove(0, 0, {origin: doneButton})+ .pointerDown()+ .pointerUp()+ .send();+ await clickOnDone;+ }++ assert_array_equals(eventsLogged.toSorted(), eventsTested.toSorted(),+ `${testNamePrefix}: Logged and tested events should be the same`);+ }, testName);+ }++ addPromiseTest("Main-frame", document.getElementById('square1'));+ addPromiseTest("Inner-frame", frames[0].document.getElementById('square2'));+ }+</script>+<style>+ #square1 {+ touch-action: none;+ user-select: none;+ height: 50px;+ width: 50px;+ }+</style>+<body onload="runTests()">+ <div id="square1" draggable="false"></div>+ <iframe onload="frameLoaded()" id="innerFrame" srcdoc='+ <style>+ #square2 {+ touch-action: none;+ user-select: none;+ height: 50px;+ width: 50px;+ }+ </style>+ <body>+ <div id="square2" draggable="false"></div>+ </body>+ '></iframe>+ <button id="done">done</button>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/pointerevents/pointerevent_support.js b/Tests/LibWeb/Text/input/wpt-import/pointerevents/pointerevent_support.jsindex 7dd60f5a54d..fe0c95c3f2c 100644--- a/Tests/LibWeb/Text/input/wpt-import/pointerevents/pointerevent_support.js+++ b/Tests/LibWeb/Text/input/wpt-import/pointerevents/pointerevent_support.js@@ -44,7 +44,8 @@ const ButtonsBitfield = {// Check for conformance to PointerEvent interface// https://w3c.github.io/pointerevents/#pointerevent-interface-function check_PointerEvent(event, testNamePrefix, standardAttrs = true) {+function check_PointerEvent(event, testNamePrefix,+ optionalAtributesOnly = false) {if (testNamePrefix === undefined)testNamePrefix = "";@@ -52,7 +53,7 @@ function check_PointerEvent(event, testNamePrefix, standardAttrs = true) {var pointerTestName = (testNamePrefix ? testNamePrefix + ' ' : '')+ (expectedPointerType == null ? event.pointerType : expectedPointerType) + ' ' + event.type;- if (standardAttrs) {+ if (!optionalAtributesOnly) {if (expectedPointerType != null) {test(function () {assert_equals(event.pointerType, expectedPointerType);@@ -75,7 +76,7 @@ function check_PointerEvent(event, testNamePrefix, standardAttrs = true) {// Check values for inherited attributes.// https://w3c.github.io/pointerevents/#attributes-and-default-actions- if (!standardAttrs) {+ if (optionalAtributesOnly) {test(function () {assert_implements_optional("fromElement" in event);assert_equals(event.fromElement, null);@@ -251,6 +252,18 @@ function checkPointerEventType(event) {assert_equals(event.pointerType, expectedPointerType, "pointerType should be the same as the requested device.");}+function getInViewCenterPoint(rect) {+ var left = Math.max(0, rect.left);+ var right = Math.min(window.innerWidth, rect.right);+ var top = Math.max(0, rect.top);+ var bottom = Math.min(window.innerHeight, rect.bottom);++ var x = 0.5 * (left + right);+ var y = 0.5 * (top + bottom);++ return [x, y];+}+function touchScrollInTarget(target, direction) {var x_delta = 0;var y_delta = 0;@@ -269,16 +282,20 @@ function touchScrollInTarget(target, direction) {} else {throw("scroll direction '" + direction + "' is not expected, direction should be 'down', 'up', 'left' or 'right'");}+ // Target's initial position relative to the viewport.+ const rect = target.getBoundingClientRect();+ const [startX, startY] = getInViewCenterPoint(rect);+return new test_driver.Actions().addPointer("touchPointer1", "touch")- .pointerMove(0, 0, {origin: target})+ .pointerMove(startX, startY, {origin: 'viewport'}).pointerDown()- .pointerMove(x_delta, y_delta, {origin: target})- .pointerMove(2 * x_delta, 2 * y_delta, {origin: target})- .pointerMove(3 * x_delta, 3 * y_delta, {origin: target})- .pointerMove(4 * x_delta, 4 * y_delta, {origin: target})- .pointerMove(5 * x_delta, 5 * y_delta, {origin: target})- .pointerMove(6 * x_delta, 6 * y_delta, {origin: target})+ .pointerMove(startX + x_delta, startY + y_delta, {origin: "viewport"})+ .pointerMove(startX + 2 * x_delta, startY + 2 * y_delta, {origin: "viewport"})+ .pointerMove(startX + 3 * x_delta, startY + 3 * y_delta, {origin: "viewport"})+ .pointerMove(startX + 4 * x_delta, startY + 4 * y_delta, {origin: "viewport"})+ .pointerMove(startX + 5 * x_delta, startY + 5 * y_delta, {origin: "viewport"})+ .pointerMove(startX + 6 * x_delta, startY + 6 * y_delta, {origin: "viewport"}).pause(100).pointerUp().send();@@ -482,6 +499,22 @@ function getEvent(event_type, target, test) {});}+// Returns a promise that resolves when a child frame posts a subframe-ready+// message back to the parent and style rules have been applied. When the child+// frame needs to execute script, such as setting up listeners, it is+// insufficient to wait for the frame to be loaded, as the load event is+// received once the child frame's document has been parsed, which is before+// script execution or style update.+function loadFrameAndExcecuteScript(frame, src) {+ return new Promise(async resolve => {+ const ready = getMessageData('subframe-ready', frame.contentWindow);+ frame.src = src;+ await ready;+ // Ensure that the child frame has been properly styled.+ requestAnimationFrame(() => requestAnimationFrame(resolve));+ });+}+// Returns a |Promise| that gets resolved with |event.data| when |window|// receives from |source| a "message" event whose |event.data.type| matches the// string |message_data_type|.