tor-browser

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

focus-event-targets-simple.html (1483B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Focus events fire at correct targets in correct order in simple case</title>
      6  <link rel="author" title="Chris Rebert" href="http://chrisrebert.com">
      7  <link rel="help" href="https://html.spec.whatwg.org/#focus-update-steps">
      8  <link rel="help" href="https://html.spec.whatwg.org/#focus-chain">
      9  <meta name="flags" content="dom">
     10  <script src="/resources/testharness.js"></script>
     11  <script src="/resources/testharnessreport.js"></script>
     12 </head>
     13 <body>
     14  <input type="text" id="a">
     15  <script>
     16 // Record all the focus event targets in an array.
     17 // Modulo special cases in the "focus update steps" algorithm,
     18 // this should be the same as the new focus chain, except in reverse order.
     19 var newFocusChainReversedNotQuite = [];
     20 var pushTarget = function (e) {
     21  newFocusChainReversedNotQuite.push(e.target);
     22 };
     23 // Window is the root node for event dispatch per https://html.spec.whatwg.org/multipage/webappapis.html#events-and-the-window-object
     24 window.addEventListener('focus', pushTarget, true);// Use event capturing since focus event doesn't bubble
     25 var input = document.getElementById('a');
     26 input.focus();
     27 window.removeEventListener('focus', pushTarget, true);
     28 test(function() {
     29  assert_array_equals(newFocusChainReversedNotQuite, [input], "Exactly 1 focus event should fire and its target should be the input");
     30 }, "Focus events fire at correct targets in correct order in simple case");
     31  </script>
     32 </body>
     33 </html>