chromium/third_party/blink/web_tests/editing/shadow/shadow-selection-not-exported.html

<!DOCTYPE html>
<html>
<pre id="console"></pre>

<p>This test ensures shadow root won't expose to JS layer.<p>
<div id='div1'>BEFORE</div>
<div id='container'>CONTAINER</div>
<div id='div4'>AFTER</di>
<script src="../editing.js"></script>
<script src="../../resources/js-test.js"></script>
<script>
if (window.testRunner)
    testRunner.dumpAsText();

var container = document.getElementById('container');
var shadowRoot = container.attachShadow({mode: 'open'});

var div2 = document.createElement('div');
div2.appendChild(document.createTextNode('IN SHADOW TREE 1'));
var div3 = document.createElement('div');
div3.appendChild(document.createTextNode('IN SHADOW TREE 2'));

shadowRoot.appendChild(div2);
shadowRoot.appendChild(div3);

function midX(element) {
    return element.offsetLeft + element.offsetWidth / 2;
}

function midY(element) {
    return element.offsetTop + element.offsetHeight / 2;
}

function assertNotInShadow(element) {
    if (element == div2 || element == div2.firstChild)
        return false;
    if (element == div3 || element == div3.firstChild)
        return false;
    return true;
}

if (window.eventSender) {
    // Try select from outside of a shadow subtree to inside of a shadow subtree.
    eventSender.mouseMoveTo(midX(div1), midY(div1));
    eventSender.mouseDown();
    eventSender.mouseMoveTo(midX(div2), midY(div2));
    eventSender.mouseUp();

    var selection = window.getSelection();
    shouldBe('assertNotInShadow(selection.anchorNode)', 'true');
    shouldBe('assertNotInShadow(selection.focusNode)', 'true');

    selection.removeAllRanges();

    // Try select from inside of a shadow subtree to outside of a shadow subtree.
    eventSender.mouseMoveTo(midX(div3), midY(div3));
    eventSender.mouseDown();
    eventSender.mouseMoveTo(midX(div4), midY(div4));
    eventSender.mouseUp();

    selection = window.getSelection();
    shouldBe('assertNotInShadow(selection.anchorNode)', 'true');
    shouldBe('assertNotInShadow(selection.focusNode)', 'true');
    selection.removeAllRanges();

    // Try select inside shadow subtrees.
    eventSender.mouseMoveTo(midX(div2), midY(div2));
    eventSender.mouseDown();
    eventSender.mouseMoveTo(midX(div3), midY(div3));
    eventSender.mouseUp();

    selection = window.getSelection();
    shouldBe('assertNotInShadow(selection.anchorNode)', 'true');
    shouldBe('assertNotInShadow(selection.focusNode)', 'true');
    selection.removeAllRanges();
}

var successfullyParsed = true;
</script>
</html>