focus-visible-005.html (2141B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title>CSS Test (Selectors): Programmatic focus causes :focus-visible to match</title> 6 <link rel="author" title="Alice Boxhall" href="aboxhall@chromium.org" /> 7 <link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" /> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/resources/testdriver.js"></script> 11 <script src="/resources/testdriver-vendor.js"></script> 12 <style> 13 @supports not selector(:focus-visible) { 14 :focus { 15 outline: red solid 5px; 16 background-color: red; 17 } 18 } 19 20 :focus-visible { 21 outline: red solid 5px; 22 } 23 24 :focus:not(:focus-visible) { 25 outline: 0; 26 background-color: lime; 27 } 28 </style> 29 </head> 30 <body> 31 This test checks that programmatically focusing an element after a click does not cause <code>:focus-visible</code> matching to trigger. 32 <ol id="instructions"> 33 <li>If the user-agent does not claim to support the <code>:focus-visible</code> pseudo-class then SKIP this test.</li> 34 <li>Click the button below that says "Click me."</li> 35 <li>If the element that says "I will be focused programmatically." has a red outline, then the test result is FAILURE. If the element has a green background, then the test result is SUCCESS.</li> 36 </ol> 37 <br /> 38 <button id="button">Click me.</button> 39 <div id="el" tabindex="-1">I will be focused programmatically.</div> 40 <script> 41 button.addEventListener("click", () => { 42 el.focus(); 43 }); 44 async_test(function(t) { 45 el.addEventListener("focus", t.step_func(function() { 46 assert_equals(getComputedStyle(el).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${el.tagName}#${el.id} should be lime`); 47 assert_not_equals(getComputedStyle(el).outlineColor, "rgb(255, 0, 0)", `outlineColor for ${el.tagName}#${el.id} should NOT be red`); 48 t.done(); 49 })); 50 test_driver.click(button); 51 }, "Programmatic focus after click should not match :focus-visible"); 52 </script> 53 </body> 54 </html>