chromium/third_party/blink/web_tests/editing/selection/stay-in-textarea.html

<!DOCTYPE HTML>
<html>
<body>
<script src="../../resources/js-test.js"></script>

<p id="before">Before</p>
<textarea id="textarea">Text</textarea>
<p id="after">After</p>

<div id="console"></div>
<script>
description("Ensure that extending a selection beyond a textarea does not escape outside its shadow root.");

var before = document.getElementById("before");
var after = document.getElementById("after");
var textarea = document.getElementById("textarea");

textarea.focus();
textarea.setSelectionRange(0, 2);
var textareaSelection = internals.shadowRoot(textarea).getSelection();
var initialTextareaFocusNode = textareaSelection.focusNode;

var initialFocusNode = window.getSelection().focusNode;
var initialFocusOffset = window.getSelection().focusOffset;

shouldBe("textareaSelection.focusOffset", "2");

textareaSelection.modify("extend", "forward", "character");
shouldBe("textareaSelection.focusNode", "initialTextareaFocusNode");
shouldBe("textareaSelection.focusOffset", "3");

textareaSelection.modify("extend", "forward", "character");
shouldBe("textareaSelection.focusNode", "initialTextareaFocusNode");
shouldBe("textareaSelection.focusOffset", "4");

// We're at the end - none of these should modify the selection any more.

textareaSelection.modify("extend", "forward", "character");
shouldBe("textareaSelection.focusNode", "initialTextareaFocusNode");
shouldBe("textareaSelection.focusOffset", "4");

textareaSelection.modify("extend", "forward", "word");
shouldBe("textareaSelection.focusNode", "initialTextareaFocusNode");
shouldBe("textareaSelection.focusOffset", "4");

textareaSelection.modify("extend", "forward", "line");
shouldBe("textareaSelection.focusNode", "initialTextareaFocusNode");
shouldBe("textareaSelection.focusOffset", "4");

shouldBe("window.getSelection().focusNode", "initialFocusNode");
shouldBe("window.getSelection().focusOffset", "initialFocusOffset");

</script>

</body>
</html>