focus-visible-015.html (1747B)
1 <!DOCTYPE html> 2 <meta charset="utf-8" /> 3 <title>CSS Selectors Test: :focus-visible does not match after script focus move</title> 4 <link rel="author" title="Manuel Rego Casasnovas" href="mailto:rego@igalia.com"> 5 <link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" /> 6 <meta name="assert" content="This test checks that if the active element does not match ':focus-visible' and a script causes focus to move elsewhere, the newly focused element should not match ':focus-visible'."> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/resources/testdriver.js"></script> 10 <script src="/resources/testdriver-vendor.js"></script> 11 <style> 12 @supports not selector(:focus-visible) { 13 :focus { 14 outline: red solid 5px; 15 background-color: red; 16 } 17 } 18 19 :focus-visible { 20 background: red; 21 } 22 23 :focus:not(:focus-visible) { 24 background-color: lime; 25 } 26 </style> 27 28 <div id="initial" tabindex="0">Initial</div> 29 <div id="target" tabindex="0">Target</div> 30 31 <script> 32 setup({ explicit_done: true }); 33 34 async_test(function(t) { 35 initial.addEventListener("focus", t.step_func(function() { 36 assert_equals(getComputedStyle(initial).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${initial.tagName}#${initial.id} should be lime`); 37 target.focus(); 38 })); 39 40 target.addEventListener("focus", t.step_func(function() { 41 assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`); 42 t.done(); 43 })); 44 45 test_driver.click(initial).then(() => done()); 46 }, ":focus-visible does not match after script focus move"); 47 </script>