chromium/third_party/blink/web_tests/editing/shadow/getRangeAt-end-of-text-node.html

<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id="shadowHost"></div>
<script>
(function () {
    var shadowRoot = shadowHost.attachShadow({mode: 'open'});
    shadowRoot.innerHTML = '<div id="editable" contenteditable>Test</div>';
    var textNode = shadowRoot.querySelector("#editable").firstChild;
    var selection = shadowRoot.getSelection();
    selection.collapse(textNode, textNode.textContent.length);
    test(function () {
        var range = selection.getRangeAt(0);
        assert_equals(range.startContainer, textNode);
        assert_equals(range.startOffset, textNode.textContent.length);
        assert_true(range.collapsed);
    }, "collapsed");

    selection.collapse(textNode, 0);
    selection.extend(textNode, 2);
    test(function () {
        var range = selection.getRangeAt(0);
        assert_equals(range.startContainer, textNode);
        assert_equals(range.startOffset, 0);
        assert_equals(range.endContainer, textNode);
        assert_equals(range.endOffset, 2);
        assert_false(range.collapsed);
    }, "range");

    test(function () {
        assert_not_equals(window.getSelection().getRangeAt(0).anchorNode, textNode);
    }, "Nodes in Shadow should not be exposed to window.getSelection()");
})();
</script>