| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8" /> |
| <title>CSS Test (Selectors): Keyboard shortcut combinations do not trigger :focus-visible</title> |
| <link rel="author" title="Alice Boxhall" href="aboxhall@chromium.org" /> |
| <link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" /> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <style> |
| :focus-visible { |
| outline: 0; |
| outline-color: tomato; |
| background-color: tomato; |
| } |
| |
| :focus:not(:focus-visible) { |
| outline: darkgreen dotted 1px; /* fallback for Edge */ |
| outline: darkgreen auto 5px; |
| } |
| </style> |
| </head> |
| <body> |
| This test checks that using keyboard combinations with [Ctrl], [Alt] or [Cmd] |
| do not trigger <code>:focus-visible</code> matching. |
| <ol id="instructions"> |
| <li>If the user-agent does not claim to support the <code>:focus-visible</code> pseudo-class then SKIP this test.</li> |
| <li>Click the element below that says "Click me, then use a keyboard shortcut."</li> |
| <li>Press a keyboard combination including [Ctrl], [Alt] or [Cmd], such as <code>Ctrl</code> + <code>y</code></li> |
| <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> |
| </ol> |
| <br> |
| <div id="el" tabindex="0">Click me, then use a keyboard shortcut.</div> |
| <script> |
| var t = async_test( "Keyboard focus should match :focus-visible"); |
| |
| el.addEventListener("click", t.step_func(function(e) { |
| assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 100, 0)", "after focus()"); |
| }), true); |
| |
| el.addEventListener("keydown", t.step_func(function(e) { |
| if (e.altKey || e.ctrlKey || e.metaKey) { |
| assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 100, 0)", "after kb event"); |
| t.done(); |
| return; |
| } |
| assert_true(false, "No modifier key"); |
| t.done(); |
| })); |
| |
| window.setTimeout(t.step_func_done(()=> { |
| assert_true(false, "timeout"); |
| }), 1000); |
| |
| </script> |
| </body> |
| </html> |