tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

focus-visible-001.html (2468B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <meta charset="utf-8" />
      5  <title>CSS Test (Selectors): Keyboard focus enables :focus-visible</title>
      6  <link rel="author" title="Rob Dodson" href="robdodson@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: green solid 5px;
     23    }
     24 
     25    :focus:not(:focus-visible) {
     26      outline: 0;
     27      background-color: red;
     28    }
     29  </style>
     30 </head>
     31 <body>
     32  This test checks that using the Tab key to navigate focus to an element triggers <code>:focus-visible</code> matching.
     33  <ol id="instructions">
     34    <li>If the user-agent does not claim to support the <code>:focus-visible</code> pseudo-class then SKIP this test.</li>
     35    <li>Use the TAB key on the keyboard to focus the element below that says "Focus me."</li>
     36    <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>
     37  </ol>
     38  <br>
     39  <div id="el" tabindex="0">Focus me.</div>
     40  <script>
     41    async_test(function(t) {
     42      el.addEventListener("focus", t.step_func_done(function() {
     43        assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${el.tagName}#${el.id} should be green`);
     44        assert_not_equals(getComputedStyle(el).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${el.tagName}#${el.id} should NOT be red`);
     45 
     46        let focusVisiblePseudoAll = document.querySelectorAll(':focus-visible');
     47        assert_equals(focusVisiblePseudoAll.length, 1, "Only 1 element matches ':focus-visible'");
     48        let focusVisiblePseudo = document.querySelector(':focus-visible');
     49        assert_equals(el, focusVisiblePseudo, "${el.tagName}#${el.id} matches ':focus-visible'");
     50      }));
     51      const tab_key = '\ue004';
     52      test_driver.send_keys(el, tab_key)
     53        .catch(e => t.step_func(() => assert_unreached("Actions sequence failed " + e)));
     54    }, "Keyboard focus should match :focus-visible");
     55  </script>
     56 </body>
     57 </html>