a.ping-functionality.html (2438B)
1 <!DOCTYPE html> 2 <title>SVG anchor ping attribute functionality</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/resource-timing/resources/observe-entry.js"></script> 6 <svg> 7 <a id="pingAnchor" href="#" ping="/xhr/resources/delay.py?ms=100">Test Link</a> 8 </svg> 9 <script> 10 promise_test(async t => { 11 const anchor = document.getElementById('pingAnchor'); 12 const pingUrl = '/xhr/resources/delay.py?ms=100'; 13 14 // Simulate click event 15 const clickEvent = new MouseEvent('click', { 16 view: window, 17 bubbles: true, 18 cancelable: true 19 }); 20 21 anchor.dispatchEvent(clickEvent); 22 23 // Wait for the ping request to be sent 24 const entry = await observe_entry(pingUrl); 25 assert_equals(entry.initiatorType, 'ping'); 26 assert_greater_than(entry.duration, 99); 27 }, "SVG anchor with ping attribute should send ping on click"); 28 29 promise_test(async t => { 30 const svg = document.querySelector('svg'); 31 const anchor = document.createElementNS('http://www.w3.org/2000/svg', 'a'); 32 const pingUrl = '/xhr/resources/delay.py?ms=200&id=multiple'; 33 34 anchor.setAttribute('href', '#'); 35 anchor.setAttribute('ping', pingUrl + ' ' + pingUrl + '2'); 36 anchor.textContent = 'Multiple Ping Link'; 37 svg.appendChild(anchor); 38 39 const clickEvent = new MouseEvent('click', { 40 view: window, 41 bubbles: true, 42 cancelable: true 43 }); 44 45 anchor.dispatchEvent(clickEvent); 46 47 // Wait for both ping requests 48 const entry1 = await observe_entry(pingUrl); 49 const entry2 = await observe_entry(pingUrl + '2'); 50 51 assert_equals(entry1.initiatorType, 'ping'); 52 assert_equals(entry2.initiatorType, 'ping'); 53 }, "SVG anchor with multiple ping URLs should send multiple pings"); 54 55 test(function() { 56 const anchor = document.createElementNS('http://www.w3.org/2000/svg', 'a'); 57 anchor.setAttribute('ping', 'https://example.com/ping1 https://example.com/ping2'); 58 59 assert_equals(anchor.ping, 'https://example.com/ping1 https://example.com/ping2'); 60 61 anchor.ping = 'https://example.com/ping3'; 62 assert_equals(anchor.getAttribute('ping'), 'https://example.com/ping3'); 63 assert_equals(anchor.ping, 'https://example.com/ping3'); 64 }, "SVG anchor ping attribute should be settable via ping IDL attribute"); 65 </script>