-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Commit-Queue: Utkarsh Pathak <[email protected]> Reviewed-by: Sanket Joshi <[email protected]> Reviewed-by: Anupam Snigdha <[email protected]> Cr-Commit-Position: refs/heads/main@{#1308524}
- Loading branch information
1 parent
a66ff7e
commit 6f491c4
Showing
6 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
input-events/input-events-arrow-key-on-number-input-delete-document.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!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", () => { | ||
evenst.push("input"); | ||
}); | ||
inputElement.addEventListener("change", () => { | ||
events.push("change"); | ||
}); | ||
|
||
inputElement.focus(); | ||
|
||
await new test_driver.send_keys(inputElement, "\uE013"); | ||
assert_array_equals(events, ['beforeinput']); | ||
}, "Number input should not crash and not fire subsequent events when event handler removes document"); | ||
</script> | ||
</body> | ||
</html> |
33 changes: 33 additions & 0 deletions
33
input-events/input-events-arrow-key-on-number-input-prevent-default.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!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> | ||
<input type="number" id="number_input"> | ||
<script> | ||
promise_test(async function() { | ||
const inputElement = document.getElementById("number_input"); | ||
let events = []; | ||
inputElement.addEventListener("beforeinput", (e) => { | ||
e.preventDefault(); | ||
events.push("beforeinput"); | ||
}); | ||
inputElement.addEventListener("input", () => { | ||
events.push("input"); | ||
}); | ||
inputElement.addEventListener("change", () => { | ||
events.push("change"); | ||
}); | ||
|
||
inputElement.focus(); | ||
|
||
await new test_driver.send_keys(inputElement, "\uE013"); | ||
assert_array_equals(events, ['beforeinput']); | ||
}, "Number input should not fire input and change event if the beforeinput event is default prevented"); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!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> | ||
<input type="number" id="number_input"> | ||
<script> | ||
promise_test(async function() { | ||
const inputElement = document.getElementById("number_input"); | ||
let events = []; | ||
inputElement.addEventListener("beforeinput", () => { | ||
events.push("beforeinput"); | ||
}); | ||
inputElement.addEventListener("input", () => { | ||
events.push("input"); | ||
}); | ||
inputElement.addEventListener("change", () => { | ||
events.push("change"); | ||
}); | ||
|
||
inputElement.focus(); | ||
|
||
await new test_driver.send_keys(inputElement, "\uE013"); | ||
assert_array_equals(events, ['beforeinput','input','change']); | ||
}, "Number input should fire beforeinput event before the input and change event"); | ||
</script> | ||
</body> | ||
</html> |
40 changes: 40 additions & 0 deletions
40
input-events/input-events-spin-button-click-on-number-input-delete-document.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!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> |
35 changes: 35 additions & 0 deletions
35
input-events/input-events-spin-button-click-on-number-input-prevent-default.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!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> | ||
<input type="number" id="number_input"> | ||
<script> | ||
promise_test(async function() { | ||
const inputElement = document.getElementById("number_input"); | ||
let events = []; | ||
inputElement.addEventListener("beforeinput", (e) => { | ||
e.preventDefault(); | ||
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 | ||
const x1 = (inputElement.offsetLeft + inputElement.offsetWidth - 10); | ||
const y1 = (inputElement.offsetTop + inputElement.offsetHeight / 4); | ||
await test_driver_internal.click(inputElement,{x: x1, y: y1}); | ||
assert_array_equals(events, ['beforeinput']); | ||
}, "Number input should not fire input and change event if the beforeinput event is default prevented"); | ||
</script> | ||
</body> | ||
</html> |
34 changes: 34 additions & 0 deletions
34
input-events/input-events-spin-button-click-on-number-input.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!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> | ||
<input type="number" id="number_input"> | ||
<script> | ||
promise_test(async function() { | ||
const inputElement = document.getElementById("number_input"); | ||
let events = []; | ||
inputElement.addEventListener("beforeinput", () => { | ||
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 | ||
const x1 = (inputElement.offsetLeft + inputElement.offsetWidth - 10); | ||
const y1 = (inputElement.offsetTop + inputElement.offsetHeight / 4); | ||
await test_driver_internal.click(inputElement,{x: x1, y: y1}); | ||
assert_array_equals(events, ['beforeinput','input','change']); | ||
}, "Number input should fire beforeinput event before the input and change event"); | ||
</script> | ||
</body> | ||
</html> |