blob: 395c7e94969085983bcd34a23d64900816e102ff [file] [log] [blame]
<html><head></head><body>
<script src="../../resources/js-test.js"></script>
<script>
description("Test the contains function that checks if a range contains a node.")
function range(startContainer, startOffset, endContainer, endOffset)
{
return new StaticRange({ startContainer: startContainer, startOffset: startOffset, endContainer: endContainer, endOffset: endOffset })
}
function contentsRange(node)
{
return range(node, 0, node, node.childNodes.length)
}
let documentElement = document.documentElement;
let body = document.body;
shouldBeTrue("internals.rangeContainsNode(contentsRange(document), documentElement, 'ComposedTree')")
shouldBeTrue("internals.rangeContainsNode(contentsRange(document), body, 'ComposedTree')");
shouldBeTrue("internals.rangeContainsNode(contentsRange(documentElement), body, 'ComposedTree')");
shouldBeFalse("internals.rangeContainsNode(contentsRange(document), document, 'ComposedTree')");
shouldBeFalse("internals.rangeContainsNode(range(document, 0, document, 2), document, 'ComposedTree')");
shouldBeFalse("internals.rangeContainsNode(range(document, 0, documentElement, 0), body, 'ComposedTree')");
shouldBeFalse("internals.rangeContainsNode(range(document, 0, documentElement, 1), body, 'ComposedTree')");
shouldBeFalse("internals.rangeContainsNode(range(document, 0, body, 0), body, 'ComposedTree')");
shouldBeFalse("internals.rangeContainsNode(range(document, 0, body, 1), body, 'ComposedTree')");
shouldBeTrue("internals.rangeContainsNode(range(document, 0, documentElement, 2), body, 'ComposedTree')");
let a = document.createElement("div")
shouldBeFalse("internals.rangeContainsNode(contentsRange(document), a, 'ComposedTree')")
body.appendChild(a)
let b = document.createElement("div")
body.appendChild(b)
let c = document.createElement("div")
b.appendChild(c)
let d = document.createElement("div")
a.appendChild(d)
let e = document.createElement("div")
let f = document.createElement("div")
e.appendChild(f)
shouldBeFalse("internals.rangeContainsNode(contentsRange(body), f, 'ComposedTree')")
let g = document.createElement("textarea");
c.appendChild(g)
let h = internals.ensureUserAgentShadowRoot(g).firstChild
shouldBeTrue("internals.rangeContainsNode(contentsRange(body), h, 'ComposedTree')")
</script>
</body></html>