tor-browser

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

focus-visible-019.html (2581B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8" />
      3 <title>CSS Test (Selectors): Script focus on keyboard event handler matches :focus-visible</title>
      4 <link rel="author" title="Manuel Rego Casasnovas" href="mailto:rego@igalia.com">
      5 <link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="/resources/testdriver.js"></script>
      9 <script src="/resources/testdriver-actions.js"></script>
     10 <script src="/resources/testdriver-vendor.js"></script>
     11 <script src="/css/support/parsing-testcommon.js"></script>
     12 <style>
     13  #warning {
     14    display: none;
     15    background: red;
     16  }
     17 
     18  @supports not selector(:focus-visible) {
     19    #instructions {
     20      display: none;
     21    }
     22 
     23    #warning {
     24      display: block;
     25    }
     26  }
     27 
     28  :focus-visible {
     29    outline: green solid 5px;
     30  }
     31 
     32  :focus:not(:focus-visible) {
     33    outline: 0;
     34    background-color: red;
     35  }
     36 </style>
     37 
     38 <p>This test checks that changing focus via script on keyboard event handler matches <code>:focus-visible</code>.</p>
     39 <ol id="instructions">
     40  <li>Type any letter with the keyboard without having done anything before.</li>
     41  <li>If the element that says "Focused" has a red background, then the test result is FAILURE. If the element has a green outline, then the test result is SUCCESS.</li>
     42 </ol>
     43 <p id="warning">Your user-agent does not support <code>:focus-visible</code> pseudo-class, please SKIP this test.</p>
     44 <div id="target" tabindex="0">Focused.</div>
     45 <script>
     46  // Check that :focus-visible is supported.
     47  test_valid_selector(':focus-visible');
     48 
     49  document.addEventListener("keydown", () => {
     50    target.focus();
     51  });
     52 
     53  async_test(function(t) {
     54    test_driver.send_keys(document.body, "a").then(t.step_func_done(function() {
     55      assert_equals(getComputedStyle(target).outlineColor, "rgb(0, 128, 0)", `outlineColor for ${target.tagName}#${target.id} should be green`);
     56      assert_not_equals(getComputedStyle(target).backgroundColor, "rgb(255, 0, 0)", `backgroundColor for ${target.tagName}#${target.id} should NOT be red`);
     57 
     58      let focusVisiblePseudoAll = document.querySelectorAll(':focus-visible');
     59      assert_equals(focusVisiblePseudoAll.length, 1, "Only 1 element matches ':focus-visible'");
     60      let focusVisiblePseudo = document.querySelector(':focus-visible');
     61      assert_equals(target, focusVisiblePseudo, "${target.tagName}#${target.id} matches ':focus-visible'");
     62    }));
     63  }, "Focus via script on keyboard event handler matches ':focus-visible'");
     64 </script>