focus-tabindex-zero.html (1595B)
1 <!DOCTYPE html> 2 <head> 3 <meta charset="utf-8"> 4 <title>HTML Test: focus - zero tabindex</title> 5 <meta name="timeout" content="long"> 6 <link rel="author" title="Intel" href="http://www.intel.com/"> 7 <link rel="help" href="https://html.spec.whatwg.org/multipage/#sequential-focus-navigation-and-the-tabindex-attribute"> 8 <meta assert="flag" content="interact"> 9 <meta assert="assert" content="Check if the tabindex attribute controls whether an element is supposed to be focusable"> 10 <script src="/resources/testharness.js"></script> 11 <script src="/resources/testharnessreport.js"></script> 12 <script src="/resources/testdriver.js"></script> 13 <script src="/resources/testdriver-vendor.js"></script> 14 </head> 15 <div id="log"></div> 16 <form id="fm"> 17 <input id="test" tabindex="0"> 18 </form> 19 <script> 20 21 var t = async_test("The element with a zero tabindex must be focused by press 'Tab' key"); 22 23 setup({timeout: 10000}); 24 25 document.forms.fm.addEventListener("focus", function (evt) { 26 t.step(function () { 27 var testEle = document.getElementById("test"); 28 assert_equals(testEle.tabIndex, 0, "The tabIndex attribute of the input element should be 0."); 29 assert_equals(evt.target, testEle, "The input element must be focused."); 30 assert_equals(document.activeElement, testEle, "The input element must be activated."); 31 }); 32 t.done(); 33 }, true); 34 35 document.addEventListener("keydown", function (evt) { 36 t.step(function () { 37 assert_equals(evt.keyCode, 9, "Please press 'Tab' key."); 38 }); 39 }, true); 40 41 t.step(function () { 42 // TAB = '\ue004' 43 test_driver.send_keys(document.body, "\ue004"); 44 }); 45 46 </script>