summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_input_time_sec_millisec_field.html
blob: 71db4942a98c4f33eb54f4f624648bef0103df2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1374967
-->
<head>
  <title>Test second and millisecond fields in input type=time</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <meta charset="UTF-8">
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1374967">Mozilla Bug 1374967</a>
<p id="display"></p>
<div id="content">
  <input id="input1" type="time">
  <input id="input2" type="time" value="12:30:40">
  <input id="input3" type="time" value="12:30:40.567">
  <input id="input4" type="time" step="1">
  <input id="input5" type="time" step="61">
  <input id="input6" type="time" step="120">
  <input id="input7" type="time" step="0.01">
  <input id="input8" type="time" step="0.001">
  <input id="input9" type="time" step="1.001">
  <input id="input10" type="time" min="01:30:05">
  <input id="input11" type="time" min="01:30:05.100">
  <input id="dummy">
</div>
<pre id="test">
<script type="application/javascript">

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
  test();
  SimpleTest.finish();
});

const NUM_OF_FIELDS_DEFAULT = 3;
const NUM_OF_FIELDS_WITH_SECOND = NUM_OF_FIELDS_DEFAULT + 1;
const NUM_OF_FIELDS_WITH_MILLISEC = NUM_OF_FIELDS_WITH_SECOND + 1;

function countNumberOfFields(aElement) {
  is(aElement.type, "time", "Input element type should be 'time'");

  let inputRect = aElement.getBoundingClientRect();
  let firstField_X = 15;
  let firstField_Y = inputRect.height / 2;

  // Make sure to start on the first field.
  synthesizeMouse(aElement, firstField_X, firstField_Y, {});
  is(document.activeElement, aElement, "Input element should be focused");

  let n = 0;
  while (document.activeElement == aElement) {
    n++;
    synthesizeKey("KEY_Tab");
  }

  return n;
}

function test() {
  // Normal input time element.
  let elem = document.getElementById("input1");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_DEFAULT, "Default input time");

  // Dynamically changing the value with second part.
  elem.value = "10:20:30";
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_SECOND,
     "Input time after changing value with second part");

  // Dynamically changing the step to 1 millisecond.
  elem.step = "0.001";
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
     "Input time after changing step to 1 millisecond");

  // Input time with value with second part.
  elem = document.getElementById("input2");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_SECOND,
     "Input time with value with second part");

  // Input time with value with second and millisecond part.
  elem = document.getElementById("input3");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
     "Input time with value with second and millisecond part");

  // Input time with step set as 1 second.
  elem = document.getElementById("input4");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_SECOND,
     "Input time with step set as 1 second");

  // Input time with step set as 61 seconds.
  elem = document.getElementById("input5");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_SECOND,
     "Input time with step set as 61 seconds");

  // Input time with step set as 2 minutes.
  elem = document.getElementById("input6");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_DEFAULT,
     "Input time with step set as 2 minutes");

  // Input time with step set as 10 milliseconds.
  elem = document.getElementById("input7");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
     "Input time with step set as 10 milliseconds");

  // Input time with step set as 100 milliseconds.
  elem = document.getElementById("input8");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
     "Input time with step set as 100 milliseconds");

  // Input time with step set as 1001 milliseconds.
  elem = document.getElementById("input9");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
     "Input time with step set as 1001 milliseconds");

  // Input time with min with second part and default step (60 seconds). Note
  // that step base is min, when there is a min.
  elem = document.getElementById("input10");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_SECOND,
     "Input time with min with second part");

  // Input time with min with second and millisecond part and default step (60
  // seconds). Note that step base is min, when there is a min.
  elem = document.getElementById("input11");
  is(countNumberOfFields(elem), NUM_OF_FIELDS_WITH_MILLISEC,
     "Input time with min with second and millisecond part");
}

</script>
</pre>
</body>
</html>