focus-tabindex-event.html (1278B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>HTML Test: tabindex - focus, click</title> 4 <link rel="author" title="Intel" href="www.intel.com/"> 5 <link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/resources/testdriver.js"></script> 9 <script src="/resources/testdriver-actions.js"></script> 10 <script src="/resources/testdriver-vendor.js"></script> 11 12 <h2>Test steps</h2> 13 <p>Focus on the button below by "Tab" key, then press "Enter" key</p> 14 15 <p><button type="button">Test tabIndex</button></p> 16 17 <script> 18 19 setup({explicit_done: true}); 20 setup({explicit_timeout: true}); 21 22 promise_test(async t => { 23 const button = document.querySelector("button"); 24 on_event(button, "click", () => { 25 test(() => { 26 assert_true(document.activeElement == button, "Focus on the button by Tab key"); 27 }, "Check if click event will be fired when press the 'enter' key while the element is focused"); 28 done(); 29 }); 30 31 window.focus(); 32 document.activeElement?.blur(); 33 getSelection().collapse(document.querySelector("p"), 0); 34 const enterKey = '\uE007'; 35 await test_driver.send_keys(button, enterKey); 36 }); 37 38 </script>