Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/forms/textfieldselection/selection-readonly-keyboard.tentative.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta name=timeout content=long>
<title>Selection modification via keyboard on readonly input and textarea</title>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#textFieldSelection">
<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>
<input id="testInput" readonly value="abcdef">
<textarea id="testTextarea" readonly>abc def</textarea>
<script>
const ArrowLeft = '\uE012';
const ArrowUp = '\uE013';
const ArrowRight = '\uE014';
const ArrowDown = '\uE015';
const Shift = '\uE008';
const Backspace = '\uE003';
const input = document.getElementById('testInput');
const textarea = document.getElementById('testTextarea');
promise_test(async () => {
input.value = "abcdef";
await test_driver.click(input);
input.setSelectionRange(0, 0);
assert_equals(input.selectionStart, 0);
assert_equals(input.selectionEnd, 0);
await (new test_driver.Actions())
.keyDown(ArrowRight)
.keyUp(ArrowRight)
.send();
assert_equals(input.selectionStart, 1, "selectionStart after ArrowRight");
assert_equals(input.selectionEnd, 1, "selectionEnd after ArrowRight");
await (new test_driver.Actions())
.keyDown(ArrowRight)
.keyUp(ArrowRight)
.send();
assert_equals(input.selectionStart, 2, "selectionStart after second ArrowRight");
assert_equals(input.selectionEnd, 2, "selectionEnd after second ArrowRight");
await (new test_driver.Actions())
.keyDown(ArrowLeft)
.keyUp(ArrowLeft)
.send();
assert_equals(input.selectionStart, 1, "selectionStart after ArrowLeft");
assert_equals(input.selectionEnd, 1, "selectionEnd after ArrowLeft");
assert_equals(input.value, "abcdef", "value must remain unchanged");
}, "Arrow keys modify caret position in readonly input");
promise_test(async () => {
input.value = "abcdef";
await test_driver.click(input);
input.setSelectionRange(1, 1);
await (new test_driver.Actions())
.keyDown(Shift)
.keyDown(ArrowRight)
.keyUp(ArrowRight)
.keyUp(Shift)
.send();
assert_equals(input.selectionStart, 1, "selectionStart after Shift+ArrowRight");
assert_equals(input.selectionEnd, 2, "selectionEnd after Shift+ArrowRight");
await (new test_driver.Actions())
.keyDown(Shift)
.keyDown(ArrowRight)
.keyUp(ArrowRight)
.keyUp(Shift)
.send();
assert_equals(input.selectionStart, 1, "selectionStart after second Shift+ArrowRight");
assert_equals(input.selectionEnd, 3, "selectionEnd after second Shift+ArrowRight");
await (new test_driver.Actions())
.keyDown(Shift)
.keyDown(ArrowLeft)
.keyUp(ArrowLeft)
.keyUp(Shift)
.send();
assert_equals(input.selectionStart, 1, "selectionStart after Shift+ArrowLeft");
assert_equals(input.selectionEnd, 2, "selectionEnd after Shift+ArrowLeft");
assert_equals(input.value, "abcdef", "value must remain unchanged");
}, "Shift+Arrow keys modify selection range in readonly input");
promise_test(async () => {
textarea.value = "abc\ndef";
await test_driver.click(textarea);
textarea.setSelectionRange(0, 0);
await (new test_driver.Actions())
.keyDown(ArrowRight)
.keyUp(ArrowRight)
.send();
assert_equals(textarea.selectionStart, 1, "selectionStart after ArrowRight");
assert_equals(textarea.selectionEnd, 1, "selectionEnd after ArrowRight");
await (new test_driver.Actions())
.keyDown(ArrowDown)
.keyUp(ArrowDown)
.send();
assert_equals(textarea.selectionStart, 5, "selectionStart after ArrowDown");
assert_equals(textarea.selectionEnd, 5, "selectionEnd after ArrowDown");
await (new test_driver.Actions())
.keyDown(Shift)
.keyDown(ArrowRight)
.keyUp(ArrowRight)
.keyUp(Shift)
.send();
assert_equals(textarea.selectionStart, 5, "selectionStart after Shift+ArrowRight");
assert_equals(textarea.selectionEnd, 6, "selectionEnd after Shift+ArrowRight");
assert_equals(textarea.value, "abc\ndef", "value must remain unchanged");
}, "Arrow keys and Shift+Arrow keys modify selection in readonly textarea");
promise_test(async () => {
input.value = "hello";
await test_driver.click(input);
input.setSelectionRange(2, 2);
await (new test_driver.Actions())
.keyDown("x")
.keyUp("x")
.send();
assert_equals(input.value, "hello", "value must not change when typing into readonly input");
assert_equals(input.selectionStart, 2, "selectionStart must remain at 2 after typing character");
assert_equals(input.selectionEnd, 2, "selectionEnd must remain at 2 after typing character");
await (new test_driver.Actions())
.keyDown(Backspace)
.keyUp(Backspace)
.send();
assert_equals(input.value, "hello", "value must not change when backspacing in readonly input");
assert_equals(input.selectionStart, 2, "selectionStart must remain at 2 after pressing backspace");
assert_equals(input.selectionEnd, 2, "selectionEnd must remain at 2 after pressing backspace");
}, "Typing and Backspace do not modify value in readonly input");
promise_test(async () => {
textarea.value = "hello";
await test_driver.click(textarea);
textarea.setSelectionRange(2, 2);
await (new test_driver.Actions())
.keyDown("x")
.keyUp("x")
.send();
assert_equals(textarea.value, "hello", "value must not change when typing into readonly textarea");
assert_equals(textarea.selectionStart, 2, "selectionStart must remain at 2 after typing character");
assert_equals(textarea.selectionEnd, 2, "selectionEnd must remain at 2 after typing character");
await (new test_driver.Actions())
.keyDown(Backspace)
.keyUp(Backspace)
.send();
assert_equals(textarea.value, "hello", "value must not change when backspacing in readonly textarea");
assert_equals(textarea.selectionStart, 2, "selectionStart must remain at 2 after pressing backspace");
assert_equals(textarea.selectionEnd, 2, "selectionEnd must remain at 2 after pressing backspace");
}, "Typing and Backspace do not modify value in readonly textarea");
</script>