Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!doctype html>
<meta charset="utf-8">
<title>SVGAElement HyperlinkElementUtils getters with href and xlink:href attributes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<svg>
<a id="test-anchor">anchor</a>
</svg>
<script>
const XLINK_NS = "http://www.w3.org/1999/xlink";
// Test cases
// Format: [property, expectedResult, primaryURL, fallbackURL]
// - primaryURL: Used in 'href', 'xlink', and as the winning 'href' in 'both' mode.
// - fallbackURL: Used as the ignored 'xlink:href' attribute in 'both' mode to prove priority.
const getterTests = [
];
/**
* Reads a SVG property or href.baseVal on SVGAElement.
*/
function getSVGProperty(element, property) {
if (property === "href") {
return element.href.baseVal;
}
return element[property];
}
["href", "xlink", "both"].forEach(mode => {
for (let i = 0; i < getterTests.length; i++) {
test(t => {
const [property, expectedResult, primaryURL, fallbackURL] = getterTests[i];
const a = document.getElementById("test-anchor");
t.add_cleanup(() => {
a.removeAttribute("href");
a.removeAttributeNS(XLINK_NS, "href");
});
// Setup DOM attributes based on mode
switch (mode) {
case "href":
a.setAttribute("href", primaryURL);
break;
case "xlink":
a.setAttributeNS(XLINK_NS, "xlink:href", primaryURL);
break;
case "both":
// Standard href attribute should take precedence over xlink:href (SVG2 spec)
a.setAttribute("href", primaryURL);
a.setAttributeNS(XLINK_NS, "xlink:href", fallbackURL);
break;
default:
assert_unreached(`Unexpected mode: ${mode}`);
}
const actualValue = getSVGProperty(a, property);
assert_equals(
actualValue,
expectedResult,
`Getter mismatch for property '${property}' under mode '${mode}'`
);
}, `SVGAElement HyperlinkElementUtils getter [Mode: ${mode}] (${i}): ${getterTests[i][0]}`);
}
});
</script>