blob: b63800029819d08e6ebb29a7a0ecbf79240d5c59 [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 another range.")
function range(startContainer, startOffset, endContainer, endOffset)
{
return new StaticRange({ startContainer: startContainer, startOffset: startOffset, endContainer: endContainer, endOffset: endOffset })
}
function collapsedRange(container, offset)
{
return range(container, offset, container, offset)
}
function contentsRange(node)
{
return range(node, 0, node, node.childNodes.length)
}
function shouldContainSelf(a)
{
shouldBeTrue("internals.rangeContainsRange(" + a + ", " + a + ", 'ComposedTree')")
}
function shouldBeNested(a, b)
{
shouldBeTrue("internals.rangeContainsRange(" + a + ", " + b + ", 'ComposedTree')")
shouldBeFalse("internals.rangeContainsRange(" + b + ", " + a + ", 'ComposedTree')")
}
function shouldNotContain(a, b)
{
shouldBeFalse("internals.rangeContainsRange(" + a + ", " + b + ", 'ComposedTree')")
shouldBeFalse("internals.rangeContainsRange(" + b + ", " + a + ", 'ComposedTree')")
}
let documentElement = document.documentElement;
let body = document.body;
shouldContainSelf("contentsRange(document)")
shouldContainSelf("contentsRange(documentElement)")
shouldContainSelf("contentsRange(body)")
shouldBeNested("contentsRange(document)", "contentsRange(documentElement)")
shouldBeNested("contentsRange(document)", "contentsRange(body)")
shouldBeNested("contentsRange(documentElement)", "contentsRange(body)")
shouldBeNested("contentsRange(document)", "contentsRange(documentElement)")
shouldBeNested("contentsRange(documentElement)", "contentsRange(body)")
shouldBeNested("contentsRange(document)", "collapsedRange(document, 0)")
shouldBeNested("contentsRange(document)", "collapsedRange(document, 1)")
shouldNotContain("contentsRange(document)", "collapsedRange(document, 2)")
shouldBeNested("range(document, 0, document, 2)", "contentsRange(document)")
shouldNotContain("contentsRange(document)", "range(document, 1, document, 2)")
shouldNotContain("range(document, 0, documentElement, 0)", "contentsRange(body)")
shouldBeNested("range(document, 0, body, 0)", "collapsedRange(body, 0)")
let a = document.createElement("div")
shouldNotContain("contentsRange(document)", "contentsRange(a)")
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)
shouldNotContain("contentsRange(body)", "contentsRange(f)")
let g = document.createElement("textarea");
c.appendChild(g)
let h = internals.ensureUserAgentShadowRoot(g).firstChild
shouldBeNested("contentsRange(body)", "contentsRange(h)")
</script>
</body></html>