<html><body>
<script src="../../resources/js-test.js"></script>
<script>

description("Test the tree ordering.")

function shouldBeBoth(a, b, forward, reversed)
{
    shouldBeEqualToString("internals.treeOrder(" + a + ", " + (b ? b : a) + ", 'ComposedTree')", forward)
    if (a != b)
        shouldBeEqualToString("internals.treeOrder(" + b + ", " + a + ", 'ComposedTree')", reversed)
}

function shouldBeEquivalent(a, b)
{
    shouldBeBoth(a, b, "equivalent", "equivalent")
}

function shouldBeLess(a, b)
{
    shouldBeBoth(a, b, "less", "greater")
}

function shouldBeUnordered(a, b)
{
    shouldBeBoth(a, b, "unordered", "unordered")
}

shouldBeEquivalent("document", "document")

let body = document.body;

shouldBeEquivalent("body", "body")
shouldBeLess("document", "body")

let a = document.createElement("div")
shouldBeEquivalent("a", "a")
shouldBeUnordered("body", "a")

body.appendChild(a)
shouldBeLess("body", "a")
shouldBeEquivalent("a", "a")

let b = document.createElement("div")
body.appendChild(b)
shouldBeLess("body", "b")
shouldBeLess("a", "b")

let c = document.createElement("div")
b.appendChild(c)
shouldBeLess("body", "c")
shouldBeLess("a", "c")
shouldBeLess("b", "c")

let d = document.createElement("div")
a.appendChild(d)
shouldBeLess("body", "d")
shouldBeLess("body", "d")
shouldBeLess("a", "d")
shouldBeLess("d", "b")
shouldBeLess("d", "c")
shouldBeLess("a", "d")
shouldBeLess("d", "b")
shouldBeLess("d", "c")

let e = document.createElement("div")
let f = document.createElement("div")
e.appendChild(f)
shouldBeUnordered("body", "f")
shouldBeUnordered("f", "body")

let g = document.createElement("textarea")
c.appendChild(g)
shouldBeLess("body", "g")

let h = internals.ensureUserAgentShadowRoot(g).firstChild
shouldBeLess("body", "h")

let i = a.attachShadow({ mode: "closed" })
shouldBeLess("body", "i")
shouldBeLess("i", "d")
shouldBeLess("i", "b")

</script>
</body></html>
