test_key_enter_prevent_default.html (838B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <script src="/tests/SimpleTest/EventUtils.js"></script> 6 <script> 7 SimpleTest.waitForExplicitFinish(); 8 function runTest() { 9 const summary = document.querySelector("summary"); 10 summary.addEventListener('click', function(e) { 11 // Prevent the details from toggling by key events. 12 e.preventDefault(); 13 }); 14 // Dispatch 'return' key to the summary element. 15 summary.focus(); 16 synthesizeKey("KEY_Enter"); 17 18 const details = document.querySelector("details"); 19 ok(!details.open, "Prevent default on summary should not open details."); 20 21 SimpleTest.finish(); 22 } 23 </script> 24 </head> 25 <body onload="runTest();"> 26 <details> 27 <summary>Summary</summary> 28 <p>This is the details.</p> 29 </details> 30 </body> 31 </html>