tor-browser

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

focus-sync-when-blur.html (1039B)


      1 <!doctype html>
      2 <head>
      3  <meta charset=utf-8>
      4  <meta name="viewport" content="width=device-width,initial-scale=1">
      5  <title>Test calling focus() on the same element in "blur" event listener when focus has moved away</title>
      6  <script src=/resources/testharness.js></script>
      7  <script src=/resources/testharnessreport.js></script>
      8 </head>
      9 <body>
     10  <input id="input1" placeholder="input1"/>
     11  <input id="input2" placeholder="input2"/>
     12 </body>
     13 <script>
     14 // This test tests calling focus() in the "blur" event
     15 // listener on the same element again when the focus has
     16 // moved away.
     17 test((t) => {
     18  let counter = 0;
     19  input1.addEventListener("focus", function(e) {
     20    counter++;
     21  });
     22 
     23  input1.addEventListener("blur", function(e) {
     24    input1.focus();
     25  });
     26 
     27  input1.focus();
     28  input2.focus();
     29 
     30  assert_equals(counter, 2, "Should have received 2 focus events on input1");
     31  assert_equals(document.activeElement, input1, "Focused element should be still input1");
     32 }, "Element.focus() in blur listener when focus has moved away");
     33 </script>