tor-browser

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

checkable-active-space-key-untrusted-event.html (1434B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>Tests active state of checkbox/radio when pressing space key emulated with untrusted key events</title>
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 </head>
      9 <body>
     10 <input type="checkbox">
     11 <input type="radio">
     12 <script>
     13 function sendSpaceKeyEvent(eventType, target) {
     14  const eventData = { keyCode: 32, which: 32, key: " ", code: "Space"};
     15  const spaceKeyEvent = new KeyboardEvent(eventType, eventData);
     16  target.dispatchEvent(spaceKeyEvent);
     17 }
     18 
     19 test(t => {
     20  const checkbox = document.querySelector("input[type=checkbox]");
     21  checkbox.focus();
     22  sendSpaceKeyEvent("keydown", checkbox);
     23  t.add_cleanup(() => {
     24    sendSpaceKeyEvent("keyup", checkbox);
     25  });
     26  assert_equals(
     27    document.querySelector("input:active"),
     28    null,
     29    "The checkbox shouldn't be activated"
     30  );
     31 }, "Space key shouldn't active the checkbox when space key press is emulated by untrusted events");
     32 
     33 test(t => {
     34  const radio = document.querySelector("input[type=radio]");
     35  radio.focus();
     36  sendSpaceKeyEvent("keydown", radio);
     37  t.add_cleanup(() => {
     38    sendSpaceKeyEvent("keyup", radio);
     39  });
     40  assert_equals(
     41    document.querySelector("input:active"),
     42    null,
     43    "The radio shouldn't be activated"
     44  );
     45 }, "Space key shouldn't active the radio when space key press is emulated by untrusted events");
     46 </script>
     47 </body>
     48 </html>