tor-browser

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

input-seconds-leading-zeroes.html (1809B)


      1 <!DOCTYPE HTML>
      2 <meta charset="utf-8">
      3 <html>
      4 <head>
      5  <title>HTMLInputElement leading zeroes in seconds/millis</title>
      6  <script src="/resources/testharness.js"></script>
      7  <script src="/resources/testharnessreport.js"></script>
      8 </head>
      9 <body>
     10  <h3>input times and datetimes with leading zeroes in seconds/millis</h3>
     11  <!-- This test ensures that seconds and milliseconds are being
     12       output with the appropriate field widths when sanitizing
     13       datetime-locals and times, e.g. that we don't see "12:30:1".
     14       The spec is not specific about how much precision to use
     15       in a sanitized time string, but an invalid string would
     16       fail at .valueAsNumber -->
     17  <hr>
     18  <div id="log"></div>
     19 
     20  <input id="inp">
     21  <script>
     22    var inp=document.getElementById("inp");
     23    var cases = [
     24      ["datetime-local", "2000-01-01T12:30:01",     946729801000],
     25      ["datetime-local", "2000-01-01T12:30:00.5",   946729800500],
     26      ["datetime-local", "2000-01-01T12:30:00.04",  946729800040],
     27      ["datetime-local", "2000-01-01T12:30:00.003", 946729800003],
     28 
     29      ["time", "12:30:01",     45001000],
     30      ["time", "12:30:00.5",   45000500],
     31      ["time", "12:30:00.04",  45000040],
     32      ["time", "12:30:00.003", 45000003],
     33    ];
     34 
     35    for (var i in cases) {
     36      var c = cases[i];
     37      test(function() {
     38        inp.setAttribute("type", c[0]);
     39        inp.value = c[1];
     40        assert_equals(inp.valueAsNumber, c[2]);
     41      },"Expected valueAsNumber=" +c[2] + " from " + c[1]);
     42      if (c[0] == "datetime-local") {
     43        test(function() {
     44          inp.setAttribute("type", c[0]);
     45          inp.value = c[1];
     46          assert_in_array(inp.value, [c[1], c[1].replace("T", " ")]);
     47        },"Expected digits unchanged in round-trip of " + c[1])
     48      }
     49    }
     50  </script>
     51 </body>
     52 </html>