focus-keyboard-js.html (1113B)
1 <!doctype html> 2 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io"> 3 <link rel="author" title="Mozilla" href="https://mozilla.org"> 4 <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1712724"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 <input type=text id=text value=abc> 10 <script> 11 let text = document.getElementById("text"); 12 13 document.addEventListener("keyup", function(e) { 14 text.focus(); 15 }); 16 17 promise_test(async t => { 18 await test_driver.send_keys(document.body, " "); 19 20 assert_equals(document.activeElement, text, "#text should be focused by our event listener"); 21 assert_true(text.matches(":focus"), "#text should match :focus"); 22 assert_true(text.matches(":focus-visible"), "#text should match :focus-visible"); 23 assert_equals(text.selectionStart, text.selectionEnd, "#text should not be selected"); 24 assert_equals(text.value, "abc", "#text should not have changed value"); 25 }); 26 </script>