tor-browser

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

focus-double-sync-calls.html (1161B)


      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() in "focus" 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 "focus" event
     15 // listener on the element again when the focus has
     16 // moved away.
     17 
     18 // This is for https://github.com/whatwg/html/pull/11182
     19 async_test((t) => {
     20  let previouslyCalled = false;
     21  let counter = 0;
     22 
     23  input1.addEventListener("focus", function(e) {
     24    counter++;
     25    if (!previouslyCalled) {
     26      input2.focus();
     27      previouslyCalled = true;
     28    }
     29 
     30    input1.focus();
     31 
     32    if (counter !== 2) {
     33      // If `lock-for-focus` is implemented, the above input1.focus()
     34      // shouldn't work, so the counter should never be 2.
     35      assert_unreached();
     36    }
     37    t.done();
     38  });
     39 
     40  input1.focus();
     41 }, "Element.focus() in focus listener when focus has moved away");
     42 </script>