Files
tubestation/testing/web-platform/tests/input-events/input-events-spin-button-click-on-number-input-delete-document.html
Utkarsh Pathak cba9b74276 Bug 1899975 [wpt PR 46561] - Dispatch BeforeInput Event for number input spin button and Arrow key, a=testonly
Automatic update from web-platform-tests
Dispatch BeforeInput Event for number input spin button and Arrow key

https://w3c.github.io/uievents/#event-type-beforeinput
A user agent MUST dispatch beforeinput event when the DOM is about to be updated.

Bug: 40948436
Change-Id: Idc894f4e7427a81e684b37cc10749b4386e5aa7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5443103
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Utkarsh Pathak <utpathak@microsoft.com>
Reviewed-by: Sanket Joshi <sajos@microsoft.com>
Reviewed-by: Anupam Snigdha <snianu@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1308524}

--

wpt-commits: 6f491c45bc5182275419be89a0820c2deaddc6b0
wpt-pr: 46561
2024-06-05 09:01:16 +00:00

40 lines
1.4 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
</head>
<body>
<iframe id="iframe"></iframe>
<script>
promise_test(async function() {
const child = document.getElementById("iframe");
const childDocument = child.contentDocument;
const inputElement = childDocument.createElement('input');
inputElement.type = "number";
childDocument.body.appendChild(inputElement);
let events = [];
inputElement.addEventListener("beforeinput", () => {
child.remove();
events.push("beforeinput");
});
inputElement.addEventListener("input", () => {
events.push("input");
});
inputElement.addEventListener("change", () => {
events.push("change");
});
inputElement.focus();
// Get the spin button up arrow key location and adjust with iframe offset to get absolute position
const x1 = (inputElement.offsetLeft + inputElement.offsetWidth - 10) + child.offsetLeft;
const y1 = (inputElement.offsetTop + inputElement.offsetHeight / 4) + child.offsetTop;
await test_driver_internal.click(inputElement,{x: x1, y: y1});
assert_array_equals(events, ['beforeinput']);
assert_false(document.body.contains(child));
}, "Number input should not crash and not fire subsequent events when event handler removes document");
</script>
</body>
</html>