tor-browser

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

test_input_time_sec_millisec_field.html (4781B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1374967
      5 -->
      6 <head>
      7  <title>Test second and millisecond fields in input type=time</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  <meta charset="UTF-8">
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1374967">Mozilla Bug 1374967</a>
     15 <p id="display"></p>
     16 <div id="content">
     17  <input id="input1" type="time">
     18  <input id="input2" type="time" value="12:30:40">
     19  <input id="input3" type="time" value="12:30:40.567">
     20  <input id="input4" type="time" step="1">
     21  <input id="input5" type="time" step="61">
     22  <input id="input6" type="time" step="120">
     23  <input id="input7" type="time" step="0.01">
     24  <input id="input8" type="time" step="0.001">
     25  <input id="input9" type="time" step="1.001">
     26  <input id="input10" type="time" min="01:30:05">
     27  <input id="input11" type="time" min="01:30:05.100">
     28  <input id="dummy">
     29 </div>
     30 <pre id="test">
     31 <script type="application/javascript">
     32 
     33 SimpleTest.waitForExplicitFinish();
     34 SimpleTest.waitForFocus(function() {
     35  test();
     36  SimpleTest.finish();
     37 });
     38 
     39 const NUM_OF_FIELDS_DEFAULT = 3;
     40 const NUM_OF_FIELDS_WITH_SECOND = NUM_OF_FIELDS_DEFAULT + 1;
     41 const NUM_OF_FIELDS_WITH_MILLISEC = NUM_OF_FIELDS_WITH_SECOND + 1;
     42 
     43 function countNumberOfFields(aElement) {
     44  is(aElement.type, "time", "Input element type should be 'time'");
     45 
     46  let inputRect = aElement.getBoundingClientRect();
     47  let firstField_X = 15;
     48  let firstField_Y = inputRect.height / 2;
     49 
     50  // Make sure to start on the first field.
     51  synthesizeMouse(aElement, firstField_X, firstField_Y, {});
     52  is(document.activeElement, aElement, "Input element should be focused");
     53 
     54  let n = 0;
     55  while (document.activeElement == aElement) {
     56    n++;
     57    synthesizeKey("KEY_Tab");
     58  }
     59 
     60  return n;
     61 }
     62 
     63 function test() {
     64  // Normal input time element.
     65  let elem = document.getElementById("input1");
     66  is(countNumberOfFields(elem), NUM_OF_FIELDS_DEFAULT, "Default input time");
     67 
     68  // Dynamically changing the value with second part.
     69  elem.value = "10:20:30";
     70  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_SECOND,
     71     "Input time after changing value with second part");
     72 
     73  // Dynamically changing the step to 1 millisecond.
     74  elem.step = "0.001";
     75  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
     76     "Input time after changing step to 1 millisecond");
     77 
     78  // Input time with value with second part.
     79  elem = document.getElementById("input2");
     80  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_SECOND,
     81     "Input time with value with second part");
     82 
     83  // Input time with value with second and millisecond part.
     84  elem = document.getElementById("input3");
     85  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
     86     "Input time with value with second and millisecond part");
     87 
     88  // Input time with step set as 1 second.
     89  elem = document.getElementById("input4");
     90  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_SECOND,
     91     "Input time with step set as 1 second");
     92 
     93  // Input time with step set as 61 seconds.
     94  elem = document.getElementById("input5");
     95  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_SECOND,
     96     "Input time with step set as 61 seconds");
     97 
     98  // Input time with step set as 2 minutes.
     99  elem = document.getElementById("input6");
    100  is(countNumberOfFields(elem), NUM_OF_FIELDS_DEFAULT,
    101     "Input time with step set as 2 minutes");
    102 
    103  // Input time with step set as 10 milliseconds.
    104  elem = document.getElementById("input7");
    105  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
    106     "Input time with step set as 10 milliseconds");
    107 
    108  // Input time with step set as 100 milliseconds.
    109  elem = document.getElementById("input8");
    110  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
    111     "Input time with step set as 100 milliseconds");
    112 
    113  // Input time with step set as 1001 milliseconds.
    114  elem = document.getElementById("input9");
    115  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
    116     "Input time with step set as 1001 milliseconds");
    117 
    118  // Input time with min with second part and default step (60 seconds). Note
    119  // that step base is min, when there is a min.
    120  elem = document.getElementById("input10");
    121  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_SECOND,
    122     "Input time with min with second part");
    123 
    124  // Input time with min with second and millisecond part and default step (60
    125  // seconds). Note that step base is min, when there is a min.
    126  elem = document.getElementById("input11");
    127  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
    128     "Input time with min with second and millisecond part");
    129 }
    130 
    131 </script>
    132 </pre>
    133 </body>
    134 </html>