focus-tabindex-order.html (2133B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>HTML Test: focus - the sequential focus navigation order</title> 4 <meta name="timeout" content="long"> 5 <link rel="author" title="Intel" href="http://www.intel.com/"> 6 <link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation"> 7 <meta assert="flag" content="interact"> 8 <meta assert="assert" content="Check the sequential focus navigation order"> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 <script src="/resources/testdriver.js"></script> 12 <script src="/resources/testdriver-vendor.js"></script> 13 <div id="log"></div> 14 <form id="fm"> 15 <button id="btn0">tabindex(omitted)</button> 16 <button id="btn1" tabindex="">tabindex(empty)</button> 17 <button id="btn2" tabindex="a">tabindex(a)</button> 18 <button id="btn3" tabindex="-1">tabindex(-1)</button> 19 <button id="btn4" tabindex="0">tabindex(0)</button> 20 <button id="btn5" tabindex="3">tabindex(3)</button> 21 <button id="btn6" tabindex="2">tabindex(2)</button> 22 <button id="btn7" tabindex="2">tabindex(2)</button> 23 <button id="btn8" tabindex="2">tabindex(2)</button> 24 <button id="btn9" tabindex="1">tabindex(1)</button> 25 </form> 26 <script> 27 28 var i = 0, 29 expectation = ["btn9", "btn6", "btn7", "btn8", "btn5", "btn0", "btn1", "btn2", "btn4"], 30 results = [], 31 t = async_test("Elements with different tabindex must be focused sequentially when pressing 'Tab' keys"); 32 33 setup(function () { 34 document.body.focus(); 35 }); 36 37 38 39 document.forms.fm.addEventListener("focus", function (evt) { 40 results.push(evt.target.id); 41 if (i >= 8) { 42 t.step(function () { 43 assert_array_equals(results, expectation); 44 }); 45 t.done(); 46 } else { 47 t.step(function () { 48 // TAB = '\ue004' 49 test_driver.send_keys(document.body, "\ue004"); 50 }); 51 } 52 i++; 53 }, true); 54 55 document.addEventListener("keydown", function (evt) { 56 t.step(function () { 57 assert_equals(evt.keyCode, 9, "Please press 'Tab' key."); 58 }); 59 }, true); 60 61 t.step(function () { 62 // TAB = '\ue004' 63 test_driver.send_keys(document.body, "\ue004"); 64 }); 65 </script>