chromium/third_party/blink/web_tests/editing/selection/extend-to-trailing-spaces.html

<!DOCTYPE html>
<html>
<body>
<script src="../../resources/js-test.js"></script>
<div id="test"></div>
<script>
description("Ensure that extending a selection to trailing spaces does not cause exceptions.");

var div = document.getElementById('test');
var selection = window.getSelection();

function testIt(text) {
    var len = text.length;
    div.textContent = text;
    selection.collapse(div.firstChild, 0);
    try {
        selection.extend(div.firstChild, len);
    } catch (e) {
        testFailed(div.outerHTML + ': ' + String(e.toString()));
        return;
    }
    try {
        selection.extend(div.firstChild, len + 1);
        testFailed(div.outerHTML + ': ' + String(e.toString()));
        return;
    } catch (e) {
    }
    testPassed(div.outerHTML);
}
testIt('0123');
testIt('012 ');
testIt('012  ');
testIt('012\n');
testIt('012\n\n');

div.textContent = '';
</script>
</body>
</html>