Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<title>MathML anchor ping attribute functionality</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resource-timing/resources/observe-entry.js"></script>
<script src="/mathml/support/mathml-fragments.js"></script>
<math>
<a id="pingAnchor" href="#" ping="/xhr/resources/delay.py?ms=100"><mtext>Test Link</mtext></a>
</math>
<script>
promise_test(async t => {
const anchor = document.getElementById('pingAnchor');
const pingUrl = '/xhr/resources/delay.py?ms=100';
// Simulate click event
const clickEvent = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
});
anchor.dispatchEvent(clickEvent);
// Wait for the ping request to be sent
const entry = await observe_entry(pingUrl);
assert_equals(entry.initiatorType, 'ping');
assert_greater_than_equal(entry.duration, 100);
}, "MathML anchor with ping attribute should send ping on click");
promise_test(async t => {
const math = document.querySelector('math');
const anchor = document.createElementNS(FragmentHelper.mathml_namespace, 'a');
const text = document.createElementNS(FragmentHelper.mathml_namespace, 'mtext');
const pingUrl = '/xhr/resources/delay.py?ms=200&id=multiple';
anchor.setAttribute('href', '#');
anchor.setAttribute('ping', `${pingUrl} ${pingUrl}2`);
text.textContent = 'Multiple Ping Link';
anchor.appendChild(text);
math.appendChild(anchor);
const clickEvent = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
});
anchor.dispatchEvent(clickEvent);
// Wait for both ping requests
const entry1 = await observe_entry(pingUrl);
const entry2 = await observe_entry(`${pingUrl}2`);
assert_equals(entry1.initiatorType, 'ping');
assert_equals(entry2.initiatorType, 'ping');
}, "MathML anchor with multiple ping URLs should send multiple pings");
test(function() {
const anchor = document.createElementNS(FragmentHelper.mathml_namespace, 'a');
anchor.setAttribute('ping', 'https://example.com/ping1 https://example.com/ping2');
assert_equals(anchor.ping, 'https://example.com/ping1 https://example.com/ping2');
anchor.ping = 'https://example.com/ping3';
assert_equals(anchor.getAttribute('ping'), 'https://example.com/ping3');
assert_equals(anchor.ping, 'https://example.com/ping3');
}, "MathML anchor ping attribute should be settable via ping IDL attribute");
</script>