tor-browser

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

checkable-active-space-key-prevented-default.html (1758B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>Tests active state of checkbox/radio when pressing space key but its default prevented</title>
      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 </head>
     12 <body>
     13 <input type="checkbox">
     14 <input type="radio">
     15 <script>
     16 const spaceKey = "\uE00D";
     17 
     18 function preventDefault(event) {
     19  event.preventDefault();
     20 }
     21 
     22 promise_test(async t => {
     23  const checkbox = document.querySelector("input[type=checkbox]");
     24  checkbox.focus();
     25  checkbox.addEventListener("keydown", preventDefault);
     26  await (new test_driver.Actions()).keyDown(spaceKey).send();
     27  t.add_cleanup(async () => {
     28    await (new test_driver.Actions()).keyUp(spaceKey).send();
     29    checkbox.removeEventListener("keydown", preventDefault);
     30  });
     31  assert_equals(
     32    document.querySelector("input:active"),
     33    null,
     34    "The checkbox shouldn't be activated"
     35  );
     36 }, "Space key shouldn't active the checkbox when its default is prevented");
     37 
     38 promise_test(async t => {
     39  const radio = document.querySelector("input[type=radio]");
     40  radio.focus();
     41  radio.addEventListener("keydown", preventDefault);
     42  await (new test_driver.Actions()).keyDown(spaceKey).send();
     43  t.add_cleanup(async () => {
     44    await (new test_driver.Actions()).keyUp(spaceKey).send();
     45    radio.removeEventListener("keydown", preventDefault);
     46  });
     47  assert_equals(
     48    document.querySelector("input:active"),
     49    null,
     50    "The radio shouldn't be activated"
     51  );
     52 }, "Space key shouldn't active the radio when its default is prevented");
     53 </script>
     54 </body>
     55 </html>