const expected = [testElement.firstChild, testElement, document.body, document.documentElement];
is(nodes.length, expected.length, "Not the amount of expected nodes");
for (let i = 0; i < nodes.length; ++i)
is(nodes[i], expected[i]);
}
// Make the test slotted, and add some fallback that we'll test later as well.
{
// Work around the sanitizer by building the DOM manually....
const slot = document.createElement("slot");
slot.innerHTML = "Y ".repeat(5000);
const expected = [testElement.firstChild, testElement, document.body, document.documentElement];
is(nodes.length, expected.length, "Not the amount of expected nodes (returned nodes in the shadow?)");
for (let i = 0; i < nodes.length; ++i)
is(nodes[i], expected[i]);
}
{
const rect = testElement.getBoundingClientRect();
const node =
testElement.shadowRoot.nodeFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
is(node, testElement.shadowRoot.firstChild, "Should return the div wrapping the text node");
const expected = [testElement.shadowRoot.firstChild];
is(nodes.length, expected.length, "Not the amount of expected nodes (returned nodes outside of the shadow?)");
for (let i = 0; i < nodes.length; ++i)
is(nodes[i], expected[i]);
}
// Show the fallback.
testElement.firstChild.remove();
{
const rect = testElement.getBoundingClientRect();
const expected = [fallbackText, testElement.shadowRoot.firstChild];
is(nodes.length, expected.length, "Not the amount of expected nodes (returned nodes outside of the shadow?)");
for (let i = 0; i < nodes.length; ++i)
is(nodes[i], expected[i]);
}
// Test the fallback from the document.
{
const rect = testElement.getBoundingClientRect();
const node =
document.nodeFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
is(node, testElement, "Should return the element, since the fallback text is in the shadow");
const expected = [testElement, document.body, document.documentElement];
is(nodes.length, expected.length, "Not the amount of expected nodes (returned nodes inside of the shadow?)");
for (let i = 0; i < nodes.length; ++i)
is(nodes[i], expected[i]);
}
</script>
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.