focus-visible-012.html (2853B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title>CSS Test (Selectors): Keyboard shortcut combinations do not trigger :focus-visible</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-actions.js"></script> 12 <script src="/resources/testdriver-vendor.js"></script> 13 <style> 14 @supports not selector(:focus-visible) { 15 :focus { 16 outline: red solid 5px; 17 background-color: red; 18 } 19 } 20 21 :focus-visible { 22 outline: 0; 23 outline-color: red; 24 background-color: red; 25 } 26 27 :focus:not(:focus-visible) { 28 outline: green solid 5px; 29 } 30 </style> 31 </head> 32 <body> 33 This test checks that using keyboard combinations with [Ctrl], [Alt] or [Cmd] 34 do not trigger <code>:focus-visible</code> matching. 35 <ol id="instructions"> 36 <li>If the user-agent does not claim to support the <code>:focus-visible</code> pseudo-class then SKIP this test.</li> 37 <li>Click the element below that says "Click me, then use a keyboard shortcut."</li> 38 <li>Press a keyboard combination including [Ctrl], [Alt] or [Cmd], such as <code>Ctrl</code> + <code>y</code></li> 39 <li>If the element has a red background, then the test result is FAILURE. If the element has a green outline, then the test result is SUCCESS.</li> 40 </ol> 41 <br> 42 <div id="el" tabindex="0">Click me, then use a keyboard shortcut.</div> 43 <script> 44 var t = async_test( "Keyboard focus should match :focus-visible"); 45 46 el.addEventListener("click", t.step_func(function(e) { 47 assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${el.tagName}#${el.id} should be green`); 48 assert_not_equals(getComputedStyle(el).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${el.tagName}#${el.id} should NOT be red`); 49 }), true); 50 51 el.addEventListener("keydown", t.step_func(function(e) { 52 if (e.altKey || e.ctrlKey || e.metaKey) { 53 assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${el.tagName}#${el.id} should be green`); 54 assert_not_equals(getComputedStyle(el).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${el.tagName}#${el.id} should NOT be red`); 55 t.done(); 56 return; 57 } 58 assert_true(false, "No modifier key"); 59 t.done(); 60 })); 61 62 const ctrl_key = '\uE009'; 63 test_driver.click(el).then(() => { 64 return test_driver.send_keys(el, ctrl_key); 65 }); 66 67 </script> 68 </body> 69 </html>