tor-browser

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

dialog-autofocus-multiple-times.html (1470B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <script src="/resources/testdriver.js"></script>
      5 <script src="/resources/testdriver-vendor.js"></script>
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="./resources/common.js"></script>
      9 <script>
     10 promise_test(() => {
     11  return waitUntilLoadedAndAutofocused().then(() => {
     12        assert_equals(document.activeElement, document.getElementById("outer-button"));
     13 
     14        var focusCount = 0;
     15        var dlg = document.getElementById("dlg");
     16        var input1 = document.getElementById("input1");
     17        var input2 = document.getElementById("input2");
     18        input2.onfocus = function() { focusCount += 1 };
     19 
     20        var expectedFocusCount = 3;
     21        for (i = 0; i < expectedFocusCount; i++) {
     22            dlg.show();
     23            assert_equals(document.activeElement, input2);
     24            input1.focus();
     25            assert_equals(document.activeElement,input1);
     26            dlg.close();
     27        }
     28 
     29        assert_equals(focusCount.toString(), expectedFocusCount.toString());
     30  });
     31 }, "autofocus is run every time a dialog is opened");
     32 </script>
     33 </head>
     34 <body>
     35 <button id="outer-button" autofocus></button>
     36 <dialog id="dlg">
     37    <!-- Unfocusable elements with [autofocus] should be ignored. -->
     38    <input autofocus disabled>
     39    <textarea autofocus hidden></textarea>
     40    <input id="input1"></input>
     41    <input id="input2" autofocus></input>
     42 </dialog>
     43 </body>
     44 </html>