<script>
add_task(async function() {
const { InspectorUtils } = SpecialPowers;
const test = (elementId, anchorName, expectedAnchorElement, expectedType) => {
info(`InspectorUtils.getAnchorFor(#${elementId}, ${anchorName ?? "null"})`);
const el = document.getElementById(elementId);
const res = InspectorUtils.getAnchorFor(el, anchorName);
if (expectedAnchorElement === null) {
is(res, null, `There should be no ${anchorName ? anchorName + " " : ""}anchor for #${elementId}`)
return;
}
// We compare the ids because res.element is a Proxy, so we can't match it against
// an element we'd retrieve.
is(
res?.element?.id,
expectedAnchorElement.id,
`Got expected ${anchorName ? anchorName + " " : ""}anchor element for #${elementId}`
);
is(
res?.type,
expectedType,
`Got expected anchor association type for #${elementId}`
);
}
// no anchor when passing an anchor name that is not set
test("abs-pos", "--undefined-name", null);
// no anchor for element that are not absolutely positioned
test("not-abs-pos", null, null);
const anchorEl = document.getElementById("anchor");
const anotherAnchorEl = document.getElementById("another-anchor");
const popoverControlEl = document.getElementById("popover-control")
// show popover so the popover element gets an implicit anchor
popoverControlEl.click();
// explicitly associated anchor
test("abs-pos", "--my-anchor", anchorEl, "explicit");
test("abs-pos", "--another-anchor", anotherAnchorEl, "explicit");
// still getting the associated anchor without passing a name
test("abs-pos", null, anchorEl, "explicit");
// implicitly associated popover anchor
test("my-popover", null, popoverControlEl, "popover");
// no anchor when the popover is not displayed
document.getElementById("my-popover").togglePopover();
test("my-popover", null, null);
// implicitly associated pseudo element
const [beforePseudoElement] = InspectorUtils.getChildrenForNode(
document.getElementById("with-pseudo"),
true,
false,
);
is(
beforePseudoElement.implementedPseudoElement, "::before", "Got expected ::before pseudo element"
);
const pseudoElementRes = InspectorUtils.getAnchorFor(beforePseudoElement);
is(
pseudoElementRes?.element?.id, "with-pseudo",
`Got expected anchor element for ::before pseudo element`
);
is(
pseudoElementRes?.type, "pseudo-element",
`Got expected anchor association type for ::before pseudo element`
);
});
</script>
</body>
</html>
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.