tor-browser

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

test_input_datetime_focus_blur_events.html (4409B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1301306
      5 -->
      6 <head>
      7 <title>Test for Bug 1301306</title>
      8 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9 <script src="/tests/SimpleTest/EventUtils.js"></script>
     10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1301306">Mozilla Bug 722599</a>
     14 <p id="display"></p>
     15 <div id="content">
     16 <input type="time" id="input_time" onfocus="++focusEvents[0]"
     17       onblur="++blurEvents[0]" onfocusin="++focusInEvents[0]"
     18       onfocusout="++focusOutEvents[0]">
     19 <input type="date" id="input_date" onfocus="++focusEvents[1]"
     20       onblur="++blurEvents[1]" onfocusin="++focusInEvents[1]"
     21       onfocusout="++focusOutEvents[1]">
     22 <input type="datetime-local" id="input_datetime-local" onfocus="++focusEvents[2]"
     23       onblur="++blurEvents[2]" onfocusin="++focusInEvents[2]"
     24       onfocusout="++focusOutEvents[2]">
     25 </div>
     26 <pre id="test">
     27 <script class="testbody" type="text/javascript">
     28 
     29 /**
     30 * Test for Bug 1301306.
     31 * This test checks that when moving inside the time input element, e.g. jumping
     32 * through the inner text boxes, does not fire extra focus/blur events.
     33 */
     34 
     35 var inputTypes = ["time", "date", "datetime-local"];
     36 var focusEvents = [0, 0, 0];
     37 var focusInEvents = [0, 0, 0];
     38 var focusOutEvents = [0, 0, 0];
     39 var blurEvents = [0, 0, 0];
     40 
     41 SimpleTest.waitForExplicitFinish();
     42 SimpleTest.waitForFocus(function() {
     43  test();
     44  SimpleTest.finish();
     45 });
     46 
     47 function test() {
     48  for (var i = 0; i < inputTypes.length; i++) {
     49    var input = document.getElementById("input_" + inputTypes[i]);
     50 
     51    input.focus();
     52    is(focusEvents[i], 1, inputTypes[i] + " input element should have dispatched focus event.");
     53    is(focusInEvents[i], 1, inputTypes[i] + " input element should have dispatched focusin event.");
     54    is(focusOutEvents[i], 0, inputTypes[i] + " input element should not have dispatched focusout event.");
     55    is(blurEvents[i], 0, inputTypes[i] + " input element should not have dispatched blur event.");
     56 
     57    // Move around inside the input element's input box.
     58    synthesizeKey("KEY_Tab");
     59    is(focusEvents[i], 1, inputTypes[i] + " input element should not have dispatched focus event.");
     60    is(focusInEvents[i], 1, inputTypes[i] + " input element should not have dispatched focusin event.");
     61    is(focusOutEvents[i], 0, inputTypes[i] + " input element should not have dispatched focusout event.");
     62    is(blurEvents[i], 0, inputTypes[i] + " time input element should not have dispatched blur event.");
     63 
     64    synthesizeKey("KEY_ArrowRight");
     65    is(focusEvents[i], 1, inputTypes[i] + " input element should not have dispatched focus event.");
     66    is(focusInEvents[i], 1, inputTypes[i] + " input element should not have dispatched focusin event.");
     67    is(focusOutEvents[i], 0, inputTypes[i] + " input element should not have dispatched focusout event.");
     68    is(blurEvents[i], 0, inputTypes[i] + " input element should not have dispatched blur event.");
     69 
     70    synthesizeKey("KEY_ArrowLeft");
     71    is(focusEvents[i], 1,inputTypes[i] + " input element should not have dispatched focus event.");
     72    is(focusInEvents[i], 1, inputTypes[i] + " input element should not have dispatched focusin event.");
     73    is(focusOutEvents[i], 0, inputTypes[i] + " input element should not have dispatched focusout event.");
     74    is(blurEvents[i], 0, inputTypes[i] + " input element should not have dispatched blur event.");
     75 
     76    synthesizeKey("KEY_ArrowRight");
     77    is(focusEvents[i], 1, inputTypes[i] + " input element should not have dispatched focus event.");
     78    is(focusInEvents[i], 1, inputTypes[i] + " input element should not have dispatched focusin event.");
     79    is(focusOutEvents[i], 0, inputTypes[i] + " input element should not have dispatched focusout event.");
     80    is(blurEvents[i], 0, inputTypes[i] + " input element should not have dispatched blur event.");
     81 
     82    input.blur();
     83    is(focusEvents[i], 1, inputTypes[i] + " input element should not have dispatched focus event.");
     84    is(focusInEvents[i], 1, inputTypes[i] + " input element should not have dispatched focusin event.");
     85    is(focusOutEvents[i], 1, inputTypes[i] + " input element should have dispatched focusout event.");
     86    is(blurEvents[i], 1, inputTypes[i] + " input element should have dispatched blur event.");
     87  }
     88 }
     89 
     90 </script>
     91 </pre>
     92 </body>
     93 </html>