diff options
Diffstat (limited to 'testing/web-platform/tests/css/selectors/focus-visible-008.html')
-rw-r--r-- | testing/web-platform/tests/css/selectors/focus-visible-008.html | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/selectors/focus-visible-008.html b/testing/web-platform/tests/css/selectors/focus-visible-008.html new file mode 100644 index 0000000000..6fc5b478a8 --- /dev/null +++ b/testing/web-platform/tests/css/selectors/focus-visible-008.html @@ -0,0 +1,66 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8" /> + <title>CSS Test (Selectors): Keyboard focus enables :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> + <script src="/resources/testdriver.js"></script> + <script src="/resources/testdriver-vendor.js"></script> + <style> + @supports not selector(:focus-visible) { + #el:focus { + outline: red solid 5px; + background-color: red; + } + } + + :focus-visible { + outline: green solid 5px; + } + + #el:focus:not(:focus-visible) { + background-color: red; + outline: 0; + } + </style> +</head> +<body> + This test checks that programmatically focusing an element after a keypress causes <code>:focus-visible</code> to match. + <ol id="instructions"> + <li>Use the tab key to move focus to the button below that says "Tab to me and press ENTER."</li> + <li>Press ENTER.</li> + <li>If the element that says "I will be focused programmatically." 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 /> + <button id="button">Tab to me and press ENTER.</button> + <div id="el" tabindex="-1">I will be focused programmatically.</div> + <script> + if ("async_test" in window) { + async_test(function(t) { + button.addEventListener("click", t.step_func(() => { + el.focus(); + })); + el.addEventListener("focus", t.step_func(function() { + assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${el.tagName}#${el.id} should be green`); + assert_not_equals(getComputedStyle(el).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${el.tagName}#${el.id} should NOT be red`); + t.done(); + })); + test_driver.send_keys(el, "\ue004\ue007"); // TAB and ENTER + }, "Programmatic focus after keypress should match :focus-visible"); + } else { + button.addEventListener("click", () => { + el.focus(); + }); + } + + const tab_key = '\ue004'; + const enter_key = '\uE007'; + test_driver.send_keys(el, tab_key).then(() => { + test_driver.send_keys(el, enter_key); + }); + </script> +</body> +</html> |